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