Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Author: Kirill Gavrilov
0002 // Copyright (c) 2019 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _RWObj_TriangulationReader_HeaderFile
0016 #define _RWObj_TriangulationReader_HeaderFile
0017 
0018 #include <RWObj_Reader.hxx>
0019 
0020 #include <Poly_Triangulation.hxx>
0021 #include <TopoDS_Compound.hxx>
0022 
0023 //! Interface to store shape attributes into document.
0024 class RWObj_IShapeReceiver
0025 {
0026 public:
0027   //! @param theShape       shape to register
0028   //! @param theName        shape name
0029   //! @param theMaterial    shape material
0030   //! @param theIsRootShape indicates that this is a root object (free shape)
0031   virtual void BindNamedShape (const TopoDS_Shape& theShape,
0032                                const TCollection_AsciiString& theName,
0033                                const RWObj_Material* theMaterial,
0034                                const Standard_Boolean theIsRootShape) = 0;
0035 };
0036 
0037 //! RWObj_Reader implementation dumping OBJ file into Poly_Triangulation.
0038 class RWObj_TriangulationReader : public RWObj_Reader
0039 {
0040   DEFINE_STANDARD_RTTIEXT(RWObj_TriangulationReader, RWObj_Reader)
0041 public:
0042 
0043   //! Constructor.
0044   RWObj_TriangulationReader() : myShapeReceiver (NULL), myToCreateShapes (Standard_True) {}
0045 
0046   //! Set flag to create shapes.
0047   void SetCreateShapes (Standard_Boolean theToCreateShapes) { myToCreateShapes = theToCreateShapes; }
0048 
0049   //! Set shape receiver callback.
0050   void SetShapeReceiver (RWObj_IShapeReceiver* theReceiver) { myShapeReceiver = theReceiver; }
0051 
0052   //! Create Poly_Triangulation from collected data
0053   Standard_EXPORT virtual Handle(Poly_Triangulation) GetTriangulation();
0054 
0055   //! Return result shape.
0056   Standard_EXPORT TopoDS_Shape ResultShape();
0057 
0058 protected:
0059 
0060   //! Flush active sub-mesh.
0061   Standard_EXPORT virtual Standard_Boolean addMesh (const RWObj_SubMesh& theMesh,
0062                                                     const RWObj_SubMeshReason theReason) Standard_OVERRIDE;
0063 
0064   //! Retrieve sub-mesh node position.
0065   virtual gp_Pnt getNode (Standard_Integer theIndex) const Standard_OVERRIDE
0066   {
0067     return myNodes.Value (theIndex - 1);
0068   }
0069 
0070   //! Add new node.
0071   virtual Standard_Integer addNode (const gp_Pnt& thePnt) Standard_OVERRIDE
0072   {
0073     myNodes.Append (thePnt);
0074     return myNodes.Size();
0075   }
0076 
0077   //! Ignore normal.
0078   virtual void setNodeNormal (const Standard_Integer theIndex,
0079                               const Graphic3d_Vec3&  theNormal) Standard_OVERRIDE
0080   {
0081     myNormals.SetValue (theIndex - 1, theNormal);
0082   }
0083 
0084   //! Ignore texture coordinates.
0085   virtual void setNodeUV (const Standard_Integer theIndex,
0086                           const Graphic3d_Vec2&  theUV) Standard_OVERRIDE
0087   {
0088     myNodesUV.SetValue (theIndex - 1, theUV);
0089   }
0090 
0091   //! Add element.
0092   virtual void addElement (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3, Standard_Integer theN4) Standard_OVERRIDE
0093   {
0094     myTriangles.Append (Poly_Triangle (theN1, theN2, theN3));
0095     if (theN4 != -1)
0096     {
0097       myTriangles.Append (Poly_Triangle (theN1, theN3, theN4));
0098     }
0099   }
0100 
0101 protected:
0102 
0103   //! Add sub-shape into specified shape
0104   Standard_EXPORT Standard_Boolean addSubShape (TopoDS_Shape& theParent,
0105                                                 const TopoDS_Shape& theSubShape,
0106                                                 const Standard_Boolean theToExpandCompound);
0107 
0108 protected:
0109 
0110   NCollection_Vector<gp_Pnt>         myNodes;     //!< nodes   of currently filled triangulation
0111   NCollection_Vector<Graphic3d_Vec3> myNormals;   //!< normals of currently filled triangulation
0112   NCollection_Vector<Graphic3d_Vec2> myNodesUV;   //!< UVs     of currently filled triangulation
0113   NCollection_Vector<Poly_Triangle>  myTriangles; //!< indexes of currently filled triangulation
0114 
0115   RWObj_IShapeReceiver*   myShapeReceiver;   //!< optional shape receiver
0116   TopoDS_Compound         myResultShape;     //!< result shape as Compound of objects
0117   TopoDS_Compound         myLastObjectShape; //!< Compound containing current object groups
0118   TopoDS_Shape            myLastGroupShape;  //!< current group shape - either a single Face or Compound of Faces
0119   TCollection_AsciiString myLastGroupName;   //!< current group name
0120   TCollection_AsciiString myLastFaceMaterial;//!< last face material name
0121   Standard_Boolean        myToCreateShapes;  //!< create a single triangulation
0122 
0123 };
0124 
0125 #endif // _RWObj_TriangulationReader_HeaderFile