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