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