b311480e |
1 | // Created on: 2007-08-04 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #ifndef VrmlData_ShapeConvert_HeaderFile |
17 | #define VrmlData_ShapeConvert_HeaderFile |
18 | |
19 | #include <VrmlData_Geometry.hxx> |
20 | #include <VrmlData_Appearance.hxx> |
a3506de7 |
21 | #include <VrmlData_Group.hxx> |
7fd59977 |
22 | #include <NCollection_List.hxx> |
a3506de7 |
23 | #include <NCollection_DataMap.hxx> |
7fd59977 |
24 | #include <TopoDS_Shape.hxx> |
25 | |
26 | class VrmlData_Scene; |
c04c30b3 |
27 | class VrmlData_Coordinate; |
7fd59977 |
28 | class TopoDS_Face; |
c04c30b3 |
29 | class Poly_Polygon3D; |
30 | class Poly_Triangulation; |
a4815d55 |
31 | class XCAFPrs_Style; |
a3506de7 |
32 | class TDocStd_Document; |
33 | class TDF_Label; |
34 | |
c04c30b3 |
35 | |
7fd59977 |
36 | /** |
37 | * Algorithm converting one shape or a set of shapes to VrmlData_Scene. |
38 | */ |
39 | |
40 | class VrmlData_ShapeConvert |
41 | { |
42 | public: |
43 | |
44 | typedef struct { |
45 | TCollection_AsciiString Name; |
46 | TopoDS_Shape Shape; |
47 | Handle(VrmlData_Node) Node; |
48 | } ShapeData; |
49 | |
50 | // ---------- PUBLIC METHODS ---------- |
51 | |
52 | |
53 | /** |
54 | * Constructor. |
55 | * @param theScene |
56 | * Scene receiving all Vrml data. |
57 | * @param theScale |
58 | * Scale factor, considering that VRML standard specifies coordinates in |
59 | * meters. So if your data are in mm, you should provide theScale=0.001 |
60 | */ |
61 | inline VrmlData_ShapeConvert (VrmlData_Scene& theScene, |
62 | const Standard_Real theScale = 1.) |
63 | : myScene (theScene), |
d533dafb |
64 | myScale (theScale), |
65 | myDeflection(0.0), |
66 | myDeflAngle(0.0) |
7fd59977 |
67 | {} |
68 | |
69 | /** |
70 | * Add one shape to the internal list, may be called several times with |
71 | * different shapes. |
72 | */ |
73 | Standard_EXPORT void AddShape (const TopoDS_Shape& theShape, |
74 | const char * theName = 0L); |
75 | |
76 | /** |
77 | * Convert all accumulated shapes and store them in myScene. |
78 | * The internal data structures are cleared in the end of convertion. |
79 | * @param theExtractFaces |
80 | * If True, converter extracst faces from the shapes. |
81 | * @param theExtractEdges |
82 | * If True, converter extracts edges from the shapes. |
83 | * @param theDeflection |
84 | * Deflection for tessellation of geometrical lines/surfaces. Existing mesh |
85 | * is used if its deflection is smaller than the one given by this |
86 | * parameter. |
87 | * @param theDeflAngle |
88 | * Angular deflection for tessellation of geometrical lines. |
89 | */ |
90 | Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces, |
91 | const Standard_Boolean theExtractEdges, |
92 | const Standard_Real theDeflection = 0.01, |
c6541a0c |
93 | const Standard_Real theDeflAngle = 20.*M_PI/180.); |
7fd59977 |
94 | //this value of theDeflAngle is used by default |
95 | //for tesselation while shading (Drawer->HLRAngle()) |
a3506de7 |
96 | |
97 | /** |
98 | * Add all shapes start from given document with colors and names to the internal structure |
99 | */ |
100 | Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc); |
101 | |
7fd59977 |
102 | protected: |
103 | // ---------- PROTECTED METHODS ---------- |
104 | |
857ffd5e |
105 | Handle(VrmlData_Geometry) triToIndexedFaceSet |
106 | (const Handle(Poly_Triangulation)&, |
7fd59977 |
107 | const TopoDS_Face&, |
857ffd5e |
108 | const Handle(VrmlData_Coordinate)&); |
7fd59977 |
109 | |
857ffd5e |
110 | Handle(VrmlData_Geometry) polToIndexedLineSet |
111 | (const Handle(Poly_Polygon3D)&); |
7fd59977 |
112 | |
857ffd5e |
113 | Handle(VrmlData_Appearance) defaultMaterialFace () const; |
7fd59977 |
114 | |
857ffd5e |
115 | Handle(VrmlData_Appearance) defaultMaterialEdge () const; |
7fd59977 |
116 | |
a3506de7 |
117 | Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape& theShape, |
118 | const TopAbs_ShapeEnum theShapeType, |
119 | TopLoc_Location& theLoc); |
120 | |
121 | void addAssembly (const Handle(VrmlData_Group)& theParent, |
122 | const TDF_Label& theLabel, |
123 | const Handle(TDocStd_Document)& theDoc, |
124 | const Standard_Boolean theNeedCreateGroup); |
125 | |
126 | void addInstance (const Handle(VrmlData_Group)& theParent, |
127 | const TDF_Label& theLabel, |
128 | const Handle(TDocStd_Document)& theDoc); |
129 | |
130 | void addShape (const Handle(VrmlData_Group)& theParent, |
131 | const TDF_Label& theLabel, |
132 | const Handle(TDocStd_Document)& theDoc); |
133 | |
a4815d55 |
134 | Handle(VrmlData_Appearance) makeMaterialFromStyle (const XCAFPrs_Style& theStyle, |
135 | const TDF_Label& theAttribLab) const; |
a3506de7 |
136 | |
7fd59977 |
137 | private: |
138 | // ---------- PRIVATE FIELDS ---------- |
139 | |
140 | VrmlData_Scene& myScene; |
141 | Standard_Real myScale; |
142 | NCollection_List <ShapeData> myShapes; |
a3506de7 |
143 | |
144 | Standard_Real myDeflection; |
145 | Standard_Real myDeflAngle; |
146 | NCollection_DataMap <TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap; |
147 | |
d390b166 |
148 | // ---------- PRIVATE METHODS ---------- |
149 | void operator= (const VrmlData_ShapeConvert&); |
7fd59977 |
150 | }; |
151 | |
152 | #endif |