0031424: Visualization - stop using Prs3d_Drawer::HLRAngle() parameter
[occt.git] / src / StdPrs / StdPrs_HLRPolyShape.cxx
1 // Created on: 1995-09-19
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-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_HLRPolyShape.hxx>
18
19 #include <BRepMesh_IncrementalMesh.hxx>
20 #include <Graphic3d_ArrayOfSegments.hxx>
21 #include <Graphic3d_Group.hxx>
22 #include <HLRAlgo_EdgeIterator.hxx>
23 #include <HLRAlgo_EdgeStatus.hxx>
24 #include <HLRBRep_BiPoint.hxx>
25 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
26 #include <HLRBRep_ListOfBPoint.hxx>
27 #include <HLRBRep_PolyAlgo.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <StdPrs_ToolTriangulatedShape.hxx>
31 #include <StdPrs_WFShape.hxx>
32 #include <TColgp_SequenceOfPnt.hxx>
33 #include <TopAbs.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopoDS_Shape.hxx>
36
37 #define PntX1 ((Standard_Real*)Coordinates)[0]
38 #define PntY1 ((Standard_Real*)Coordinates)[1]
39 #define PntZ1 ((Standard_Real*)Coordinates)[2]
40 #define PntX2 ((Standard_Real*)Coordinates)[3]
41 #define PntY2 ((Standard_Real*)Coordinates)[4]
42 #define PntZ2 ((Standard_Real*)Coordinates)[5]
43
44 IMPLEMENT_STANDARD_RTTIEXT(StdPrs_HLRPolyShape, StdPrs_HLRShapeI)
45
46 //=======================================================================
47 //function : Add
48 //purpose  :
49 //=======================================================================
50 void StdPrs_HLRPolyShape::ComputeHLR (const Handle(Prs3d_Presentation)& aPresentation,
51                                       const TopoDS_Shape& aShape,
52                                       const Handle(Prs3d_Drawer)& aDrawer,
53                                       const Handle(Graphic3d_Camera)& theProjector) const
54 {
55   gp_Dir aBackDir = -theProjector->Direction();
56   gp_Dir aXpers   = theProjector->Up().Crossed (aBackDir);
57   gp_Ax3 anAx3 (theProjector->Center(), aBackDir, aXpers);
58   gp_Trsf aTrsf;
59   aTrsf.SetTransformation (anAx3);
60   const HLRAlgo_Projector aProj (aTrsf, !theProjector->IsOrthographic(), theProjector->Scale());
61
62   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
63
64   TopExp_Explorer ex;
65
66   // find vertices not under ancestors.
67   TopAbs_ShapeEnum E = aShape.ShapeType();
68   if (E == TopAbs_COMPOUND) {
69     // it is necessary to present isolated vertexes instead of hiding them.
70     for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
71       StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
72     }
73   }
74
75   if (aDrawer->IsAutoTriangulation())
76   {
77     StdPrs_ToolTriangulatedShape::Tessellate (aShape, aDrawer);
78   }
79   
80   Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
81   hider->Projector (aProj);
82   hider->Update();
83   Standard_Real sta,end,dx,dy,dz;
84   Standard_ShortReal tolsta, tolend;
85   HLRAlgo_EdgeStatus status;
86   HLRAlgo_EdgeIterator It;
87   Standard_Boolean reg1,regn,outl, intl;
88   Standard_Address Coordinates;
89   TopoDS_Shape S;
90
91   HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
92   
93   for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
94   {
95     Coordinates = &hider->Hide(status, S, reg1, regn, outl, intl);
96     
97     dx = PntX2 - PntX1;
98     dy = PntY2 - PntY1;
99     dz = PntZ2 - PntZ1;
100     
101     for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
102     {
103       It.Visible(sta,tolsta,end,tolend);
104       BiPntVis.Append
105         (HLRBRep_BiPoint
106            (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
107             PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
108             S,reg1,regn,outl,intl));
109     }
110     
111     for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
112     {
113       It.Hidden(sta,tolsta,end,tolend);
114       BiPntHid.Append
115         (HLRBRep_BiPoint
116            (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
117             PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
118             S,reg1,regn,outl,intl));    
119     }
120   }
121
122   // storage in the group
123   if (aDrawer->DrawHiddenLine())
124   {
125     Standard_Integer aNbHiddenSegments = 0;
126     for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
127     {
128       const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
129       if (!aBPnt.RgNLine()
130         || aBPnt.OutLine())
131       {
132         ++aNbHiddenSegments;
133       }
134     }
135     if (aNbHiddenSegments > 0)
136     {
137       Handle(Graphic3d_ArrayOfSegments) aHiddenArray = new Graphic3d_ArrayOfSegments (aNbHiddenSegments * 2);
138       for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
139       {
140         const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
141         if (!aBPnt.RgNLine()
142           || aBPnt.OutLine())
143         {
144           aHiddenArray->AddVertex (aBPnt.P1());
145           aHiddenArray->AddVertex (aBPnt.P2());
146         }
147       }
148
149       aGroup->SetPrimitivesAspect (aDrawer->HiddenLineAspect()->Aspect());
150       aGroup->AddPrimitiveArray (aHiddenArray);
151     }
152   }
153   {
154     Standard_Integer aNbSeenSegments = 0;
155     for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
156     {
157       const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
158       if (!aBPnt.RgNLine()
159         || aBPnt.OutLine())
160       {
161         ++aNbSeenSegments;
162       }
163     }
164     if (aNbSeenSegments > 0)
165     {
166       Handle(Graphic3d_ArrayOfSegments) aSeenArray = new Graphic3d_ArrayOfSegments (aNbSeenSegments * 2);
167       for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
168       {
169         const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
170         if (!aBPnt.RgNLine()
171           || aBPnt.OutLine())
172         {
173           aSeenArray->AddVertex (aBPnt.P1());
174           aSeenArray->AddVertex (aBPnt.P2());
175         }
176       }
177       aGroup->SetPrimitivesAspect (aDrawer->SeenLineAspect()->Aspect());
178       aGroup->AddPrimitiveArray (aSeenArray);
179     }
180   }
181 }