973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
7fd59977 |
15 | #include <Bnd_Box.hxx> |
42cf5bc1 |
16 | #include <BRep_Tool.hxx> |
7fd59977 |
17 | #include <BRepAdaptor_Curve.hxx> |
42cf5bc1 |
18 | #include <BRepAdaptor_HSurface.hxx> |
7fd59977 |
19 | #include <BRepBndLib.hxx> |
42cf5bc1 |
20 | #include <gp_Pnt.hxx> |
21 | #include <Poly_PolygonOnTriangulation.hxx> |
22 | #include <Precision.hxx> |
7f24b768 |
23 | #include <StdPrs_ShapeTool.hxx> |
42cf5bc1 |
24 | #include <TColgp_HArray1OfVec.hxx> |
25 | #include <TopoDS_Shape.hxx> |
7fd59977 |
26 | #include <Vrml_Coordinate3.hxx> |
27 | #include <Vrml_Material.hxx> |
28 | #include <Vrml_PointSet.hxx> |
42cf5bc1 |
29 | #include <Vrml_Separator.hxx> |
30 | #include <VrmlConverter_DeflectionCurve.hxx> |
31 | #include <VrmlConverter_Drawer.hxx> |
32 | #include <VrmlConverter_IsoAspect.hxx> |
33 | #include <VrmlConverter_LineAspect.hxx> |
34 | #include <VrmlConverter_PointAspect.hxx> |
35 | #include <VrmlConverter_WFDeflectionRestrictedFace.hxx> |
36 | #include <VrmlConverter_WFDeflectionShape.hxx> |
7fd59977 |
37 | |
38 | //========================================================================= |
39 | // function: Add |
40 | // purpose |
41 | //========================================================================= |
42 | void VrmlConverter_WFDeflectionShape::Add( Standard_OStream& anOStream, |
43 | const TopoDS_Shape& aShape, |
44 | const Handle (VrmlConverter_Drawer)& aDrawer) |
45 | { |
46 | |
7f24b768 |
47 | StdPrs_ShapeTool Tool(aShape); |
7fd59977 |
48 | |
49 | Standard_Real theRequestedDeflection; |
50 | if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE |
51 | { |
52 | Bnd_Box box; |
53 | BRepBndLib::AddClose(aShape, box); |
54 | |
55 | Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal; |
56 | box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax ); |
57 | if (!(box.IsOpenXmin() || box.IsOpenXmax() || |
58 | box.IsOpenYmin() || box.IsOpenYmax() || |
59 | box.IsOpenZmin() || box.IsOpenZmax())) |
60 | { |
61 | |
62 | diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin)); |
63 | diagonal = Max(diagonal, Precision::Confusion()); |
64 | theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal; |
65 | } |
66 | else |
67 | { |
68 | diagonal =1000000.; |
69 | theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal; |
70 | } |
71 | |
72 | } |
73 | else |
74 | { |
75 | theRequestedDeflection = aDrawer->MaximalChordialDeviation(); |
76 | } |
f5fa6b33 |
77 | //== Is not used to reach the same wireframe representation with VRML#2.0 |
78 | /*if (aDrawer->UIsoAspect()->Number() != 0 || |
7fd59977 |
79 | aDrawer->VIsoAspect()->Number() != 0 ) { |
80 | |
81 | BRepAdaptor_Surface S; |
82 | Standard_Boolean isoU, isoV; |
83 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
84 | isoU = (aDrawer->UIsoAspect()->Number() != 0); |
85 | isoV = (aDrawer->VIsoAspect()->Number() != 0); |
86 | if (Tool.HasSurface()) { |
87 | if (Tool.IsPlanarFace()) { |
88 | isoU = (isoU && aDrawer->IsoOnPlane()); |
89 | isoV = (isoV && aDrawer->IsoOnPlane()); |
90 | } |
91 | if (isoU || isoV) { |
92 | S.Initialize(Tool.GetFace()); |
93 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
94 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
95 | isoU, isoV, |
96 | theRequestedDeflection, |
97 | aDrawer->UIsoAspect()->Number(), |
98 | aDrawer->VIsoAspect()->Number(), |
99 | aDrawer); |
100 | } |
101 | } |
102 | } |
103 | } |
104 | |
105 | else { |
106 | |
107 | if (aDrawer->UIsoAspect()->Number() != 0) { |
108 | |
109 | BRepAdaptor_Surface S; |
110 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
111 | Standard_Boolean isoU = Standard_True; |
112 | if (Tool.HasSurface()) { |
113 | if (Tool.IsPlanarFace()) isoU = aDrawer->IsoOnPlane(); |
114 | if (isoU) { |
115 | S.Initialize(Tool.GetFace()); |
116 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
117 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
118 | isoU, Standard_False, |
119 | theRequestedDeflection, |
120 | aDrawer->UIsoAspect()->Number(), |
121 | 0, |
122 | aDrawer); |
123 | } |
124 | } |
125 | } |
126 | } |
127 | |
128 | if (aDrawer->VIsoAspect()->Number() != 0) { |
129 | |
130 | BRepAdaptor_Surface S; |
131 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
132 | Standard_Boolean isoV = Standard_True; |
133 | if (Tool.HasSurface()) { |
134 | if (Tool.IsPlanarFace()) isoV = aDrawer->IsoOnPlane(); |
135 | if (isoV) { |
136 | S.Initialize(Tool.GetFace()); |
137 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
138 | VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS, |
139 | Standard_False, isoV, |
140 | theRequestedDeflection, |
141 | 0, |
142 | aDrawer->VIsoAspect()->Number(), |
143 | aDrawer); |
144 | } |
145 | } |
146 | } |
147 | } |
f5fa6b33 |
148 | }*/ |
7fd59977 |
149 | |
150 | //==== |
151 | Standard_Integer qnt=0; |
152 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()) |
153 | { |
154 | qnt++; |
155 | } |
156 | |
f5fa6b33 |
157 | Handle(Poly_PolygonOnTriangulation) aPT; |
158 | Handle(Poly_Triangulation) aT; |
159 | TopLoc_Location aL; |
160 | |
04232180 |
161 | // std::cout << "Quantity of Curves = " << qnt << std::endl; |
7fd59977 |
162 | |
163 | // Wire (without any neighbour) |
164 | |
165 | if (aDrawer->WireDraw()) { |
166 | if (qnt != 0) |
167 | { |
168 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
169 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
170 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
171 | |
172 | aDrawer->SetLineAspect(aDrawer->WireAspect()); |
173 | |
174 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
175 | if (Tool.Neighbours() == 0) { |
176 | if (Tool.HasCurve()) { |
177 | BRepAdaptor_Curve C(Tool.GetCurve()); |
f5fa6b33 |
178 | BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL); |
179 | if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters()) |
180 | VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer); |
181 | else |
182 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
7fd59977 |
183 | } |
184 | } |
185 | } |
186 | aDrawer->SetLineAspect(latmp); |
187 | } |
188 | } |
189 | //end of wire |
190 | |
191 | // Free boundaries; |
192 | if (aDrawer->FreeBoundaryDraw()) { |
193 | if (qnt != 0) |
194 | { |
195 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
196 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
197 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
198 | |
199 | aDrawer->SetLineAspect(aDrawer->FreeBoundaryAspect()); |
200 | |
201 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
202 | if (Tool.Neighbours() == 1) { |
203 | if (Tool.HasCurve()) { |
204 | BRepAdaptor_Curve C(Tool.GetCurve()); |
f5fa6b33 |
205 | BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL); |
206 | if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters()) |
207 | VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer); |
208 | else |
209 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
7fd59977 |
210 | } |
211 | } |
212 | } |
213 | aDrawer->SetLineAspect(latmp); |
214 | } |
215 | } |
216 | // end of Free boundaries |
217 | |
218 | // Unfree boundaries; |
219 | if (aDrawer->UnFreeBoundaryDraw()) { |
220 | if (qnt != 0) |
221 | { |
222 | Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect; |
223 | latmp->SetMaterial(aDrawer->LineAspect()->Material()); |
224 | latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial()); |
225 | |
226 | aDrawer->SetLineAspect(aDrawer->UnFreeBoundaryAspect()); |
227 | |
228 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
229 | if (Tool.Neighbours() >= 2) { |
230 | if (Tool.HasCurve()) { |
231 | BRepAdaptor_Curve C(Tool.GetCurve()); |
f5fa6b33 |
232 | BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL); |
233 | if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters()) |
234 | VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer); |
235 | else |
236 | VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer); |
7fd59977 |
237 | } |
238 | } |
239 | } |
240 | aDrawer->SetLineAspect(latmp); |
241 | } |
242 | } |
243 | // end of Unfree boundaries |
244 | |
245 | // Points |
246 | |
247 | qnt=0; |
248 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
249 | { |
250 | qnt++; |
251 | } |
252 | |
04232180 |
253 | // std::cout << "Quantity of Vertexes = " << qnt << std::endl; |
7fd59977 |
254 | |
255 | if (qnt != 0) |
256 | { |
257 | Handle(TColgp_HArray1OfVec) HAV = new TColgp_HArray1OfVec(1,qnt); |
258 | gp_Vec V; |
259 | gp_Pnt P; |
260 | Standard_Integer i=0; |
261 | |
262 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
263 | { |
264 | i++; |
265 | P = BRep_Tool::Pnt(Tool.GetVertex()); |
266 | V.SetX(P.X()); V.SetY(P.Y()); V.SetZ(P.Z()); |
267 | HAV->SetValue (i,V); |
268 | } |
269 | |
270 | Handle(VrmlConverter_PointAspect) PA = new VrmlConverter_PointAspect; |
271 | PA = aDrawer->PointAspect(); |
272 | |
273 | // Separator P { |
274 | Vrml_Separator SEP; |
275 | SEP.Print(anOStream); |
276 | |
277 | // Material |
278 | if (PA->HasMaterial()){ |
279 | |
280 | Handle(Vrml_Material) MP; |
281 | MP = PA->Material(); |
282 | |
283 | MP->Print(anOStream); |
284 | } |
285 | // Coordinate3 |
286 | Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV); |
287 | C3->Print(anOStream); |
288 | |
289 | // PointSet |
290 | Vrml_PointSet PS; |
291 | PS.Print(anOStream); |
292 | |
293 | // Separator P } |
294 | SEP.Print(anOStream); |
295 | } |
296 | |
297 | } |