Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-04 10:58:48

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