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