Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-15 08:29:14

0001 // Created on: 1992-08-28
0002 // Created by: Remi LEQUETTE
0003 // Copyright (c) 1992-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 _BRepTools_HeaderFile
0018 #define _BRepTools_HeaderFile
0019 
0020 #include <TopTools_FormatVersion.hxx>
0021 #include <Standard.hxx>
0022 #include <Standard_DefineAlloc.hxx>
0023 #include <Standard_Handle.hxx>
0024 
0025 #include <Standard_Real.hxx>
0026 #include <TopTools_IndexedMapOfShape.hxx>
0027 #include <Standard_OStream.hxx>
0028 #include <Standard_IStream.hxx>
0029 #include <Message_ProgressRange.hxx>
0030 #include <TopTools_ListOfShape.hxx>
0031 
0032 class TopoDS_Face;
0033 class TopoDS_Wire;
0034 class TopoDS_Edge;
0035 class Bnd_Box2d;
0036 class TopoDS_Vertex;
0037 class TopoDS_Shell;
0038 class TopoDS_Solid;
0039 class TopoDS_CompSolid;
0040 class TopoDS_Compound;
0041 class TopoDS_Shape;
0042 class BRep_Builder;
0043 class Geom_Curve;
0044 class Geom2d_Curve;
0045 class Geom_Surface;
0046 class OSD_FileSystem;
0047 
0048 //! The BRepTools package provides  utilities for BRep
0049 //! data structures.
0050 //!
0051 //! * WireExplorer : A tool to explore the topology of
0052 //! a wire in the order of the edges.
0053 //!
0054 //! * ShapeSet :  Tools used for  dumping, writing and
0055 //! reading.
0056 //!
0057 //! * UVBounds : Methods to compute the  limits of the
0058 //! boundary  of a  face,  a wire or   an edge in  the
0059 //! parametric space of a face.
0060 //!
0061 //! *  Update : Methods  to call when   a topology has
0062 //! been created to compute all missing data.
0063 //!
0064 //! * UpdateFaceUVPoints: Method to update the UV points
0065 //! stored with the edges on a face.
0066 //!
0067 //! * Compare : Method to compare two vertices.
0068 //!
0069 //! * Compare : Method to compare two edges.
0070 //!
0071 //! * OuterWire : A method to find the outer wire of a
0072 //! face.
0073 //!
0074 //! * Map3DEdges : A method to map all the 3D Edges of
0075 //! a Shape.
0076 //!
0077 //! * Dump : A method to dump a BRep object.
0078 class BRepTools
0079 {
0080 public:
0081   DEFINE_STANDARD_ALLOC
0082 
0083   //! Returns in UMin,  UMax, VMin,  VMax  the  bounding
0084   //! values in the parametric space of F.
0085   Standard_EXPORT static void UVBounds(const TopoDS_Face& F,
0086                                        Standard_Real&     UMin,
0087                                        Standard_Real&     UMax,
0088                                        Standard_Real&     VMin,
0089                                        Standard_Real&     VMax);
0090 
0091   //! Returns in UMin,  UMax, VMin,  VMax  the  bounding
0092   //! values of the wire in the parametric space of F.
0093   Standard_EXPORT static void UVBounds(const TopoDS_Face& F,
0094                                        const TopoDS_Wire& W,
0095                                        Standard_Real&     UMin,
0096                                        Standard_Real&     UMax,
0097                                        Standard_Real&     VMin,
0098                                        Standard_Real&     VMax);
0099 
0100   //! Returns in UMin,  UMax, VMin,  VMax  the  bounding
0101   //! values of the edge in the parametric space of F.
0102   Standard_EXPORT static void UVBounds(const TopoDS_Face& F,
0103                                        const TopoDS_Edge& E,
0104                                        Standard_Real&     UMin,
0105                                        Standard_Real&     UMax,
0106                                        Standard_Real&     VMin,
0107                                        Standard_Real&     VMax);
0108 
0109   //! Adds  to  the box <B>  the bounding values in  the
0110   //! parametric space of F.
0111   Standard_EXPORT static void AddUVBounds(const TopoDS_Face& F, Bnd_Box2d& B);
0112 
0113   //! Adds  to the box  <B>  the bounding  values of the
0114   //! wire in the parametric space of F.
0115   Standard_EXPORT static void AddUVBounds(const TopoDS_Face& F, const TopoDS_Wire& W, Bnd_Box2d& B);
0116 
0117   //! Adds to  the box <B>  the  bounding values  of the
0118   //! edge in the parametric space of F.
0119   Standard_EXPORT static void AddUVBounds(const TopoDS_Face& F, const TopoDS_Edge& E, Bnd_Box2d& B);
0120 
0121   //! Update a vertex (nothing is done)
0122   Standard_EXPORT static void Update(const TopoDS_Vertex& V);
0123 
0124   //! Update an edge, compute 2d bounding boxes.
0125   Standard_EXPORT static void Update(const TopoDS_Edge& E);
0126 
0127   //! Update a wire (nothing is done)
0128   Standard_EXPORT static void Update(const TopoDS_Wire& W);
0129 
0130   //! Update a Face, update UV points.
0131   Standard_EXPORT static void Update(const TopoDS_Face& F);
0132 
0133   //! Update a shell (nothing is done)
0134   Standard_EXPORT static void Update(const TopoDS_Shell& S);
0135 
0136   //! Update a solid (nothing is done)
0137   Standard_EXPORT static void Update(const TopoDS_Solid& S);
0138 
0139   //! Update a composite solid (nothing is done)
0140   Standard_EXPORT static void Update(const TopoDS_CompSolid& C);
0141 
0142   //! Update a compound (nothing is done)
0143   Standard_EXPORT static void Update(const TopoDS_Compound& C);
0144 
0145   //! Update a shape, call the correct update.
0146   Standard_EXPORT static void Update(const TopoDS_Shape& S);
0147 
0148   //! For each edge of the face <F> reset the UV points
0149   //! to the bounding points of the parametric curve of the
0150   //! edge on the face.
0151   Standard_EXPORT static void UpdateFaceUVPoints(const TopoDS_Face& theF);
0152 
0153   //! Removes all cached polygonal representation of the shape,
0154   //! i.e. the triangulations of the faces of <S> and polygons on
0155   //! triangulations and polygons 3d of the edges.
0156   //! In case polygonal representation is the only available representation
0157   //! for the shape (shape does not have geometry) it is not removed.
0158   //! @param[in] theShape   the shape to clean
0159   //! @param[in] theForce   allows removing all polygonal representations from the shape,
0160   //!                       including polygons on triangulations irrelevant for the faces of the
0161   //!                       given shape.
0162   Standard_EXPORT static void Clean(const TopoDS_Shape&    theShape,
0163                                     const Standard_Boolean theForce = Standard_False);
0164 
0165   //! Removes geometry (curves and surfaces) from all edges and faces of the shape
0166   Standard_EXPORT static void CleanGeometry(const TopoDS_Shape& theShape);
0167 
0168   //! Removes all the pcurves of the edges of <S> that
0169   //! refer to surfaces not belonging to any face of <S>
0170   Standard_EXPORT static void RemoveUnusedPCurves(const TopoDS_Shape& S);
0171 
0172 public:
0173   //! Verifies that each Face from the shape has got a triangulation with a deflection smaller or
0174   //! equal to specified one and the Edges a discretization on this triangulation.
0175   //! @param[in] theShape    shape to verify
0176   //! @param[in] theLinDefl  maximum allowed linear deflection
0177   //! @param[in] theToCheckFreeEdges  if TRUE, then free Edges are required to have 3D polygon
0178   //! @return FALSE if input Shape contains Faces without triangulation,
0179   //!               or that triangulation has worse (greater) deflection than specified one,
0180   //!               or Edges in Shape lack polygons on triangulation
0181   //!               or free Edges in Shape lack 3D polygons
0182   Standard_EXPORT static Standard_Boolean Triangulation(
0183     const TopoDS_Shape&    theShape,
0184     const Standard_Real    theLinDefl,
0185     const Standard_Boolean theToCheckFreeEdges = Standard_False);
0186 
0187   //! Loads triangulation data for each face of the shape
0188   //! from some deferred storage using specified shared input file system
0189   //! @param[in] theShape             shape to load triangulations
0190   //! @param[in] theTriangulationIdx  index defining what triangulation should be loaded. Starts
0191   //! from 0.
0192   //!        -1 is used in specific case to load currently already active triangulation.
0193   //!        If some face doesn't contain triangulation with this index, nothing will be loaded for
0194   //!        it. Exception will be thrown in case of invalid negative index
0195   //! @param[in] theToSetAsActive     flag to activate triangulation after its loading
0196   //! @param[in] theFileSystem        shared file system
0197   //! @return TRUE if at least one triangulation is loaded.
0198   Standard_EXPORT static Standard_Boolean LoadTriangulation(
0199     const TopoDS_Shape&           theShape,
0200     const Standard_Integer        theTriangulationIdx = -1,
0201     const Standard_Boolean        theToSetAsActive    = Standard_False,
0202     const Handle(OSD_FileSystem)& theFileSystem       = Handle(OSD_FileSystem)());
0203 
0204   //! Releases triangulation data for each face of the shape if there is deferred storage to load it
0205   //! later
0206   //! @param[in] theShape             shape to unload triangulations
0207   //! @param[in] theTriangulationIdx  index defining what triangulation should be unloaded. Starts
0208   //! from 0.
0209   //!        -1 is used in specific case to unload currently already active triangulation.
0210   //!        If some face doesn't contain triangulation with this index, nothing will be unloaded
0211   //!        for it. Exception will be thrown in case of invalid negative index
0212   //! @return TRUE if at least one triangulation is unloaded.
0213   Standard_EXPORT static Standard_Boolean UnloadTriangulation(
0214     const TopoDS_Shape&    theShape,
0215     const Standard_Integer theTriangulationIdx = -1);
0216 
0217   //! Activates triangulation data for each face of the shape
0218   //! from some deferred storage using specified shared input file system
0219   //! @param[in] theShape               shape to activate triangulations
0220   //! @param[in] theTriangulationIdx    index defining what triangulation should be activated.
0221   //! Starts from 0.
0222   //!        Exception will be thrown in case of invalid negative index
0223   //! @param[in] theToActivateStrictly  flag to activate exactly triangulation with defined
0224   //! theTriangulationIdx index.
0225   //!        In TRUE case if some face doesn't contain triangulation with this index, active
0226   //!        triangulation will not be changed for it. Else the last available triangulation will be
0227   //!        activated.
0228   //! @return TRUE if at least one active triangulation was changed.
0229   Standard_EXPORT static Standard_Boolean ActivateTriangulation(
0230     const TopoDS_Shape&    theShape,
0231     const Standard_Integer theTriangulationIdx,
0232     const Standard_Boolean theToActivateStrictly = false);
0233 
0234   //! Loads all available triangulations for each face of the shape
0235   //! from some deferred storage using specified shared input file system
0236   //! @param[in] theShape       shape to load triangulations
0237   //! @param[in] theFileSystem  shared file system
0238   //! @return TRUE if at least one triangulation is loaded.
0239   Standard_EXPORT static Standard_Boolean LoadAllTriangulations(
0240     const TopoDS_Shape&           theShape,
0241     const Handle(OSD_FileSystem)& theFileSystem = Handle(OSD_FileSystem)());
0242 
0243   //! Releases all available triangulations for each face of the shape if there is deferred storage
0244   //! to load them later
0245   //! @param[in] theShape       shape to unload triangulations
0246   //! @return TRUE if at least one triangulation is unloaded.
0247   Standard_EXPORT static Standard_Boolean UnloadAllTriangulations(const TopoDS_Shape& theShape);
0248 
0249 public:
0250   //! Returns  True if  the    distance between the  two
0251   //! vertices is lower than their tolerance.
0252   Standard_EXPORT static Standard_Boolean Compare(const TopoDS_Vertex& V1, const TopoDS_Vertex& V2);
0253 
0254   //! Returns  True if  the    distance between the  two
0255   //! edges is lower than their tolerance.
0256   Standard_EXPORT static Standard_Boolean Compare(const TopoDS_Edge& E1, const TopoDS_Edge& E2);
0257 
0258   //! Returns the outer most wire of <F>. Returns a Null
0259   //! wire if <F> has no wires.
0260   Standard_EXPORT static TopoDS_Wire OuterWire(const TopoDS_Face& F);
0261 
0262   //! Stores in the map  <M> all the 3D topology edges
0263   //! of <S>.
0264   Standard_EXPORT static void Map3DEdges(const TopoDS_Shape& S, TopTools_IndexedMapOfShape& M);
0265 
0266   //! Verifies that the edge  <E> is found two  times on
0267   //! the face <F> before calling BRep_Tool::IsClosed.
0268   Standard_EXPORT static Standard_Boolean IsReallyClosed(const TopoDS_Edge& E,
0269                                                          const TopoDS_Face& F);
0270 
0271   //! Detect closedness of face in U and V directions
0272   Standard_EXPORT static void DetectClosedness(const TopoDS_Face& theFace,
0273                                                Standard_Boolean&  theUclosed,
0274                                                Standard_Boolean&  theVclosed);
0275 
0276   //! Dumps the topological structure and the geometry
0277   //! of <Sh> on the stream <S>.
0278   Standard_EXPORT static void Dump(const TopoDS_Shape& Sh, Standard_OStream& S);
0279 
0280   //! Writes the shape to the stream in an ASCII format TopTools_FormatVersion_VERSION_1.
0281   //! This alias writes shape with triangulation data.
0282   //! @param[in] theShape        the shape to write
0283   //! @param[in][out] theStream  the stream to output shape into
0284   //! @param theRange            the range of progress indicator to fill in
0285   static void Write(const TopoDS_Shape&          theShape,
0286                     Standard_OStream&            theStream,
0287                     const Message_ProgressRange& theProgress = Message_ProgressRange())
0288   {
0289     Write(theShape,
0290           theStream,
0291           Standard_True,
0292           Standard_False,
0293           TopTools_FormatVersion_CURRENT,
0294           theProgress);
0295   }
0296 
0297   //! Writes the shape to the stream in an ASCII format of specified version.
0298   //! @param[in] theShape          the shape to write
0299   //! @param[in][out] theStream    the stream to output shape into
0300   //! @param[in] theWithTriangles  flag which specifies whether to save shape with (TRUE) or without
0301   //! (FALSE) triangles;
0302   //!                              has no effect on triangulation-only geometry
0303   //! @param[in] theWithNormals    flag which specifies whether to save triangulation with (TRUE) or
0304   //! without (FALSE) normals;
0305   //!                              has no effect on triangulation-only geometry
0306   //! @param[in] theVersion        the TopTools format version
0307   //! @param theProgress the range of progress indicator to fill in
0308   Standard_EXPORT static void Write(
0309     const TopoDS_Shape&          theShape,
0310     Standard_OStream&            theStream,
0311     const Standard_Boolean       theWithTriangles,
0312     const Standard_Boolean       theWithNormals,
0313     const TopTools_FormatVersion theVersion,
0314     const Message_ProgressRange& theProgress = Message_ProgressRange());
0315 
0316   //! Reads a Shape  from <S> in  returns it in  <Sh>.
0317   //! <B> is used to build the shape.
0318   Standard_EXPORT static void Read(
0319     TopoDS_Shape&                Sh,
0320     Standard_IStream&            S,
0321     const BRep_Builder&          B,
0322     const Message_ProgressRange& theProgress = Message_ProgressRange());
0323 
0324   //! Writes the shape to the file in an ASCII format TopTools_FormatVersion_VERSION_1.
0325   //! This alias writes shape with triangulation data.
0326   //! @param[in] theShape  the shape to write
0327   //! @param[in] theFile   the path to file to output shape into
0328   //! @param theProgress the range of progress indicator to fill in
0329   static Standard_Boolean Write(const TopoDS_Shape&          theShape,
0330                                 const Standard_CString       theFile,
0331                                 const Message_ProgressRange& theProgress = Message_ProgressRange())
0332   {
0333     return Write(theShape,
0334                  theFile,
0335                  Standard_True,
0336                  Standard_False,
0337                  TopTools_FormatVersion_CURRENT,
0338                  theProgress);
0339   }
0340 
0341   //! Writes the shape to the file in an ASCII format of specified version.
0342   //! @param[in] theShape          the shape to write
0343   //! @param[in] theFile           the path to file to output shape into
0344   //! @param[in] theWithTriangles  flag which specifies whether to save shape with (TRUE) or without
0345   //! (FALSE) triangles;
0346   //!                              has no effect on triangulation-only geometry
0347   //! @param[in] theWithNormals    flag which specifies whether to save triangulation with (TRUE) or
0348   //! without (FALSE) normals;
0349   //!                              has no effect on triangulation-only geometry
0350   //! @param[in] theVersion        the TopTools format version
0351   //! @param theProgress the range of progress indicator to fill in
0352   Standard_EXPORT static Standard_Boolean Write(
0353     const TopoDS_Shape&          theShape,
0354     const Standard_CString       theFile,
0355     const Standard_Boolean       theWithTriangles,
0356     const Standard_Boolean       theWithNormals,
0357     const TopTools_FormatVersion theVersion,
0358     const Message_ProgressRange& theProgress = Message_ProgressRange());
0359 
0360   //! Reads a Shape  from <File>,  returns it in  <Sh>.
0361   //! <B> is used to build the shape.
0362   Standard_EXPORT static Standard_Boolean Read(
0363     TopoDS_Shape&                Sh,
0364     const Standard_CString       File,
0365     const BRep_Builder&          B,
0366     const Message_ProgressRange& theProgress = Message_ProgressRange());
0367 
0368   //! Evals real tolerance of edge  <theE>.
0369   //! <theC3d>, <theC2d>, <theS>, <theF>, <theL> are
0370   //! correspondently 3d curve of edge, 2d curve on surface <theS> and
0371   //! rang of edge
0372   //! If calculated tolerance is more then current edge tolerance, edge is updated.
0373   //! Method returns actual tolerance of edge
0374   Standard_EXPORT static Standard_Real EvalAndUpdateTol(const TopoDS_Edge&          theE,
0375                                                         const Handle(Geom_Curve)&   theC3d,
0376                                                         const Handle(Geom2d_Curve)& theC2d,
0377                                                         const Handle(Geom_Surface)& theS,
0378                                                         const Standard_Real         theF,
0379                                                         const Standard_Real         theL);
0380 
0381   //! returns the cumul  of the orientation  of <Edge>
0382   //! and thc containing wire in <Face>
0383   Standard_EXPORT static TopAbs_Orientation OriEdgeInFace(const TopoDS_Edge& theEdge,
0384                                                           const TopoDS_Face& theFace);
0385 
0386   //! Removes internal sub-shapes from the shape.
0387   //! The check on internal status is based on orientation of sub-shapes,
0388   //! classification is not performed.
0389   //! Before removal of internal sub-shapes the algorithm checks if such
0390   //! removal is not going to break topological connectivity between sub-shapes.
0391   //! The flag <theForce> if set to true disables the connectivity check and clears
0392   //! the given shape from all sub-shapes with internal orientation.
0393   Standard_EXPORT static void RemoveInternals(TopoDS_Shape&          theS,
0394                                               const Standard_Boolean theForce = Standard_False);
0395 
0396   //! Check all locations of shape according criterium:
0397   //! aTrsf.IsNegative() || (Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec())
0398   //! All sub-shapes having such locations are put in list theProblemShapes
0399   Standard_EXPORT static void CheckLocations(const TopoDS_Shape&   theS,
0400                                              TopTools_ListOfShape& theProblemShapes);
0401 };
0402 
0403 #endif // _BRepTools_HeaderFile