1 // Copyright: Open CASCADE 2014
2 // Created on: 2012-06-09
3 // Created by: jgv@ROLEX
4 // Copyright (c) 2012-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _ShapeUpgrade_UnifySameDomain_HeaderFile
18 #define _ShapeUpgrade_UnifySameDomain_HeaderFile
20 #include <BRepTools_History.hxx>
21 #include <Standard.hxx>
22 #include <Standard_Type.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_Transient.hxx>
27 #include <TopTools_DataMapOfShapeShape.hxx>
28 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
29 #include <TopTools_MapOfShape.hxx>
30 #include <TopTools_SequenceOfShape.hxx>
31 #include <Geom_Plane.hxx>
32 #include <Precision.hxx>
33 class ShapeBuild_ReShape;
36 class ShapeUpgrade_UnifySameDomain;
37 DEFINE_STANDARD_HANDLE(ShapeUpgrade_UnifySameDomain, Standard_Transient)
39 //! This tool tries to unify faces and edges of the shape which lie on the same geometry.
40 //! Faces/edges are considering as 'same-domain' if a group of neighbouring faces/edges
41 //! are lying on coincident surfaces/curves.
42 //! In this case these faces/edges can be unified into one face/edge.
43 //! ShapeUpgrade_UnifySameDomain is initialized by a shape and the next optional parameters:
44 //! UnifyFaces - tries to unify all possible faces
45 //! UnifyEdges - tries to unify all possible edges
46 //! ConcatBSplines - if this flag is set to true then all neighbouring edges, which lay
47 //! on BSpline or Bezier curves with C1 continuity on their common vertices,
48 //! will be merged into one common edge.
50 //! The input shape can be of any type containing faces or edges - compsolid, solid, shell,
51 //! wire, compound of any kind of shapes. The algorithm preserves the structure of compsolids,
52 //! solids, shells and wires. E.g., if two shells have a common edge and the faces sharing
53 //! this edge lie on the same surface the algorithm will not unify these faces, otherwise
54 //! the structure of shells would be broken. However, if such faces belong to different
55 //! compounds of faces they will be unified.
57 //! The output result of the tool is the unified shape.
59 //! All the modifications of initial shape are recorded during unifying.
60 //! Methods History are intended to: <br>
61 //! - set a place holder for the history of modifications of sub-shapes of
62 //! the initial shape; <br>
63 //! - get the collected history. <br>
64 //! The algorithm provides a place holder for the history and collects the
65 //! history by default.
66 //! To avoid collecting of the history the place holder should be set to null handle.
67 class ShapeUpgrade_UnifySameDomain : public Standard_Transient
72 typedef NCollection_DataMap<TopoDS_Shape, Handle(Geom_Plane), TopTools_ShapeMapHasher> DataMapOfFacePlane;
75 Standard_EXPORT ShapeUpgrade_UnifySameDomain();
77 //! Constructor defining input shape and necessary flags.
78 //! It does not perform unification.
79 Standard_EXPORT ShapeUpgrade_UnifySameDomain
80 (const TopoDS_Shape& aShape,
81 const Standard_Boolean UnifyEdges = Standard_True,
82 const Standard_Boolean UnifyFaces = Standard_True,
83 const Standard_Boolean ConcatBSplines = Standard_False);
85 //! Initializes with a shape and necessary flags.
86 //! It does not perform unification.
87 //! If you intend to nullify the History place holder do it after
89 Standard_EXPORT void Initialize
90 (const TopoDS_Shape& aShape,
91 const Standard_Boolean UnifyEdges = Standard_True,
92 const Standard_Boolean UnifyFaces = Standard_True,
93 const Standard_Boolean ConcatBSplines = Standard_False);
95 //! Sets the flag defining whether it is allowed to create
96 //! internal edges inside merged faces in the case of non-manifold
97 //! topology. Without this flag merging through multi connected edge
98 //! is forbidden. Default value is false.
99 Standard_EXPORT void AllowInternalEdges (const Standard_Boolean theValue);
101 //! Sets the shape for avoid merging of the faces/edges.
102 //! This shape can be vertex or edge.
103 //! If the shape is a vertex it forbids merging of connected edges.
104 //! If the shape is a edge it forbids merging of connected faces.
105 //! This method can be called several times to keep several shapes.
106 Standard_EXPORT void KeepShape(const TopoDS_Shape& theShape);
108 //! Sets the map of shapes for avoid merging of the faces/edges.
109 //! It allows passing a ready to use map instead of calling many times
110 //! the method KeepShape.
111 Standard_EXPORT void KeepShapes(const TopTools_MapOfShape& theShapes);
113 //! Sets the flag defining the behavior of the algorithm regarding
114 //! modification of input shape.
115 //! If this flag is equal to True then the input (original) shape can't be
116 //! modified during modification process. Default value is true.
117 Standard_EXPORT void SetSafeInputMode(Standard_Boolean theValue);
119 //! Sets the linear tolerance. It plays the role of chord error when
120 //! taking decision about merging of shapes. Default value is Precision::Confusion().
121 void SetLinearTolerance(const Standard_Real theValue)
126 //! Sets the angular tolerance. If two shapes form a connection angle greater than
127 //! this value they will not be merged. Default value is Precision::Angular().
128 void SetAngularTolerance(const Standard_Real theValue)
130 myAngTol = (theValue < Precision::Angular() ? Precision::Angular() : theValue);
133 //! Performs unification and builds the resulting shape.
134 Standard_EXPORT void Build();
136 //! Gives the resulting shape
137 const TopoDS_Shape& Shape() const
142 //! Returns the history of the processed shapes.
143 const Handle(BRepTools_History)& History() const
148 //! Returns the history of the processed shapes.
149 Handle(BRepTools_History)& History()
154 DEFINE_STANDARD_RTTIEXT(ShapeUpgrade_UnifySameDomain,Standard_Transient)
158 struct SubSequenceOfEdges;
162 //! This method makes if possible a common face from each
163 //! group of faces lying on coincident surfaces
164 Standard_EXPORT void UnifyFaces();
166 //! This method makes if possible a common edge from each
167 //! group of smothly connected edges, which are common for the same couple of faces
168 Standard_EXPORT void UnifyEdges();
170 void IntUnifyFaces(const TopoDS_Shape& theInpShape,
171 TopTools_IndexedDataMapOfShapeListOfShape& theGMapEdgeFaces,
172 const TopTools_MapOfShape& theFreeBoundMap);
174 //! Splits the sequence of edges into the sequence of chains
175 Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges,
176 const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
177 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
178 const TopTools_MapOfShape& NonMergVrt);
180 //! Tries to unify the sequence of edges with the set of
181 //! another edges which lies on the same geometry
182 Standard_Boolean MergeSeq(TopTools_SequenceOfShape& SeqEdges,
183 const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
184 const TopTools_MapOfShape& nonMergVert);
186 //! Merges a sequence of edges into one edge if possible
187 Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape& theChain,
188 const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap,
189 TopoDS_Edge& OutEdge);
191 //! Unifies the pcurve of the chain into one pcurve of the edge
192 void UnionPCurves(const TopTools_SequenceOfShape& theChain,
193 TopoDS_Edge& theEdge);
195 //! Fills the history of the modifications during the operation.
196 Standard_EXPORT void FillHistory();
200 //! Generates sub-sequences of edges from sequence of edges.
201 //! Edges from each subsequences can be merged into the one edge.
202 static void generateSubSeq (const TopTools_SequenceOfShape& anInpEdgeSeq,
203 NCollection_Sequence<SubSequenceOfEdges>& SeqOfSubSeqOfEdges,
204 Standard_Boolean IsClosed, double theAngTol, double theLinTol,
205 const TopTools_MapOfShape& AvoidEdgeVrt,
206 const TopTools_IndexedDataMapOfShapeListOfShape& theVFmap);
210 TopoDS_Shape myInitShape;
211 Standard_Real myLinTol;
212 Standard_Real myAngTol;
213 Standard_Boolean myUnifyFaces;
214 Standard_Boolean myUnifyEdges;
215 Standard_Boolean myConcatBSplines;
216 Standard_Boolean myAllowInternal;
217 Standard_Boolean mySafeInputMode;
218 TopoDS_Shape myShape;
219 Handle(ShapeBuild_ReShape) myContext;
220 TopTools_MapOfShape myKeepShapes;
221 DataMapOfFacePlane myFacePlaneMap;
222 TopTools_IndexedDataMapOfShapeListOfShape myEFmap;
223 TopTools_DataMapOfShapeShape myFaceNewFace;
225 Handle(BRepTools_History) myHistory; //!< The history.
228 #endif // _ShapeUpgrade_UnifySameDomain_HeaderFile