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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Bnd_Box.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepTools.hxx>
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>
32 #include <TopLoc_Location.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>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
42 //=======================================================================
43 //function : Prs3d_ShapeTool
45 //=======================================================================
46 Prs3d_ShapeTool::Prs3d_ShapeTool (const TopoDS_Shape& theShape,
47 const Standard_Boolean theAllVertices)
52 TopExp::MapShapesAndAncestors (theShape,TopAbs_EDGE,TopAbs_FACE, myEdgeMap);
54 TopExp_Explorer anExpl;
57 for (anExpl.Init (theShape, TopAbs_VERTEX); anExpl.More(); anExpl.Next())
59 myVertexMap.Add (anExpl.Current());
64 // Extracting isolated vertices
65 for (anExpl.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExpl.More(); anExpl.Next())
67 myVertexMap.Add (anExpl.Current());
70 // Extracting internal vertices
71 for (anExpl.Init (theShape, TopAbs_EDGE); anExpl.More(); anExpl.Next())
73 TopoDS_Iterator aIt (anExpl.Current(), Standard_False, Standard_True);
74 for (; aIt.More(); aIt.Next())
76 const TopoDS_Shape& aV = aIt.Value();
77 if (aV.Orientation() == TopAbs_INTERNAL)
86 //=======================================================================
89 //=======================================================================
91 void Prs3d_ShapeTool::InitFace()
93 myFaceExplorer.Init(myShape,TopAbs_FACE);
96 //=======================================================================
99 //=======================================================================
101 Standard_Boolean Prs3d_ShapeTool::MoreFace() const
103 return myFaceExplorer.More();
106 //=======================================================================
107 //function : NextFace
109 //=======================================================================
111 void Prs3d_ShapeTool::NextFace()
113 myFaceExplorer.Next();
116 //=======================================================================
119 //=======================================================================
121 const TopoDS_Face& Prs3d_ShapeTool::GetFace () const
123 return TopoDS::Face(myFaceExplorer.Current());
127 //=======================================================================
128 //function : FaceBound
130 //=======================================================================
132 Bnd_Box Prs3d_ShapeTool::FaceBound() const
134 const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
136 BRepBndLib::Add(F, B);
140 //=======================================================================
141 //function : IsPlanarFace
143 //=======================================================================
145 Standard_Boolean Prs3d_ShapeTool::IsPlanarFace() const
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();
152 if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
153 Handle(Geom_RectangularTrimmedSurface)
154 RTS = Handle(Geom_RectangularTrimmedSurface)::DownCast (S);
155 TheType = RTS->BasisSurface()->DynamicType();
157 return (TheType == STANDARD_TYPE(Geom_Plane));
162 //=======================================================================
163 //function : InitCurve
165 //=======================================================================
167 void Prs3d_ShapeTool::InitCurve()
172 //=======================================================================
173 //function : MoreCurve
175 //=======================================================================
177 Standard_Boolean Prs3d_ShapeTool::MoreCurve() const
179 return myEdge <= myEdgeMap.Extent();
182 //=======================================================================
183 //function : NextCurve
185 //=======================================================================
187 void Prs3d_ShapeTool::NextCurve()
192 //=======================================================================
193 //function : GetCurve
195 //=======================================================================
197 const TopoDS_Edge& Prs3d_ShapeTool::GetCurve () const
199 return TopoDS::Edge(myEdgeMap.FindKey(myEdge));
202 //=======================================================================
203 //function : CurveBound
205 //=======================================================================
207 Bnd_Box Prs3d_ShapeTool::CurveBound () const
209 const TopoDS_Edge& E = TopoDS::Edge(myEdgeMap.FindKey(myEdge));
211 BRepBndLib::Add(E, B);
215 //=======================================================================
216 //function : Neighbours
218 //=======================================================================
220 Standard_Integer Prs3d_ShapeTool::Neighbours () const
222 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
226 //=======================================================================
227 //function : FacesOfEdge
229 //=======================================================================
231 Handle(TopTools_HSequenceOfShape) Prs3d_ShapeTool::FacesOfEdge () const
233 Handle(TopTools_HSequenceOfShape) H = new TopTools_HSequenceOfShape;
235 const TopTools_ListOfShape& L = myEdgeMap.FindFromIndex(myEdge);
236 TopTools_ListIteratorOfListOfShape LI;
238 for (LI.Initialize(L); LI.More(); LI.Next()) H->Append(LI.Value());
243 //=======================================================================
244 //function : InitVertex
246 //=======================================================================
248 void Prs3d_ShapeTool::InitVertex()
253 //=======================================================================
254 //function : MoreVertex
256 //=======================================================================
258 Standard_Boolean Prs3d_ShapeTool::MoreVertex() const
260 return myVertex <= myVertexMap.Extent();
263 //=======================================================================
264 //function : NextVertex
266 //=======================================================================
268 void Prs3d_ShapeTool::NextVertex()
273 //=======================================================================
274 //function : GetVertex
276 //=======================================================================
278 const TopoDS_Vertex& Prs3d_ShapeTool::GetVertex () const
280 return TopoDS::Vertex(myVertexMap.FindKey(myVertex));
284 //=======================================================================
285 //function : HasSurface
287 //=======================================================================
289 Standard_Boolean Prs3d_ShapeTool::HasSurface() const
292 const Handle(Geom_Surface)& S = BRep_Tool::Surface(GetFace(), l);
293 return (!S.IsNull());
298 //=======================================================================
299 //function : CurrentTriangulation
301 //=======================================================================
303 Handle(Poly_Triangulation) Prs3d_ShapeTool::CurrentTriangulation(TopLoc_Location& l) const
305 return BRep_Tool::Triangulation(GetFace(), l);
309 //=======================================================================
310 //function : HasCurve
312 //=======================================================================
314 Standard_Boolean Prs3d_ShapeTool::HasCurve() const
316 return (BRep_Tool::IsGeometric(GetCurve()));
322 //=======================================================================
323 //function : PolygonOnTriangulation
325 //=======================================================================
327 void Prs3d_ShapeTool::PolygonOnTriangulation
328 (Handle(Poly_PolygonOnTriangulation)& Indices,
329 Handle(Poly_Triangulation)& T,
330 TopLoc_Location& l) const
332 BRep_Tool::PolygonOnTriangulation(GetCurve(), Indices, T, l);
337 //=======================================================================
338 //function : Polygon3D
340 //=======================================================================
342 Handle(Poly_Polygon3D) Prs3d_ShapeTool::Polygon3D(TopLoc_Location& l) const
344 return BRep_Tool::Polygon3D(GetCurve(), l);