Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:43

0001 // Copyright (c) 2015-2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _RWObj_CafWriter_HeaderFiler
0015 #define _RWObj_CafWriter_HeaderFiler
0016 
0017 #include <TColStd_IndexedDataMapOfStringString.hxx>
0018 #include <TColStd_MapOfAsciiString.hxx>
0019 #include <TDF_LabelSequence.hxx>
0020 #include <TopTools_ShapeMapHasher.hxx>
0021 #include <RWMesh_CoordinateSystemConverter.hxx>
0022 #include <XCAFPrs_Style.hxx>
0023 
0024 #include <memory>
0025 
0026 class Message_ProgressRange;
0027 class RWMesh_FaceIterator;
0028 class TDocStd_Document;
0029 
0030 class Message_LazyProgressScope;
0031 class RWObj_ObjWriterContext;
0032 class RWObj_ObjMaterialMap;
0033 
0034 //! OBJ writer context from XCAF document.
0035 class RWObj_CafWriter : public Standard_Transient
0036 {
0037   DEFINE_STANDARD_RTTIEXT(RWObj_CafWriter, Standard_Transient)
0038 public:
0039 
0040   //! Main constructor.
0041   //! @param theFile [in] path to output OBJ file
0042   Standard_EXPORT RWObj_CafWriter (const TCollection_AsciiString& theFile);
0043 
0044   //! Destructor.
0045   Standard_EXPORT virtual ~RWObj_CafWriter();
0046 
0047   //! Return transformation from OCCT to OBJ coordinate system.
0048   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
0049 
0050   //! Return transformation from OCCT to OBJ coordinate system.
0051   RWMesh_CoordinateSystemConverter& ChangeCoordinateSystemConverter() { return myCSTrsf; }
0052 
0053   //! Set transformation from OCCT to OBJ coordinate system.
0054   void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCSTrsf = theConverter; }
0055 
0056   //! Return default material definition to be used for nodes with only color defined.
0057   const XCAFPrs_Style& DefaultStyle() const { return myDefaultStyle; }
0058 
0059   //! Set default material definition to be used for nodes with only color defined.
0060   void SetDefaultStyle (const XCAFPrs_Style& theStyle) { myDefaultStyle = theStyle; }
0061 
0062   //! Write OBJ file and associated MTL material file.
0063   //! Triangulation data should be precomputed within shapes!
0064   //! @param theDocument    [in] input document
0065   //! @param theRootLabels  [in] list of root shapes to export
0066   //! @param theLabelFilter [in] optional filter with document nodes to export,
0067   //!                            with keys defined by XCAFPrs_DocumentExplorer::DefineChildId() and filled recursively
0068   //!                            (leaves and parent assembly nodes at all levels);
0069   //!                            when not NULL, all nodes not included into the map will be ignored
0070   //! @param theFileInfo    [in] map with file metadata to put into OBJ header section
0071   //! @param theProgress    [in] optional progress indicator
0072   //! @return FALSE on file writing failure
0073   Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0074                                         const TDF_LabelSequence& theRootLabels,
0075                                         const TColStd_MapOfAsciiString* theLabelFilter,
0076                                         const TColStd_IndexedDataMapOfStringString& theFileInfo,
0077                                         const Message_ProgressRange& theProgress);
0078 
0079   //! Write OBJ file and associated MTL material file.
0080   //! Triangulation data should be precomputed within shapes!
0081   //! @param theDocument    [in] input document
0082   //! @param theFileInfo    [in] map with file metadata to put into glTF header section
0083   //! @param theProgress    [in] optional progress indicator
0084   //! @return FALSE on file writing failure
0085   Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0086                                         const TColStd_IndexedDataMapOfStringString& theFileInfo,
0087                                         const Message_ProgressRange& theProgress);
0088 
0089 protected:
0090 
0091   //! Return TRUE if face mesh should be skipped (e.g. because it is invalid or empty).
0092   Standard_EXPORT virtual Standard_Boolean toSkipFaceMesh (const RWMesh_FaceIterator& theFaceIter);
0093 
0094   //! Collect face triangulation info.
0095   //! @param theFace [in] face to process
0096   //! @param theNbNodes [in] [out] overall number of triangulation nodes (should be appended)
0097   //! @param theNbElems [in] [out] overall number of triangulation elements (should be appended)
0098   //! @param theNbProgressSteps [in] [out] overall number of progress steps (should be appended)
0099   //! @param theToCreateMatFile [in] [out] flag to create material file or not (should be appended)
0100   Standard_EXPORT virtual void addFaceInfo (const RWMesh_FaceIterator& theFace,
0101                                             Standard_Integer& theNbNodes,
0102                                             Standard_Integer& theNbElems,
0103                                             Standard_Real& theNbProgressSteps,
0104                                             Standard_Boolean& theToCreateMatFile);
0105 
0106   //! Write the shape.
0107   //! @param theWriter  [in] OBJ writer context
0108   //! @param theMatMgr  [in] OBJ material map
0109   //! @param thePSentry [in] progress sentry
0110   //! @param theLabel   [in] document label to process
0111   //! @param theParentTrsf  [in] parent node transformation
0112   //! @param theParentStyle [in] parent node style
0113   //! @param theName    [in] node name
0114   Standard_EXPORT virtual bool writeShape (RWObj_ObjWriterContext&        theWriter,
0115                                            RWObj_ObjMaterialMap&          theMatMgr,
0116                                            Message_LazyProgressScope&     thePSentry,
0117                                            const TDF_Label&               theLabel,
0118                                            const TopLoc_Location&         theParentTrsf,
0119                                            const XCAFPrs_Style&           theParentStyle,
0120                                            const TCollection_AsciiString& theName);
0121 
0122   //! Write face triangle vertex positions.
0123   //! @param theWriter  [in] OBJ writer context
0124   //! @param thePSentry [in] progress sentry
0125   //! @param theFace    [in] current face
0126   //! @return FALSE on writing file error
0127   Standard_EXPORT virtual bool writePositions (RWObj_ObjWriterContext&    theWriter,
0128                                                Message_LazyProgressScope& thePSentry,
0129                                                const RWMesh_FaceIterator& theFace);
0130 
0131   //! Write face triangle vertex normals.
0132   //! @param theWriter  [in] OBJ writer context
0133   //! @param thePSentry [in] progress sentry
0134   //! @param theFace    [in] current face
0135   //! @return FALSE on writing file error
0136   Standard_EXPORT virtual bool writeNormals (RWObj_ObjWriterContext&    theWriter,
0137                                              Message_LazyProgressScope& thePSentry,
0138                                              const RWMesh_FaceIterator& theFace);
0139 
0140   //! Write face triangle vertex texture coordinates.
0141   //! @param theWriter  [in] OBJ writer context
0142   //! @param thePSentry [in] progress sentry
0143   //! @param theFace    [in] current face
0144   //! @return FALSE on writing file error
0145   Standard_EXPORT virtual bool writeTextCoords (RWObj_ObjWriterContext&    theWriter,
0146                                                 Message_LazyProgressScope& thePSentry,
0147                                                 const RWMesh_FaceIterator& theFace);
0148 
0149   //! Write face triangles indices.
0150   //! @param theWriter  [in] OBJ writer context
0151   //! @param thePSentry [in] progress sentry
0152   //! @param theFace    [in] current face
0153   //! @return FALSE on writing file error
0154   Standard_EXPORT virtual bool writeIndices (RWObj_ObjWriterContext&    theWriter,
0155                                              Message_LazyProgressScope& thePSentry,
0156                                              const RWMesh_FaceIterator& theFace);
0157 
0158 
0159 protected:
0160 
0161   TCollection_AsciiString          myFile;         //!< output OBJ file
0162   RWMesh_CoordinateSystemConverter myCSTrsf;       //!< transformation from OCCT to OBJ coordinate system
0163   XCAFPrs_Style                    myDefaultStyle; //!< default material definition to be used for nodes with only color defined
0164 
0165 };
0166 
0167 #endif // _RWObj_CafWriter_HeaderFiler