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