1 // Created on: 1993-07-07 2 // Created by: Remi LEQUETTE 3 // Copyright (c) 1993-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 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. 13 // 14 // Alternatively, this file may be used under the terms of Open CASCADE 15 // commercial license or contractual agreement. 16 17 #ifndef _BRep_Tool_HeaderFile 18 #define _BRep_Tool_HeaderFile 19 20 #include <Standard.hxx> 21 #include <Standard_DefineAlloc.hxx> 22 #include <Standard_Handle.hxx> 23 24 #include <GeomAbs_Shape.hxx> 25 #include <Geom_Surface.hxx> 26 #include <Geom_Curve.hxx> 27 #include <Geom2d_Curve.hxx> 28 #include <gp_Pnt2d.hxx> 29 #include <gp_Pnt.hxx> 30 #include <Poly_ListOfTriangulation.hxx> 31 #include <Poly_Polygon3D.hxx> 32 #include <Poly_Polygon2D.hxx> 33 #include <Poly_PolygonOnTriangulation.hxx> 34 #include <TopAbs_ShapeEnum.hxx> 35 36 class TopoDS_Shape; 37 class TopoDS_Face; 38 class TopLoc_Location; 39 class TopoDS_Edge; 40 class TopoDS_Vertex; 41 42 43 //! Provides class methods to access to the geometry 44 //! of BRep shapes. 45 class BRep_Tool 46 { 47 public: 48 49 DEFINE_STANDARD_ALLOC 50 51 52 //! If S is Shell, returns True if it has no free boundaries (edges). 53 //! If S is Wire, returns True if it has no free ends (vertices). 54 //! (Internal and External sub-shepes are ignored in these checks) 55 //! If S is Edge, returns True if its vertices are the same. 56 //! For other shape types returns S.Closed(). 57 Standard_EXPORT static Standard_Boolean IsClosed (const TopoDS_Shape& S); 58 59 //! Returns the geometric surface of the face. Returns 60 //! in <L> the location for the surface. 61 Standard_EXPORT static const Handle(Geom_Surface)& Surface (const TopoDS_Face& F, TopLoc_Location& L); 62 63 //! Returns the geometric surface of the face. It can 64 //! be a copy if there is a Location. 65 Standard_EXPORT static Handle(Geom_Surface) Surface (const TopoDS_Face& F); 66 67 //! Returns the triangulation of the face according to the mesh purpose. 68 //! @param theFace [in] the input face to find triangulation. 69 //! @param theLocation [out] the face location. 70 //! @param theMeshPurpose [in] a mesh purpose to find appropriate triangulation (NONE by default). 71 //! @return an active triangulation in case of NONE purpose, 72 //! the first triangulation appropriate for the input purpose, 73 //! just the first triangulation if none matching other criteria and input purpose is AnyFallback 74 //! or null handle if there is no any suitable triangulation. 75 Standard_EXPORT static const Handle(Poly_Triangulation)& Triangulation (const TopoDS_Face& theFace, TopLoc_Location& theLocation, 76 const Poly_MeshPurpose theMeshPurpose = Poly_MeshPurpose_NONE); 77 78 //! Returns all triangulations of the face. 79 //! @param theFace [in] the input face. 80 //! @param theLocation [out] the face location. 81 //! @return list of all available face triangulations. 82 Standard_EXPORT static const Poly_ListOfTriangulation& Triangulations (const TopoDS_Face& theFace, TopLoc_Location& theLocation); 83 84 //! Returns the tolerance of the face. 85 Standard_EXPORT static Standard_Real Tolerance (const TopoDS_Face& F); 86 87 //! Returns the NaturalRestriction flag of the face. 88 Standard_EXPORT static Standard_Boolean NaturalRestriction (const TopoDS_Face& F); 89 90 //! Returns True if <F> has a surface, false otherwise. 91 Standard_EXPORT static Standard_Boolean IsGeometric (const TopoDS_Face& F); 92 93 //! Returns True if <E> is a 3d curve or a curve on 94 //! surface. 95 Standard_EXPORT static Standard_Boolean IsGeometric (const TopoDS_Edge& E); 96 97 //! Returns the 3D curve of the edge. May be a Null 98 //! handle. Returns in <L> the location for the curve. 99 //! In <First> and <Last> the parameter range. 100 Standard_EXPORT static const Handle(Geom_Curve)& Curve (const TopoDS_Edge& E, TopLoc_Location& L, Standard_Real& First, Standard_Real& Last); 101 102 //! Returns the 3D curve of the edge. May be a Null handle. 103 //! In <First> and <Last> the parameter range. 104 //! It can be a copy if there is a Location. 105 Standard_EXPORT static Handle(Geom_Curve) Curve (const TopoDS_Edge& E, Standard_Real& First, Standard_Real& Last); 106 107 //! Returns the 3D polygon of the edge. May be a Null 108 //! handle. Returns in <L> the location for the polygon. 109 Standard_EXPORT static const Handle(Poly_Polygon3D)& Polygon3D (const TopoDS_Edge& E, TopLoc_Location& L); 110 111 //! Returns the curve associated to the edge in the 112 //! parametric space of the face. Returns a NULL 113 //! handle if this curve does not exist. Returns in 114 //! <First> and <Last> the parameter range. 115 //! If the surface is a plane the curve can be not stored but created a new 116 //! each time. The flag pointed by <theIsStored> serves to indicate storage status. 117 //! It is valued if the pointer is non-null. 118 Standard_EXPORT static Handle(Geom2d_Curve) CurveOnSurface (const TopoDS_Edge& E, 119 const TopoDS_Face& F, 120 Standard_Real& First, 121 Standard_Real& Last, 122 Standard_Boolean* theIsStored = NULL); 123 124 //! Returns the curve associated to the edge in the 125 //! parametric space of the surface. Returns a NULL 126 //! handle if this curve does not exist. Returns in 127 //! <First> and <Last> the parameter range. 128 //! If the surface is a plane the curve can be not stored but created a new 129 //! each time. The flag pointed by <theIsStored> serves to indicate storage status. 130 //! It is valued if the pointer is non-null. 131 Standard_EXPORT static Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, 132 const Handle(Geom_Surface)& S, 133 const TopLoc_Location& L, 134 Standard_Real& First, 135 Standard_Real& Last, 136 Standard_Boolean* theIsStored = NULL); 137 138 //! For the planar surface builds the 2d curve for the edge 139 //! by projection of the edge on plane. 140 //! Returns a NULL handle if the surface is not planar or 141 //! the projection failed. 142 Standard_EXPORT static Handle(Geom2d_Curve) CurveOnPlane (const TopoDS_Edge& E, 143 const Handle(Geom_Surface)& S, 144 const TopLoc_Location& L, 145 Standard_Real& First, 146 Standard_Real& Last); 147 148 //! Returns in <C>, <S>, <L> a 2d curve, a surface and 149 //! a location for the edge <E>. <C> and <S> are null 150 //! if the edge has no curve on surface. Returns in 151 //! <First> and <Last> the parameter range. 152 Standard_EXPORT static void CurveOnSurface (const TopoDS_Edge& E, Handle(Geom2d_Curve)& C, Handle(Geom_Surface)& S, TopLoc_Location& L, Standard_Real& First, Standard_Real& Last); 153 154 //! Returns in <C>, <S>, <L> the 2d curve, the surface 155 //! and the location for the edge <E> of rank <Index>. 156 //! <C> and <S> are null if the index is out of range. 157 //! Returns in <First> and <Last> the parameter range. 158 Standard_EXPORT static void CurveOnSurface (const TopoDS_Edge& E, Handle(Geom2d_Curve)& C, Handle(Geom_Surface)& S, TopLoc_Location& L, Standard_Real& First, Standard_Real& Last, const Standard_Integer Index); 159 160 //! Returns the polygon associated to the edge in the 161 //! parametric space of the face. Returns a NULL 162 //! handle if this polygon does not exist. 163 Standard_EXPORT static Handle(Poly_Polygon2D) PolygonOnSurface (const TopoDS_Edge& E, const TopoDS_Face& F); 164 165 //! Returns the polygon associated to the edge in the 166 //! parametric space of the surface. Returns a NULL 167 //! handle if this polygon does not exist. 168 Standard_EXPORT static Handle(Poly_Polygon2D) PolygonOnSurface (const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L); 169 170 //! Returns in <C>, <S>, <L> a 2d curve, a surface and 171 //! a location for the edge <E>. <C> and <S> are null 172 //! if the edge has no polygon on surface. 173 Standard_EXPORT static void PolygonOnSurface (const TopoDS_Edge& E, Handle(Poly_Polygon2D)& C, Handle(Geom_Surface)& S, TopLoc_Location& L); 174 175 //! Returns in <C>, <S>, <L> the 2d curve, the surface 176 //! and the location for the edge <E> of rank <Index>. 177 //! <C> and <S> are null if the index is out of range. 178 Standard_EXPORT static void PolygonOnSurface (const TopoDS_Edge& E, Handle(Poly_Polygon2D)& C, Handle(Geom_Surface)& S, TopLoc_Location& L, const Standard_Integer Index); 179 180 //! Returns the polygon associated to the edge in the 181 //! parametric space of the face. Returns a NULL 182 //! handle if this polygon does not exist. 183 Standard_EXPORT static const Handle(Poly_PolygonOnTriangulation)& PolygonOnTriangulation (const TopoDS_Edge& E, const Handle(Poly_Triangulation)& T, const TopLoc_Location& L); 184 185 //! Returns in <P>, <T>, <L> a polygon on triangulation, a 186 //! triangulation and a location for the edge <E>. 187 //! <P> and <T> are null if the edge has no 188 //! polygon on triangulation. 189 Standard_EXPORT static void PolygonOnTriangulation (const TopoDS_Edge& E, Handle(Poly_PolygonOnTriangulation)& P, Handle(Poly_Triangulation)& T, TopLoc_Location& L); 190 191 //! Returns in <P>, <T>, <L> a polygon on 192 //! triangulation, a triangulation and a location for 193 //! the edge <E> for the range index. <C> and <S> are 194 //! null if the edge has no polygon on triangulation. 195 Standard_EXPORT static void PolygonOnTriangulation (const TopoDS_Edge& E, Handle(Poly_PolygonOnTriangulation)& P, Handle(Poly_Triangulation)& T, TopLoc_Location& L, const Standard_Integer Index); 196 197 //! Returns True if <E> has two PCurves in the 198 //! parametric space of <F>. i.e. <F> is on a closed 199 //! surface and <E> is on the closing curve. 200 Standard_EXPORT static Standard_Boolean IsClosed (const TopoDS_Edge& E, const TopoDS_Face& F); 201 202 //! Returns True if <E> has two PCurves in the 203 //! parametric space of <S>. i.e. <S> is a closed 204 //! surface and <E> is on the closing curve. 205 Standard_EXPORT static Standard_Boolean IsClosed (const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L); 206 207 //! Returns True if <E> has two arrays of indices in 208 //! the triangulation <T>. 209 Standard_EXPORT static Standard_Boolean IsClosed (const TopoDS_Edge& E, const Handle(Poly_Triangulation)& T, const TopLoc_Location& L); 210 211 //! Returns the tolerance for <E>. 212 Standard_EXPORT static Standard_Real Tolerance (const TopoDS_Edge& E); 213 214 //! Returns the SameParameter flag for the edge. 215 Standard_EXPORT static Standard_Boolean SameParameter (const TopoDS_Edge& E); 216 217 //! Returns the SameRange flag for the edge. 218 Standard_EXPORT static Standard_Boolean SameRange (const TopoDS_Edge& E); 219 220 //! Returns True if the edge is degenerated. 221 Standard_EXPORT static Standard_Boolean Degenerated (const TopoDS_Edge& E); 222 223 //! Gets the range of the 3d curve. 224 Standard_EXPORT static void Range (const TopoDS_Edge& E, Standard_Real& First, Standard_Real& Last); 225 226 //! Gets the range of the edge on the pcurve on the 227 //! surface. 228 Standard_EXPORT static void Range (const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L, Standard_Real& First, Standard_Real& Last); 229 230 //! Gets the range of the edge on the pcurve on the face. 231 Standard_EXPORT static void Range (const TopoDS_Edge& E, const TopoDS_Face& F, Standard_Real& First, Standard_Real& Last); 232 233 //! Gets the UV locations of the extremities of the edge. 234 Standard_EXPORT static void UVPoints (const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L, gp_Pnt2d& PFirst, gp_Pnt2d& PLast); 235 236 //! Gets the UV locations of the extremities of the edge. 237 Standard_EXPORT static void UVPoints (const TopoDS_Edge& E, const TopoDS_Face& F, gp_Pnt2d& PFirst, gp_Pnt2d& PLast); 238 239 //! Sets the UV locations of the extremities of the edge. 240 Standard_EXPORT static void SetUVPoints (const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L, const gp_Pnt2d& PFirst, const gp_Pnt2d& PLast); 241 242 //! Sets the UV locations of the extremities of the edge. 243 Standard_EXPORT static void SetUVPoints (const TopoDS_Edge& E, const TopoDS_Face& F, const gp_Pnt2d& PFirst, const gp_Pnt2d& PLast); 244 245 //! Returns True if the edge is on the surfaces of the 246 //! two faces. 247 Standard_EXPORT static Standard_Boolean HasContinuity (const TopoDS_Edge& E, const TopoDS_Face& F1, const TopoDS_Face& F2); 248 249 //! Returns the continuity. 250 Standard_EXPORT static GeomAbs_Shape Continuity (const TopoDS_Edge& E, const TopoDS_Face& F1, const TopoDS_Face& F2); 251 252 //! Returns True if the edge is on the surfaces. 253 Standard_EXPORT static Standard_Boolean HasContinuity (const TopoDS_Edge& E, const Handle(Geom_Surface)& S1, const Handle(Geom_Surface)& S2, const TopLoc_Location& L1, const TopLoc_Location& L2); 254 255 //! Returns the continuity. 256 Standard_EXPORT static GeomAbs_Shape Continuity (const TopoDS_Edge& E, const Handle(Geom_Surface)& S1, const Handle(Geom_Surface)& S2, const TopLoc_Location& L1, const TopLoc_Location& L2); 257 258 //! Returns True if the edge has regularity on some 259 //! two surfaces 260 Standard_EXPORT static Standard_Boolean HasContinuity (const TopoDS_Edge& E); 261 262 //! Returns the max continuity of edge between some surfaces or GeomAbs_C0 if there no such surfaces. 263 Standard_EXPORT static GeomAbs_Shape MaxContinuity (const TopoDS_Edge& theEdge); 264 265 //! Returns the 3d point. 266 Standard_EXPORT static gp_Pnt Pnt (const TopoDS_Vertex& V); 267 268 //! Returns the tolerance. 269 Standard_EXPORT static Standard_Real Tolerance (const TopoDS_Vertex& V); 270 271 //! Finds the parameter of <theV> on <theE>. 272 //! @param theV [in] input vertex 273 //! @param theE [in] input edge 274 //! @param theParam [out] calculated parameter on the curve 275 //! @return TRUE if done 276 Standard_EXPORT static Standard_Boolean Parameter (const TopoDS_Vertex& theV, 277 const TopoDS_Edge& theE, 278 Standard_Real &theParam); 279 280 //! Returns the parameter of <V> on <E>. 281 //! Throws Standard_NoSuchObject if no parameter on edge 282 Standard_EXPORT static Standard_Real Parameter (const TopoDS_Vertex& V, const TopoDS_Edge& E); 283 284 //! Returns the parameters of the vertex on the 285 //! pcurve of the edge on the face. 286 Standard_EXPORT static Standard_Real Parameter (const TopoDS_Vertex& V, const TopoDS_Edge& E, const TopoDS_Face& F); 287 288 //! Returns the parameters of the vertex on the 289 //! pcurve of the edge on the surface. 290 Standard_EXPORT static Standard_Real Parameter (const TopoDS_Vertex& V, const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L); 291 292 //! Returns the parameters of the vertex on the face. 293 Standard_EXPORT static gp_Pnt2d Parameters (const TopoDS_Vertex& V, const TopoDS_Face& F); 294 295 //! Returns the maximum tolerance of input shape subshapes. 296 //@param theShape - Shape to search tolerance. 297 //@param theSubShape - Search subshape, only Face, Edge or Vertex are supported. 298 Standard_EXPORT static Standard_Real MaxTolerance (const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theSubShape); 299 300 }; 301 302 #endif // _BRep_Tool_HeaderFile 303