Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2022 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 _RWPly_CafWriter_HeaderFiler
0015 #define _RWPly_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 RWPly_PlyWriterContext;
0032 
0033 //! PLY writer context from XCAF document.
0034 class RWPly_CafWriter : public Standard_Transient
0035 {
0036   DEFINE_STANDARD_RTTIEXT(RWPly_CafWriter, Standard_Transient)
0037 public:
0038 
0039   //! Main constructor.
0040   //! @param[in] theFile path to output PLY file
0041   Standard_EXPORT RWPly_CafWriter (const TCollection_AsciiString& theFile);
0042 
0043   //! Destructor.
0044   Standard_EXPORT virtual ~RWPly_CafWriter();
0045 
0046   //! Return transformation from OCCT to PLY coordinate system.
0047   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
0048 
0049   //! Return transformation from OCCT to PLY coordinate system.
0050   RWMesh_CoordinateSystemConverter& ChangeCoordinateSystemConverter() { return myCSTrsf; }
0051 
0052   //! Set transformation from OCCT to PLY coordinate system.
0053   void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCSTrsf = theConverter; }
0054 
0055   //! Return default material definition to be used for nodes with only color defined.
0056   const XCAFPrs_Style& DefaultStyle() const { return myDefaultStyle; }
0057 
0058   //! Set default material definition to be used for nodes with only color defined.
0059   void SetDefaultStyle (const XCAFPrs_Style& theStyle) { myDefaultStyle = theStyle; }
0060 
0061 public:
0062 
0063   //! Return TRUE if vertex position should be stored with double floating point precision; FALSE by default.
0064   bool IsDoublePrecision() const { return myIsDoublePrec; }
0065 
0066   //! Set if vertex position should be stored with double floating point precision.
0067   void SetDoublePrecision (bool theDoublePrec) { myIsDoublePrec = theDoublePrec; }
0068 
0069   //! Return TRUE if normals should be written; TRUE by default.
0070   bool HasNormals() const { return myHasNormals; }
0071 
0072   //! Set if normals are defined.
0073   void SetNormals (const bool theHasNormals) { myHasNormals = theHasNormals; }
0074 
0075   //! Return TRUE if UV / texture coordinates should be written; FALSE by default.
0076   bool HasTexCoords() const { return myHasTexCoords; }
0077 
0078   //! Set if UV / texture coordinates should be written.
0079   void SetTexCoords (const bool theHasTexCoords) { myHasTexCoords = theHasTexCoords; }
0080 
0081   //! Return TRUE if point colors should be written; TRUE by default.
0082   bool HasColors() const { return myHasColors; }
0083 
0084   //! Set if point colors should be written.
0085   void SetColors (bool theToWrite) { myHasColors = theToWrite; }
0086 
0087   //! Return TRUE if part Id should be written as element attribute; TRUE by default.
0088   bool HasPartId() const { return myHasPartId; }
0089 
0090   //! Set if part Id should be written as element attribute; FALSE by default.
0091   //! Cannot be combined with HasFaceId().
0092   void SetPartId (bool theSurfId)
0093   {
0094     myHasPartId = theSurfId;
0095     myHasFaceId = myHasFaceId && !myHasPartId;
0096   }
0097 
0098   //! Return TRUE if face Id should be written as element attribute; FALSE by default.
0099   bool HasFaceId() const { return myHasFaceId; }
0100 
0101   //! Set if face Id should be written as element attribute; FALSE by default.
0102   //! Cannot be combined with HasPartId().
0103   void SetFaceId (bool theSurfId)
0104   {
0105     myHasFaceId = theSurfId;
0106     myHasPartId = myHasPartId && !myHasFaceId;
0107   }
0108 
0109 public:
0110 
0111   //! Write PLY file and associated MTL material file.
0112   //! Triangulation data should be precomputed within shapes!
0113   //! @param[in] theDocument    input document
0114   //! @param[in] theRootLabels  list of root shapes to export
0115   //! @param[in] theLabelFilter optional filter with document nodes to export,
0116   //!                           with keys defined by XCAFPrs_DocumentExplorer::DefineChildId() and filled recursively
0117   //!                           (leaves and parent assembly nodes at all levels);
0118   //!                           when not NULL, all nodes not included into the map will be ignored
0119   //! @param[in] theFileInfo    map with file metadata to put into PLY header section
0120   //! @param[in] theProgress    optional progress indicator
0121   //! @return FALSE on file writing failure
0122   Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0123                                         const TDF_LabelSequence& theRootLabels,
0124                                         const TColStd_MapOfAsciiString* theLabelFilter,
0125                                         const TColStd_IndexedDataMapOfStringString& theFileInfo,
0126                                         const Message_ProgressRange& theProgress);
0127 
0128   //! Write PLY file and associated MTL material file.
0129   //! Triangulation data should be precomputed within shapes!
0130   //! @param[in] theDocument input document
0131   //! @param[in] theFileInfo map with file metadata to put into PLY header section
0132   //! @param[in] theProgress optional progress indicator
0133   //! @return FALSE on file writing failure
0134   Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0135                                         const TColStd_IndexedDataMapOfStringString& theFileInfo,
0136                                         const Message_ProgressRange& theProgress);
0137 
0138 protected:
0139 
0140   //! Return TRUE if face mesh should be skipped (e.g. because it is invalid or empty).
0141   Standard_EXPORT virtual Standard_Boolean toSkipFaceMesh (const RWMesh_FaceIterator& theFaceIter);
0142 
0143   //! Collect face triangulation info.
0144   //! @param[in] theFace face to process
0145   //! @param[in,out] theNbNodes overall number of triangulation nodes (should be appended)
0146   //! @param[in,out] theNbElems overall number of triangulation elements (should be appended)
0147   Standard_EXPORT virtual void addFaceInfo (const RWMesh_FaceIterator& theFace,
0148                                             Standard_Integer& theNbNodes,
0149                                             Standard_Integer& theNbElems);
0150 
0151   //! Write the shape.
0152   //! @param[in] theWriter      PLY writer context
0153   //! @param[in] thePSentry     progress sentry
0154   //! @param[in] theWriteStep   export step, 0 for vertex attributes, 1 for elements
0155   //! @param[in] theLabel       document label to process
0156   //! @param[in] theParentTrsf  parent node transformation
0157   //! @param[in] theParentStyle parent node style
0158   Standard_EXPORT virtual bool writeShape (RWPly_PlyWriterContext& theWriter,
0159                                            Message_LazyProgressScope& thePSentry,
0160                                            const Standard_Integer theWriteStep,
0161                                            const TDF_Label& theLabel,
0162                                            const TopLoc_Location& theParentTrsf,
0163                                            const XCAFPrs_Style& theParentStyle);
0164 
0165   //! Write face triangle vertices and attributes.
0166   //! @param[in] theWriter  PLY writer context
0167   //! @param[in] thePSentry progress sentry
0168   //! @param[in] theFace    current face
0169   //! @return FALSE on writing file error
0170   Standard_EXPORT virtual bool writeNodes (RWPly_PlyWriterContext& theWriter,
0171                                            Message_LazyProgressScope& thePSentry,
0172                                            const RWMesh_FaceIterator& theFace);
0173 
0174   //! Write face triangles indices.
0175   //! @param[in] theWriter  PLY writer context
0176   //! @param[in] thePSentry progress sentry
0177   //! @param[in] theFace    current face
0178   //! @return FALSE on writing file error
0179   Standard_EXPORT virtual bool writeIndices (RWPly_PlyWriterContext& theWriter,
0180                                              Message_LazyProgressScope& thePSentry,
0181                                              const RWMesh_FaceIterator& theFace);
0182 
0183 
0184 protected:
0185 
0186   TCollection_AsciiString          myFile;         //!< output PLY file
0187   RWMesh_CoordinateSystemConverter myCSTrsf;       //!< transformation from OCCT to PLY coordinate system
0188   XCAFPrs_Style                    myDefaultStyle; //!< default material definition to be used for nodes with only color defined
0189   Standard_Boolean                 myIsDoublePrec;
0190   Standard_Boolean                 myHasNormals;
0191   Standard_Boolean                 myHasColors;
0192   Standard_Boolean                 myHasTexCoords;
0193   Standard_Boolean                 myHasPartId;
0194   Standard_Boolean                 myHasFaceId;
0195 
0196 };
0197 
0198 #endif // _RWPly_CafWriter_HeaderFiler