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