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 | |
17 | #include <StdPrs_HLRPolyShape.ixx> |
18 | |
19 | #include <StdPrs_WFShape.hxx> |
20 | #include <TopAbs.hxx> |
21 | #include <TopExp_Explorer.hxx> |
22 | #include <Graphic3d_Group.hxx> |
7fd59977 |
23 | #include <Graphic3d_ArrayOfPolylines.hxx> |
24 | #include <Prs3d_LineAspect.hxx> |
25 | #include <BRepMesh_IncrementalMesh.hxx> |
26 | #include <HLRBRep_PolyAlgo.hxx> |
27 | #include <HLRBRep_ListOfBPoint.hxx> |
28 | #include <HLRBRep_BiPoint.hxx> |
29 | #include <HLRAlgo_EdgeStatus.hxx> |
30 | #include <HLRAlgo_EdgeIterator.hxx> |
31 | #include <HLRBRep_ListIteratorOfListOfBPoint.hxx> |
32 | #include <TColgp_SequenceOfPnt.hxx> |
33 | |
34 | #define PntX1 ((Standard_Real*)Coordinates)[0] |
35 | #define PntY1 ((Standard_Real*)Coordinates)[1] |
36 | #define PntZ1 ((Standard_Real*)Coordinates)[2] |
37 | #define PntX2 ((Standard_Real*)Coordinates)[3] |
38 | #define PntY2 ((Standard_Real*)Coordinates)[4] |
39 | #define PntZ2 ((Standard_Real*)Coordinates)[5] |
40 | |
41 | //======================================================================= |
42 | //function : Add |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation, |
47 | const TopoDS_Shape& aShape, |
48 | const Handle (Prs3d_Drawer)& aDrawer, |
49 | const Handle (Prs3d_Projector)& aProjector) |
50 | { |
51 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); |
52 | |
53 | TopExp_Explorer ex; |
54 | |
7fd59977 |
55 | // find vertices not under ancestors. |
56 | TopAbs_ShapeEnum E = aShape.ShapeType(); |
57 | if (E == TopAbs_COMPOUND) { |
81bba717 |
58 | // it is necessary to present isolated vertexes instead of hiding them. |
7fd59977 |
59 | for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) { |
60 | StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer); |
61 | } |
62 | } |
63 | |
7fd59977 |
64 | TColgp_SequenceOfPnt HiddenPnts; |
65 | TColgp_SequenceOfPnt SeenPnts; |
66 | |
b8ddfc2f |
67 | const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE; |
68 | Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation(); |
fc9b36d6 |
69 | BRepMesh_IncrementalMesh mesh(aShape, def, aDrawer->HLRAngle(), rel); |
7fd59977 |
70 | |
71 | Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape); |
72 | |
73 | hider->Projector(aProjector->Projector()); |
74 | hider->Angle(aDrawer->HLRAngle()); |
75 | hider->Update(); |
7fd59977 |
76 | Standard_Real sta,end,dx,dy,dz; |
77 | Standard_ShortReal tolsta, tolend; |
7fd59977 |
78 | HLRAlgo_EdgeStatus status; |
79 | HLRAlgo_EdgeIterator It; |
80 | Standard_Boolean reg1,regn,outl, intl; |
81 | Standard_Address Coordinates; |
82 | TopoDS_Shape S; |
83 | |
84 | HLRBRep_ListOfBPoint BiPntVis, BiPntHid; |
85 | |
b8ddfc2f |
86 | for (hider->InitHide(); hider->MoreHide(); hider->NextHide()) |
87 | { |
7fd59977 |
88 | hider->Hide(Coordinates, status, S, reg1, regn, outl, intl); |
89 | |
90 | dx = PntX2 - PntX1; |
91 | dy = PntY2 - PntY1; |
92 | dz = PntZ2 - PntZ1; |
93 | |
b8ddfc2f |
94 | for (It.InitVisible(status); It.MoreVisible(); It.NextVisible()) |
95 | { |
7fd59977 |
96 | It.Visible(sta,tolsta,end,tolend); |
97 | BiPntVis.Append |
b8ddfc2f |
98 | (HLRBRep_BiPoint |
99 | (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz, |
100 | PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz, |
101 | S,reg1,regn,outl,intl)); |
7fd59977 |
102 | } |
103 | |
b8ddfc2f |
104 | for (It.InitHidden(status); It.MoreHidden(); It.NextHidden()) |
105 | { |
7fd59977 |
106 | It.Hidden(sta,tolsta,end,tolend); |
107 | BiPntHid.Append |
b8ddfc2f |
108 | (HLRBRep_BiPoint |
109 | (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz, |
110 | PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz, |
111 | S,reg1,regn,outl,intl)); |
7fd59977 |
112 | } |
113 | } |
114 | |
81bba717 |
115 | // storage in the group: |
7fd59977 |
116 | HLRBRep_ListIteratorOfListOfBPoint ItB; |
117 | |
118 | if (aDrawer->DrawHiddenLine()) { |
7fd59977 |
119 | for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) { |
120 | const HLRBRep_BiPoint& BP = ItB.Value(); |
121 | if (!BP.RgNLine() || BP.OutLine()) { |
b8ddfc2f |
122 | HiddenPnts.Append(BP.P1()); |
123 | HiddenPnts.Append(BP.P2()); |
7fd59977 |
124 | } |
125 | } |
7fd59977 |
126 | } |
127 | |
7fd59977 |
128 | for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) { |
129 | const HLRBRep_BiPoint& BP = ItB.Value(); |
130 | if (!BP.RgNLine() || BP.OutLine()) { |
b8ddfc2f |
131 | SeenPnts.Append(BP.P1()); |
132 | SeenPnts.Append(BP.P2()); |
7fd59977 |
133 | } |
134 | } |
b8ddfc2f |
135 | |
136 | Standard_Integer nbVertices = HiddenPnts.Length(); |
137 | if(nbVertices > 0) { |
138 | Handle(Graphic3d_ArrayOfPolylines) HiddenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2); |
139 | for(int i=1; i<=nbVertices; i+=2) { |
140 | HiddenArray->AddBound(2); |
141 | HiddenArray->AddVertex(HiddenPnts.Value(i)); |
142 | HiddenArray->AddVertex(HiddenPnts.Value(i+1)); |
7fd59977 |
143 | } |
b8ddfc2f |
144 | aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect()); |
145 | aGroup->AddPrimitiveArray(HiddenArray); |
146 | } |
147 | nbVertices = SeenPnts.Length(); |
148 | if(nbVertices > 0) { |
149 | Handle(Graphic3d_ArrayOfPolylines) SeenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2); |
150 | for(int i=1; i<=nbVertices; i+=2) { |
151 | SeenArray->AddBound(2); |
152 | SeenArray->AddVertex(SeenPnts.Value(i)); |
153 | SeenArray->AddVertex(SeenPnts.Value(i+1)); |
7fd59977 |
154 | } |
b8ddfc2f |
155 | aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect()); |
156 | aGroup->AddPrimitiveArray(SeenArray); |
7fd59977 |
157 | } |
158 | } |