Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/RWObj_CafWriter.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 <TCollection_AsciiString.hxx>
0018 #include <NCollection_IndexedDataMap.hxx>
0019 #include <NCollection_Map.hxx>
0020 #include <TDF_Label.hxx>
0021 #include <NCollection_Sequence.hxx>
0022 #include <TopTools_ShapeMapHasher.hxx>
0023 #include <RWMesh_CoordinateSystemConverter.hxx>
0024 #include <XCAFPrs_Style.hxx>
0025 
0026 #include <memory>
0027 
0028 class Message_ProgressRange;
0029 class RWMesh_FaceIterator;
0030 class TDocStd_Document;
0031 
0032 class Message_LazyProgressScope;
0033 class RWObj_ObjWriterContext;
0034 class RWObj_ObjMaterialMap;
0035 
0036 //! OBJ writer context from XCAF document.
0037 class RWObj_CafWriter : public Standard_Transient
0038 {
0039   DEFINE_STANDARD_RTTIEXT(RWObj_CafWriter, Standard_Transient)
0040 public:
0041   //! Main constructor.
0042   //! @param[in] theFile  path to output OBJ file
0043   Standard_EXPORT RWObj_CafWriter(const TCollection_AsciiString& theFile);
0044 
0045   //! Destructor.
0046   Standard_EXPORT ~RWObj_CafWriter() override;
0047 
0048   //! Return transformation from OCCT to OBJ coordinate system.
0049   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
0050 
0051   //! Return transformation from OCCT to OBJ coordinate system.
0052   RWMesh_CoordinateSystemConverter& ChangeCoordinateSystemConverter() { return myCSTrsf; }
0053 
0054   //! Set transformation from OCCT to OBJ coordinate system.
0055   void SetCoordinateSystemConverter(const RWMesh_CoordinateSystemConverter& theConverter)
0056   {
0057     myCSTrsf = theConverter;
0058   }
0059 
0060   //! Return default material definition to be used for nodes with only color defined.
0061   const XCAFPrs_Style& DefaultStyle() const { return myDefaultStyle; }
0062 
0063   //! Set default material definition to be used for nodes with only color defined.
0064   void SetDefaultStyle(const XCAFPrs_Style& theStyle) { myDefaultStyle = theStyle; }
0065 
0066   //! Write OBJ file and associated MTL material file.
0067   //! Triangulation data should be precomputed within shapes!
0068   //! @param[in] theDocument     input document
0069   //! @param[in] theRootLabels   list of root shapes to export
0070   //! @param[in] theLabelFilter  optional filter with document nodes to export,
0071   //!                            with keys defined by XCAFPrs_DocumentExplorer::DefineChildId() and
0072   //!                            filled recursively (leaves and parent assembly nodes at all
0073   //!                            levels); when not NULL, all nodes not included into the map will be
0074   //!                            ignored
0075   //! @param[in] theFileInfo     map with file metadata to put into OBJ header section
0076   //! @param[in] theProgress     optional progress indicator
0077   //! @return FALSE on file writing failure
0078   Standard_EXPORT virtual bool Perform(
0079     const occ::handle<TDocStd_Document>&            theDocument,
0080     const NCollection_Sequence<TDF_Label>&          theRootLabels,
0081     const NCollection_Map<TCollection_AsciiString>* theLabelFilter,
0082     const NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>& theFileInfo,
0083     const Message_ProgressRange& theProgress);
0084 
0085   //! Write OBJ file and associated MTL material file.
0086   //! Triangulation data should be precomputed within shapes!
0087   //! @param[in] theDocument     input document
0088   //! @param[in] theFileInfo     map with file metadata to put into glTF header section
0089   //! @param[in] theProgress     optional progress indicator
0090   //! @return FALSE on file writing failure
0091   Standard_EXPORT virtual bool Perform(
0092     const occ::handle<TDocStd_Document>&                                                theDocument,
0093     const NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>& theFileInfo,
0094     const Message_ProgressRange& theProgress);
0095 
0096 protected:
0097   //! Return TRUE if face mesh should be skipped (e.g. because it is invalid or empty).
0098   Standard_EXPORT virtual bool toSkipFaceMesh(const RWMesh_FaceIterator& theFaceIter);
0099 
0100   //! Collect face triangulation info.
0101   //! @param[in] theFace  face to process
0102   //! @param[in][out] theNbNodes   overall number of triangulation nodes (should be appended)
0103   //! @param[in][out] theNbElems   overall number of triangulation elements (should be appended)
0104   //! @param[in][out] theNbProgressSteps   overall number of progress steps (should be appended)
0105   //! @param[in][out] theToCreateMatFile   flag to create material file or not (should be appended)
0106   Standard_EXPORT virtual void addFaceInfo(const RWMesh_FaceIterator& theFace,
0107                                            int&                       theNbNodes,
0108                                            int&                       theNbElems,
0109                                            double&                    theNbProgressSteps,
0110                                            bool&                      theToCreateMatFile);
0111 
0112   //! Write the shape.
0113   //! @param[in] theWriter   OBJ writer context
0114   //! @param[in] theMatMgr   OBJ material map
0115   //! @param[in] thePSentry  progress sentry
0116   //! @param[in] theLabel    document label to process
0117   //! @param[in] theParentTrsf   parent node transformation
0118   //! @param[in] theParentStyle  parent node style
0119   //! @param[in] theName     node name
0120   Standard_EXPORT virtual bool writeShape(RWObj_ObjWriterContext&        theWriter,
0121                                           RWObj_ObjMaterialMap&          theMatMgr,
0122                                           Message_LazyProgressScope&     thePSentry,
0123                                           const TDF_Label&               theLabel,
0124                                           const TopLoc_Location&         theParentTrsf,
0125                                           const XCAFPrs_Style&           theParentStyle,
0126                                           const TCollection_AsciiString& theName);
0127 
0128   //! Write face triangle vertex positions.
0129   //! @param[in] theWriter   OBJ writer context
0130   //! @param[in] thePSentry  progress sentry
0131   //! @param[in] theFace     current face
0132   //! @return FALSE on writing file error
0133   Standard_EXPORT virtual bool writePositions(RWObj_ObjWriterContext&    theWriter,
0134                                               Message_LazyProgressScope& thePSentry,
0135                                               const RWMesh_FaceIterator& theFace);
0136 
0137   //! Write face triangle vertex normals.
0138   //! @param[in] theWriter   OBJ writer context
0139   //! @param[in] thePSentry  progress sentry
0140   //! @param[in] theFace     current face
0141   //! @return FALSE on writing file error
0142   Standard_EXPORT virtual bool writeNormals(RWObj_ObjWriterContext&    theWriter,
0143                                             Message_LazyProgressScope& thePSentry,
0144                                             const RWMesh_FaceIterator& theFace);
0145 
0146   //! Write face triangle vertex texture coordinates.
0147   //! @param[in] theWriter   OBJ writer context
0148   //! @param[in] thePSentry  progress sentry
0149   //! @param[in] theFace     current face
0150   //! @return FALSE on writing file error
0151   Standard_EXPORT virtual bool writeTextCoords(RWObj_ObjWriterContext&    theWriter,
0152                                                Message_LazyProgressScope& thePSentry,
0153                                                const RWMesh_FaceIterator& theFace);
0154 
0155   //! Write face triangles indices.
0156   //! @param[in] theWriter   OBJ writer context
0157   //! @param[in] thePSentry  progress sentry
0158   //! @param[in] theFace     current face
0159   //! @return FALSE on writing file error
0160   Standard_EXPORT virtual bool writeIndices(RWObj_ObjWriterContext&    theWriter,
0161                                             Message_LazyProgressScope& thePSentry,
0162                                             const RWMesh_FaceIterator& theFace);
0163 
0164 protected:
0165   TCollection_AsciiString myFile; //!< output OBJ file
0166   // clang-format off
0167   RWMesh_CoordinateSystemConverter myCSTrsf;       //!< transformation from OCCT to OBJ coordinate system
0168   XCAFPrs_Style                    myDefaultStyle; //!< default material definition to be used for nodes with only color defined
0169   // clang-format on
0170 };
0171 
0172 #endif // _RWObj_CafWriter_HeaderFiler