4151c94d |
1 | // Author: Kirill Gavrilov |
2 | // Copyright (c) 2019 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #ifndef _RWObj_TriangulationReader_HeaderFile |
16 | #define _RWObj_TriangulationReader_HeaderFile |
17 | |
18 | #include <RWObj_Reader.hxx> |
19 | |
20 | #include <Poly_Triangulation.hxx> |
21 | #include <TopoDS_Compound.hxx> |
22 | |
23 | //! Interface to store shape attributes into document. |
24 | class RWObj_IShapeReceiver |
25 | { |
26 | public: |
27 | //! @param theShape shape to register |
28 | //! @param theName shape name |
29 | //! @param theMaterial shape material |
30 | //! @param theIsRootShape indicates that this is a root object (free shape) |
31 | virtual void BindNamedShape (const TopoDS_Shape& theShape, |
32 | const TCollection_AsciiString& theName, |
33 | const RWObj_Material* theMaterial, |
34 | const Standard_Boolean theIsRootShape) = 0; |
35 | }; |
36 | |
37 | //! RWObj_Reader implementation dumping OBJ file into Poly_Triangulation. |
38 | class RWObj_TriangulationReader : public RWObj_Reader |
39 | { |
40 | DEFINE_STANDARD_RTTIEXT(RWObj_TriangulationReader, RWObj_Reader) |
41 | public: |
42 | |
43 | //! Constructor. |
44 | RWObj_TriangulationReader() : myShapeReceiver (NULL), myToCreateShapes (Standard_True) {} |
45 | |
46 | //! Set flag to create shapes. |
47 | void SetCreateShapes (Standard_Boolean theToCreateShapes) { myToCreateShapes = theToCreateShapes; } |
48 | |
49 | //! Set shape receiver callback. |
50 | void SetShapeReceiver (RWObj_IShapeReceiver* theReceiver) { myShapeReceiver = theReceiver; } |
51 | |
52 | //! Create Poly_Triangulation from collected data |
53 | Standard_EXPORT virtual Handle(Poly_Triangulation) GetTriangulation(); |
54 | |
55 | //! Return result shape. |
56 | Standard_EXPORT TopoDS_Shape ResultShape(); |
57 | |
58 | protected: |
59 | |
60 | //! Flush active sub-mesh. |
61 | Standard_EXPORT virtual Standard_Boolean addMesh (const RWObj_SubMesh& theMesh, |
62 | const RWObj_SubMeshReason theReason) Standard_OVERRIDE; |
63 | |
64 | //! Retrieve sub-mesh node position. |
65 | virtual gp_Pnt getNode (Standard_Integer theIndex) const Standard_OVERRIDE |
66 | { |
67 | return myNodes.Value (theIndex - 1); |
68 | } |
69 | |
70 | //! Add new node. |
71 | virtual Standard_Integer addNode (const gp_Pnt& thePnt) Standard_OVERRIDE |
72 | { |
73 | myNodes.Append (thePnt); |
74 | return myNodes.Size(); |
75 | } |
76 | |
77 | //! Ignore normal. |
78 | virtual void setNodeNormal (const Standard_Integer theIndex, |
79 | const Graphic3d_Vec3& theNormal) Standard_OVERRIDE |
80 | { |
81 | myNormals.SetValue (theIndex - 1, theNormal); |
82 | } |
83 | |
84 | //! Ignore texture coordinates. |
85 | virtual void setNodeUV (const Standard_Integer theIndex, |
86 | const Graphic3d_Vec2& theUV) Standard_OVERRIDE |
87 | { |
88 | myNodesUV.SetValue (theIndex - 1, theUV); |
89 | } |
90 | |
91 | //! Add element. |
92 | virtual void addElement (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3, Standard_Integer theN4) Standard_OVERRIDE |
93 | { |
94 | myTriangles.Append (Poly_Triangle (theN1, theN2, theN3)); |
95 | if (theN4 != -1) |
96 | { |
97 | myTriangles.Append (Poly_Triangle (theN1, theN3, theN4)); |
98 | } |
99 | } |
100 | |
101 | protected: |
102 | |
103 | //! Add sub-shape into specified shape |
104 | Standard_EXPORT Standard_Boolean addSubShape (TopoDS_Shape& theParent, |
105 | const TopoDS_Shape& theSubShape, |
106 | const Standard_Boolean theToExpandCompound); |
107 | |
108 | protected: |
109 | |
110 | NCollection_Vector<gp_Pnt> myNodes; //!< nodes of currently filled triangulation |
111 | NCollection_Vector<Graphic3d_Vec3> myNormals; //!< normals of currently filled triangulation |
112 | NCollection_Vector<Graphic3d_Vec2> myNodesUV; //!< UVs of currently filled triangulation |
113 | NCollection_Vector<Poly_Triangle> myTriangles; //!< indexes of currently filled triangulation |
114 | |
115 | RWObj_IShapeReceiver* myShapeReceiver; //!< optional shape receiver |
116 | TopoDS_Compound myResultShape; //!< result shape as Compound of objects |
117 | TopoDS_Compound myLastObjectShape; //!< Compound containing current object groups |
118 | TopoDS_Shape myLastGroupShape; //!< current group shape - either a single Face or Compound of Faces |
119 | TCollection_AsciiString myLastGroupName; //!< current group name |
d9dd0754 |
120 | TCollection_AsciiString myLastFaceMaterial;//!< last face material name |
4151c94d |
121 | Standard_Boolean myToCreateShapes; //!< create a single triangulation |
122 | |
123 | }; |
124 | |
125 | #endif // _RWObj_TriangulationReader_HeaderFile |