Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:02:31

0001 // Created on: 1993-07-07
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 _BRep_Tool_HeaderFile
0018 #define _BRep_Tool_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <GeomAbs_Shape.hxx>
0025 #include <Geom_Surface.hxx>
0026 #include <Geom_Curve.hxx>
0027 #include <Geom2d_Curve.hxx>
0028 #include <gp_Pnt2d.hxx>
0029 #include <gp_Pnt.hxx>
0030 #include <Poly_Triangulation.hxx>
0031 #include <Poly_Polygon3D.hxx>
0032 #include <Poly_Polygon2D.hxx>
0033 #include <Poly_PolygonOnTriangulation.hxx>
0034 #include <TopAbs_ShapeEnum.hxx>
0035 
0036 class TopoDS_Shape;
0037 class TopoDS_Face;
0038 class TopLoc_Location;
0039 class TopoDS_Edge;
0040 class TopoDS_Vertex;
0041 
0042 //! Provides class methods to access to the geometry
0043 //! of BRep shapes.
0044 class BRep_Tool
0045 {
0046 public:
0047   DEFINE_STANDARD_ALLOC
0048 
0049   //! If S is Shell, returns True if it has no free boundaries (edges).
0050   //! If S is Wire, returns True if it has no free ends (vertices).
0051   //! (Internal and External sub-shepes are ignored in these checks)
0052   //! If S is Edge, returns True if its vertices are the same.
0053   //! For other shape types returns S.Closed().
0054   Standard_EXPORT static bool IsClosed(const TopoDS_Shape& S);
0055 
0056   //! Returns the geometric surface of the face. Returns
0057   //! in <L> the location for the surface.
0058   Standard_EXPORT static const occ::handle<Geom_Surface>& Surface(const TopoDS_Face& F,
0059                                                                   TopLoc_Location&   L);
0060 
0061   //! Returns the geometric  surface of the face. It can
0062   //! be a copy if there is a Location.
0063   Standard_EXPORT static occ::handle<Geom_Surface> Surface(const TopoDS_Face& F);
0064 
0065   //! Returns the triangulation of the face according to the mesh purpose.
0066   //! @param[in] theFace  the input face to find triangulation.
0067   //! @param[out] theLocation  the face location.
0068   //! @param[in] theMeshPurpose  a mesh purpose to find appropriate triangulation (NONE by default).
0069   //! @return an active triangulation in case of NONE purpose,
0070   //!         the first triangulation appropriate for the input purpose,
0071   //!         just the first triangulation if none matching other criteria and input purpose is
0072   //!         AnyFallback or null handle if there is no any suitable triangulation.
0073   Standard_EXPORT static const occ::handle<Poly_Triangulation>& Triangulation(
0074     const TopoDS_Face&     theFace,
0075     TopLoc_Location&       theLocation,
0076     const Poly_MeshPurpose theMeshPurpose = Poly_MeshPurpose_NONE);
0077 
0078   //! Returns all triangulations of the face.
0079   //! @param[in] theFace  the input face.
0080   //! @param[out] theLocation  the face location.
0081   //! @return list of all available face triangulations.
0082   Standard_EXPORT static const NCollection_List<occ::handle<Poly_Triangulation>>& Triangulations(
0083     const TopoDS_Face& theFace,
0084     TopLoc_Location&   theLocation);
0085 
0086   //! Returns the tolerance of the face.
0087   Standard_EXPORT static double Tolerance(const TopoDS_Face& F);
0088 
0089   //! Returns the NaturalRestriction flag of the face.
0090   Standard_EXPORT static bool NaturalRestriction(const TopoDS_Face& F);
0091 
0092   //! Returns True if <F> has a surface, false otherwise.
0093   Standard_EXPORT static bool IsGeometric(const TopoDS_Face& F);
0094 
0095   //! Returns True if <E> is a 3d curve or a curve on surface.
0096   Standard_EXPORT static bool IsGeometric(const TopoDS_Edge& E);
0097 
0098   //! Returns the 3D curve of the edge. May be a Null
0099   //! handle. Returns in <L> the location for the curve.
0100   //! In <First> and <Last> the parameter range.
0101   Standard_EXPORT static const occ::handle<Geom_Curve>& Curve(const TopoDS_Edge& E,
0102                                                               TopLoc_Location&   L,
0103                                                               double&            First,
0104                                                               double&            Last);
0105 
0106   //! Returns the 3D curve of the edge. May be a Null handle.
0107   //! In <First> and <Last> the parameter range.
0108   //! It can be a copy if there is a Location.
0109   Standard_EXPORT static occ::handle<Geom_Curve> Curve(const TopoDS_Edge& E,
0110                                                        double&            First,
0111                                                        double&            Last);
0112 
0113   //! Returns the 3D polygon of the edge. May be a Null
0114   //! handle. Returns in <L> the location for the polygon.
0115   Standard_EXPORT static const occ::handle<Poly_Polygon3D>& Polygon3D(const TopoDS_Edge& E,
0116                                                                       TopLoc_Location&   L);
0117 
0118   //! Returns the curve associated to the edge in the
0119   //! parametric space of the face. Returns a NULL
0120   //! handle if this curve does not exist. Returns in
0121   //! <First> and <Last> the parameter range.
0122   //! If the surface is a plane the curve can be not stored but created a new
0123   //! each time. The flag pointed by <theIsStored> serves to indicate storage status.
0124   //! It is valued if the pointer is non-null.
0125   Standard_EXPORT static occ::handle<Geom2d_Curve> CurveOnSurface(const TopoDS_Edge& E,
0126                                                                   const TopoDS_Face& F,
0127                                                                   double&            First,
0128                                                                   double&            Last,
0129                                                                   bool* theIsStored = nullptr);
0130 
0131   //! Returns the curve associated to the edge in the
0132   //! parametric space of the surface. Returns a NULL
0133   //! handle if this curve does not exist. Returns in
0134   //! <First> and <Last> the parameter range.
0135   //! If the surface is a plane the curve can be not stored but created a new
0136   //! each time. The flag pointed by <theIsStored> serves to indicate storage status.
0137   //! It is valued if the pointer is non-null.
0138   Standard_EXPORT static occ::handle<Geom2d_Curve> CurveOnSurface(
0139     const TopoDS_Edge&               E,
0140     const occ::handle<Geom_Surface>& S,
0141     const TopLoc_Location&           L,
0142     double&                          First,
0143     double&                          Last,
0144     bool*                            theIsStored = nullptr);
0145 
0146   //! For the planar surface builds the 2d curve for the edge
0147   //! by projection of the edge on plane.
0148   //! Returns a NULL handle if the surface is not planar or
0149   //! the projection failed.
0150   Standard_EXPORT static occ::handle<Geom2d_Curve> CurveOnPlane(const TopoDS_Edge&               E,
0151                                                                 const occ::handle<Geom_Surface>& S,
0152                                                                 const TopLoc_Location&           L,
0153                                                                 double& First,
0154                                                                 double& Last);
0155 
0156   //! Returns in <C>, <S>, <L> a 2d curve, a surface and
0157   //! a location for the edge <E>. <C> and <S> are null
0158   //! if the edge has no curve on surface. Returns in
0159   //! <First> and <Last> the parameter range.
0160   Standard_EXPORT static void CurveOnSurface(const TopoDS_Edge&         E,
0161                                              occ::handle<Geom2d_Curve>& C,
0162                                              occ::handle<Geom_Surface>& S,
0163                                              TopLoc_Location&           L,
0164                                              double&                    First,
0165                                              double&                    Last);
0166 
0167   //! Returns in <C>, <S>, <L> the 2d curve, the surface
0168   //! and the location for the edge <E> of rank <Index>.
0169   //! <C> and <S> are null if the index is out of range.
0170   //! Returns in <First> and <Last> the parameter range.
0171   Standard_EXPORT static void CurveOnSurface(const TopoDS_Edge&         E,
0172                                              occ::handle<Geom2d_Curve>& C,
0173                                              occ::handle<Geom_Surface>& S,
0174                                              TopLoc_Location&           L,
0175                                              double&                    First,
0176                                              double&                    Last,
0177                                              const int                  Index);
0178 
0179   //! Returns the polygon associated to the edge in the
0180   //! parametric space of the face. Returns a NULL
0181   //! handle if this polygon does not exist.
0182   Standard_EXPORT static occ::handle<Poly_Polygon2D> PolygonOnSurface(const TopoDS_Edge& E,
0183                                                                       const TopoDS_Face& F);
0184 
0185   //! Returns the polygon associated to the edge in the
0186   //! parametric space of the surface. Returns a NULL
0187   //! handle if this polygon does not exist.
0188   Standard_EXPORT static occ::handle<Poly_Polygon2D> PolygonOnSurface(
0189     const TopoDS_Edge&               E,
0190     const occ::handle<Geom_Surface>& S,
0191     const TopLoc_Location&           L);
0192 
0193   //! Returns in <C>, <S>, <L> a 2d curve, a surface and
0194   //! a location for the edge <E>. <C> and <S> are null
0195   //! if the edge has no polygon on surface.
0196   Standard_EXPORT static void PolygonOnSurface(const TopoDS_Edge&           E,
0197                                                occ::handle<Poly_Polygon2D>& C,
0198                                                occ::handle<Geom_Surface>&   S,
0199                                                TopLoc_Location&             L);
0200 
0201   //! Returns in <C>, <S>, <L> the 2d curve, the surface
0202   //! and the location for the edge <E> of rank <Index>.
0203   //! <C> and <S> are null if the index is out of range.
0204   Standard_EXPORT static void PolygonOnSurface(const TopoDS_Edge&           E,
0205                                                occ::handle<Poly_Polygon2D>& C,
0206                                                occ::handle<Geom_Surface>&   S,
0207                                                TopLoc_Location&             L,
0208                                                const int                    Index);
0209 
0210   //! Returns the polygon associated to the edge in the
0211   //! parametric space of the face. Returns a NULL
0212   //! handle if this polygon does not exist.
0213   Standard_EXPORT static const occ::handle<Poly_PolygonOnTriangulation>& PolygonOnTriangulation(
0214     const TopoDS_Edge&                     E,
0215     const occ::handle<Poly_Triangulation>& T,
0216     const TopLoc_Location&                 L);
0217 
0218   //! Returns in <P>, <T>, <L> a polygon on triangulation, a
0219   //! triangulation and a location for the edge <E>.
0220   //! <P> and <T> are null if the edge has no
0221   //! polygon on triangulation.
0222   Standard_EXPORT static void PolygonOnTriangulation(const TopoDS_Edge&                        E,
0223                                                      occ::handle<Poly_PolygonOnTriangulation>& P,
0224                                                      occ::handle<Poly_Triangulation>&          T,
0225                                                      TopLoc_Location&                          L);
0226 
0227   //! Returns in <P>, <T>, <L> a polygon on
0228   //! triangulation, a triangulation and a location for
0229   //! the edge <E> for the range index. <C> and <S> are
0230   //! null if the edge has no polygon on triangulation.
0231   Standard_EXPORT static void PolygonOnTriangulation(const TopoDS_Edge&                        E,
0232                                                      occ::handle<Poly_PolygonOnTriangulation>& P,
0233                                                      occ::handle<Poly_Triangulation>&          T,
0234                                                      TopLoc_Location&                          L,
0235                                                      const int Index);
0236 
0237   //! Returns True if <E> has two PCurves in the
0238   //! parametric space of <F>. i.e. <F> is on a closed
0239   //! surface and <E> is on the closing curve.
0240   Standard_EXPORT static bool IsClosed(const TopoDS_Edge& E, const TopoDS_Face& F);
0241 
0242   //! Returns True if <E> has two PCurves in the
0243   //! parametric space of <S>. i.e. <S> is a closed
0244   //! surface and <E> is on the closing curve.
0245   Standard_EXPORT static bool IsClosed(const TopoDS_Edge&               E,
0246                                        const occ::handle<Geom_Surface>& S,
0247                                        const TopLoc_Location&           L);
0248 
0249   //! Returns True if <E> has two arrays of indices in
0250   //! the triangulation <T>.
0251   Standard_EXPORT static bool IsClosed(const TopoDS_Edge&                     E,
0252                                        const occ::handle<Poly_Triangulation>& T,
0253                                        const TopLoc_Location&                 L);
0254 
0255   //! Returns the tolerance for <E>.
0256   Standard_EXPORT static double Tolerance(const TopoDS_Edge& E);
0257 
0258   //! Returns the SameParameter flag for the edge.
0259   Standard_EXPORT static bool SameParameter(const TopoDS_Edge& E);
0260 
0261   //! Returns the SameRange flag for the edge.
0262   Standard_EXPORT static bool SameRange(const TopoDS_Edge& E);
0263 
0264   //! Returns True if the edge is degenerated.
0265   Standard_EXPORT static bool Degenerated(const TopoDS_Edge& E);
0266 
0267   //! Gets the range of the 3d curve.
0268   Standard_EXPORT static void Range(const TopoDS_Edge& E, double& First, double& Last);
0269 
0270   //! Gets the range of the edge on the pcurve on the surface.
0271   Standard_EXPORT static void Range(const TopoDS_Edge&               E,
0272                                     const occ::handle<Geom_Surface>& S,
0273                                     const TopLoc_Location&           L,
0274                                     double&                          First,
0275                                     double&                          Last);
0276 
0277   //! Gets the range of the edge on the pcurve on the face.
0278   Standard_EXPORT static void Range(const TopoDS_Edge& E,
0279                                     const TopoDS_Face& F,
0280                                     double&            First,
0281                                     double&            Last);
0282 
0283   //! Gets the UV locations of the extremities of the edge.
0284   Standard_EXPORT static void UVPoints(const TopoDS_Edge&               E,
0285                                        const occ::handle<Geom_Surface>& S,
0286                                        const TopLoc_Location&           L,
0287                                        gp_Pnt2d&                        PFirst,
0288                                        gp_Pnt2d&                        PLast);
0289 
0290   //! Gets the UV locations of the extremities of the edge.
0291   Standard_EXPORT static void UVPoints(const TopoDS_Edge& E,
0292                                        const TopoDS_Face& F,
0293                                        gp_Pnt2d&          PFirst,
0294                                        gp_Pnt2d&          PLast);
0295 
0296   //! Sets the UV locations of the extremities of the edge.
0297   Standard_EXPORT static void SetUVPoints(const TopoDS_Edge&               E,
0298                                           const occ::handle<Geom_Surface>& S,
0299                                           const TopLoc_Location&           L,
0300                                           const gp_Pnt2d&                  PFirst,
0301                                           const gp_Pnt2d&                  PLast);
0302 
0303   //! Sets the UV locations of the extremities of the edge.
0304   Standard_EXPORT static void SetUVPoints(const TopoDS_Edge& E,
0305                                           const TopoDS_Face& F,
0306                                           const gp_Pnt2d&    PFirst,
0307                                           const gp_Pnt2d&    PLast);
0308 
0309   //! Returns True if the edge is on the surfaces of the
0310   //! two faces.
0311   Standard_EXPORT static bool HasContinuity(const TopoDS_Edge& E,
0312                                             const TopoDS_Face& F1,
0313                                             const TopoDS_Face& F2);
0314 
0315   //! Returns the continuity.
0316   Standard_EXPORT static GeomAbs_Shape Continuity(const TopoDS_Edge& E,
0317                                                   const TopoDS_Face& F1,
0318                                                   const TopoDS_Face& F2);
0319 
0320   //! Returns True if the edge is on the surfaces.
0321   Standard_EXPORT static bool HasContinuity(const TopoDS_Edge&               E,
0322                                             const occ::handle<Geom_Surface>& S1,
0323                                             const occ::handle<Geom_Surface>& S2,
0324                                             const TopLoc_Location&           L1,
0325                                             const TopLoc_Location&           L2);
0326 
0327   //! Returns the continuity.
0328   Standard_EXPORT static GeomAbs_Shape Continuity(const TopoDS_Edge&               E,
0329                                                   const occ::handle<Geom_Surface>& S1,
0330                                                   const occ::handle<Geom_Surface>& S2,
0331                                                   const TopLoc_Location&           L1,
0332                                                   const TopLoc_Location&           L2);
0333 
0334   //! Returns True if the edge has regularity on some two surfaces.
0335   Standard_EXPORT static bool HasContinuity(const TopoDS_Edge& E);
0336 
0337   //! Returns the max continuity of edge between some surfaces or GeomAbs_C0
0338   //! if there are no such surfaces.
0339   Standard_EXPORT static GeomAbs_Shape MaxContinuity(const TopoDS_Edge& theEdge);
0340 
0341   //! Returns the 3d point.
0342   Standard_EXPORT static gp_Pnt Pnt(const TopoDS_Vertex& V);
0343 
0344   //! Returns the tolerance.
0345   Standard_EXPORT static double Tolerance(const TopoDS_Vertex& V);
0346 
0347   //! Finds the parameter of <theV> on <theE>.
0348   //! @param[in] theV  input vertex
0349   //! @param[in] theE  input edge
0350   //! @param[out] theParam   calculated parameter on the curve
0351   //! @return TRUE if done
0352   Standard_EXPORT static bool Parameter(const TopoDS_Vertex& theV,
0353                                         const TopoDS_Edge&   theE,
0354                                         double&              theParam);
0355 
0356   //! Returns the parameter of <V> on <E>.
0357   //! Throws Standard_NoSuchObject if no parameter on edge
0358   Standard_EXPORT static double Parameter(const TopoDS_Vertex& V, const TopoDS_Edge& E);
0359 
0360   //! Returns the parameters of the vertex on the
0361   //! pcurve of the edge on the face.
0362   Standard_EXPORT static double Parameter(const TopoDS_Vertex& V,
0363                                           const TopoDS_Edge&   E,
0364                                           const TopoDS_Face&   F);
0365 
0366   //! Returns the parameters of the vertex on the
0367   //! pcurve of the edge on the surface.
0368   Standard_EXPORT static double Parameter(const TopoDS_Vertex&             V,
0369                                           const TopoDS_Edge&               E,
0370                                           const occ::handle<Geom_Surface>& S,
0371                                           const TopLoc_Location&           L);
0372 
0373   //! Returns the parameters of the vertex on the face.
0374   Standard_EXPORT static gp_Pnt2d Parameters(const TopoDS_Vertex& V, const TopoDS_Face& F);
0375 
0376   //! Returns the maximum tolerance of input shape subshapes.
0377   //@param theShape    - Shape to search tolerance.
0378   //@param theSubShape - Search subshape, only Face, Edge or Vertex are supported.
0379   Standard_EXPORT static double MaxTolerance(const TopoDS_Shape&    theShape,
0380                                              const TopAbs_ShapeEnum theSubShape);
0381 };
0382 
0383 #endif // _BRep_Tool_HeaderFile