Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:12

0001 // Created on: 1993-12-15
0002 // Created by: Remi LEQUETTE
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _BRepLib_HeaderFile
0018 #define _BRepLib_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Real.hxx>
0025 #include <Standard_Boolean.hxx>
0026 #include <GeomAbs_Shape.hxx>
0027 #include <Standard_Integer.hxx>
0028 #include <TopoDS.hxx>
0029 #include <TopoDS_Edge.hxx>
0030 #include <TopTools_ListOfShape.hxx>
0031 #include <NCollection_List.hxx>
0032 
0033 class Geom2d_Curve;
0034 class Adaptor3d_Curve;
0035 class Geom_Plane;
0036 class TopoDS_Shape;
0037 class TopoDS_Solid;
0038 class TopoDS_Face;
0039 class BRepTools_ReShape;
0040 
0041 
0042 //! The BRepLib package provides general utilities for
0043 //! BRep.
0044 //!
0045 //! * FindSurface : Class to compute a surface through
0046 //! a set of edges.
0047 //!
0048 //! * Compute missing 3d curve on an edge.
0049 class BRepLib 
0050 {
0051 public:
0052 
0053   DEFINE_STANDARD_ALLOC
0054 
0055   
0056 
0057   //! Computes the max distance between edge
0058   //! and its 2d representation on the face.
0059   //! Sets the default precision.  The current Precision
0060   //! is returned.
0061   Standard_EXPORT static void Precision (const Standard_Real P);
0062   
0063   //! Returns the default precision.
0064   Standard_EXPORT static Standard_Real Precision();
0065   
0066   //! Sets the current plane to P.
0067   Standard_EXPORT static void Plane (const Handle(Geom_Plane)& P);
0068   
0069   //! Returns the current plane.
0070   Standard_EXPORT static const Handle(Geom_Plane)& Plane();
0071   
0072   //! checks if the Edge is same range IGNORING
0073   //! the same range flag of the edge
0074   //! Confusion argument is to compare real numbers
0075   //! idenpendently of any model space tolerance
0076   Standard_EXPORT static Standard_Boolean CheckSameRange (const TopoDS_Edge& E, const Standard_Real Confusion = 1.0e-12);
0077   
0078   //! will make all the curve representation have
0079   //! the same range domain for the parameters.
0080   //! This will IGNORE the same range flag value
0081   //! to proceed.
0082   //! If there is a 3D curve there it will the
0083   //! range of that curve. If not the first curve representation
0084   //! encountered in the list will give its range to
0085   //! the all the other curves.
0086   Standard_EXPORT static void SameRange (const TopoDS_Edge& E, const Standard_Real Tolerance = 1.0e-5);
0087   
0088   //! Computes the 3d curve for the edge  <E> if it does
0089   //! not exist. Returns True  if the curve was computed
0090   //! or  existed. Returns False  if there is no  planar
0091   //! pcurve or the computation failed.
0092   //! <MaxSegment> >= 30 in approximation
0093   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);
0094   
0095   //! Computes  the 3d curves  for all the  edges of <S>
0096   //! return False if one of the computation failed.
0097   //! <MaxSegment> >= 30 in approximation
0098   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);
0099   
0100   //! Computes  the 3d curves  for all the  edges of <S>
0101   //! return False if one of the computation failed.
0102   Standard_EXPORT static Standard_Boolean BuildCurves3d (const TopoDS_Shape& S);
0103 
0104   //! Builds pcurve of edge on face if the surface is plane, and updates the edge.
0105   Standard_EXPORT static void BuildPCurveForEdgeOnPlane(const TopoDS_Edge& theE, const TopoDS_Face& theF);
0106 
0107   //! Builds pcurve of edge on face if the surface is plane, but does not update the edge.
0108   //! The output are the pcurve and the flag telling that pcurve was built.
0109   Standard_EXPORT static void BuildPCurveForEdgeOnPlane(const TopoDS_Edge& theE, const TopoDS_Face& theF,
0110                                                         Handle(Geom2d_Curve)& aC2D, Standard_Boolean& bToUpdate);
0111 
0112   //! Builds pcurves of edges on face if the surface is plane, and update the edges.
0113   template<class TCont> static void BuildPCurveForEdgesOnPlane(const TCont& theLE, const TopoDS_Face& theF)
0114   {
0115     for (typename TCont::Iterator aIt(theLE); aIt.More(); aIt.Next())
0116     {
0117       const TopoDS_Edge& aE = TopoDS::Edge(aIt.Value());
0118       if (!aE.IsNull())
0119         BRepLib::BuildPCurveForEdgeOnPlane(aE, theF);
0120     }
0121   }
0122 
0123   //! Checks if the edge has a  Tolerance smaller than -- --
0124   //! -- -- MaxToleranceToCheck  if  so it will compute  the
0125   //! radius    of  -- the   cylindrical  pipe  surface that
0126   //! MinToleranceRequest is the minimum tolerance before it
0127   //! is useful to start testing.
0128   //! Usually it should be around 10e-5
0129   //! contains all -- the curve representation of the edge
0130   //! returns True if the Edge tolerance had to be updated
0131   Standard_EXPORT static Standard_Boolean UpdateEdgeTol (const TopoDS_Edge& E, const Standard_Real MinToleranceRequest, const Standard_Real MaxToleranceToCheck);
0132   
0133   //! -- Checks all the edges of the shape whose -- -- --
0134   //! Tolerance  is  smaller than  MaxToleranceToCheck --
0135   //! Returns True if at  least  one edge was updated --
0136   //! MinToleranceRequest is the minimum tolerance before
0137   //! --  it -- is  useful to start  testing.
0138   //! Usually it should be around -- 10e-5--
0139   //!
0140   //! Warning :The  method is  very  slow  as it  checks all.
0141   //! Use  only  in interfaces or  processing assimilate batch
0142   Standard_EXPORT static Standard_Boolean UpdateEdgeTolerance (const TopoDS_Shape& S, const Standard_Real MinToleranceRequest, const Standard_Real MaxToleranceToCheck);
0143   
0144   //! Computes new 2d curve(s)  for the edge <theEdge> to have
0145   //! the same parameter  as  the  3d curve.
0146   //! The algorithm is not done if the flag SameParameter
0147   //! was True  on the  Edge.
0148   Standard_EXPORT static void SameParameter (const TopoDS_Edge& theEdge, const Standard_Real Tolerance = 1.0e-5);
0149 
0150   //! Computes new 2d curve(s)  for the edge <theEdge> to have
0151   //! the same parameter  as  the  3d curve.
0152   //! The algorithm is not done if the flag SameParameter
0153   //! was True  on the  Edge.<br>
0154   //! theNewTol is a new tolerance of vertices of the input edge
0155   //! (not applied inside the algorithm, but pre-computed).
0156   //! If IsUseOldEdge is true then the input edge will be modified,
0157   //! otherwise the new copy of input edge will be created.
0158   //! Returns the new edge as a result, can be ignored if IsUseOldEdge is true.
0159   Standard_EXPORT static TopoDS_Edge SameParameter(const TopoDS_Edge& theEdge,
0160   const Standard_Real theTolerance, Standard_Real& theNewTol, const Standard_Boolean IsUseOldEdge);
0161   
0162   //! Computes new 2d curve(s) for all the edges of  <S>
0163   //! to have the same parameter  as  the  3d curve.
0164   //! The algorithm is not done if the flag SameParameter
0165   //! was True  on an  Edge.
0166   Standard_EXPORT static void SameParameter(const TopoDS_Shape& S,
0167     const Standard_Real Tolerance = 1.0e-5, const Standard_Boolean forced = Standard_False);
0168 
0169   //! Computes new 2d curve(s) for all the edges of  <S>
0170   //! to have the same parameter  as  the  3d curve.
0171   //! The algorithm is not done if the flag SameParameter
0172   //! was True  on an  Edge.<br>
0173   //! theReshaper is used to record the modifications of input shape <S> to prevent any 
0174   //! modifications on the shape itself.
0175   //! Thus the input shape (and its subshapes) will not be modified, instead the reshaper will 
0176   //! contain a modified empty-copies of original subshapes as substitutions.
0177   Standard_EXPORT static void SameParameter(const TopoDS_Shape& S, BRepTools_ReShape& theReshaper,
0178     const Standard_Real Tolerance = 1.0e-5, const Standard_Boolean forced = Standard_False );
0179  
0180   //! Replaces tolerance   of  FACE EDGE VERTEX  by  the
0181   //! tolerance Max of their connected handling shapes.
0182   //! It is not necessary to use this call after
0183   //! SameParameter. (called in)
0184   Standard_EXPORT static void UpdateTolerances (const TopoDS_Shape& S, const Standard_Boolean verifyFaceTolerance = Standard_False);
0185 
0186   //! Replaces tolerance   of  FACE EDGE VERTEX  by  the
0187   //! tolerance Max of their connected handling shapes.
0188   //! It is not necessary to use this call after
0189   //! SameParameter. (called in)<br>
0190   //! theReshaper is used to record the modifications of input shape <S> to prevent any 
0191   //! modifications on the shape itself.
0192   //! Thus the input shape (and its subshapes) will not be modified, instead the reshaper will 
0193   //! contain a modified empty-copies of original subshapes as substitutions.
0194   Standard_EXPORT static void UpdateTolerances (const TopoDS_Shape& S, BRepTools_ReShape& theReshaper, 
0195     const Standard_Boolean verifyFaceTolerance = Standard_False );
0196   
0197   //! Checks tolerances of edges (including inner points) and vertices
0198   //! of a shape and updates them to satisfy "SameParameter" condition
0199   Standard_EXPORT static void UpdateInnerTolerances (const TopoDS_Shape& S);
0200   
0201   //! Orients the solid forward  and the  shell with the
0202   //! orientation to have  matter in the solid. Returns
0203   //! False if the solid is unOrientable (open or incoherent)
0204   Standard_EXPORT static Standard_Boolean OrientClosedSolid (TopoDS_Solid& solid);
0205 
0206   //! Returns the order of continuity between two faces
0207   //! connected by an edge
0208   Standard_EXPORT static GeomAbs_Shape ContinuityOfFaces(const TopoDS_Edge&  theEdge,
0209                                                          const TopoDS_Face&  theFace1,
0210                                                          const TopoDS_Face&  theFace2,
0211                                                          const Standard_Real theAngleTol);
0212 
0213   //! Encodes the Regularity of edges on a Shape.
0214   //! Warning: <TolAng> is an angular tolerance, expressed in Rad.
0215   //! Warning: If the edges's regularity are coded before, nothing
0216   //! is done.
0217   Standard_EXPORT static void EncodeRegularity (const TopoDS_Shape& S, const Standard_Real TolAng = 1.0e-10);
0218 
0219   //! Encodes the Regularity of edges in list <LE> on the shape <S>
0220   //! Warning: <TolAng> is an angular tolerance, expressed in Rad.
0221   //! Warning: If the edges's regularity are coded before, nothing
0222   //! is done.
0223   Standard_EXPORT static void EncodeRegularity(const TopoDS_Shape& S, const TopTools_ListOfShape& LE, const Standard_Real TolAng = 1.0e-10);
0224   
0225   //! Encodes the Regularity between <F1> and <F2> by <E>
0226   //! Warning: <TolAng> is an angular tolerance, expressed in Rad.
0227   //! Warning: If the edge's regularity is coded before, nothing
0228   //! is done.
0229   Standard_EXPORT static void EncodeRegularity (TopoDS_Edge& E, const TopoDS_Face& F1, const TopoDS_Face& F2, const Standard_Real TolAng = 1.0e-10);
0230   
0231   //! Sorts in  LF the Faces of   S on the  complexity of
0232   //! their                  surfaces
0233   //! (Plane,Cylinder,Cone,Sphere,Torus,other)
0234   Standard_EXPORT static void SortFaces (const TopoDS_Shape& S, TopTools_ListOfShape& LF);
0235   
0236   //! Sorts in  LF  the   Faces  of S   on the reverse
0237   //! complexity       of       their      surfaces
0238   //! (other,Torus,Sphere,Cone,Cylinder,Plane)
0239   Standard_EXPORT static void ReverseSortFaces (const TopoDS_Shape& S, TopTools_ListOfShape& LF);
0240   
0241   //! Corrects the normals in Poly_Triangulation of faces,
0242   //! in such way that normals at nodes lying along smooth
0243   //! edges have the same value on both adjacent triangulations.
0244   //! Returns TRUE if any correction is done.
0245   Standard_EXPORT static Standard_Boolean EnsureNormalConsistency (const TopoDS_Shape& S, const Standard_Real theAngTol = 0.001, const Standard_Boolean ForceComputeNormals = Standard_False);
0246 
0247   //! Updates value of deflection in Poly_Triangulation of faces
0248   //! by the maximum deviation measured on existing triangulation.
0249   Standard_EXPORT static void UpdateDeflection (const TopoDS_Shape& S);
0250 
0251   //! Calculates the bounding sphere around the set of vertexes from the theLV list.
0252   //! Returns the center (theNewCenter) and the radius (theNewTol) of this sphere.
0253   //! This can be used to construct the new vertex which covers the given set of
0254   //! other vertices.
0255   Standard_EXPORT static  void BoundingVertex(const NCollection_List<TopoDS_Shape>& theLV,
0256                                               gp_Pnt& theNewCenter, Standard_Real& theNewTol);
0257 
0258   //! For an edge defined by 3d curve and tolerance and vertices defined by points,
0259   //! parameters on curve and tolerances,
0260   //! finds a range of curve between vertices not covered by vertices tolerances.
0261   //! Returns false if there is no such range. Otherwise, sets theFirst and 
0262   //! theLast as its bounds.
0263   Standard_EXPORT static Standard_Boolean FindValidRange
0264     (const Adaptor3d_Curve& theCurve, const Standard_Real theTolE,
0265      const Standard_Real theParV1, const gp_Pnt& thePntV1, const Standard_Real theTolV1,
0266      const Standard_Real theParV2, const gp_Pnt& thePntV2, const Standard_Real theTolV2,
0267      Standard_Real& theFirst, Standard_Real& theLast);
0268 
0269   //! Finds a range of 3d curve of the edge not covered by vertices tolerances.
0270   //! Returns false if there is no such range. Otherwise, sets theFirst and 
0271   //! theLast as its bounds.
0272   Standard_EXPORT static Standard_Boolean FindValidRange
0273     (const TopoDS_Edge& theEdge, Standard_Real& theFirst, Standard_Real& theLast);
0274 
0275 
0276   //! Enlarges the face on the given value.
0277   //! @param theF [in] The face to extend
0278   //! @param theExtVal [in] The extension value
0279   //! @param theExtUMin [in] Defines whether to extend the face in UMin direction
0280   //! @param theExtUMax [in] Defines whether to extend the face in UMax direction
0281   //! @param theExtVMin [in] Defines whether to extend the face in VMin direction
0282   //! @param theExtVMax [in] Defines whether to extend the face in VMax direction
0283   //! @param theFExtended [in] The extended face
0284   Standard_EXPORT static void ExtendFace(const TopoDS_Face& theF,
0285                                          const Standard_Real theExtVal,
0286                                          const Standard_Boolean theExtUMin,
0287                                          const Standard_Boolean theExtUMax,
0288                                          const Standard_Boolean theExtVMin,
0289                                          const Standard_Boolean theExtVMax,
0290                                          TopoDS_Face& theFExtended);
0291 
0292 };
0293 
0294 #endif // _BRepLib_HeaderFile