0028213: Visualization, StdPrs_ShadedShape - compute face edges for triangulation...
[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     Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All);
64
65     if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND)
66     {
67       return;
68     }
69
70     TopExp_Explorer aShapeIter (theShape, TopAbs_FACE);
71     if (!aShapeIter.More())
72     {
73       // compound contains no shaded elements at all
74       StdPrs_WFShape::Add (thePrs, theShape, theDrawer);
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       Poly_Connect aPolyConnect (aT);
192       // Extracts vertices & normals from nodes
193       const TColgp_Array1OfPnt&   aNodes   = aT->Nodes();
194       const TColgp_Array1OfPnt2d& aUVNodes = aT->UVNodes();
195       TColgp_Array1OfDir aNormals (aNodes.Lower(), aNodes.Upper());
196       StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals);
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         if (!aLoc.IsIdentity())
210         {
211           aPoint.Transform (aTrsf);
212
213           aNormals (aNodeIter) = aNormals (aNodeIter).Transformed (aTrsf);
214         }
215
216         if (theHasTexels && aUVNodes.Upper() == aNodes.Upper())
217         {
218           const gp_Pnt2d aTexel = gp_Pnt2d ((-theUVOrigin.X() + (theUVRepeat.X() * (aUVNodes (aNodeIter).X() - aUmin)) / dUmax) / theUVScale.X(),
219                                             (-theUVOrigin.Y() + (theUVRepeat.Y() * (aUVNodes (aNodeIter).Y() - aVmin)) / dVmax) / theUVScale.Y());
220           anArray->AddVertex (aPoint, aNormals (aNodeIter), aTexel);
221         }
222         else
223         {
224           anArray->AddVertex (aPoint, aNormals (aNodeIter));
225         }
226       }
227
228       // Fill array with vertex and edge visibility info
229       const Poly_Array1OfTriangle& aTriangles = aT->Triangles();
230       Standard_Integer anIndex[3];
231       for (Standard_Integer aTriIter = 1; aTriIter <= aT->NbTriangles(); ++aTriIter)
232       {
233         if ((aFace.Orientation() == TopAbs_REVERSED) ^ isMirrored)
234         {
235           aTriangles (aTriIter).Get (anIndex[0], anIndex[2], anIndex[1]);
236         }
237         else
238         {
239           aTriangles (aTriIter).Get (anIndex[0], anIndex[1], anIndex[2]);
240         }
241
242         gp_Pnt aP1 = aNodes (anIndex[0]);
243         gp_Pnt aP2 = aNodes (anIndex[1]);
244         gp_Pnt aP3 = aNodes (anIndex[2]);
245
246         gp_Vec aV1 (aP1, aP2);
247         if (aV1.SquareMagnitude() <= aPreci)
248         {
249           continue;
250         }
251         gp_Vec aV2 (aP2, aP3);
252         if (aV2.SquareMagnitude() <= aPreci)
253         {
254           continue;
255         }
256         gp_Vec aV3 (aP3, aP1);
257         if (aV3.SquareMagnitude() <= aPreci)
258         {
259           continue;
260         }
261         aV1.Normalize();
262         aV2.Normalize();
263         aV1.Cross (aV2);
264         if (aV1.SquareMagnitude() > aPreci)
265         {
266           anArray->AddEdge (anIndex[0] + aDecal);
267           anArray->AddEdge (anIndex[1] + aDecal);
268           anArray->AddEdge (anIndex[2] + aDecal);
269         }
270       }
271     }
272     return anArray;
273   }
274
275   //! Prepare shaded presentation for specified shape
276   static Standard_Boolean shadeFromShape (const TopoDS_Shape&               theShape,
277                                           const Handle(Prs3d_Presentation)& thePrs,
278                                           const Handle(Prs3d_Drawer)&       theDrawer,
279                                           const Standard_Boolean            theHasTexels,
280                                           const gp_Pnt2d&                   theUVOrigin,
281                                           const gp_Pnt2d&                   theUVRepeat,
282                                           const gp_Pnt2d&                   theUVScale,
283                                           const bool                        theIsClosed)
284   {
285     Handle(Graphic3d_ArrayOfTriangles) aPArray = fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale);
286     if (aPArray.IsNull())
287     {
288       return Standard_False;
289     }
290
291     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
292     aGroup->SetClosed (theIsClosed);
293     aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect());
294     aGroup->AddPrimitiveArray (aPArray);
295     return Standard_True;
296   }
297
298   //! Compute boundary presentation for faces of the shape.
299   static Handle(Graphic3d_ArrayOfSegments) fillFaceBoundaries (const TopoDS_Shape& theShape)
300   {
301     // collection of all triangulation nodes on edges
302     // for computing boundaries presentation
303     Standard_Integer aNodeNumber = 0;
304     Standard_Integer aNbPolylines = 0;
305
306     TopLoc_Location aTrsf;
307     TColgp_SequenceOfPnt aSeqPntsExtra;
308     for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
309     {
310       const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
311       TopoDS_Iterator aSubShapeIter (aFace);
312       if (!aSubShapeIter.More())
313       {
314         // handle specifically faces without boundary definition (triangulation-only)
315         StdPrs_WFShape::AddEdgesOnTriangulation (aSeqPntsExtra, aFace, Standard_False);
316       }
317     }
318
319     // explore all boundary edges
320     TopTools_IndexedDataMapOfShapeListOfShape anEdgesMap;
321     TopExp::MapShapesAndAncestors (theShape, TopAbs_EDGE, TopAbs_FACE, anEdgesMap);
322     for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
323     {
324       // reject free edges
325       if (anEdgeIter.Value().Extent() == 0)
326       {
327         continue;
328       }
329
330       // take one of the shared edges and get edge triangulation
331       const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First());
332       Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf);
333       if (aTriangulation.IsNull())
334       {
335         continue;
336       }
337
338       const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key());
339       Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf);
340       if (!anEdgePoly.IsNull()
341         && anEdgePoly->Nodes().Length() >= 2)
342       {
343         aNodeNumber += anEdgePoly->Nodes().Length();
344         ++aNbPolylines;
345       }
346     }
347     if (aNodeNumber == 0)
348     {
349       if (aSeqPntsExtra.Size() < 2)
350       {
351         return Handle(Graphic3d_ArrayOfSegments)();
352       }
353
354       Standard_Integer aNbVertices = aSeqPntsExtra.Size();
355       Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbVertices);
356       for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
357       {
358         aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
359         aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
360       }
361       return aSegments;
362     }
363
364     // create indexed segments array to pack polylines from different edges into single array
365     const Standard_Integer aSegmentEdgeNb = (aNodeNumber - aNbPolylines) * 2;
366     Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNodeNumber + aSeqPntsExtra.Size(), aSegmentEdgeNb + aSeqPntsExtra.Size());
367     for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
368     {
369       if (anEdgeIter.Value().Extent() == 0)
370       {
371         continue;
372       }
373
374       const TopoDS_Face& aFace = TopoDS::Face (anEdgeIter.Value().First());
375       Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aTrsf);
376       if (aTriangulation.IsNull())
377       {
378         continue;
379       }
380
381       const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key());
382       Handle(Poly_PolygonOnTriangulation) anEdgePoly = BRep_Tool::PolygonOnTriangulation (anEdge, aTriangulation, aTrsf);
383       if (anEdgePoly.IsNull()
384        || anEdgePoly->Nodes().Length () < 2)
385       {
386         continue;
387       }
388
389       // get edge nodes indexes from face triangulation
390       const TColgp_Array1OfPnt&      aTriNodes   = aTriangulation->Nodes();
391       const TColStd_Array1OfInteger& anEdgeNodes = anEdgePoly->Nodes();
392
393       // collect the edge nodes
394       Standard_Integer aSegmentEdge = aSegments->VertexNumber() + 1;
395       for (Standard_Integer aNodeIdx = anEdgeNodes.Lower(); aNodeIdx <= anEdgeNodes.Upper(); ++aNodeIdx)
396       {
397         // node index in face triangulation
398         // get node and apply location transformation to the node
399         const Standard_Integer aTriIndex = anEdgeNodes.Value (aNodeIdx);
400         gp_Pnt aTriNode = aTriNodes.Value (aTriIndex);
401         if (!aTrsf.IsIdentity())
402         {
403           aTriNode.Transform (aTrsf);
404         }
405
406         aSegments->AddVertex (aTriNode);
407         if (aNodeIdx != anEdgeNodes.Lower())
408         {
409           aSegments->AddEdge (  aSegmentEdge);
410           aSegments->AddEdge (++aSegmentEdge);
411         }
412       }
413     }
414
415     {
416       Standard_Integer aSegmentEdge = aSegments->VertexNumber();
417       const Standard_Integer aNbVertices = aSeqPntsExtra.Size();
418       for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
419       {
420         aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
421         aSegments->AddEdge (++aSegmentEdge);
422         aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
423         aSegments->AddEdge (++aSegmentEdge);
424       }
425     }
426
427     return aSegments;
428   }
429
430 } // anonymous namespace
431
432 // =======================================================================
433 // function : ExploreSolids
434 // purpose  :
435 // =======================================================================
436 void StdPrs_ShadedShape::ExploreSolids (const TopoDS_Shape&    theShape,
437                                         const BRep_Builder&    theBuilder,
438                                         TopoDS_Compound&       theClosed,
439                                         TopoDS_Compound&       theOpened,
440                                         const Standard_Boolean theIgnore1DSubShape)
441 {
442   if (theShape.IsNull())
443   {
444     return;
445   }
446
447   switch (theShape.ShapeType())
448   {
449     case TopAbs_COMPOUND:
450     case TopAbs_COMPSOLID:
451     {
452       for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next())
453       {
454         ExploreSolids (anIter.Value(), theBuilder, theClosed, theOpened, theIgnore1DSubShape);
455       }
456       return;
457     }
458     case TopAbs_SOLID:
459     {
460       for (TopoDS_Iterator anIter (theShape); anIter.More(); anIter.Next())
461       {
462         const TopoDS_Shape& aSubShape   = anIter.Value();
463         const Standard_Boolean isClosed = aSubShape.ShapeType() == TopAbs_SHELL &&
464                                           BRep_Tool::IsClosed (aSubShape)       &&
465                                           StdPrs_ToolTriangulatedShape::IsTriangulated (aSubShape);
466         theBuilder.Add (isClosed ? theClosed : theOpened, aSubShape);
467       }
468       return;
469     }
470     case TopAbs_SHELL:
471     case TopAbs_FACE:
472     {
473       theBuilder.Add (theOpened, theShape);
474       return;
475     }
476     case TopAbs_WIRE:
477     case TopAbs_EDGE:
478     case TopAbs_VERTEX:
479     {
480       if (!theIgnore1DSubShape)
481       {
482         theBuilder.Add (theOpened, theShape);
483       }
484       return;
485     }
486     case TopAbs_SHAPE:
487     default:
488       return;
489   }
490 }
491
492 // =======================================================================
493 // function : Add
494 // purpose  :
495 // =======================================================================
496 void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs,
497                               const TopoDS_Shape&               theShape,
498                               const Handle(Prs3d_Drawer)&       theDrawer,
499                               const StdPrs_Volume               theVolume)
500 {
501   gp_Pnt2d aDummy;
502   StdPrs_ShadedShape::Add (thePrs, theShape, theDrawer,
503                            Standard_False, aDummy, aDummy, aDummy, theVolume);
504 }
505
506 // =======================================================================
507 // function : Add
508 // purpose  :
509 // =======================================================================
510 void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
511                               const TopoDS_Shape&                theShape,
512                               const Handle (Prs3d_Drawer)&       theDrawer,
513                               const Standard_Boolean             theHasTexels,
514                               const gp_Pnt2d&                    theUVOrigin,
515                               const gp_Pnt2d&                    theUVRepeat,
516                               const gp_Pnt2d&                    theUVScale,
517                               const StdPrs_Volume                theVolume)
518 {
519   if (theShape.IsNull())
520   {
521     return;
522   }
523
524   // add wireframe presentation for isolated edges and vertices
525   wireframeFromShape (thePrs, theShape, theDrawer);
526
527   // Use automatic re-triangulation with deflection-check logic only if this feature is enable
528   if (theDrawer->IsAutoTriangulation())
529   {
530     // Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand
531     StdPrs_ToolTriangulatedShape::Tessellate (theShape, theDrawer);
532   }
533
534   // add special wireframe presentation for faces without triangulation
535   wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer);
536
537   // The shape types listed below need advanced analysis as potentially containing
538   // both closed and open parts. Solids are also included, because they might
539   // contain non-manifold parts inside (internal open shells)
540   if ((theShape.ShapeType() == TopAbs_COMPOUND
541     || theShape.ShapeType() == TopAbs_COMPSOLID
542     || theShape.ShapeType() == TopAbs_SOLID)
543    &&  theVolume == StdPrs_Volume_Autodetection)
544   {
545     // collect two compounds: for opened and closed (solid) sub-shapes
546     TopoDS_Compound anOpened, aClosed;
547     BRep_Builder aBuilder;
548     aBuilder.MakeCompound (aClosed);
549     aBuilder.MakeCompound (anOpened);
550     ExploreSolids (theShape, aBuilder, aClosed, anOpened, Standard_True);
551
552     TopoDS_Iterator aShapeIter (aClosed);
553     if (aShapeIter.More())
554     {
555       shadeFromShape (aClosed, thePrs, theDrawer,
556                       theHasTexels, theUVOrigin, theUVRepeat, theUVScale, true);
557     }
558
559     aShapeIter.Initialize (anOpened);
560     if (aShapeIter.More())
561     {
562       shadeFromShape (anOpened, thePrs, theDrawer,
563                       theHasTexels, theUVOrigin, theUVRepeat, theUVScale, false);
564     }
565   }
566   else
567   {
568     // if the shape type is not compound, composolid or solid, use autodetection back-facing filled
569     shadeFromShape (theShape, thePrs, theDrawer,
570                     theHasTexels, theUVOrigin, theUVRepeat, theUVScale,
571                     theVolume == StdPrs_Volume_Closed);
572   }
573
574   if (theDrawer->FaceBoundaryDraw())
575   {
576     Handle(Graphic3d_ArrayOfSegments) aBndSegments = fillFaceBoundaries (theShape);
577     if (!aBndSegments.IsNull())
578     {
579       Handle(Graphic3d_AspectLine3d) aBoundaryAspect = theDrawer->FaceBoundaryAspect()->Aspect();
580       Handle(Graphic3d_Group) aPrsGrp = Prs3d_Root::CurrentGroup (thePrs);
581       aPrsGrp->SetGroupPrimitivesAspect (aBoundaryAspect);
582       aPrsGrp->AddPrimitiveArray (aBndSegments);
583     }
584   }
585 }
586
587 // =======================================================================
588 // function : FillTriangles
589 // purpose  :
590 // =======================================================================
591 Handle(Graphic3d_ArrayOfTriangles) StdPrs_ShadedShape::FillTriangles (const TopoDS_Shape&    theShape,
592                                                                       const Standard_Boolean theHasTexels,
593                                                                       const gp_Pnt2d&        theUVOrigin,
594                                                                       const gp_Pnt2d&        theUVRepeat,
595                                                                       const gp_Pnt2d&        theUVScale)
596 {
597   return fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale);
598 }
599
600 // =======================================================================
601 // function : FillFaceBoundaries
602 // purpose  :
603 // =======================================================================
604 Handle(Graphic3d_ArrayOfSegments) StdPrs_ShadedShape::FillFaceBoundaries (const TopoDS_Shape& theShape)
605 {
606   return fillFaceBoundaries (theShape);
607 }
608
609 // =======================================================================
610 // function : AddWireframeForFreeElements
611 // purpose  :
612 // =======================================================================
613 void StdPrs_ShadedShape::AddWireframeForFreeElements (const Handle (Prs3d_Presentation)& thePrs,
614                                                       const TopoDS_Shape&                theShape,
615                                                       const Handle (Prs3d_Drawer)&       theDrawer)
616 {
617   wireframeFromShape (thePrs, theShape, theDrawer);
618 }
619
620 // =======================================================================
621 // function : AddWireframeForFacesWithoutTriangles
622 // purpose  :
623 // =======================================================================
624 void StdPrs_ShadedShape::AddWireframeForFacesWithoutTriangles (const Handle(Prs3d_Presentation)& thePrs,
625                                                                const TopoDS_Shape&               theShape,
626                                                                const Handle(Prs3d_Drawer)&       theDrawer)
627 {
628   wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer);
629 }