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> |
20 | #include <BRep_Builder.hxx> |
21 | #include <BRepBndLib.hxx> |
22 | #include <BRepMesh_DiscretFactory.hxx> |
23 | #include <BRepMesh_DiscretRoot.hxx> |
24 | #include <BRepTools.hxx> |
31c0e219 |
25 | #include <Graphic3d_ArrayOfSegments.hxx> |
2bd4c032 |
26 | #include <Graphic3d_ArrayOfTriangles.hxx> |
27 | #include <Graphic3d_AspectFillArea3d.hxx> |
28 | #include <Graphic3d_Group.hxx> |
29 | #include <gp_Dir.hxx> |
30 | #include <gp_Vec.hxx> |
31 | #include <gp_Pnt.hxx> |
31c0e219 |
32 | #include <NCollection_List.hxx> |
2bd4c032 |
33 | #include <Precision.hxx> |
9dba391d |
34 | #include <Prs3d.hxx> |
2bd4c032 |
35 | #include <Prs3d_Drawer.hxx> |
31c0e219 |
36 | #include <Prs3d_LineAspect.hxx> |
2bd4c032 |
37 | #include <Prs3d_Presentation.hxx> |
38 | #include <Prs3d_ShadingAspect.hxx> |
39 | #include <Poly_Connect.hxx> |
31c0e219 |
40 | #include <Poly_PolygonOnTriangulation.hxx> |
2bd4c032 |
41 | #include <Poly_Triangulation.hxx> |
42 | #include <StdPrs_ToolShadedShape.hxx> |
43 | #include <StdPrs_WFShape.hxx> |
31c0e219 |
44 | #include <TopExp.hxx> |
fc9b36d6 |
45 | #include <TopExp_Explorer.hxx> |
46 | #include <TopoDS.hxx> |
31c0e219 |
47 | #include <TopoDS_Compound.hxx> |
2bd4c032 |
48 | #include <TopoDS_Face.hxx> |
31c0e219 |
49 | #include <TopoDS_Shape.hxx> |
2bd4c032 |
50 | #include <TColgp_Array1OfDir.hxx> |
51 | #include <TColgp_Array1OfPnt2d.hxx> |
31c0e219 |
52 | #include <TColgp_HArray1OfPnt.hxx> |
a2d5ab2e |
53 | #include <TopTools_ListOfShape.hxx> |
54 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
2bd4c032 |
55 | |
56 | namespace |
57 | { |
31c0e219 |
58 | |
59 | //! Computes wireframe presentation for free wires and vertices |
60 | void wireframeFromShape (const Handle (Prs3d_Presentation)& thePrs, |
61 | const TopoDS_Shape& theShape, |
62 | const Handle (Prs3d_Drawer)& theDrawer) |
63 | { |
53b15292 |
64 | Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All); |
65 | |
66 | if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND) |
31c0e219 |
67 | { |
68 | return; |
69 | } |
70 | |
71 | TopExp_Explorer aShapeIter (theShape, TopAbs_FACE); |
72 | if (!aShapeIter.More()) |
73 | { |
74 | // compound contains no shaded elements at all |
75 | StdPrs_WFShape::Add (thePrs, theShape, theDrawer); |
76 | return; |
77 | } |
78 | |
53b15292 |
79 | // We have to create a compound and collect all subshapes not drawn by the shading algo. |
80 | // This includes: |
81 | // - isolated edges |
82 | // - isolated vertices, if aDrawAllVerticesFlag == Standard_False |
83 | // - all shape's vertices, if aDrawAllVerticesFlag == Standard_True |
31c0e219 |
84 | TopoDS_Compound aCompoundWF; |
85 | BRep_Builder aBuilder; |
86 | aBuilder.MakeCompound (aCompoundWF); |
87 | Standard_Boolean hasElement = Standard_False; |
88 | |
89 | // isolated edges |
90 | for (aShapeIter.Init (theShape, TopAbs_EDGE, TopAbs_FACE); aShapeIter.More(); aShapeIter.Next()) |
91 | { |
92 | hasElement = Standard_True; |
93 | aBuilder.Add (aCompoundWF, aShapeIter.Current()); |
94 | } |
53b15292 |
95 | // isolated or all vertices |
96 | aShapeIter.Init (theShape, TopAbs_VERTEX, aDrawAllVerticesFlag ? TopAbs_SHAPE : TopAbs_EDGE); |
97 | for (; aShapeIter.More(); aShapeIter.Next()) |
31c0e219 |
98 | { |
99 | hasElement = Standard_True; |
100 | aBuilder.Add (aCompoundWF, aShapeIter.Current()); |
101 | } |
102 | if (hasElement) |
103 | { |
104 | StdPrs_WFShape::Add (thePrs, aCompoundWF, theDrawer); |
105 | } |
106 | } |
107 | |
31c0e219 |
108 | //! Gets triangulation of every face of shape and fills output array of triangles |
109 | static Handle(Graphic3d_ArrayOfTriangles) fillTriangles (const TopoDS_Shape& theShape, |
110 | const Standard_Boolean theHasTexels, |
111 | const gp_Pnt2d& theUVOrigin, |
112 | const gp_Pnt2d& theUVRepeat, |
113 | const gp_Pnt2d& theUVScale) |
2bd4c032 |
114 | { |
31c0e219 |
115 | Handle(Poly_Triangulation) aT; |
2bd4c032 |
116 | TopLoc_Location aLoc; |
31c0e219 |
117 | gp_Pnt aPoint; |
118 | Standard_Integer aNbTriangles = 0; |
119 | Standard_Integer aNbVertices = 0; |
2bd4c032 |
120 | |
31c0e219 |
121 | // Precision for compare square distances |
3b1817a9 |
122 | const Standard_Real aPreci = Precision::SquareConfusion(); |
2bd4c032 |
123 | |
fc9b36d6 |
124 | TopExp_Explorer aFaceIt(theShape, TopAbs_FACE); |
125 | for (; aFaceIt.More(); aFaceIt.Next()) |
2bd4c032 |
126 | { |
fc9b36d6 |
127 | const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); |
128 | aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc); |
31c0e219 |
129 | if (!aT.IsNull()) |
2bd4c032 |
130 | { |
31c0e219 |
131 | aNbTriangles += aT->NbTriangles(); |
132 | aNbVertices += aT->NbNodes(); |
2bd4c032 |
133 | } |
2bd4c032 |
134 | } |
31c0e219 |
135 | if (aNbVertices < 3 || aNbTriangles <= 0) |
2bd4c032 |
136 | { |
31c0e219 |
137 | return Handle(Graphic3d_ArrayOfTriangles)(); |
3b1817a9 |
138 | } |
2bd4c032 |
139 | |
31c0e219 |
140 | Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbVertices, 3 * aNbTriangles, |
871fa103 |
141 | Standard_True, Standard_False, theHasTexels); |
31c0e219 |
142 | Standard_Real aUmin (0.0), aUmax (0.0), aVmin (0.0), aVmax (0.0), dUmax (0.0), dVmax (0.0); |
fc9b36d6 |
143 | for (aFaceIt.Init (theShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) |
2bd4c032 |
144 | { |
fc9b36d6 |
145 | const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current()); |
146 | aT = StdPrs_ToolShadedShape::Triangulation (aFace, aLoc); |
31c0e219 |
147 | if (aT.IsNull()) |
3b1817a9 |
148 | { |
149 | continue; |
150 | } |
151 | const gp_Trsf& aTrsf = aLoc.Transformation(); |
31c0e219 |
152 | Poly_Connect aPolyConnect (aT); |
3b1817a9 |
153 | // Extracts vertices & normals from nodes |
31c0e219 |
154 | const TColgp_Array1OfPnt& aNodes = aT->Nodes(); |
155 | const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes(); |
3b1817a9 |
156 | TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper()); |
fc9b36d6 |
157 | StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals); |
3b1817a9 |
158 | |
159 | if (theHasTexels) |
2bd4c032 |
160 | { |
3b1817a9 |
161 | BRepTools::UVBounds (aFace, aUmin, aUmax, aVmin, aVmax); |
162 | dUmax = (aUmax - aUmin); |
163 | dVmax = (aVmax - aVmin); |
164 | } |
165 | |
31c0e219 |
166 | const Standard_Integer aDecal = anArray->VertexNumber(); |
3b1817a9 |
167 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) |
168 | { |
31c0e219 |
169 | aPoint = aNodes (aNodeIter); |
3b1817a9 |
170 | if (!aLoc.IsIdentity()) |
2bd4c032 |
171 | { |
31c0e219 |
172 | aPoint.Transform (aTrsf); |
3b1817a9 |
173 | aNormals (aNodeIter).Transform (aTrsf); |
2bd4c032 |
174 | } |
3b1817a9 |
175 | |
176 | if (theHasTexels && aUVNodes.Upper() == aNodes.Upper()) |
2bd4c032 |
177 | { |
3b1817a9 |
178 | const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(), |
179 | (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y()); |
31c0e219 |
180 | anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel); |
2bd4c032 |
181 | } |
3b1817a9 |
182 | else |
2bd4c032 |
183 | { |
31c0e219 |
184 | anArray->AddVertex (aPoint, aNormals (aNodeIter)); |
2bd4c032 |
185 | } |
3b1817a9 |
186 | } |
2bd4c032 |
187 | |
3b1817a9 |
188 | // Fill array with vertex and edge visibility info |
31c0e219 |
189 | const Poly_Array1OfTriangle& aTriangles = aT->Triangles(); |
190 | Standard_Integer anIndex[3]; |
191 | for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter) |
3b1817a9 |
192 | { |
fc9b36d6 |
193 | if (aFace.Orientation() == TopAbs_REVERSED) |
31c0e219 |
194 | { |
195 | aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]); |
196 | } |
3b1817a9 |
197 | else |
31c0e219 |
198 | { |
199 | aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]); |
200 | } |
3b1817a9 |
201 | |
31c0e219 |
202 | gp_Pnt aP1 = aNodes (anIndex[0]); |
203 | gp_Pnt aP2 = aNodes (anIndex[1]); |
204 | gp_Pnt aP3 = aNodes (anIndex[2]); |
3b1817a9 |
205 | |
31c0e219 |
206 | gp_Vec aV1 (aP1, aP2); |
207 | if (aV1.SquareMagnitude() <= aPreci) |
3b1817a9 |
208 | { |
209 | continue; |
210 | } |
31c0e219 |
211 | gp_Vec aV2 (aP2, aP3); |
212 | if (aV2.SquareMagnitude() <= aPreci) |
3b1817a9 |
213 | { |
214 | continue; |
215 | } |
31c0e219 |
216 | gp_Vec aV3 (aP3, aP1); |
217 | if (aV3.SquareMagnitude() <= aPreci) |
3b1817a9 |
218 | { |
219 | continue; |
220 | } |
31c0e219 |
221 | aV1.Normalize(); |
222 | aV2.Normalize(); |
223 | aV1.Cross (aV2); |
224 | if (aV1.SquareMagnitude() > aPreci) |
2bd4c032 |
225 | { |
31c0e219 |
226 | anArray->AddEdge (anIndex[0] + aDecal); |
227 | anArray->AddEdge (anIndex[1] + aDecal); |
228 | anArray->AddEdge (anIndex[2] + aDecal); |
2bd4c032 |
229 | } |
230 | } |
2bd4c032 |
231 | } |
31c0e219 |
232 | return anArray; |
233 | } |
234 | |
235 | //! Searches closed and unclosed subshapes in shape structure |
236 | //! and puts them into two compounds for separate processing of closed and unclosed sub-shapes. |
237 | static void exploreSolids (const TopoDS_Shape& theShape, |
238 | const BRep_Builder& theBuilder, |
239 | TopoDS_Compound& theCompoundForClosed, |
240 | TopoDS_Compound& theCompoundForOpened) |
241 | { |
242 | if (theShape.IsNull()) |
243 | { |
244 | return; |
245 | } |
246 | |
247 | switch (theShape.ShapeType()) |
248 | { |
249 | case TopAbs_COMPOUND: |
250 | case TopAbs_COMPSOLID: |
251 | { |
252 | for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next()) |
253 | { |
254 | exploreSolids (anIter.Value(), theBuilder, theCompoundForClosed, theCompoundForOpened); |
255 | } |
256 | return; |
257 | } |
258 | case TopAbs_SOLID: |
259 | { |
4769a395 |
260 | for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next()) |
261 | { |
262 | const TopoDS_Shape& aSubShape = anIter.Value(); |
263 | const Standard_Boolean isClosed = aSubShape.ShapeType() == TopAbs_SHELL && |
264 | BRep_Tool::IsClosed (aSubShape) && |
265 | StdPrs_ToolShadedShape::IsTriangulated (aSubShape); |
266 | theBuilder.Add (isClosed ? theCompoundForClosed : theCompoundForOpened, aSubShape); |
267 | } |
31c0e219 |
268 | return; |
269 | } |
270 | case TopAbs_SHELL: |
271 | case TopAbs_FACE: |
272 | { |
273 | theBuilder.Add (theCompoundForOpened, theShape); |
274 | return; |
275 | } |
276 | case TopAbs_WIRE: |
277 | case TopAbs_EDGE: |
278 | case TopAbs_VERTEX: |
279 | case TopAbs_SHAPE: |
280 | default: |
281 | return; |
282 | } |
283 | } |
284 | |
285 | //! Prepare shaded presentation for specified shape |
286 | static Standard_Boolean shadeFromShape (const TopoDS_Shape& theShape, |
287 | const Handle(Prs3d_Presentation)& thePrs, |
288 | const Handle(Prs3d_Drawer)& theDrawer, |
289 | const Standard_Boolean theHasTexels, |
290 | const gp_Pnt2d& theUVOrigin, |
291 | const gp_Pnt2d& theUVRepeat, |
292 | const gp_Pnt2d& theUVScale, |
293 | const Standard_Boolean theIsClosed) |
294 | { |
295 | Handle(Graphic3d_ArrayOfTriangles) aPArray = fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale); |
296 | if (aPArray.IsNull()) |
297 | { |
298 | return Standard_False; |
299 | } |
3b1817a9 |
300 | |
31c0e219 |
301 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs); |
302 | aGroup->SetClosed (theIsClosed); |
303 | if (!theDrawer->ShadingAspectGlobal()) |
304 | { |
305 | Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect(); |
306 | theIsClosed ? anAsp->SuppressBackFace() : anAsp->AllowBackFace(); |
307 | aGroup->SetGroupPrimitivesAspect (anAsp); |
308 | } |
309 | aGroup->AddPrimitiveArray (aPArray); |
2bd4c032 |
310 | return Standard_True; |
311 | } |
a2d5ab2e |
312 | |
31c0e219 |
313 | //! Compute boundary presentation for faces of the shape. |
314 | static void computeFaceBoundaries (const TopoDS_Shape& theShape, |
315 | const Handle(Prs3d_Presentation)& thePrs, |
316 | const Handle(Prs3d_Drawer)& theDrawer) |
a2d5ab2e |
317 | { |
318 | // collection of all triangulation nodes on edges |
319 | // for computing boundaries presentation |
320 | NCollection_List<Handle(TColgp_HArray1OfPnt)> aNodeCollection; |
321 | Standard_Integer aNodeNumber = 0; |
322 | |
323 | TopLoc_Location aTrsf; |
324 | |
325 | // explore all boundary edges |
326 | TopTools_IndexedDataMapOfShapeListOfShape anEdgesMap; |
327 | TopExp::MapShapesAndAncestors ( |
328 | theShape, TopAbs_EDGE, TopAbs_FACE, anEdgesMap); |
329 | |
330 | Standard_Integer anEdgeIdx = 1; |
331 | for ( ; anEdgeIdx <= anEdgesMap.Extent (); anEdgeIdx++) |
332 | { |
333 | // reject free edges |
334 | const TopTools_ListOfShape& aFaceList = anEdgesMap.FindFromIndex (anEdgeIdx); |
335 | if (aFaceList.Extent() == 0) |
336 | continue; |
337 | |
338 | // take one of the shared edges and get edge triangulation |
339 | const TopoDS_Face& aFace = TopoDS::Face (aFaceList.First ()); |
340 | const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgesMap.FindKey (anEdgeIdx)); |
341 | |
342 | Handle(Poly_Triangulation) aTriangulation = |
343 | BRep_Tool::Triangulation (aFace, aTrsf); |
344 | |
345 | if (aTriangulation.IsNull ()) |
346 | continue; |
347 | |
348 | Handle(Poly_PolygonOnTriangulation) anEdgePoly = |
349 | BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf); |
350 | |
351 | if (anEdgePoly.IsNull ()) |
352 | continue; |
353 | |
354 | // get edge nodes indexes from face triangulation |
355 | const TColgp_Array1OfPnt& aTriNodes = aTriangulation->Nodes (); |
356 | const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes (); |
357 | |
358 | if (anEdgeNodes.Length () < 2) |
359 | continue; |
360 | |
361 | // collect the edge nodes |
362 | Handle(TColgp_HArray1OfPnt) aCollected = |
363 | new TColgp_HArray1OfPnt (anEdgeNodes.Lower (), anEdgeNodes.Upper ()); |
364 | |
365 | Standard_Integer aNodeIdx = anEdgeNodes.Lower (); |
366 | for ( ; aNodeIdx <= anEdgeNodes.Upper (); aNodeIdx++) |
367 | { |
368 | // node index in face triangulation |
369 | Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx); |
370 | |
371 | // get node and apply location transformation to the node |
372 | gp_Pnt aTriNode = aTriNodes.Value (aTriIndex); |
373 | if (!aTrsf.IsIdentity ()) |
374 | aTriNode.Transform (aTrsf); |
375 | |
376 | // add node to the boundary array |
377 | aCollected->SetValue (aNodeIdx, aTriNode); |
378 | } |
379 | |
380 | aNodeNumber += anEdgeNodes.Length (); |
381 | aNodeCollection.Append (aCollected); |
382 | } |
383 | |
384 | // check if it possible to continue building the presentation |
385 | if (aNodeNumber == 0) |
386 | return; |
387 | |
388 | // allocate polyline array for presentation |
389 | Standard_Integer aSegmentEdgeNb = |
390 | (aNodeNumber - aNodeCollection.Extent()) * 2; |
391 | |
392 | Handle(Graphic3d_ArrayOfSegments) aSegments = |
393 | new Graphic3d_ArrayOfSegments (aNodeNumber, aSegmentEdgeNb); |
394 | |
395 | // build presentation for edge bondaries |
396 | NCollection_List<Handle(TColgp_HArray1OfPnt)>::Iterator |
397 | aCollIt (aNodeCollection); |
398 | |
399 | // the edge index is increased in each iteration step to |
400 | // avoid contiguous segments between different face edges. |
401 | for ( ; aCollIt.More(); aCollIt.Next () ) |
402 | { |
403 | const Handle(TColgp_HArray1OfPnt)& aNodeArray = aCollIt.Value (); |
404 | |
405 | Standard_Integer aNodeIdx = aNodeArray->Lower (); |
406 | |
407 | // add first node (this node is not shared with previous segment). |
408 | // for each face edge, indices for sharing nodes |
409 | // between segments begin from the first added node. |
410 | Standard_Integer aSegmentEdge = |
411 | aSegments->AddVertex (aNodeArray->Value (aNodeIdx)); |
412 | |
413 | // add subsequent nodes and provide edge indexes for sharing |
414 | // the nodes between the sequential segments. |
415 | for ( aNodeIdx++; aNodeIdx <= aNodeArray->Upper (); aNodeIdx++ ) |
416 | { |
417 | aSegments->AddVertex (aNodeArray->Value (aNodeIdx)); |
418 | aSegments->AddEdge ( aSegmentEdge); |
419 | aSegments->AddEdge (++aSegmentEdge); |
420 | } |
421 | } |
422 | |
423 | // set up aspect and add polyline data |
424 | Handle(Graphic3d_AspectLine3d) aBoundaryAspect = |
425 | theDrawer->FaceBoundaryAspect ()->Aspect (); |
426 | |
31c0e219 |
427 | Handle(Graphic3d_Group) aPrsGrp = Prs3d_Root::CurrentGroup (thePrs); |
a2d5ab2e |
428 | aPrsGrp->SetGroupPrimitivesAspect (aBoundaryAspect); |
a2d5ab2e |
429 | aPrsGrp->AddPrimitiveArray (aSegments); |
a2d5ab2e |
430 | } |
2bd4c032 |
431 | }; |
432 | |
433 | // ======================================================================= |
434 | // function : Add |
435 | // purpose : |
436 | // ======================================================================= |
31c0e219 |
437 | void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs, |
438 | const TopoDS_Shape& theShape, |
439 | const Handle(Prs3d_Drawer)& theDrawer, |
440 | const Standard_Boolean theToExploreSolids) |
2bd4c032 |
441 | { |
442 | gp_Pnt2d aDummy; |
31c0e219 |
443 | StdPrs_ShadedShape::Add (thePrs, theShape, theDrawer, |
444 | Standard_False, aDummy, aDummy, aDummy, theToExploreSolids); |
2bd4c032 |
445 | } |
446 | |
ad3217cd |
447 | // ======================================================================= |
448 | // function : Tessellate |
449 | // purpose : |
450 | // ======================================================================= |
451 | void StdPrs_ShadedShape::Tessellate (const TopoDS_Shape& theShape, |
452 | const Handle (Prs3d_Drawer)& theDrawer) |
453 | { |
31c0e219 |
454 | // Check if it is possible to avoid unnecessary recomputation of shape triangulation |
9dba391d |
455 | Standard_Real aDeflection = Prs3d::GetDeflection (theShape, theDrawer); |
ad3217cd |
456 | if (BRepTools::Triangulation (theShape, aDeflection)) |
457 | { |
458 | return; |
459 | } |
460 | |
461 | // retrieve meshing tool from Factory |
ad3217cd |
462 | Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape, |
463 | aDeflection, |
464 | theDrawer->HLRAngle()); |
465 | if (!aMeshAlgo.IsNull()) |
466 | { |
467 | aMeshAlgo->Perform(); |
468 | } |
469 | } |
470 | |
2bd4c032 |
471 | // ======================================================================= |
472 | // function : Add |
473 | // purpose : |
474 | // ======================================================================= |
31c0e219 |
475 | void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs, |
2bd4c032 |
476 | const TopoDS_Shape& theShape, |
477 | const Handle (Prs3d_Drawer)& theDrawer, |
478 | const Standard_Boolean theHasTexels, |
479 | const gp_Pnt2d& theUVOrigin, |
480 | const gp_Pnt2d& theUVRepeat, |
31c0e219 |
481 | const gp_Pnt2d& theUVScale, |
482 | const Standard_Boolean theToExploreSolids) |
2bd4c032 |
483 | { |
484 | if (theShape.IsNull()) |
485 | { |
486 | return; |
487 | } |
488 | |
31c0e219 |
489 | // add wireframe presentation for isolated edges and vertices |
490 | wireframeFromShape (thePrs, theShape, theDrawer); |
491 | |
4769a395 |
492 | // Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand |
31c0e219 |
493 | Tessellate (theShape, theDrawer); |
4769a395 |
494 | |
495 | // The shape types listed below need advanced analysis as potentially containing |
496 | // both closed and open parts. Solids are also included, because they might |
497 | // contain non-manifold parts inside (internal open shells) |
31c0e219 |
498 | if ((theShape.ShapeType() == TopAbs_COMPOUND |
4769a395 |
499 | || theShape.ShapeType() == TopAbs_COMPSOLID |
500 | || theShape.ShapeType() == TopAbs_SOLID) |
31c0e219 |
501 | && theToExploreSolids) |
2bd4c032 |
502 | { |
31c0e219 |
503 | // collect two compounds: for opened and closed (solid) sub-shapes |
504 | TopoDS_Compound anOpened, aClosed; |
505 | BRep_Builder aBuilder; |
506 | aBuilder.MakeCompound (aClosed); |
507 | aBuilder.MakeCompound (anOpened); |
508 | exploreSolids (theShape, aBuilder, aClosed, anOpened); |
509 | |
510 | TopoDS_Iterator aShapeIter (aClosed); |
511 | if (aShapeIter.More()) |
2bd4c032 |
512 | { |
31c0e219 |
513 | shadeFromShape (aClosed, thePrs, theDrawer, |
514 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, Standard_True); |
2bd4c032 |
515 | } |
31c0e219 |
516 | |
517 | aShapeIter.Initialize (anOpened); |
518 | if (aShapeIter.More()) |
2bd4c032 |
519 | { |
31c0e219 |
520 | shadeFromShape (anOpened, thePrs, theDrawer, |
521 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, Standard_False); |
2bd4c032 |
522 | } |
523 | } |
31c0e219 |
524 | else |
525 | { |
526 | shadeFromShape (theShape, thePrs, theDrawer, |
4769a395 |
527 | theHasTexels, theUVOrigin, theUVRepeat, theUVScale, |
528 | StdPrs_ToolShadedShape::IsClosed (theShape)); |
31c0e219 |
529 | } |
2bd4c032 |
530 | |
31c0e219 |
531 | if (theDrawer->IsFaceBoundaryDraw()) |
a2d5ab2e |
532 | { |
31c0e219 |
533 | computeFaceBoundaries (theShape, thePrs, theDrawer); |
a2d5ab2e |
534 | } |
535 | } |