Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:58

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