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