Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-22 10:19:15

0001 // Created on: 1995-03-23
0002 // Created by: Jing Cheng MEI
0003 // Copyright (c) 1995-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 _BRepBuilderAPI_Sewing_HeaderFile
0018 #define _BRepBuilderAPI_Sewing_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 #include <TopoDS_Shape.hxx>
0024 #include <TopTools_ShapeMapHasher.hxx>
0025 #include <NCollection_IndexedDataMap.hxx>
0026 #include <NCollection_IndexedMap.hxx>
0027 #include <NCollection_List.hxx>
0028 #include <NCollection_DataMap.hxx>
0029 #include <Standard_Integer.hxx>
0030 #include <NCollection_Map.hxx>
0031 #include <Standard_Transient.hxx>
0032 #include <NCollection_Sequence.hxx>
0033 #include <NCollection_Array1.hxx>
0034 #include <gp_Pnt.hxx>
0035 
0036 #include <Message_ProgressRange.hxx>
0037 
0038 class BRepTools_ReShape;
0039 class TopoDS_Edge;
0040 class TopoDS_Face;
0041 class Geom_Surface;
0042 class TopLoc_Location;
0043 class Geom2d_Curve;
0044 class Geom_Curve;
0045 
0046 //! Provides methods to
0047 //!
0048 //! - identify possible contiguous boundaries (for control
0049 //! afterwards (of continuity: C0, C1, ...))
0050 //!
0051 //! - assemble contiguous shapes into one shape.
0052 //! Only manifold shapes will be found. Sewing will not
0053 //! be done in case of multiple edges.
0054 //!
0055 //! For sewing, use this function as following:
0056 //! - create an empty object
0057 //! - default tolerance 1.E-06
0058 //! - with face analysis on
0059 //! - with sewing operation on
0060 //! - set the cutting option as you need (default True)
0061 //! - define a tolerance
0062 //! - add shapes to be sewed -> Add
0063 //! - compute -> Perform
0064 //! - output the resulted shapes
0065 //! - output free edges if necessary
0066 //! - output multiple edges if necessary
0067 //! - output the problems if any
0068 class BRepBuilderAPI_Sewing : public Standard_Transient
0069 {
0070 
0071 public:
0072   //! Creates an object with
0073   //! tolerance of connexity
0074   //! option for sewing (if false only control)
0075   //! option for analysis of degenerated shapes
0076   //! option for cutting of free edges.
0077   //! option for non manifold processing
0078   Standard_EXPORT BRepBuilderAPI_Sewing(const double tolerance = 1.0e-06,
0079                                         const bool   option1   = true,
0080                                         const bool   option2   = true,
0081                                         const bool   option3   = true,
0082                                         const bool   option4   = false);
0083 
0084   //! initialize the parameters if necessary
0085   Standard_EXPORT void Init(const double tolerance = 1.0e-06,
0086                             const bool   option1   = true,
0087                             const bool   option2   = true,
0088                             const bool   option3   = true,
0089                             const bool   option4   = false);
0090 
0091   //! Loads the context shape.
0092   Standard_EXPORT void Load(const TopoDS_Shape& shape);
0093 
0094   //! Defines the shapes to be sewed or controlled
0095   Standard_EXPORT void Add(const TopoDS_Shape& shape);
0096 
0097   //! Computing
0098   //! theProgress - progress indicator of algorithm
0099   Standard_EXPORT void Perform(const Message_ProgressRange& theProgress = Message_ProgressRange());
0100 
0101   //! Gives the sewed shape
0102   //! a null shape if nothing constructed
0103   //! may be a face, a shell, a solid or a compound
0104   Standard_EXPORT const TopoDS_Shape& SewedShape() const;
0105 
0106   //! set context
0107   Standard_EXPORT void SetContext(const occ::handle<BRepTools_ReShape>& theContext);
0108 
0109   //! return context
0110   Standard_EXPORT const occ::handle<BRepTools_ReShape>& GetContext() const;
0111 
0112   //! Gives the number of free edges (edge shared by one face)
0113   Standard_EXPORT int NbFreeEdges() const;
0114 
0115   //! Gives each free edge
0116   Standard_EXPORT const TopoDS_Edge& FreeEdge(const int index) const;
0117 
0118   //! Gives the number of multiple edges
0119   //! (edge shared by more than two faces)
0120   Standard_EXPORT int NbMultipleEdges() const;
0121 
0122   //! Gives each multiple edge
0123   Standard_EXPORT const TopoDS_Edge& MultipleEdge(const int index) const;
0124 
0125   //! Gives the number of contiguous edges (edge shared by two faces)
0126   Standard_EXPORT int NbContigousEdges() const;
0127 
0128   //! Gives each contiguous edge
0129   Standard_EXPORT const TopoDS_Edge& ContigousEdge(const int index) const;
0130 
0131   //! Gives the sections (edge) belonging to a contiguous edge
0132   Standard_EXPORT const NCollection_List<TopoDS_Shape>& ContigousEdgeCouple(const int index) const;
0133 
0134   //! Indicates if a section is bound (before use SectionToBoundary)
0135   Standard_EXPORT bool IsSectionBound(const TopoDS_Edge& section) const;
0136 
0137   //! Gives the original edge (free boundary) which becomes the
0138   //! the section. Remember that sections constitute common edges.
0139   //! This information is important for control because with
0140   //! original edge we can find the surface to which the section
0141   //! is attached.
0142   Standard_EXPORT const TopoDS_Edge& SectionToBoundary(const TopoDS_Edge& section) const;
0143 
0144   //! Gives the number of degenerated shapes
0145   Standard_EXPORT int NbDegeneratedShapes() const;
0146 
0147   //! Gives each degenerated shape
0148   Standard_EXPORT const TopoDS_Shape& DegeneratedShape(const int index) const;
0149 
0150   //! Indicates if a input shape is degenerated
0151   Standard_EXPORT bool IsDegenerated(const TopoDS_Shape& shape) const;
0152 
0153   //! Indicates if a input shape has been modified
0154   Standard_EXPORT bool IsModified(const TopoDS_Shape& shape) const;
0155 
0156   //! Gives a modifieded shape
0157   Standard_EXPORT const TopoDS_Shape& Modified(const TopoDS_Shape& shape) const;
0158 
0159   //! Indicates if a input subshape has been modified
0160   Standard_EXPORT bool IsModifiedSubShape(const TopoDS_Shape& shape) const;
0161 
0162   //! Gives a modifieded subshape
0163   Standard_EXPORT TopoDS_Shape ModifiedSubShape(const TopoDS_Shape& shape) const;
0164 
0165   //! print the information
0166   Standard_EXPORT void Dump() const;
0167 
0168   //! Gives the number of deleted faces (faces smallest than tolerance)
0169   Standard_EXPORT int NbDeletedFaces() const;
0170 
0171   //! Gives each deleted face
0172   Standard_EXPORT const TopoDS_Face& DeletedFace(const int index) const;
0173 
0174   //! Gives a modified shape
0175   Standard_EXPORT TopoDS_Face WhichFace(const TopoDS_Edge& theEdg, const int index = 1) const;
0176 
0177   //! Gets same parameter mode.
0178   bool SameParameterMode() const;
0179 
0180   //! Sets same parameter mode.
0181   void SetSameParameterMode(const bool SameParameterMode);
0182 
0183   //! Gives set tolerance.
0184   double Tolerance() const;
0185 
0186   //! Sets tolerance
0187   void SetTolerance(const double theToler);
0188 
0189   //! Gives set min tolerance.
0190   double MinTolerance() const;
0191 
0192   //! Sets min tolerance
0193   void SetMinTolerance(const double theMinToler);
0194 
0195   //! Gives set max tolerance
0196   double MaxTolerance() const;
0197 
0198   //! Sets max tolerance.
0199   void SetMaxTolerance(const double theMaxToler);
0200 
0201   //! Returns mode for sewing faces By default - true.
0202   bool FaceMode() const;
0203 
0204   //! Sets mode for sewing faces By default - true.
0205   void SetFaceMode(const bool theFaceMode);
0206 
0207   //! Returns mode for sewing floating edges By default - false.
0208   bool FloatingEdgesMode() const;
0209 
0210   //! Sets mode for sewing floating edges By default - false.
0211   //! Returns mode for cutting floating edges By default - false.
0212   //! Sets mode for cutting floating edges By default - false.
0213   void SetFloatingEdgesMode(const bool theFloatingEdgesMode);
0214 
0215   //! Returns mode for accounting of local tolerances
0216   //! of edges and vertices during of merging.
0217   bool LocalTolerancesMode() const;
0218 
0219   //! Sets mode for accounting of local tolerances
0220   //! of edges and vertices during of merging
0221   //! in this case WorkTolerance = myTolerance + tolEdge1+ tolEdg2;
0222   void SetLocalTolerancesMode(const bool theLocalTolerancesMode);
0223 
0224   //! Sets mode for non-manifold sewing.
0225   void SetNonManifoldMode(const bool theNonManifoldMode);
0226 
0227   //! Gets mode for non-manifold sewing.
0228   //!
0229   //! INTERNAL FUNCTIONS ---
0230   bool NonManifoldMode() const;
0231 
0232   DEFINE_STANDARD_RTTIEXT(BRepBuilderAPI_Sewing, Standard_Transient)
0233 
0234 protected:
0235   //! Performs cutting of sections
0236   //! theProgress - progress indicator of processing
0237   Standard_EXPORT void Cutting(const Message_ProgressRange& theProgress = Message_ProgressRange());
0238 
0239   Standard_EXPORT void Merging(const bool                   passage,
0240                                const Message_ProgressRange& theProgress = Message_ProgressRange());
0241 
0242   Standard_EXPORT bool IsMergedClosed(const TopoDS_Edge& Edge1,
0243                                       const TopoDS_Edge& Edge2,
0244                                       const TopoDS_Face& fase) const;
0245 
0246   Standard_EXPORT bool FindCandidates(NCollection_Sequence<TopoDS_Shape>& seqSections,
0247                                       NCollection_IndexedMap<int>&        mapReference,
0248                                       NCollection_Sequence<int>&          seqCandidates,
0249                                       NCollection_Sequence<bool>&         seqOrientations);
0250 
0251   Standard_EXPORT void AnalysisNearestEdges(const NCollection_Sequence<TopoDS_Shape>& sequenceSec,
0252                                             NCollection_Sequence<int>&  seqIndCandidate,
0253                                             NCollection_Sequence<bool>& seqOrientations,
0254                                             const bool                  evalDist = true);
0255 
0256   //! Merged nearest edges.
0257   Standard_EXPORT bool MergedNearestEdges(const TopoDS_Shape&                 edge,
0258                                           NCollection_Sequence<TopoDS_Shape>& SeqMergedEdge,
0259                                           NCollection_Sequence<bool>&         SeqMergedOri);
0260 
0261   Standard_EXPORT void EdgeProcessing(
0262     const Message_ProgressRange& theProgress = Message_ProgressRange());
0263 
0264   //! Recompute regularity on merged edges
0265   Standard_EXPORT void EdgeRegularity(
0266     const Message_ProgressRange& theProgress = Message_ProgressRange());
0267 
0268   Standard_EXPORT void CreateOutputInformations();
0269 
0270   //! Defines if surface is U closed.
0271   Standard_EXPORT virtual bool IsUClosedSurface(const occ::handle<Geom_Surface>& surf,
0272                                                 const TopoDS_Shape&              theEdge,
0273                                                 const TopLoc_Location&           theloc) const;
0274 
0275   //! Defines if surface is V closed.
0276   Standard_EXPORT virtual bool IsVClosedSurface(const occ::handle<Geom_Surface>& surf,
0277                                                 const TopoDS_Shape&              theEdge,
0278                                                 const TopLoc_Location&           theloc) const;
0279 
0280   //! This method is called from Perform only
0281   //! theProgress - progress indicator of processing
0282   Standard_EXPORT virtual void FaceAnalysis(
0283     const Message_ProgressRange& theProgress = Message_ProgressRange());
0284 
0285   //! This method is called from Perform only
0286   Standard_EXPORT virtual void FindFreeBoundaries();
0287 
0288   //! This method is called from Perform only
0289   //! theProgress - progress indicator of processing
0290   Standard_EXPORT virtual void VerticesAssembling(
0291     const Message_ProgressRange& theProgress = Message_ProgressRange());
0292 
0293   //! This method is called from Perform only
0294   Standard_EXPORT virtual void CreateSewedShape();
0295 
0296   //! Get wire from free edges.
0297   //! This method is called from EdgeProcessing only
0298   Standard_EXPORT virtual void GetFreeWires(
0299     NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& MapFreeEdges,
0300     NCollection_Sequence<TopoDS_Shape>&                            seqWires);
0301 
0302   //! This method is called from MergingOfSections only
0303   Standard_EXPORT virtual void EvaluateAngulars(NCollection_Sequence<TopoDS_Shape>& sequenceSec,
0304                                                 NCollection_Array1<bool>&           secForward,
0305                                                 NCollection_Array1<double>&         tabAng,
0306                                                 const int                           indRef) const;
0307 
0308   //! This method is called from MergingOfSections only
0309   Standard_EXPORT virtual void EvaluateDistances(NCollection_Sequence<TopoDS_Shape>& sequenceSec,
0310                                                  NCollection_Array1<bool>&           secForward,
0311                                                  NCollection_Array1<double>&         tabAng,
0312                                                  NCollection_Array1<double>&         arrLen,
0313                                                  NCollection_Array1<double>&         tabMinDist,
0314                                                  const int                           indRef) const;
0315 
0316   //! This method is called from SameParameterEdge only
0317   Standard_EXPORT virtual occ::handle<Geom2d_Curve> SameRange(
0318     const occ::handle<Geom2d_Curve>& CurvePtr,
0319     const double                     FirstOnCurve,
0320     const double                     LastOnCurve,
0321     const double                     RequestedFirst,
0322     const double                     RequestedLast) const;
0323 
0324   //! This method is called from SameParameterEdge only
0325   Standard_EXPORT virtual void SameParameter(const TopoDS_Edge& edge) const;
0326 
0327   //! This method is called from Merging only
0328   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge(
0329     const TopoDS_Shape&                                     edge,
0330     const NCollection_Sequence<TopoDS_Shape>&               seqEdges,
0331     const NCollection_Sequence<bool>&                       seqForward,
0332     NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher>& mapMerged,
0333     const occ::handle<BRepTools_ReShape>&                   locReShape);
0334 
0335   //! This method is called from Merging only
0336   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge(
0337     const TopoDS_Edge&                    edge1,
0338     const TopoDS_Edge&                    edge2,
0339     const NCollection_List<TopoDS_Shape>& listFaces1,
0340     const NCollection_List<TopoDS_Shape>& listFaces2,
0341     const bool                            secForward,
0342     int&                                  whichSec,
0343     const bool                            firstCall = true);
0344 
0345   //! Projects points on curve
0346   //! This method is called from Cutting only
0347   Standard_EXPORT void ProjectPointsOnCurve(const NCollection_Array1<gp_Pnt>& arrPnt,
0348                                             const occ::handle<Geom_Curve>&    Crv,
0349                                             const double                      first,
0350                                             const double                      last,
0351                                             NCollection_Array1<double>&       arrDist,
0352                                             NCollection_Array1<double>&       arrPara,
0353                                             NCollection_Array1<gp_Pnt>&       arrProj,
0354                                             const bool                        isConsiderEnds) const;
0355 
0356   //! Creates cutting vertices on projections
0357   //! This method is called from Cutting only
0358   Standard_EXPORT virtual void CreateCuttingNodes(
0359     const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& MapVert,
0360     const TopoDS_Shape&                                                  bound,
0361     const TopoDS_Shape&                                                  vfirst,
0362     const TopoDS_Shape&                                                  vlast,
0363     const NCollection_Array1<double>&                                    arrDist,
0364     const NCollection_Array1<double>&                                    arrPara,
0365     const NCollection_Array1<gp_Pnt>&                                    arrPnt,
0366     NCollection_Sequence<TopoDS_Shape>&                                  seqNode,
0367     NCollection_Sequence<double>&                                        seqPara);
0368 
0369   //! Performs cutting of bound
0370   //! This method is called from Cutting only
0371   Standard_EXPORT virtual void CreateSections(const TopoDS_Shape&                       bound,
0372                                               const NCollection_Sequence<TopoDS_Shape>& seqNode,
0373                                               const NCollection_Sequence<double>&       seqPara,
0374                                               NCollection_List<TopoDS_Shape>&           listEdge);
0375 
0376   //! Makes all edges from shape same parameter
0377   //! if SameParameterMode is equal to true
0378   //! This method is called from Perform only
0379   Standard_EXPORT virtual void SameParameterShape();
0380 
0381   double                                                                          myTolerance;
0382   bool                                                                            mySewing;
0383   bool                                                                            myAnalysis;
0384   bool                                                                            myCutting;
0385   bool                                                                            myNonmanifold;
0386   NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> myOldShapes;
0387   TopoDS_Shape                                                                    mySewedShape;
0388   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>                   myDegenerated;
0389   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>                   myFreeEdges;
0390   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>                   myMultipleEdges;
0391   NCollection_IndexedDataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
0392                                                                            myContigousEdges;
0393   NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> myContigSecBound;
0394   int                                                                      myNbShapes;
0395   int                                                                      myNbVertices;
0396   int                                                                      myNbEdges;
0397   NCollection_IndexedDataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
0398     myBoundFaces;
0399   NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
0400                                                                                   myBoundSections;
0401   NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>        mySectionBound;
0402   NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> myVertexNode;
0403   NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> myVertexNodeFree;
0404   NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
0405     myNodeSections;
0406   NCollection_DataMap<TopoDS_Shape, NCollection_List<TopoDS_Shape>, TopTools_ShapeMapHasher>
0407                                                                 myCuttingNode;
0408   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> myLittleFace;
0409   TopoDS_Shape                                                  myShape;
0410   occ::handle<BRepTools_ReShape>                                myReShape;
0411 
0412 private:
0413   bool                                                   myFaceMode;
0414   bool                                                   myFloatingEdgesMode;
0415   bool                                                   mySameParameterMode;
0416   bool                                                   myLocalToleranceMode;
0417   double                                                 myMinTolerance;
0418   double                                                 myMaxTolerance;
0419   NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> myMergedEdges;
0420 };
0421 
0422 #include <BRepBuilderAPI_Sewing.lxx>
0423 
0424 #endif // _BRepBuilderAPI_Sewing_HeaderFile