Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-02 08:23:23

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   //! Constructor.
0043   RWObj_TriangulationReader()
0044       : myShapeReceiver(NULL),
0045         myToCreateShapes(Standard_True)
0046   {
0047   }
0048 
0049   //! Set flag to create shapes.
0050   void SetCreateShapes(Standard_Boolean theToCreateShapes) { myToCreateShapes = theToCreateShapes; }
0051 
0052   //! Set shape receiver callback.
0053   void SetShapeReceiver(RWObj_IShapeReceiver* theReceiver) { myShapeReceiver = theReceiver; }
0054 
0055   //! Create Poly_Triangulation from collected data
0056   Standard_EXPORT virtual Handle(Poly_Triangulation) GetTriangulation();
0057 
0058   //! Return result shape.
0059   Standard_EXPORT TopoDS_Shape ResultShape();
0060 
0061 protected:
0062   //! Flush active sub-mesh.
0063   Standard_EXPORT virtual Standard_Boolean addMesh(const RWObj_SubMesh&      theMesh,
0064                                                    const RWObj_SubMeshReason theReason)
0065     Standard_OVERRIDE;
0066 
0067   //! Retrieve sub-mesh node position.
0068   virtual gp_Pnt getNode(Standard_Integer theIndex) const Standard_OVERRIDE
0069   {
0070     return myNodes.Value(theIndex - 1);
0071   }
0072 
0073   //! Add new node.
0074   virtual Standard_Integer addNode(const gp_Pnt& thePnt) Standard_OVERRIDE
0075   {
0076     myNodes.Append(thePnt);
0077     return myNodes.Size();
0078   }
0079 
0080   //! Ignore normal.
0081   virtual void setNodeNormal(const Standard_Integer theIndex,
0082                              const Graphic3d_Vec3&  theNormal) Standard_OVERRIDE
0083   {
0084     myNormals.SetValue(theIndex - 1, theNormal);
0085   }
0086 
0087   //! Ignore texture coordinates.
0088   virtual void setNodeUV(const Standard_Integer theIndex,
0089                          const Graphic3d_Vec2&  theUV) Standard_OVERRIDE
0090   {
0091     myNodesUV.SetValue(theIndex - 1, theUV);
0092   }
0093 
0094   //! Add element.
0095   virtual void addElement(Standard_Integer theN1,
0096                           Standard_Integer theN2,
0097                           Standard_Integer theN3,
0098                           Standard_Integer theN4) Standard_OVERRIDE
0099   {
0100     myTriangles.Append(Poly_Triangle(theN1, theN2, theN3));
0101     if (theN4 != -1)
0102     {
0103       myTriangles.Append(Poly_Triangle(theN1, theN3, theN4));
0104     }
0105   }
0106 
0107 protected:
0108   //! Add sub-shape into specified shape
0109   Standard_EXPORT Standard_Boolean addSubShape(TopoDS_Shape&          theParent,
0110                                                const TopoDS_Shape&    theSubShape,
0111                                                const Standard_Boolean theToExpandCompound);
0112 
0113 protected:
0114   NCollection_Vector<gp_Pnt>         myNodes;     //!< nodes   of currently filled triangulation
0115   NCollection_Vector<Graphic3d_Vec3> myNormals;   //!< normals of currently filled triangulation
0116   NCollection_Vector<Graphic3d_Vec2> myNodesUV;   //!< UVs     of currently filled triangulation
0117   NCollection_Vector<Poly_Triangle>  myTriangles; //!< indexes of currently filled triangulation
0118 
0119   RWObj_IShapeReceiver* myShapeReceiver;      //!< optional shape receiver
0120   TopoDS_Compound       myResultShape;        //!< result shape as Compound of objects
0121   TopoDS_Compound       myLastObjectShape;    //!< Compound containing current object groups
0122                                               // clang-format off
0123   TopoDS_Shape            myLastGroupShape;  //!< current group shape - either a single Face or Compound of Faces
0124                                               // clang-format on
0125   TCollection_AsciiString myLastGroupName;    //!< current group name
0126   TCollection_AsciiString myLastFaceMaterial; //!< last face material name
0127   Standard_Boolean        myToCreateShapes;   //!< create a single triangulation
0128 };
0129 
0130 #endif // _RWObj_TriangulationReader_HeaderFile