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