1 // Created on: 1992-08-28 2 // Created by: Remi LEQUETTE 3 // Copyright (c) 1992-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 _BRepTools_HeaderFile 18 #define _BRepTools_HeaderFile 19 20 #include <TopTools_FormatVersion.hxx> 21 #include <Standard.hxx> 22 #include <Standard_DefineAlloc.hxx> 23 #include <Standard_Handle.hxx> 24 25 #include <Standard_Real.hxx> 26 #include <Standard_Boolean.hxx> 27 #include <TopTools_IndexedMapOfShape.hxx> 28 #include <Standard_OStream.hxx> 29 #include <Standard_IStream.hxx> 30 #include <Standard_CString.hxx> 31 #include <Message_ProgressRange.hxx> 32 #include <TopTools_ListOfShape.hxx> 33 34 class TopoDS_Face; 35 class TopoDS_Wire; 36 class TopoDS_Edge; 37 class Bnd_Box2d; 38 class TopoDS_Vertex; 39 class TopoDS_Shell; 40 class TopoDS_Solid; 41 class TopoDS_CompSolid; 42 class TopoDS_Compound; 43 class TopoDS_Shape; 44 class BRep_Builder; 45 class Geom_Curve; 46 class Geom2d_Curve; 47 class Geom_Surface; 48 class OSD_FileSystem; 49 50 51 //! The BRepTools package provides utilities for BRep 52 //! data structures. 53 //! 54 //! * WireExplorer : A tool to explore the topology of 55 //! a wire in the order of the edges. 56 //! 57 //! * ShapeSet : Tools used for dumping, writing and 58 //! reading. 59 //! 60 //! * UVBounds : Methods to compute the limits of the 61 //! boundary of a face, a wire or an edge in the 62 //! parametric space of a face. 63 //! 64 //! * Update : Methods to call when a topology has 65 //! been created to compute all missing data. 66 //! 67 //! * UpdateFaceUVPoints: Method to update the UV points 68 //! stored with the edges on a face. 69 //! 70 //! * Compare : Method to compare two vertices. 71 //! 72 //! * Compare : Method to compare two edges. 73 //! 74 //! * OuterWire : A method to find the outer wire of a 75 //! face. 76 //! 77 //! * Map3DEdges : A method to map all the 3D Edges of 78 //! a Shape. 79 //! 80 //! * Dump : A method to dump a BRep object. 81 class BRepTools 82 { 83 public: 84 85 DEFINE_STANDARD_ALLOC 86 87 88 //! Returns in UMin, UMax, VMin, VMax the bounding 89 //! values in the parametric space of F. 90 Standard_EXPORT static void UVBounds (const TopoDS_Face& F, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax); 91 92 //! Returns in UMin, UMax, VMin, VMax the bounding 93 //! values of the wire in the parametric space of F. 94 Standard_EXPORT static void UVBounds (const TopoDS_Face& F, const TopoDS_Wire& W, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax); 95 96 //! Returns in UMin, UMax, VMin, VMax the bounding 97 //! values of the edge in the parametric space of F. 98 Standard_EXPORT static void UVBounds (const TopoDS_Face& F, const TopoDS_Edge& E, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax); 99 100 //! Adds to the box <B> the bounding values in the 101 //! parametric space of F. 102 Standard_EXPORT static void AddUVBounds (const TopoDS_Face& F, Bnd_Box2d& B); 103 104 //! Adds to the box <B> the bounding values of the 105 //! wire in the parametric space of F. 106 Standard_EXPORT static void AddUVBounds (const TopoDS_Face& F, const TopoDS_Wire& W, Bnd_Box2d& B); 107 108 //! Adds to the box <B> the bounding values of the 109 //! edge in the parametric space of F. 110 Standard_EXPORT static void AddUVBounds (const TopoDS_Face& F, const TopoDS_Edge& E, Bnd_Box2d& B); 111 112 //! Update a vertex (nothing is done) 113 Standard_EXPORT static void Update (const TopoDS_Vertex& V); 114 115 //! Update an edge, compute 2d bounding boxes. 116 Standard_EXPORT static void Update (const TopoDS_Edge& E); 117 118 //! Update a wire (nothing is done) 119 Standard_EXPORT static void Update (const TopoDS_Wire& W); 120 121 //! Update a Face, update UV points. 122 Standard_EXPORT static void Update (const TopoDS_Face& F); 123 124 //! Update a shell (nothing is done) 125 Standard_EXPORT static void Update (const TopoDS_Shell& S); 126 127 //! Update a solid (nothing is done) 128 Standard_EXPORT static void Update (const TopoDS_Solid& S); 129 130 //! Update a composite solid (nothing is done) 131 Standard_EXPORT static void Update (const TopoDS_CompSolid& C); 132 133 //! Update a compound (nothing is done) 134 Standard_EXPORT static void Update (const TopoDS_Compound& C); 135 136 //! Update a shape, call the correct update. 137 Standard_EXPORT static void Update (const TopoDS_Shape& S); 138 139 //! For each edge of the face <F> reset the UV points 140 //! to the bounding points of the parametric curve of the 141 //! edge on the face. 142 Standard_EXPORT static void UpdateFaceUVPoints (const TopoDS_Face& theF); 143 144 //! Removes all cached polygonal representation of the shape, 145 //! i.e. the triangulations of the faces of <S> and polygons on 146 //! triangulations and polygons 3d of the edges. 147 //! In case polygonal representation is the only available representation 148 //! for the shape (shape does not have geometry) it is not removed. 149 //! @param theShape [in] the shape to clean 150 //! @param theForce [in] allows removing all polygonal representations from the shape, 151 //! including polygons on triangulations irrelevant for the faces of the given shape. 152 Standard_EXPORT static void Clean (const TopoDS_Shape& theShape, const Standard_Boolean theForce = Standard_False); 153 154 //! Removes geometry (curves and surfaces) from all edges and faces of the shape 155 Standard_EXPORT static void CleanGeometry(const TopoDS_Shape& theShape); 156 157 //! Removes all the pcurves of the edges of <S> that 158 //! refer to surfaces not belonging to any face of <S> 159 Standard_EXPORT static void RemoveUnusedPCurves (const TopoDS_Shape& S); 160 161 public: 162 163 //! Verifies that each Face from the shape has got a triangulation with a deflection smaller or equal to specified one 164 //! and the Edges a discretization on this triangulation. 165 //! @param theShape [in] shape to verify 166 //! @param theLinDefl [in] maximum allowed linear deflection 167 //! @param theToCheckFreeEdges [in] if TRUE, then free Edges are required to have 3D polygon 168 //! @return FALSE if input Shape contains Faces without triangulation, 169 //! or that triangulation has worse (greater) deflection than specified one, 170 //! or Edges in Shape lack polygons on triangulation 171 //! or free Edges in Shape lack 3D polygons 172 Standard_EXPORT static Standard_Boolean Triangulation (const TopoDS_Shape& theShape, 173 const Standard_Real theLinDefl, 174 const Standard_Boolean theToCheckFreeEdges = Standard_False); 175 176 //! Loads triangulation data for each face of the shape 177 //! from some deferred storage using specified shared input file system 178 //! @param theShape [in] shape to load triangulations 179 //! @param theTriangulationIdx [in] index defining what triangulation should be loaded. Starts from 0. 180 //! -1 is used in specific case to load currently already active triangulation. 181 //! If some face doesn't contain triangulation with this index, nothing will be loaded for it. 182 //! Exception will be thrown in case of invalid negative index 183 //! @param theToSetAsActive [in] flag to activate triangulation after its loading 184 //! @param theFileSystem [in] shared file system 185 //! @return TRUE if at least one triangulation is loaded. 186 Standard_EXPORT static Standard_Boolean LoadTriangulation (const TopoDS_Shape& theShape, 187 const Standard_Integer theTriangulationIdx = -1, 188 const Standard_Boolean theToSetAsActive = Standard_False, 189 const Handle(OSD_FileSystem)& theFileSystem = Handle(OSD_FileSystem)()); 190 191 //! Releases triangulation data for each face of the shape if there is deferred storage to load it later 192 //! @param theShape [in] shape to unload triangulations 193 //! @param theTriangulationIdx [in] index defining what triangulation should be unloaded. Starts from 0. 194 //! -1 is used in specific case to unload currently already active triangulation. 195 //! If some face doesn't contain triangulation with this index, nothing will be unloaded for it. 196 //! Exception will be thrown in case of invalid negative index 197 //! @return TRUE if at least one triangulation is unloaded. 198 Standard_EXPORT static Standard_Boolean UnloadTriangulation (const TopoDS_Shape& theShape, 199 const Standard_Integer theTriangulationIdx = -1); 200 201 //! Activates triangulation data for each face of the shape 202 //! from some deferred storage using specified shared input file system 203 //! @param theShape [in] shape to activate triangulations 204 //! @param theTriangulationIdx [in] index defining what triangulation should be activated. Starts from 0. 205 //! Exception will be thrown in case of invalid negative index 206 //! @param theToActivateStrictly [in] flag to activate exactly triangulation with defined theTriangulationIdx index. 207 //! In TRUE case if some face doesn't contain triangulation with this index, active triangulation 208 //! will not be changed for it. Else the last available triangulation will be activated. 209 //! @return TRUE if at least one active triangulation was changed. 210 Standard_EXPORT static Standard_Boolean ActivateTriangulation (const TopoDS_Shape& theShape, 211 const Standard_Integer theTriangulationIdx, 212 const Standard_Boolean theToActivateStrictly = false); 213 214 //! Loads all available triangulations for each face of the shape 215 //! from some deferred storage using specified shared input file system 216 //! @param theShape [in] shape to load triangulations 217 //! @param theFileSystem [in] shared file system 218 //! @return TRUE if at least one triangulation is loaded. 219 Standard_EXPORT static Standard_Boolean LoadAllTriangulations (const TopoDS_Shape& theShape, 220 const Handle(OSD_FileSystem)& theFileSystem = Handle(OSD_FileSystem)()); 221 222 //! Releases all available triangulations for each face of the shape if there is deferred storage to load them later 223 //! @param theShape [in] shape to unload triangulations 224 //! @return TRUE if at least one triangulation is unloaded. 225 Standard_EXPORT static Standard_Boolean UnloadAllTriangulations (const TopoDS_Shape& theShape); 226 227 public: 228 229 //! Returns True if the distance between the two 230 //! vertices is lower than their tolerance. 231 Standard_EXPORT static Standard_Boolean Compare (const TopoDS_Vertex& V1, const TopoDS_Vertex& V2); 232 233 //! Returns True if the distance between the two 234 //! edges is lower than their tolerance. 235 Standard_EXPORT static Standard_Boolean Compare (const TopoDS_Edge& E1, const TopoDS_Edge& E2); 236 237 //! Returns the outer most wire of <F>. Returns a Null 238 //! wire if <F> has no wires. 239 Standard_EXPORT static TopoDS_Wire OuterWire (const TopoDS_Face& F); 240 241 //! Stores in the map <M> all the 3D topology edges 242 //! of <S>. 243 Standard_EXPORT static void Map3DEdges (const TopoDS_Shape& S, TopTools_IndexedMapOfShape& M); 244 245 //! Verifies that the edge <E> is found two times on 246 //! the face <F> before calling BRep_Tool::IsClosed. 247 Standard_EXPORT static Standard_Boolean IsReallyClosed (const TopoDS_Edge& E, const TopoDS_Face& F); 248 249 //! Detect closedness of face in U and V directions 250 Standard_EXPORT static void DetectClosedness (const TopoDS_Face& theFace, 251 Standard_Boolean& theUclosed, 252 Standard_Boolean& theVclosed); 253 254 //! Dumps the topological structure and the geometry 255 //! of <Sh> on the stream <S>. 256 Standard_EXPORT static void Dump (const TopoDS_Shape& Sh, Standard_OStream& S); 257 258 //! Writes the shape to the stream in an ASCII format TopTools_FormatVersion_VERSION_1. 259 //! This alias writes shape with triangulation data. 260 //! @param theShape [in] the shape to write 261 //! @param theStream [in][out] the stream to output shape into 262 //! @param theRange the range of progress indicator to fill in Write(const TopoDS_Shape & theShape,Standard_OStream & theStream,const Message_ProgressRange & theProgress=Message_ProgressRange ())263 static void Write (const TopoDS_Shape& theShape, 264 Standard_OStream& theStream, 265 const Message_ProgressRange& theProgress = Message_ProgressRange()) 266 { 267 Write (theShape, theStream, Standard_True, Standard_False, 268 TopTools_FormatVersion_CURRENT, theProgress); 269 } 270 271 //! Writes the shape to the stream in an ASCII format of specified version. 272 //! @param theShape [in] the shape to write 273 //! @param theStream [in][out] the stream to output shape into 274 //! @param theWithTriangles [in] flag which specifies whether to save shape with (TRUE) or without (FALSE) triangles; 275 //! has no effect on triangulation-only geometry 276 //! @param theWithNormals [in] flag which specifies whether to save triangulation with (TRUE) or without (FALSE) normals; 277 //! has no effect on triangulation-only geometry 278 //! @param theVersion [in] the TopTools format version 279 //! @param theRange the range of progress indicator to fill in 280 Standard_EXPORT static void Write (const TopoDS_Shape& theShape, 281 Standard_OStream& theStream, 282 const Standard_Boolean theWithTriangles, 283 const Standard_Boolean theWithNormals, 284 const TopTools_FormatVersion theVersion, 285 const Message_ProgressRange& theProgress = Message_ProgressRange()); 286 287 //! Reads a Shape from <S> in returns it in <Sh>. 288 //! <B> is used to build the shape. 289 Standard_EXPORT static void Read (TopoDS_Shape& Sh, Standard_IStream& S, const BRep_Builder& B, 290 const Message_ProgressRange& theProgress = Message_ProgressRange()); 291 292 //! Writes the shape to the file in an ASCII format TopTools_FormatVersion_VERSION_1. 293 //! This alias writes shape with triangulation data. 294 //! @param theShape [in] the shape to write 295 //! @param theFile [in] the path to file to output shape into 296 //! @param theRange the range of progress indicator to fill in Write(const TopoDS_Shape & theShape,const Standard_CString theFile,const Message_ProgressRange & theProgress=Message_ProgressRange ())297 static Standard_Boolean Write (const TopoDS_Shape& theShape, 298 const Standard_CString theFile, 299 const Message_ProgressRange& theProgress = Message_ProgressRange()) 300 { 301 return Write (theShape, theFile, Standard_True, Standard_False, 302 TopTools_FormatVersion_CURRENT, theProgress); 303 } 304 305 //! Writes the shape to the file in an ASCII format of specified version. 306 //! @param theShape [in] the shape to write 307 //! @param theFile [in] the path to file to output shape into 308 //! @param theWithTriangles [in] flag which specifies whether to save shape with (TRUE) or without (FALSE) triangles; 309 //! has no effect on triangulation-only geometry 310 //! @param theWithNormals [in] flag which specifies whether to save triangulation with (TRUE) or without (FALSE) normals; 311 //! has no effect on triangulation-only geometry 312 //! @param theVersion [in] the TopTools format version 313 //! @param theRange the range of progress indicator to fill in 314 Standard_EXPORT static Standard_Boolean Write (const TopoDS_Shape& theShape, 315 const Standard_CString theFile, 316 const Standard_Boolean theWithTriangles, 317 const Standard_Boolean theWithNormals, 318 const TopTools_FormatVersion theVersion, 319 const Message_ProgressRange& theProgress = Message_ProgressRange()); 320 321 //! Reads a Shape from <File>, returns it in <Sh>. 322 //! <B> is used to build the shape. 323 Standard_EXPORT static Standard_Boolean Read (TopoDS_Shape& Sh, const Standard_CString File, 324 const BRep_Builder& B, 325 const Message_ProgressRange& theProgress = Message_ProgressRange()); 326 327 //! Evals real tolerance of edge <theE>. 328 //! <theC3d>, <theC2d>, <theS>, <theF>, <theL> are 329 //! correspondently 3d curve of edge, 2d curve on surface <theS> and 330 //! rang of edge 331 //! If calculated tolerance is more then current edge tolerance, edge is updated. 332 //! Method returns actual tolerance of edge 333 Standard_EXPORT static Standard_Real EvalAndUpdateTol(const TopoDS_Edge& theE, 334 const Handle(Geom_Curve)& theC3d, 335 const Handle(Geom2d_Curve) theC2d, 336 const Handle(Geom_Surface)& theS, 337 const Standard_Real theF, 338 const Standard_Real theL); 339 340 //! returns the cumul of the orientation of <Edge> 341 //! and thc containing wire in <Face> 342 Standard_EXPORT static TopAbs_Orientation OriEdgeInFace(const TopoDS_Edge& theEdge, 343 const TopoDS_Face& theFace); 344 345 //! Removes internal sub-shapes from the shape. 346 //! The check on internal status is based on orientation of sub-shapes, 347 //! classification is not performed. 348 //! Before removal of internal sub-shapes the algorithm checks if such 349 //! removal is not going to break topological connectivity between sub-shapes. 350 //! The flag <theForce> if set to true disables the connectivity check and clears 351 //! the given shape from all sub-shapes with internal orientation. 352 Standard_EXPORT static void RemoveInternals(TopoDS_Shape& theS, 353 const Standard_Boolean theForce = Standard_False); 354 355 //! Check all locations of shape according criterium: 356 //! aTrsf.IsNegative() || (Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec()) 357 //! All sub-shapes having such locations are put in list theProblemShapes 358 Standard_EXPORT static void CheckLocations(const TopoDS_Shape& theS, 359 TopTools_ListOfShape& theProblemShapes); 360 361 protected: 362 363 364 365 366 367 private: 368 369 370 371 372 friend class BRepTools_WireExplorer; 373 friend class BRepTools_Modification; 374 friend class BRepTools_Modifier; 375 friend class BRepTools_TrsfModification; 376 friend class BRepTools_NurbsConvertModification; 377 friend class BRepTools_GTrsfModification; 378 friend class BRepTools_Substitution; 379 friend class BRepTools_Quilt; 380 friend class BRepTools_ShapeSet; 381 friend class BRepTools_ReShape; 382 383 }; 384 385 #endif // _BRepTools_HeaderFile 386