42cf5bc1 |
1 | // Created on: 1993-12-15 |
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 _BRepLib_HeaderFile |
18 | #define _BRepLib_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <Standard_Real.hxx> |
25 | #include <Standard_Boolean.hxx> |
26 | #include <GeomAbs_Shape.hxx> |
27 | #include <Standard_Integer.hxx> |
f16a6cc5 |
28 | #include <TopoDS.hxx> |
29 | #include <TopoDS_Edge.hxx> |
42cf5bc1 |
30 | #include <TopTools_ListOfShape.hxx> |
07ef8bdf |
31 | #include <NCollection_List.hxx> |
c0a1a35f |
32 | |
f16a6cc5 |
33 | class Geom2d_Curve; |
c0a1a35f |
34 | class Adaptor3d_Curve; |
42cf5bc1 |
35 | class Geom_Plane; |
42cf5bc1 |
36 | class TopoDS_Shape; |
37 | class TopoDS_Solid; |
38 | class TopoDS_Face; |
39 | class BRepLib_Command; |
40 | class BRepLib_MakeShape; |
41 | class BRepLib_MakeVertex; |
42 | class BRepLib_MakeEdge; |
43 | class BRepLib_MakeEdge2d; |
44 | class BRepLib_MakePolygon; |
45 | class BRepLib_MakeFace; |
46 | class BRepLib_MakeWire; |
47 | class BRepLib_MakeShell; |
48 | class BRepLib_MakeSolid; |
49 | class BRepLib_FindSurface; |
50 | class BRepLib_FuseEdges; |
51 | class BRepLib_CheckCurveOnSurface; |
b60e8432 |
52 | class BRepTools_ReShape; |
42cf5bc1 |
53 | |
54 | |
55 | //! The BRepLib package provides general utilities for |
56 | //! BRep. |
57 | //! |
58 | //! * FindSurface : Class to compute a surface through |
59 | //! a set of edges. |
60 | //! |
61 | //! * Compute missing 3d curve on an edge. |
62 | class BRepLib |
63 | { |
64 | public: |
65 | |
66 | DEFINE_STANDARD_ALLOC |
67 | |
68 | |
69 | |
70 | //! Computes the max distance between edge |
71 | //! and its 2d representation on the face. |
72 | //! Sets the default precision. The current Precision |
73 | //! is returned. |
74 | Standard_EXPORT static void Precision (const Standard_Real P); |
75 | |
76 | //! Returns the default precision. |
77 | Standard_EXPORT static Standard_Real Precision(); |
78 | |
79 | //! Sets the current plane to P. |
80 | Standard_EXPORT static void Plane (const Handle(Geom_Plane)& P); |
81 | |
82 | //! Returns the current plane. |
83 | Standard_EXPORT static const Handle(Geom_Plane)& Plane(); |
84 | |
85 | //! checks if the Edge is same range IGNORING |
86 | //! the same range flag of the edge |
87 | //! Confusion argument is to compare real numbers |
88 | //! idenpendently of any model space tolerance |
89 | Standard_EXPORT static Standard_Boolean CheckSameRange (const TopoDS_Edge& E, const Standard_Real Confusion = 1.0e-12); |
90 | |
91 | //! will make all the curve representation have |
92 | //! the same range domain for the parameters. |
93 | //! This will IGNORE the same range flag value |
94 | //! to proceed. |
95 | //! If there is a 3D curve there it will the |
96 | //! range of that curve. If not the first curve representation |
97 | //! encountered in the list will give its range to |
98 | //! the all the other curves. |
99 | Standard_EXPORT static void SameRange (const TopoDS_Edge& E, const Standard_Real Tolerance = 1.0e-5); |
100 | |
101 | //! Computes the 3d curve for the edge <E> if it does |
102 | //! not exist. Returns True if the curve was computed |
103 | //! or existed. Returns False if there is no planar |
104 | //! pcurve or the computation failed. |
105 | //! <MaxSegment> >= 30 in approximation |
106 | Standard_EXPORT static Standard_Boolean BuildCurve3d (const TopoDS_Edge& E, const Standard_Real Tolerance = 1.0e-5, const GeomAbs_Shape Continuity = GeomAbs_C1, const Standard_Integer MaxDegree = 14, const Standard_Integer MaxSegment = 0); |
107 | |
108 | //! Computes the 3d curves for all the edges of <S> |
109 | //! return False if one of the computation failed. |
110 | //! <MaxSegment> >= 30 in approximation |
111 | Standard_EXPORT static Standard_Boolean BuildCurves3d (const TopoDS_Shape& S, const Standard_Real Tolerance, const GeomAbs_Shape Continuity = GeomAbs_C1, const Standard_Integer MaxDegree = 14, const Standard_Integer MaxSegment = 0); |
112 | |
113 | //! Computes the 3d curves for all the edges of <S> |
114 | //! return False if one of the computation failed. |
115 | Standard_EXPORT static Standard_Boolean BuildCurves3d (const TopoDS_Shape& S); |
f16a6cc5 |
116 | |
117 | //! Builds pcurve of edge on face if the surface is plane, and updates the edge. |
118 | Standard_EXPORT static void BuildPCurveForEdgeOnPlane(const TopoDS_Edge& theE, const TopoDS_Face& theF); |
119 | |
120 | //! Builds pcurve of edge on face if the surface is plane, but does not update the edge. |
121 | //! The output are the pcurve and the flag telling that pcurve was built. |
122 | Standard_EXPORT static void BuildPCurveForEdgeOnPlane(const TopoDS_Edge& theE, const TopoDS_Face& theF, |
123 | Handle(Geom2d_Curve)& aC2D, Standard_Boolean& bToUpdate); |
124 | |
125 | //! Builds pcurves of edges on face if the surface is plane, and update the edges. |
126 | template<class TCont> static void BuildPCurveForEdgesOnPlane(const TCont& theLE, const TopoDS_Face& theF) |
127 | { |
128 | for (typename TCont::Iterator aIt(theLE); aIt.More(); aIt.Next()) |
129 | { |
130 | const TopoDS_Edge& aE = TopoDS::Edge(aIt.Value()); |
131 | if (!aE.IsNull()) |
132 | BRepLib::BuildPCurveForEdgeOnPlane(aE, theF); |
133 | } |
134 | } |
135 | |
42cf5bc1 |
136 | //! Checks if the edge has a Tolerance smaller than -- -- |
137 | //! -- -- MaxToleranceToCheck if so it will compute the |
138 | //! radius of -- the cylindrical pipe surface that |
139 | //! MinToleranceRequest is the minimum tolerance before it |
140 | //! is usefull to start testing. Usually it should be arround |
141 | //! 10e-5 |
142 | //! contains all -- the curve represenation of the edge |
143 | //! returns True if the Edge tolerance had to be updated |
144 | Standard_EXPORT static Standard_Boolean UpdateEdgeTol (const TopoDS_Edge& E, const Standard_Real MinToleranceRequest, const Standard_Real MaxToleranceToCheck); |
145 | |
146 | //! -- Checks all the edges of the shape whose -- -- -- |
147 | //! Tolerance is smaller than MaxToleranceToCheck -- |
148 | //! Returns True if at least one edge was updated -- |
149 | //! MinToleranceRequest is the minimum tolerance before |
150 | //! -- it -- is usefull to start testing. Usually it |
151 | //! should be arround -- 10e-5-- |
152 | //! |
153 | //! Warning :The method is very slow as it checks all. |
154 | //! Use only in interfaces or processing assimilate batch |
155 | Standard_EXPORT static Standard_Boolean UpdateEdgeTolerance (const TopoDS_Shape& S, const Standard_Real MinToleranceRequest, const Standard_Real MaxToleranceToCheck); |
156 | |
b60e8432 |
157 | //! Computes new 2d curve(s) for the edge <theEdge> to have |
42cf5bc1 |
158 | //! the same parameter as the 3d curve. |
159 | //! The algorithm is not done if the flag SameParameter |
160 | //! was True on the Edge. |
b60e8432 |
161 | Standard_EXPORT static void SameParameter (const TopoDS_Edge& theEdge, const Standard_Real Tolerance = 1.0e-5); |
162 | |
163 | //! Computes new 2d curve(s) for the edge <theEdge> to have |
164 | //! the same parameter as the 3d curve. |
165 | //! The algorithm is not done if the flag SameParameter |
166 | //! was True on the Edge.<br> |
167 | //! theNewTol is a new tolerance of vertices of the input edge |
168 | //! (not applied inside the algorithm, but pre-computed). |
169 | //! If IsUseOldEdge is true then the input edge will be modified, |
170 | //! otherwise the new copy of input edge will be created. |
171 | //! Returns the new edge as a result, can be ignored if IsUseOldEdge is true. |
172 | Standard_EXPORT static TopoDS_Edge SameParameter(const TopoDS_Edge& theEdge, |
173 | const Standard_Real theTolerance, Standard_Real& theNewTol, const Standard_Boolean IsUseOldEdge); |
42cf5bc1 |
174 | |
175 | //! Computes new 2d curve(s) for all the edges of <S> |
176 | //! to have the same parameter as the 3d curve. |
177 | //! The algorithm is not done if the flag SameParameter |
178 | //! was True on an Edge. |
b60e8432 |
179 | Standard_EXPORT static void SameParameter(const TopoDS_Shape& S, |
180 | const Standard_Real Tolerance = 1.0e-5, const Standard_Boolean forced = Standard_False); |
181 | |
182 | //! Computes new 2d curve(s) for all the edges of <S> |
183 | //! to have the same parameter as the 3d curve. |
184 | //! The algorithm is not done if the flag SameParameter |
185 | //! was True on an Edge.<br> |
186 | //! theReshaper is used to record the modifications of input shape <S> to prevent any |
187 | //! modifications on the shape itself. |
188 | //! Thus the input shape (and its subshapes) will not be modified, instead the reshaper will |
189 | //! contain a modified empty-copies of original subshapes as substitutions. |
190 | Standard_EXPORT static void SameParameter(const TopoDS_Shape& S, BRepTools_ReShape& theReshaper, |
191 | const Standard_Real Tolerance = 1.0e-5, const Standard_Boolean forced = Standard_False ); |
192 | |
42cf5bc1 |
193 | //! Replaces tolerance of FACE EDGE VERTEX by the |
194 | //! tolerance Max of their connected handling shapes. |
195 | //! It is not necessary to use this call after |
196 | //! SameParameter. (called in) |
197 | Standard_EXPORT static void UpdateTolerances (const TopoDS_Shape& S, const Standard_Boolean verifyFaceTolerance = Standard_False); |
b60e8432 |
198 | |
199 | //! Replaces tolerance of FACE EDGE VERTEX by the |
200 | //! tolerance Max of their connected handling shapes. |
201 | //! It is not necessary to use this call after |
202 | //! SameParameter. (called in)<br> |
203 | //! theReshaper is used to record the modifications of input shape <S> to prevent any |
204 | //! modifications on the shape itself. |
205 | //! Thus the input shape (and its subshapes) will not be modified, instead the reshaper will |
206 | //! contain a modified empty-copies of original subshapes as substitutions. |
207 | Standard_EXPORT static void UpdateTolerances (const TopoDS_Shape& S, BRepTools_ReShape& theReshaper, |
208 | const Standard_Boolean verifyFaceTolerance = Standard_False ); |
42cf5bc1 |
209 | |
420f79f8 |
210 | //! Checks tolerances of edges (including inner points) and vertices |
211 | //! of a shape and updates them to satisfy "SameParameter" condition |
212 | Standard_EXPORT static void UpdateInnerTolerances (const TopoDS_Shape& S); |
213 | |
42cf5bc1 |
214 | //! Orients the solid forward and the shell with the |
215 | //! orientation to have matter in the solid. Returns |
216 | //! False if the solid is unOrientable (open or incoherent) |
217 | Standard_EXPORT static Standard_Boolean OrientClosedSolid (TopoDS_Solid& solid); |
218 | |
219 | //! Encodes the Regularity of edges on a Shape. |
220 | //! Warning: <TolAng> is an angular tolerance, expressed in Rad. |
221 | //! Warning: If the edges's regularity are coded before, nothing |
222 | //! is done. |
223 | Standard_EXPORT static void EncodeRegularity (const TopoDS_Shape& S, const Standard_Real TolAng = 1.0e-10); |
712879c8 |
224 | |
225 | //! Encodes the Regularity of edges in list <LE> on the shape <S> |
226 | //! Warning: <TolAng> is an angular tolerance, expressed in Rad. |
227 | //! Warning: If the edges's regularity are coded before, nothing |
228 | //! is done. |
229 | Standard_EXPORT static void EncodeRegularity(const TopoDS_Shape& S, const TopTools_ListOfShape& LE, const Standard_Real TolAng = 1.0e-10); |
42cf5bc1 |
230 | |
21c7c457 |
231 | //! Encodes the Regularity between <F1> and <F2> by <E> |
42cf5bc1 |
232 | //! Warning: <TolAng> is an angular tolerance, expressed in Rad. |
233 | //! Warning: If the edge's regularity is coded before, nothing |
234 | //! is done. |
712879c8 |
235 | Standard_EXPORT static void EncodeRegularity (TopoDS_Edge& E, const TopoDS_Face& F1, const TopoDS_Face& F2, const Standard_Real TolAng = 1.0e-10); |
42cf5bc1 |
236 | |
237 | //! Sorts in LF the Faces of S on the complexity of |
238 | //! their surfaces |
239 | //! (Plane,Cylinder,Cone,Sphere,Torus,other) |
240 | Standard_EXPORT static void SortFaces (const TopoDS_Shape& S, TopTools_ListOfShape& LF); |
241 | |
242 | //! Sorts in LF the Faces of S on the reverse |
243 | //! complexity of their surfaces |
244 | //! (other,Torus,Sphere,Cone,Cylinder,Plane) |
245 | Standard_EXPORT static void ReverseSortFaces (const TopoDS_Shape& S, TopTools_ListOfShape& LF); |
246 | |
247 | //! Corrects the normals in Poly_Triangulation of faces, |
248 | //! in such way that normals at nodes lying along smooth |
249 | //! edges have the same value on both adjacent triangulations. |
250 | //! Returns TRUE if any correction is done. |
251 | Standard_EXPORT static Standard_Boolean EnsureNormalConsistency (const TopoDS_Shape& S, const Standard_Real theAngTol = 0.001, const Standard_Boolean ForceComputeNormals = Standard_False); |
252 | |
07ef8bdf |
253 | //! Calculates the bounding sphere around the set of vertexes from the theLV list. |
254 | //! Returns the center (theNewCenter) and the radius (theNewTol) of this sphere. |
255 | //! This can be used to construct the new vertex which covers the given set of |
256 | //! other vertices. |
257 | Standard_EXPORT static void BoundingVertex(const NCollection_List<TopoDS_Shape>& theLV, |
258 | gp_Pnt& theNewCenter, Standard_Real& theNewTol); |
42cf5bc1 |
259 | |
c0a1a35f |
260 | //! For an edge defined by 3d curve and tolerance and vertices defined by points, |
261 | //! parameters on curve and tolerances, |
262 | //! finds a range of curve between vertices not covered by vertices tolerances. |
263 | //! Returns false if there is no such range. Otherwise, sets theFirst and |
264 | //! theLast as its bounds. |
265 | Standard_EXPORT static Standard_Boolean FindValidRange |
266 | (const Adaptor3d_Curve& theCurve, const Standard_Real theTolE, |
267 | const Standard_Real theParV1, const gp_Pnt& thePntV1, const Standard_Real theTolV1, |
268 | const Standard_Real theParV2, const gp_Pnt& thePntV2, const Standard_Real theTolV2, |
269 | Standard_Real& theFirst, Standard_Real& theLast); |
270 | |
271 | //! Finds a range of 3d curve of the edge not covered by vertices tolerances. |
272 | //! Returns false if there is no such range. Otherwise, sets theFirst and |
273 | //! theLast as its bounds. |
274 | Standard_EXPORT static Standard_Boolean FindValidRange |
275 | (const TopoDS_Edge& theEdge, Standard_Real& theFirst, Standard_Real& theLast); |
276 | |
d9ca2e0c |
277 | |
278 | //! Enlarges the face on the given value. |
279 | //! @param theF [in] The face to extend |
280 | //! @param theExtVal [in] The extension value |
281 | //! @param theExtUMin [in] Defines whether to extend the face in UMin direction |
282 | //! @param theExtUMax [in] Defines whether to extend the face in UMax direction |
283 | //! @param theExtVMin [in] Defines whether to extend the face in VMin direction |
284 | //! @param theExtVMax [in] Defines whether to extend the face in VMax direction |
285 | //! @param theFExtended [in] The extended face |
286 | Standard_EXPORT static void ExtendFace(const TopoDS_Face& theF, |
287 | const Standard_Real theExtVal, |
288 | const Standard_Boolean theExtUMin, |
289 | const Standard_Boolean theExtUMax, |
290 | const Standard_Boolean theExtVMin, |
291 | const Standard_Boolean theExtVMax, |
292 | TopoDS_Face& theFExtended); |
293 | |
294 | |
42cf5bc1 |
295 | protected: |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | private: |
302 | |
303 | |
304 | |
305 | |
306 | friend class BRepLib_Command; |
307 | friend class BRepLib_MakeShape; |
308 | friend class BRepLib_MakeVertex; |
309 | friend class BRepLib_MakeEdge; |
310 | friend class BRepLib_MakeEdge2d; |
311 | friend class BRepLib_MakePolygon; |
312 | friend class BRepLib_MakeFace; |
313 | friend class BRepLib_MakeWire; |
314 | friend class BRepLib_MakeShell; |
315 | friend class BRepLib_MakeSolid; |
316 | friend class BRepLib_FindSurface; |
317 | friend class BRepLib_FuseEdges; |
318 | friend class BRepLib_CheckCurveOnSurface; |
319 | |
320 | }; |
321 | |
322 | |
323 | |
324 | |
325 | |
326 | |
327 | |
328 | #endif // _BRepLib_HeaderFile |