0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / Prs3d / Prs3d_ShapeTool.cxx
1 // Created on: 1995-08-07
2 // Created by: Modelistation
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
9 // under the terms of the GNU Lesser General Public 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 #define OCC215           //SAV: 01/04/02 vertex exploring is done for all types of shape.
18 #define OCC598           //SAV: 22/10/02 searching for internal vertices. 
19
20 #include <Prs3d_ShapeTool.ixx>
21
22 #include <BRepTools.hxx>
23 #include <TopoDS.hxx>
24 #include <TopExp.hxx>
25 #include <TopTools_ListOfShape.hxx>
26 #include <TopTools_MapOfShape.hxx>
27 #include <TopTools_ListIteratorOfListOfShape.hxx>
28
29 #include <BRepBndLib.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepAdaptor_Curve.hxx>
32 #include <Bnd_Box.hxx>
33 #include <BRep_Tool.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_RectangularTrimmedSurface.hxx>
36 #include <Geom_Plane.hxx>
37
38
39 //=======================================================================
40 //function : Prs3d_ShapeTool
41 //purpose  : 
42 //=======================================================================
43
44 Prs3d_ShapeTool::Prs3d_ShapeTool(const TopoDS_Shape& TheShape):
45                                  myShape (TheShape) 
46 {
47   myEdgeMap.Clear();
48   myVertexMap.Clear();
49   TopExp::MapShapesAndAncestors(TheShape,TopAbs_EDGE,TopAbs_FACE,myEdgeMap);
50
51 #ifndef OCC215
52   // find vertices not under ancestors.
53   TopAbs_ShapeEnum E = TheShape.ShapeType();
54
55
56   // this check were done to reduce the number of selectable objects
57   // in a local context. By now, there's no noticeable performance improvement.
58   if (E != TopAbs_SOLID && E != TopAbs_SHELL)
59 #endif
60     {
61       TopExp_Explorer ex(TheShape,TopAbs_VERTEX, TopAbs_EDGE);
62       while (ex.More()) {
63         const TopoDS_Shape& aV=ex.Current();
64         myVertexMap.Add(aV);
65         ex.Next();
66       }
67     }
68 #ifdef OCC598
69   TopExp_Explorer edges( TheShape, TopAbs_EDGE );
70   while( edges.More() ) {
71     //xf
72     const TopoDS_Shape& aE= edges.Current();
73     TopoDS_Iterator aIt(aE, Standard_False, Standard_True);
74     while( aIt.More() ) {
75       const TopoDS_Shape& aV=aIt.Value();
76       if (aV.Orientation()==TopAbs_INTERNAL) {
77         myVertexMap.Add(aV);
78       }
79       aIt.Next();
80     }
81     /*
82     TopExp_Explorer vertices( edges.Current(), TopAbs_VERTEX );
83     while( vertices.More() ) {
84       TopoDS_Vertex current = TopoDS::Vertex( vertices.Current() );
85       if ( current.Orientation() == TopAbs_INTERNAL )
86         myVertexMap.Add( current );
87       vertices.Next();
88     }
89     */
90     //xt
91     edges.Next();
92   }
93 #endif
94 }
95
96 //=======================================================================
97 //function : InitFace
98 //purpose  : 
99 //=======================================================================
100
101 void Prs3d_ShapeTool::InitFace() 
102 {
103   myFaceExplorer.Init(myShape,TopAbs_FACE);
104 }
105
106 //=======================================================================
107 //function : MoreFace
108 //purpose  : 
109 //=======================================================================
110
111 Standard_Boolean Prs3d_ShapeTool::MoreFace() const 
112 {
113   return myFaceExplorer.More();
114 }
115
116 //=======================================================================
117 //function : NextFace
118 //purpose  : 
119 //=======================================================================
120
121 void Prs3d_ShapeTool::NextFace() 
122 {
123   myFaceExplorer.Next();
124 }
125
126 //=======================================================================
127 //function : GetFace
128 //purpose  : 
129 //=======================================================================
130
131 const TopoDS_Face& Prs3d_ShapeTool::GetFace () const 
132 {
133   return TopoDS::Face(myFaceExplorer.Current());
134 }
135
136
137 //=======================================================================
138 //function : FaceBound
139 //purpose  : 
140 //=======================================================================
141
142 Bnd_Box Prs3d_ShapeTool::FaceBound() const 
143 {
144   const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
145   Bnd_Box B;
146   BRepBndLib::Add(F, B);
147   return B;
148 }
149
150 //=======================================================================
151 //function : IsPlanarFace
152 //purpose  : 
153 //=======================================================================
154
155 Standard_Boolean Prs3d_ShapeTool::IsPlanarFace() const 
156 {
157   TopLoc_Location l;
158   const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
159   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F, l);
160   Handle(Standard_Type) TheType = S->DynamicType();
161
162   if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
163     Handle(Geom_RectangularTrimmedSurface) 
164         RTS = *((Handle(Geom_RectangularTrimmedSurface)*)&S);
165     TheType = RTS->BasisSurface()->DynamicType();
166   }
167   return (TheType == STANDARD_TYPE(Geom_Plane));
168 }
169
170
171
172 //=======================================================================
173 //function : InitCurve
174 //purpose  : 
175 //=======================================================================
176
177 void Prs3d_ShapeTool::InitCurve() 
178 {
179   myEdge = 1;
180 }
181
182 //=======================================================================
183 //function : MoreCurve
184 //purpose  : 
185 //=======================================================================
186
187 Standard_Boolean Prs3d_ShapeTool::MoreCurve() const 
188 {
189   return myEdge <= myEdgeMap.Extent();
190 }
191
192 //=======================================================================
193 //function : NextCurve
194 //purpose  : 
195 //=======================================================================
196
197 void Prs3d_ShapeTool::NextCurve() 
198 {
199   myEdge++;
200 }
201
202 //=======================================================================
203 //function : GetCurve
204 //purpose  : 
205 //=======================================================================
206
207 const TopoDS_Edge& Prs3d_ShapeTool::GetCurve () const 
208 {
209   return  TopoDS::Edge(myEdgeMap.FindKey(myEdge));
210 }
211
212 //=======================================================================
213 //function : CurveBound
214 //purpose  : 
215 //=======================================================================
216
217 Bnd_Box Prs3d_ShapeTool::CurveBound () const 
218 {
219   const TopoDS_Edge& E = TopoDS::Edge(myEdgeMap.FindKey(myEdge));
220   Bnd_Box B;
221   BRepBndLib::Add(E, B);
222   return B;
223 }
224
225 //=======================================================================
226 //function : Neighbours
227 //purpose  : 
228 //=======================================================================
229
230 Standard_Integer Prs3d_ShapeTool::Neighbours () const 
231 {
232   const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
233   return L.Extent();
234 }
235
236 //=======================================================================
237 //function : FacesOfEdge
238 //purpose  : 
239 //=======================================================================
240
241 Handle(TopTools_HSequenceOfShape) Prs3d_ShapeTool::FacesOfEdge () const 
242 {
243   Handle(TopTools_HSequenceOfShape) H = new TopTools_HSequenceOfShape;
244
245   const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
246   TopTools_ListIteratorOfListOfShape LI;
247
248   for (LI.Initialize(L); LI.More(); LI.Next()) H->Append(LI.Value());
249   return H;
250 }
251
252
253 //=======================================================================
254 //function : InitVertex
255 //purpose  : 
256 //=======================================================================
257
258 void Prs3d_ShapeTool::InitVertex() 
259 {
260   myVertex = 1;
261 }
262
263 //=======================================================================
264 //function : MoreVertex
265 //purpose  : 
266 //=======================================================================
267
268 Standard_Boolean Prs3d_ShapeTool::MoreVertex() const 
269 {
270   return myVertex <= myVertexMap.Extent();
271 }
272
273 //=======================================================================
274 //function : NextVertex
275 //purpose  : 
276 //=======================================================================
277
278 void Prs3d_ShapeTool::NextVertex() 
279 {
280   myVertex++;
281 }
282
283 //=======================================================================
284 //function : GetVertex
285 //purpose  : 
286 //=======================================================================
287
288 const TopoDS_Vertex& Prs3d_ShapeTool::GetVertex () const 
289 {
290   return  TopoDS::Vertex(myVertexMap.FindKey(myVertex));
291 }
292
293
294 //=======================================================================
295 //function : HasSurface
296 //purpose  : 
297 //=======================================================================
298
299 Standard_Boolean Prs3d_ShapeTool::HasSurface() const
300 {
301   TopLoc_Location l;
302   const Handle(Geom_Surface)& S = BRep_Tool::Surface(GetFace(), l);
303   return (!S.IsNull());
304 }
305
306
307
308 //=======================================================================
309 //function : CurrentTriangulation
310 //purpose  : 
311 //=======================================================================
312
313 Handle(Poly_Triangulation) Prs3d_ShapeTool::CurrentTriangulation(TopLoc_Location& l) const
314 {
315   return BRep_Tool::Triangulation(GetFace(), l);
316 }
317
318
319 //=======================================================================
320 //function : HasCurve
321 //purpose  : 
322 //=======================================================================
323
324 Standard_Boolean Prs3d_ShapeTool::HasCurve() const
325 {
326   return (BRep_Tool::IsGeometric(GetCurve()));
327 }
328
329
330
331
332 //=======================================================================
333 //function : PolygonOnTriangulation
334 //purpose  : 
335 //=======================================================================
336
337 void Prs3d_ShapeTool::PolygonOnTriangulation
338 (Handle(Poly_PolygonOnTriangulation)& Indices,
339  Handle(Poly_Triangulation)&          T,
340  TopLoc_Location&                     l) const
341 {
342   BRep_Tool::PolygonOnTriangulation(GetCurve(), Indices, T, l);
343 }
344
345
346
347 //=======================================================================
348 //function : Polygon3D
349 //purpose  : 
350 //=======================================================================
351
352 Handle(Poly_Polygon3D) Prs3d_ShapeTool::Polygon3D(TopLoc_Location& l) const
353 {
354   return BRep_Tool::Polygon3D(GetCurve(), l);
355 }