Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-26 08:16:40

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