Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/RWPly_PlyWriterContext.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) 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_PlyWriterContext_HeaderFiler
0015 #define _RWPly_PlyWriterContext_HeaderFiler
0016 
0017 #include <NCollection_Vec2.hxx>
0018 
0019 #include <Standard_TypeDef.hxx>
0020 
0021 #include <NCollection_Vec3.hxx>
0022 
0023 #include <NCollection_Vec4.hxx>
0024 
0025 #include <NCollection_Mat4.hxx>
0026 #include <gp_Pnt.hxx>
0027 #include <TCollection_AsciiString.hxx>
0028 #include <NCollection_IndexedDataMap.hxx>
0029 
0030 #include <memory>
0031 
0032 //! Auxiliary low-level tool writing PLY file.
0033 class RWPly_PlyWriterContext
0034 {
0035 public:
0036   //! Empty constructor.
0037   Standard_EXPORT RWPly_PlyWriterContext();
0038 
0039   //! Destructor, will emit error message if file was not closed.
0040   Standard_EXPORT ~RWPly_PlyWriterContext();
0041 
0042 public: //! @name vertex attributes parameters
0043   //! Return TRUE if vertex position should be stored with double floating point precision; FALSE by
0044   //! default.
0045   bool IsDoublePrecision() const { return myIsDoublePrec; }
0046 
0047   //! Set if vertex position should be stored with double floating point precision.
0048   void SetDoublePrecision(bool theDoublePrec) { myIsDoublePrec = theDoublePrec; }
0049 
0050   //! Return TRUE if normals should be written as vertex attribute; FALSE by default.
0051   bool HasNormals() const { return myHasNormals; }
0052 
0053   //! Set if normals should be written.
0054   void SetNormals(const bool theHasNormals) { myHasNormals = theHasNormals; }
0055 
0056   //! Return TRUE if UV / texture coordinates should be written as vertex attribute; FALSE by
0057   //! default.
0058   bool HasTexCoords() const { return myHasTexCoords; }
0059 
0060   //! Set if UV / texture coordinates should be written.
0061   void SetTexCoords(const bool theHasTexCoords) { myHasTexCoords = theHasTexCoords; }
0062 
0063   //! Return TRUE if point colors should be written as vertex attribute; FALSE by default.
0064   bool HasColors() const { return myHasColors; }
0065 
0066   //! Set if point colors should be written.
0067   void SetColors(bool theToWrite) { myHasColors = theToWrite; }
0068 
0069 public: //! @name element attributes parameters
0070   //! Return TRUE if surface Id should be written as element attribute; FALSE by default.
0071   bool HasSurfaceId() const { return myHasSurfId; }
0072 
0073   //! Set if surface Id should be written as element attribute; FALSE by default.
0074   void SetSurfaceId(bool theSurfId) { myHasSurfId = theSurfId; }
0075 
0076 public: //! @name writing into file
0077   //! Return TRUE if file has been opened.
0078   bool IsOpened() const { return myStream.get() != nullptr; }
0079 
0080   //! Open file for writing.
0081   Standard_EXPORT bool Open(
0082     const TCollection_AsciiString&       theName,
0083     const std::shared_ptr<std::ostream>& theStream = std::shared_ptr<std::ostream>());
0084 
0085   //! Write the header.
0086   //! @param[in] theNbNodes number of vertex nodes
0087   //! @param[in] theNbElems number of mesh elements
0088   //! @param[in] theFileInfo optional comments
0089   Standard_EXPORT bool WriteHeader(
0090     const int theNbNodes,
0091     const int theNbElems,
0092     const NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>&
0093       theFileInfo);
0094 
0095   //! Write single point with all attributes.
0096   //! @param[in] thePoint 3D point coordinates
0097   //! @param[in] theNorm  surface normal direction at the point
0098   //! @param[in] theUV    surface/texture UV coordinates
0099   //! @param[in] theColor RGB color values
0100   Standard_EXPORT bool WriteVertex(const gp_Pnt&                    thePoint,
0101                                    const NCollection_Vec3<float>&   theNorm,
0102                                    const NCollection_Vec2<float>&   theUV,
0103                                    const NCollection_Vec4<uint8_t>& theColor);
0104 
0105   //! Return number of written vertices.
0106   int NbWrittenVertices() const { return myNbVerts; }
0107 
0108   //! Return vertex offset to be applied to element indices; 0 by default.
0109   int VertexOffset() const { return myVertOffset; }
0110 
0111   //! Set vertex offset to be applied to element indices.
0112   void SetVertexOffset(int theOffset) { myVertOffset = theOffset; }
0113 
0114   //! Return surface id to write with element; 0 by default.
0115   int SurfaceId() const { return mySurfId; }
0116 
0117   //! Set surface id to write with element.
0118   void SetSurfaceId(int theSurfId) { mySurfId = theSurfId; }
0119 
0120   //! Writing a triangle.
0121   Standard_EXPORT bool WriteTriangle(const NCollection_Vec3<int>& theTri);
0122 
0123   //! Writing a quad.
0124   Standard_EXPORT bool WriteQuad(const NCollection_Vec4<int>& theQuad);
0125 
0126   //! Return number of written elements.
0127   int NbWrittenElements() const { return myNbElems; }
0128 
0129   //! Correctly close the file.
0130   //! @return FALSE in case of writing error
0131   Standard_EXPORT bool Close(bool theIsAborted = false);
0132 
0133 private:
0134   std::shared_ptr<std::ostream> myStream;
0135   TCollection_AsciiString       myName;
0136   int                           myNbHeaderVerts;
0137   int                           myNbHeaderElems;
0138   int                           myNbVerts;
0139   int                           myNbElems;
0140   int                           mySurfId;
0141   int                           myVertOffset;
0142   bool                          myIsDoublePrec;
0143   bool                          myHasNormals;
0144   bool                          myHasColors;
0145   bool                          myHasTexCoords;
0146   bool                          myHasSurfId;
0147 };
0148 
0149 #endif // _RWPly_PlyWriterContext_HeaderFiler