Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-05 08:37:46

0001 // Copyright: Open CASCADE 2014
0002 // Created on: 2012-06-09
0003 // Created by: jgv@ROLEX
0004 // Copyright (c) 2012-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 _ShapeUpgrade_UnifySameDomain_HeaderFile
0018 #define _ShapeUpgrade_UnifySameDomain_HeaderFile
0019 
0020 #include <BRepTools_History.hxx>
0021 #include <Standard.hxx>
0022 #include <Standard_Type.hxx>
0023 
0024 #include <TopoDS_Shape.hxx>
0025 #include <Standard_Boolean.hxx>
0026 #include <Standard_Transient.hxx>
0027 #include <TopTools_DataMapOfShapeShape.hxx>
0028 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
0029 #include <TopTools_MapOfShape.hxx>
0030 #include <TopTools_SequenceOfShape.hxx>
0031 #include <Geom_Plane.hxx>
0032 #include <Precision.hxx>
0033 class ShapeBuild_ReShape;
0034 
0035 class ShapeUpgrade_UnifySameDomain;
0036 DEFINE_STANDARD_HANDLE(ShapeUpgrade_UnifySameDomain, Standard_Transient)
0037 
0038 //! This tool tries to unify faces and edges of the shape which lie on the same geometry.
0039 //! Faces/edges are considering as 'same-domain' if a group of neighbouring faces/edges
0040 //! are lying on coincident surfaces/curves.
0041 //! In this case these faces/edges can be unified into one face/edge.
0042 //! ShapeUpgrade_UnifySameDomain is initialized by a shape and the next optional parameters:
0043 //! UnifyFaces - tries to unify all possible faces
0044 //! UnifyEdges - tries to unify all possible edges
0045 //! ConcatBSplines - if this flag is set to true then all neighbouring edges, which lay
0046 //! on BSpline or Bezier curves with C1 continuity on their common vertices,
0047 //! will be merged into one common edge.
0048 //!
0049 //! The input shape can be of any type containing faces or edges - compsolid, solid, shell,
0050 //! wire, compound of any kind of shapes. The algorithm preserves the structure of compsolids,
0051 //! solids, shells and wires. E.g., if two shells have a common edge and the faces sharing
0052 //! this edge lie on the same surface the algorithm will not unify these faces, otherwise
0053 //! the structure of shells would be broken. However, if such faces belong to different
0054 //! compounds of faces they will be unified.
0055 //!
0056 //! The output result of the tool is the unified shape.
0057 //!
0058 //! All the modifications of initial shape are recorded during unifying.
0059 //! Methods History are intended to: <br>
0060 //! - set a place holder for the history of modifications of sub-shapes of
0061 //!   the initial shape; <br>
0062 //! - get the collected history. <br>
0063 //! The algorithm provides a place holder for the history and collects the
0064 //! history by default.
0065 //! To avoid collecting of the history the place holder should be set to null handle.
0066 class ShapeUpgrade_UnifySameDomain : public Standard_Transient
0067 {
0068 
0069 public:
0070   typedef NCollection_DataMap<TopoDS_Shape, Handle(Geom_Plane), TopTools_ShapeMapHasher>
0071     DataMapOfFacePlane;
0072   typedef NCollection_DataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>
0073     DataMapOfShapeMapOfShape;
0074 
0075   //! Empty constructor
0076   Standard_EXPORT ShapeUpgrade_UnifySameDomain();
0077 
0078   //! Constructor defining input shape and necessary flags.
0079   //! It does not perform unification.
0080   Standard_EXPORT ShapeUpgrade_UnifySameDomain(
0081     const TopoDS_Shape&    aShape,
0082     const Standard_Boolean UnifyEdges     = Standard_True,
0083     const Standard_Boolean UnifyFaces     = Standard_True,
0084     const Standard_Boolean ConcatBSplines = Standard_False);
0085 
0086   //! Initializes with a shape and necessary flags.
0087   //! It does not perform unification.
0088   //! If you intend to nullify the History place holder do it after
0089   //! initialization.
0090   Standard_EXPORT void Initialize(const TopoDS_Shape&    aShape,
0091                                   const Standard_Boolean UnifyEdges     = Standard_True,
0092                                   const Standard_Boolean UnifyFaces     = Standard_True,
0093                                   const Standard_Boolean ConcatBSplines = Standard_False);
0094 
0095   //! Sets the flag defining whether it is allowed to create
0096   //! internal edges inside merged faces in the case of non-manifold
0097   //! topology. Without this flag merging through multi connected edge
0098   //! is forbidden. Default value is false.
0099   Standard_EXPORT void AllowInternalEdges(const Standard_Boolean theValue);
0100 
0101   //! Sets the shape for avoid merging of the faces/edges.
0102   //! This shape can be vertex or edge.
0103   //! If the shape is a vertex it forbids merging of connected edges.
0104   //! If the shape is a edge it forbids merging of connected faces.
0105   //! This method can be called several times to keep several shapes.
0106   Standard_EXPORT void KeepShape(const TopoDS_Shape& theShape);
0107 
0108   //! Sets the map of shapes for avoid merging of the faces/edges.
0109   //! It allows passing a ready to use map instead of calling many times
0110   //! the method KeepShape.
0111   Standard_EXPORT void KeepShapes(const TopTools_MapOfShape& theShapes);
0112 
0113   //! Sets the flag defining the behavior of the algorithm regarding
0114   //! modification of input shape.
0115   //! If this flag is equal to True then the input (original) shape can't be
0116   //! modified during modification process. Default value is true.
0117   Standard_EXPORT void SetSafeInputMode(Standard_Boolean theValue);
0118 
0119   //! Sets the linear tolerance. It plays the role of chord error when
0120   //! taking decision about merging of shapes. Default value is Precision::Confusion().
0121   void SetLinearTolerance(const Standard_Real theValue) { myLinTol = theValue; }
0122 
0123   //! Sets the angular tolerance. If two shapes form a connection angle greater than
0124   //! this value they will not be merged. Default value is Precision::Angular().
0125   void SetAngularTolerance(const Standard_Real theValue)
0126   {
0127     myAngTol = (theValue < Precision::Angular() ? Precision::Angular() : theValue);
0128   }
0129 
0130   //! Performs unification and builds the resulting shape.
0131   Standard_EXPORT void Build();
0132 
0133   //! Gives the resulting shape
0134   const TopoDS_Shape& Shape() const { return myShape; }
0135 
0136   //! Returns the history of the processed shapes.
0137   const Handle(BRepTools_History)& History() const { return myHistory; }
0138 
0139   //! Returns the history of the processed shapes.
0140   Handle(BRepTools_History)& History() { return myHistory; }
0141 
0142   DEFINE_STANDARD_RTTIEXT(ShapeUpgrade_UnifySameDomain, Standard_Transient)
0143 
0144 protected:
0145   struct SubSequenceOfEdges;
0146 
0147 protected:
0148   //! This method makes if possible a common face from each
0149   //! group of faces lying on coincident surfaces
0150   Standard_EXPORT void UnifyFaces();
0151 
0152   //! This method makes if possible a common edge from each
0153   //! group of smothly connected edges, which are common for the same couple of faces
0154   Standard_EXPORT void UnifyEdges();
0155 
0156   void IntUnifyFaces(const TopoDS_Shape&                              theInpShape,
0157                      const TopTools_IndexedDataMapOfShapeListOfShape& theGMapEdgeFaces,
0158                      const DataMapOfShapeMapOfShape&                  theGMapFaceShells,
0159                      const TopTools_MapOfShape&                       theFreeBoundMap);
0160 
0161   //! Splits the sequence of edges into the sequence of chains
0162   Standard_Boolean MergeEdges(TopTools_SequenceOfShape&                        SeqEdges,
0163                               const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
0164                               NCollection_Sequence<SubSequenceOfEdges>&        SeqOfSubSeqOfEdges,
0165                               const TopTools_MapOfShape&                       NonMergVrt);
0166 
0167   //! Tries to unify the sequence of edges with the set of
0168   //! another edges which lies on the same geometry
0169   Standard_Boolean MergeSeq(TopTools_SequenceOfShape&                        SeqEdges,
0170                             const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
0171                             const TopTools_MapOfShape&                       nonMergVert);
0172 
0173   //! Merges a sequence of edges into one edge if possible
0174   Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape&                  theChain,
0175                                const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
0176                                TopoDS_Edge&                                     OutEdge);
0177 
0178   //! Unifies the pcurve of the chain into one pcurve of the edge
0179   void UnionPCurves(const TopTools_SequenceOfShape& theChain, TopoDS_Edge& theEdge);
0180 
0181   //! Fills the history of the modifications during the operation.
0182   Standard_EXPORT void FillHistory();
0183 
0184 private:
0185   //! Generates sub-sequences of edges from sequence of edges.
0186   //! Edges from each subsequences can be merged into the one edge.
0187   static void generateSubSeq(const TopTools_SequenceOfShape&                  anInpEdgeSeq,
0188                              NCollection_Sequence<SubSequenceOfEdges>&        SeqOfSubSeqOfEdges,
0189                              Standard_Boolean                                 IsClosed,
0190                              double                                           theAngTol,
0191                              double                                           theLinTol,
0192                              const TopTools_MapOfShape&                       AvoidEdgeVrt,
0193                              const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap);
0194 
0195 private:
0196   TopoDS_Shape                              myInitShape;
0197   Standard_Real                             myLinTol;
0198   Standard_Real                             myAngTol;
0199   Standard_Boolean                          myUnifyFaces;
0200   Standard_Boolean                          myUnifyEdges;
0201   Standard_Boolean                          myConcatBSplines;
0202   Standard_Boolean                          myAllowInternal;
0203   Standard_Boolean                          mySafeInputMode;
0204   TopoDS_Shape                              myShape;
0205   Handle(ShapeBuild_ReShape)                myContext;
0206   TopTools_MapOfShape                       myKeepShapes;
0207   DataMapOfFacePlane                        myFacePlaneMap;
0208   TopTools_IndexedDataMapOfShapeListOfShape myEFmap;
0209   TopTools_DataMapOfShapeShape              myFaceNewFace;
0210 
0211   Handle(BRepTools_History) myHistory; //!< The history.
0212 };
0213 
0214 #endif // _ShapeUpgrade_UnifySameDomain_HeaderFile