973c2be1 |
1 | // Created on: 1993-09-23 |
2 | // Created by: Jean-Louis FRENKEL |
3 | // Copyright (c) 1993-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
2bd4c032 |
16 | |
17 | #include <StdPrs_ShadedShape.hxx> |
18 | |
19 | #include <Bnd_Box.hxx> |
2bd4c032 |
20 | #include <BRepTools.hxx> |
5ad8c033 |
21 | #include <BRepBndLib.hxx> |
22 | #include <BRep_Builder.hxx> |
23 | #include <BRep_Tool.hxx> |
31c0e219 |
24 | #include <Graphic3d_ArrayOfSegments.hxx> |
2bd4c032 |
25 | #include <Graphic3d_ArrayOfTriangles.hxx> |
26 | #include <Graphic3d_AspectFillArea3d.hxx> |
27 | #include <Graphic3d_Group.hxx> |
28 | #include <gp_Dir.hxx> |
29 | #include <gp_Vec.hxx> |
30 | #include <gp_Pnt.hxx> |
31c0e219 |
31 | #include <NCollection_List.hxx> |
2bd4c032 |
32 | #include <Precision.hxx> |
33 | #include <Prs3d_Drawer.hxx> |
4c513386 |
34 | #include <Prs3d_IsoAspect.hxx> |
31c0e219 |
35 | #include <Prs3d_LineAspect.hxx> |
2bd4c032 |
36 | #include <Prs3d_Presentation.hxx> |
37 | #include <Prs3d_ShadingAspect.hxx> |
38 | #include <Poly_Connect.hxx> |
31c0e219 |
39 | #include <Poly_PolygonOnTriangulation.hxx> |
2bd4c032 |
40 | #include <Poly_Triangulation.hxx> |
5ad8c033 |
41 | #include <StdPrs_ToolTriangulatedShape.hxx> |
2bd4c032 |
42 | #include <StdPrs_WFShape.hxx> |
31c0e219 |
43 | #include <TopExp.hxx> |
fc9b36d6 |
44 | #include <TopExp_Explorer.hxx> |
45 | #include <TopoDS.hxx> |
31c0e219 |
46 | #include <TopoDS_Compound.hxx> |
2bd4c032 |
47 | #include <TopoDS_Face.hxx> |
31c0e219 |
48 | #include <TopoDS_Shape.hxx> |
2bd4c032 |
49 | #include <TColgp_Array1OfDir.hxx> |
50 | #include <TColgp_Array1OfPnt2d.hxx> |
31c0e219 |
51 | #include <TColgp_HArray1OfPnt.hxx> |
a2d5ab2e |
52 | #include <TopTools_ListOfShape.hxx> |
53 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
2bd4c032 |
54 | |
55 | namespace |
56 | { |
31c0e219 |
57 | |
58 | //! Computes wireframe presentation for free wires and vertices |
59 | void wireframeFromShape (const Handle (Prs3d_Presentation)& thePrs, |
60 | const TopoDS_Shape& theShape, |
61 | const Handle (Prs3d_Drawer)& theDrawer) |
62 | { |
53b15292 |
63 | Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All); |
64 | |
65 | if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND) |
31c0e219 |
66 | { |
67 | return; |
68 | } |
69 | |
70 | TopExp_Explorer aShapeIter (theShape, TopAbs_FACE); |
71 | if (!aShapeIter.More()) |
72 | { |
73 | // compound contains no shaded elements at all |
5ad8c033 |
74 | StdPrs_WFShape::Add (thePrs, theShape, theDrawer); |
31c0e219 |
75 | return; |
76 | } |
77 | |
53b15292 |
78 | // We have to create a compound and collect all subshapes not drawn by the shading algo. |
79 | // This includes: |
80 | // - isolated edges |
81 | // - isolated vertices, if aDrawAllVerticesFlag == Standard_False |
82 | // - all shape's vertices, if aDrawAllVerticesFlag == Standard_True |
31c0e219 |
83 | TopoDS_Compound aCompoundWF; |
84 | BRep_Builder aBuilder; |
85 | aBuilder.MakeCompound (aCompoundWF); |
86 | Standard_Boolean hasElement = Standard_False; |
87 | |
88 | // isolated edges |
89 | for (aShapeIter.Init (theShape, TopAbs_EDGE, TopAbs_FACE); aShapeIter.More(); aShapeIter.Next()) |
90 | { |
91 | hasElement = Standard_True; |
92 | aBuilder.Add (aCompoundWF, aShapeIter.Current()); |
93 | } |
53b15292 |
94 | // isolated or all vertices |
95 | aShapeIter.Init (theShape, TopAbs_VERTEX, aDrawAllVerticesFlag ? TopAbs_SHAPE : TopAbs_EDGE); |
96 | for (; aShapeIter.More(); aShapeIter.Next()) |
31c0e219 |
97 | { |
98 | hasElement = Standard_True; |
99 | aBuilder.Add (aCompoundWF, aShapeIter.Current()); |
100 | } |
101 | if (hasElement) |
102 | { |
5ad8c033 |
103 | StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer); |
31c0e219 |
104 | } |
105 | } |
106 | |
4c513386 |
107 | //! Computes special wireframe presentation for faces without triangulation. |
108 | void wireframeNoTriangFacesFromShape (const Handle(Prs3d_Presentation)& thePrs, |
109 | const TopoDS_Shape& theShape, |
110 | const Handle(Prs3d_Drawer)& theDrawer) |
111 | { |
112 | TopoDS_Compound aCompoundWF; |
113 | BRep_Builder aBuilder; |
114 | aBuilder.MakeCompound (aCompoundWF); |
115 | TopLoc_Location aLoc; |
116 | Standard_Boolean hasElement = Standard_False; |
117 | |
118 | for (TopExp_Explorer aShapeIter(theShape, TopAbs_FACE); aShapeIter.More(); aShapeIter.Next()) |
119 | { |
120 | const TopoDS_Face& aFace = TopoDS::Face (aShapeIter.Current()); |
121 | const Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation (aFace, aLoc); |
122 | if (aTriang.IsNull()) |
123 | { |
124 | hasElement = Standard_True; |
125 | aBuilder.Add (aCompoundWF, aFace); |
126 | } |
127 | } |
128 | |
129 | if (hasElement) |
130 | { |
131 | Standard_Integer aPrevUIsoNb = theDrawer->UIsoAspect()->Number(); |
132 | Standard_Integer aPrevVIsoNb = theDrawer->VIsoAspect()->Number(); |
133 | theDrawer->UIsoAspect()->SetNumber (5); |
134 | theDrawer->VIsoAspect()->SetNumber (5); |
135 | |
5ad8c033 |
136 | StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer); |
4c513386 |
137 | |
138 | theDrawer->UIsoAspect()->SetNumber (aPrevUIsoNb); |
139 | theDrawer->VIsoAspect()->SetNumber (aPrevVIsoNb); |
140 | } |
141 | } |
142 | |
31c0e219 |
143 | //! Gets triangulation of every face of shape and fills output array of triangles |
144 | static Handle(Graphic3d_ArrayOfTriangles) fillTriangles (const TopoDS_Shape& theShape, |
145 | const Standard_Boolean theHasTexels, |
146 | const gp_Pnt2d& theUVOrigin, |
147 | const gp_Pnt2d& theUVRepeat, |
148 | const gp_Pnt2d& theUVScale) |
2bd4c032 |
149 | { |
31c0e219 |
150 | Handle(Poly_Triangulation) aT; |
2bd4c032 |
151 | TopLoc_Location aLoc; |
31c0e219 |
152 | gp_Pnt aPoint; |
153 | Standard_Integer aNbTriangles = 0; |
154 | Standard_Integer aNbVertices = 0; |
2bd4c032 |
155 | |
31c0e219 |
156 | // Precision for compare square distances |
3b1817a9 |
157 | const Standard_Real aPreci = Precision::SquareConfusion(); |
2bd4c032 |
158 | |
fc9b36d6 |
159 | TopExp_Explorer aFaceIt(theShape, TopAbs_FACE); |
160 | for (; aFaceIt.More(); aFaceIt.Next()) |
2bd4c032 |
161 | { |
fc9b36d6 |
162 | const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); |
5ad8c033 |
163 | aT = BRep_Tool::Triangulation (aFace, aLoc); |
31c0e219 |
164 | if (!aT.IsNull()) |
2bd4c032 |
165 | { |
31c0e219 |
166 | aNbTriangles += aT->NbTriangles(); |
167 | aNbVertices += aT->NbNodes(); |
2bd4c032 |
168 | } |
2bd4c032 |
169 | } |
31c0e219 |
170 | if (aNbVertices < 3 || aNbTriangles <= 0) |
2bd4c032 |
171 | { |
31c0e219 |
172 | return Handle(Graphic3d_ArrayOfTriangles)(); |
3b1817a9 |
173 | } |
2bd4c032 |
174 | |
31c0e219 |
175 | Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbVertices, 3 * aNbTriangles, |
871fa103 |
176 | Standard_True, Standard_False, theHasTexels); |
31c0e219 |
177 | Standard_Real aUmin (0.0), aUmax (0.0), aVmin (0.0), aVmax (0.0), dUmax (0.0), dVmax (0.0); |
fc9b36d6 |
178 | for (aFaceIt.Init (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) |
2bd4c032 |
179 | { |
fc9b36d6 |
180 | const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); |
5ad8c033 |
181 | aT = BRep_Tool::Triangulation (aFace, aLoc); |
31c0e219 |
182 | if (aT.IsNull()) |
3b1817a9 |
183 | { |
184 | continue; |
185 | } |
186 | const gp_Trsf& aTrsf = aLoc.Transformation(); |
7d9e854b |
187 | |
188 | // Determinant of transform matrix less then 0 means that mirror transform applied. |
189 | Standard_Boolean isMirrored = aTrsf.VectorialPart().Determinant() < 0; |
190 | |
31c0e219 |
191 | Poly_Connect aPolyConnect (aT); |
3b1817a9 |
192 | // Extracts vertices & normals from nodes |
31c0e219 |
193 | const TColgp_Array1OfPnt& aNodes = aT->Nodes(); |
194 | const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes(); |
3b1817a9 |
195 | TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper()); |
5ad8c033 |
196 | StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); |
3b1817a9 |
197 | |
198 | if (theHasTexels) |
2bd4c032 |
199 | { |
3b1817a9 |
200 | BRepTools::UVBounds (aFace, aUmin, aUmax, aVmin, aVmax); |
201 | dUmax = (aUmax - aUmin); |
202 | dVmax = (aVmax - aVmin); |
203 | } |
204 | |
31c0e219 |
205 | const Standard_Integer aDecal = anArray->VertexNumber(); |
3b1817a9 |
206 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) |
207 | { |
31c0e219 |
208 | aPoint = aNodes (aNodeIter); |
3b1817a9 |
209 | if (!aLoc.IsIdentity()) |
2bd4c032 |
210 | { |
31c0e219 |
211 | aPoint.Transform (aTrsf); |
7d9e854b |
212 | |
213 | aNormals (aNodeIter) = aNormals (aNodeIter).Transformed (aTrsf); |
2bd4c032 |
214 | } |
3b1817a9 |
215 | |
216 | if (theHasTexels && aUVNodes.Upper() == aNodes.Upper()) |
2bd4c032 |
217 | { |
3b1817a9 |
218 | const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(), |
219 | (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y()); |
31c0e219 |
220 | anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel); |
2bd4c032 |
221 | } |
3b1817a9 |
222 | else |
2bd4c032 |
223 | { |
31c0e219 |
224 | anArray->AddVertex (aPoint, aNormals (aNodeIter)); |
2bd4c032 |
225 | } |
3b1817a9 |
226 | } |
2bd4c032 |
227 | |
3b1817a9 |
228 | // Fill array with vertex and edge visibility info |
31c0e219 |
229 | const Poly_Array1OfTriangle& aTriangles = aT->Triangles(); |
230 | Standard_Integer anIndex[3]; |
231 | for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter) |
3b1817a9 |
232 | { |
7d9e854b |
233 | if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored) |
31c0e219 |
234 | { |
235 | aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]); |
236 | } |
3b1817a9 |
237 | else |
31c0e219 |
238 | { |
239 | aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]); |
240 | } |
3b1817a9 |
241 | |
31c0e219 |
242 | gp_Pnt aP1 = aNodes (anIndex[0]); |
243 | gp_Pnt aP2 = aNodes (anIndex[1]); |
244 | gp_Pnt aP3 = aNodes (anIndex[2]); |
3b1817a9 |
245 | |
31c0e219 |
246 | gp_Vec aV1 (aP1, aP2); |
247 | if (aV1.SquareMagnitude() <= aPreci) |
3b1817a9 |
248 | { |
249 | continue; |
250 | } |
31c0e219 |
251 | gp_Vec aV2 (aP2, aP3); |
252 | if (aV2.SquareMagnitude() <= aPreci) |
3b1817a9 |
253 | { |
254 | continue; |
255 | } |
31c0e219 |
256 | gp_Vec aV3 (aP3, aP1); |
257 | if (aV3.SquareMagnitude() <= aPreci) |
3b1817a9 |
258 | { |
259 | continue; |
260 | } |
31c0e219 |
261 | aV1.Normalize(); |
262 | aV2.Normalize(); |
263 | aV1.Cross (aV2); |
264 | if (aV1.SquareMagnitude() > aPreci) |
2bd4c032 |
265 | { |
31c0e219 |
266 | anArray->AddEdge (anIndex[0] + aDecal); |
267 | anArray->AddEdge (anIndex[1] + aDecal); |
268 | anArray->AddEdge (anIndex[2] + aDecal); |
2bd4c032 |
269 | } |
270 | } |
2bd4c032 |
271 | } |
31c0e219 |
272 | return anArray; |
273 | } |
274 | |
31c0e219 |
275 | //! Prepare shaded presentation for specified shape |
276 | static Standard_Boolean shadeFromShape (const TopoDS_Shape& theShape, |
277 | const Handle(Prs3d_Presentation)& thePrs, |
278 | const Handle(Prs3d_Drawer)& theDrawer, |
279 | const Standard_Boolean theHasTexels, |
280 | const gp_Pnt2d& theUVOrigin, |
281 | const gp_Pnt2d& theUVRepeat, |
282 | const gp_Pnt2d& theUVScale, |
b6472664 |
283 | const bool theIsClosed) |
31c0e219 |
284 | { |
285 | Handle(Graphic3d_ArrayOfTriangles) aPArray = fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale); |
286 | if (aPArray.IsNull()) |
287 | { |
288 | return Standard_False; |
289 | } |
3b1817a9 |
290 | |
31c0e219 |
291 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs); |
292 | aGroup->SetClosed (theIsClosed); |
6887652a |
293 | aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect()); |
31c0e219 |
294 | aGroup->AddPrimitiveArray (aPArray); |
2bd4c032 |
295 | return Standard_True; |
296 | } |
a2d5ab2e |
297 | |
31c0e219 |
298 | //! Compute boundary presentation for faces of the shape. |
9c86076b |
299 | static Handle(Graphic3d_ArrayOfSegments) fillFaceBoundaries (const TopoDS_Shape& theShape) |
a2d5ab2e |
300 | { |
301 | // collection of all triangulation nodes on edges |
302 | // for computing boundaries presentation |
a2d5ab2e |
303 | Standard_Integer aNodeNumber = 0; |
1b9f5d95 |
304 | Standard_Integer aNbPolylines = 0; |
a2d5ab2e |
305 | |
306 | TopLoc_Location aTrsf; |
307 | |
308 | // explore all boundary edges |
309 | TopTools_IndexedDataMapOfShapeListOfShape anEdgesMap; |
1b9f5d95 |
310 | TopExp::MapShapesAndAncestors (theShape, TopAbs_EDGE, TopAbs_FACE, anEdgesMap); |
311 | for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next()) |
a2d5ab2e |
312 | { |
313 | // reject free edges |
1b9f5d95 |
314 | if (anEdgeIter.Value().Extent() == 0) |
315 | { |
a2d5ab2e |
316 | continue; |
1b9f5d95 |
317 | } |
a2d5ab2e |
318 | |
319 | // take one of the shared edges and get edge triangulation |
1b9f5d95 |
320 | const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First()); |
321 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf); |
322 | if (aTriangulation.IsNull()) |
323 | { |
324 | continue; |
325 | } |
a2d5ab2e |
326 | |
1b9f5d95 |
327 | const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key()); |
328 | Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf); |
329 | if (!anEdgePoly.IsNull() |
330 | && anEdgePoly->Nodes().Length() >= 2) |
331 | { |
332 | aNodeNumber += anEdgePoly->Nodes().Length(); |
333 | ++aNbPolylines; |
334 | } |
335 | } |
336 | if (aNodeNumber == 0) |
337 | { |
9c86076b |
338 | return Handle(Graphic3d_ArrayOfSegments)(); |
1b9f5d95 |
339 | } |
a2d5ab2e |
340 | |
1b9f5d95 |
341 | // create indexed segments array to pack polylines from different edges into single array |
342 | const Standard_Integer aSegmentEdgeNb = (aNodeNumber - aNbPolylines) * 2; |
343 | Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNodeNumber, aSegmentEdgeNb); |
344 | for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next()) |
345 | { |
346 | if (anEdgeIter.Value().Extent() == 0) |
347 | { |
a2d5ab2e |
348 | continue; |
1b9f5d95 |
349 | } |
a2d5ab2e |
350 | |
1b9f5d95 |
351 | const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First()); |
352 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf); |
353 | if (aTriangulation.IsNull()) |
354 | { |
355 | continue; |
356 | } |
a2d5ab2e |
357 | |
1b9f5d95 |
358 | const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key()); |
359 | Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf); |
360 | if (anEdgePoly.IsNull() |
361 | || anEdgePoly->Nodes().Length () < 2) |
362 | { |
a2d5ab2e |
363 | continue; |
1b9f5d95 |
364 | } |
a2d5ab2e |
365 | |
366 | // get edge nodes indexes from face triangulation |
1b9f5d95 |
367 | const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes(); |
368 | const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes(); |
a2d5ab2e |
369 | |
370 | // collect the edge nodes |
1b9f5d95 |
371 | Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1; |
372 | for (Standard_Integer aNodeIdx = anEdgeNodes.Lower(); aNodeIdx <= anEdgeNodes.Upper(); ++aNodeIdx) |
a2d5ab2e |
373 | { |
374 | // node index in face triangulation |
a2d5ab2e |
375 | // get node and apply location transformation to the node |
1b9f5d95 |
376 | const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx); |
a2d5ab2e |
377 | gp_Pnt aTriNode = aTriNodes.Value (aTriIndex); |
1b9f5d95 |
378 | if (!aTrsf.IsIdentity()) |
379 | { |
a2d5ab2e |
380 | aTriNode.Transform (aTrsf); |
1b9f5d95 |
381 | } |
a2d5ab2e |
382 | |
1b9f5d95 |
383 | aSegments->AddVertex (aTriNode); |
384 | if (aNodeIdx != anEdgeNodes.Lower()) |
385 | { |
386 | aSegments->AddEdge ( aSegmentEdge); |
387 | aSegments->AddEdge (++aSegmentEdge); |
388 | } |
a2d5ab2e |
389 | } |
390 | } |
9c86076b |
391 | return aSegments; |
a2d5ab2e |
392 | } |
68858c7d |
393 | |
394 | } // anonymous namespace |
2bd4c032 |
395 | |
5bffb882 |
396 | // ======================================================================= |
397 | // function : ExploreSolids |
398 | // purpose : |
399 | // ======================================================================= |
400 | void StdPrs_ShadedShape::ExploreSolids (const TopoDS_Shape& theShape, |
401 | const BRep_Builder& theBuilder, |
402 | TopoDS_Compound& theClosed, |
403 | TopoDS_Compound& theOpened, |
404 | const Standard_Boolean theIgnore1DSubShape) |
405 | { |
406 | if (theShape.IsNull()) |
407 | { |
408 | return; |
409 | } |
410 | |
411 | switch (theShape.ShapeType()) |
412 | { |
413 | case TopAbs_COMPOUND: |
414 | case TopAbs_COMPSOLID: |
415 | { |
416 | for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next()) |
417 | { |
418 | ExploreSolids (anIter.Value(), theBuilder, theClosed, theOpened, theIgnore1DSubShape); |
419 | } |
420 | return; |
421 | } |
422 | case TopAbs_SOLID: |
423 | { |
424 | for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next()) |
425 | { |
426 | const TopoDS_Shape& aSubShape = anIter.Value(); |
427 | const Standard_Boolean isClosed = aSubShape.ShapeType() == TopAbs_SHELL && |
428 | BRep_Tool::IsClosed (aSubShape) && |
5ad8c033 |
429 | StdPrs_ToolTriangulatedShape::IsTriangulated (aSubShape); |
5bffb882 |
430 | theBuilder.Add (isClosed ? theClosed : theOpened, aSubShape); |
431 | } |
432 | return; |
433 | } |
434 | case TopAbs_SHELL: |
435 | case TopAbs_FACE: |
436 | { |
437 | theBuilder.Add (theOpened, theShape); |
438 | return; |
439 | } |
440 | case TopAbs_WIRE: |
441 | case TopAbs_EDGE: |
442 | case TopAbs_VERTEX: |
443 | { |
444 | if (!theIgnore1DSubShape) |
445 | { |
446 | theBuilder.Add (theOpened, theShape); |
447 | } |
448 | return; |
449 | } |
450 | case TopAbs_SHAPE: |
451 | default: |
452 | return; |
453 | } |
454 | } |
455 | |
2bd4c032 |
456 | // ======================================================================= |
457 | // function : Add |
458 | // purpose : |
459 | // ======================================================================= |
31c0e219 |
460 | void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs, |
461 | const TopoDS_Shape& theShape, |
462 | const Handle(Prs3d_Drawer)& theDrawer, |
5bffb882 |
463 | const StdPrs_Volume theVolume) |
2bd4c032 |
464 | { |
465 | gp_Pnt2d aDummy; |
31c0e219 |
466 | StdPrs_ShadedShape::Add (thePrs, theShape, theDrawer, |
5bffb882 |
467 | Standard_False, aDummy, aDummy, aDummy, theVolume); |
2bd4c032 |
468 | } |
469 | |
470 | // ======================================================================= |
471 | // function : Add |
472 | // purpose : |
473 | // ======================================================================= |
31c0e219 |
474 | void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs, |
2bd4c032 |
475 | const TopoDS_Shape& theShape, |
476 | const Handle (Prs3d_Drawer)& theDrawer, |
477 | const Standard_Boolean theHasTexels, |
478 | const gp_Pnt2d& theUVOrigin, |
479 | const gp_Pnt2d& theUVRepeat, |
31c0e219 |
480 | const gp_Pnt2d& theUVScale, |
5bffb882 |
481 | const StdPrs_Volume theVolume) |
2bd4c032 |
482 | { |
483 | if (theShape.IsNull()) |
484 | { |
485 | return; |
486 | } |
487 | |
31c0e219 |
488 | // add wireframe presentation for isolated edges and vertices |
489 | wireframeFromShape (thePrs, theShape, theDrawer); |
490 | |
4c513386 |
491 | // Use automatic re-triangulation with deflection-check logic only if this feature is enable |
492 | if (theDrawer->IsAutoTriangulation()) |
493 | { |
494 | // Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand |
5ad8c033 |
495 | StdPrs_ToolTriangulatedShape::Tessellate (theShape, theDrawer); |
4c513386 |
496 | } |
497 | |
498 | // add special wireframe presentation for faces without triangulation |
499 | wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer); |
4769a395 |
500 | |
501 | // The shape types listed below need advanced analysis as potentially containing |
502 | // both closed and open parts. Solids are also included, because they might |
503 | // contain non-manifold parts inside (internal open shells) |
31c0e219 |
504 | if ((theShape.ShapeType() == TopAbs_COMPOUND |
4769a395 |
505 | || theShape.ShapeType() == TopAbs_COMPSOLID |
506 | || theShape.ShapeType() == TopAbs_SOLID) |
5bffb882 |
507 | && theVolume == StdPrs_Volume_Autodetection) |
2bd4c032 |
508 | { |
31c0e219 |
509 | // collect two compounds: for opened and closed (solid) sub-shapes |
510 | TopoDS_Compound anOpened, aClosed; |
511 | BRep_Builder aBuilder; |
512 | aBuilder.MakeCompound (aClosed); |
513 | aBuilder.MakeCompound (anOpened); |
5bffb882 |
514 | ExploreSolids (theShape, aBuilder, aClosed, anOpened, Standard_True); |
31c0e219 |
515 | |
516 | TopoDS_Iterator aShapeIter (aClosed); |
517 | if (aShapeIter.More()) |
2bd4c032 |
518 | { |
31c0e219 |
519 | shadeFromShape (aClosed, thePrs, theDrawer, |
b6472664 |
520 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, true); |
2bd4c032 |
521 | } |
31c0e219 |
522 | |
523 | aShapeIter.Initialize (anOpened); |
524 | if (aShapeIter.More()) |
2bd4c032 |
525 | { |
31c0e219 |
526 | shadeFromShape (anOpened, thePrs, theDrawer, |
b6472664 |
527 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, false); |
2bd4c032 |
528 | } |
529 | } |
31c0e219 |
530 | else |
531 | { |
5bffb882 |
532 | // if the shape type is not compound, composolid or solid, use autodetection back-facing filled |
31c0e219 |
533 | shadeFromShape (theShape, thePrs, theDrawer, |
4769a395 |
534 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, |
b6472664 |
535 | theVolume == StdPrs_Volume_Closed); |
31c0e219 |
536 | } |
2bd4c032 |
537 | |
6262338c |
538 | if (theDrawer->FaceBoundaryDraw()) |
a2d5ab2e |
539 | { |
9c86076b |
540 | Handle(Graphic3d_ArrayOfSegments) aBndSegments = fillFaceBoundaries (theShape); |
541 | if (!aBndSegments.IsNull()) |
542 | { |
543 | Handle(Graphic3d_AspectLine3d) aBoundaryAspect = theDrawer->FaceBoundaryAspect()->Aspect(); |
544 | Handle(Graphic3d_Group) aPrsGrp = Prs3d_Root::CurrentGroup (thePrs); |
545 | aPrsGrp->SetGroupPrimitivesAspect (aBoundaryAspect); |
546 | aPrsGrp->AddPrimitiveArray (aBndSegments); |
547 | } |
a2d5ab2e |
548 | } |
549 | } |
9c86076b |
550 | |
551 | // ======================================================================= |
552 | // function : FillTriangles |
553 | // purpose : |
554 | // ======================================================================= |
555 | Handle(Graphic3d_ArrayOfTriangles) StdPrs_ShadedShape::FillTriangles (const TopoDS_Shape& theShape, |
556 | const Standard_Boolean theHasTexels, |
557 | const gp_Pnt2d& theUVOrigin, |
558 | const gp_Pnt2d& theUVRepeat, |
559 | const gp_Pnt2d& theUVScale) |
560 | { |
561 | return fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale); |
562 | } |
563 | |
564 | // ======================================================================= |
565 | // function : FillFaceBoundaries |
566 | // purpose : |
567 | // ======================================================================= |
568 | Handle(Graphic3d_ArrayOfSegments) StdPrs_ShadedShape::FillFaceBoundaries (const TopoDS_Shape& theShape) |
569 | { |
570 | return fillFaceBoundaries (theShape); |
571 | } |
572 | |
573 | // ======================================================================= |
574 | // function : AddWireframeForFreeElements |
575 | // purpose : |
576 | // ======================================================================= |
577 | void StdPrs_ShadedShape::AddWireframeForFreeElements (const Handle (Prs3d_Presentation)& thePrs, |
578 | const TopoDS_Shape& theShape, |
579 | const Handle (Prs3d_Drawer)& theDrawer) |
580 | { |
581 | wireframeFromShape (thePrs, theShape, theDrawer); |
582 | } |
583 | |
584 | // ======================================================================= |
585 | // function : AddWireframeForFacesWithoutTriangles |
586 | // purpose : |
587 | // ======================================================================= |
588 | void StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (const Handle(Prs3d_Presentation)& thePrs, |
589 | const TopoDS_Shape& theShape, |
590 | const Handle(Prs3d_Drawer)& theDrawer) |
591 | { |
592 | wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer); |
593 | } |