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