Back to home page

EIC code displayed by LXR

 
 

    


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

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