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