74e950cbc97ce9cbc4dda3d3c1bb97f09f2d8218
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_Sewing.hxx
1 // Created on: 1995-03-23
2 // Created by: Jing Cheng MEI
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _BRepBuilderAPI_Sewing_HeaderFile
18 #define _BRepBuilderAPI_Sewing_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_Real.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
29 #include <TopTools_DataMapOfShapeShape.hxx>
30 #include <Standard_Integer.hxx>
31 #include <TopTools_DataMapOfShapeListOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
33 #include <Standard_Transient.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_SequenceOfShape.hxx>
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TColStd_SequenceOfBoolean.hxx>
38 #include <TColStd_SequenceOfInteger.hxx>
39 #include <TColStd_Array1OfBoolean.hxx>
40 #include <TColStd_Array1OfReal.hxx>
41 #include <TColgp_Array1OfPnt.hxx>
42 #include <TColStd_SequenceOfReal.hxx>
43
44 #include <Message_ProgressRange.hxx>
45
46 class BRepTools_ReShape;
47 class Standard_OutOfRange;
48 class Standard_NoSuchObject;
49 class TopoDS_Shape;
50 class TopoDS_Edge;
51 class TopoDS_Face;
52 class Geom_Surface;
53 class TopLoc_Location;
54 class Geom2d_Curve;
55 class Geom_Curve;
56
57
58 class BRepBuilderAPI_Sewing;
59 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_Sewing, Standard_Transient)
60
61 //! Provides methods to
62 //!
63 //! - identify possible contigous boundaries (for control
64 //! afterwards (of continuity: C0, C1, ...))
65 //!
66 //! - assemble contigous shapes into one shape.
67 //! Only manifold shapes will be found. Sewing will not
68 //! be done in case of multiple edges.
69 //!
70 //! For sewing, use this function as following:
71 //! - create an empty object
72 //! - default tolerance 1.E-06
73 //! - with face analysis on
74 //! - with sewing operation on
75 //! - set the cutting option as you need (default True)
76 //! - define a tolerance
77 //! - add shapes to be sewed -> Add
78 //! - compute -> Perfom
79 //! - output the resulted shapes
80 //! - output free edges if necessary
81 //! - output multiple edges if necessary
82 //! - output the problems if any
83 class BRepBuilderAPI_Sewing : public Standard_Transient
84 {
85
86 public:
87
88   
89   //! Creates an object with
90   //! tolerance of connexity
91   //! option for sewing (if false only control)
92   //! option for analysis of degenerated shapes
93   //! option for cutting of free edges.
94   //! option for non manifold processing
95   Standard_EXPORT BRepBuilderAPI_Sewing(const Standard_Real tolerance = 1.0e-06, const Standard_Boolean option1 = Standard_True, const Standard_Boolean option2 = Standard_True, const Standard_Boolean option3 = Standard_True, const Standard_Boolean option4 = Standard_False);
96   
97   //! initialize the parameters if necessary
98   Standard_EXPORT void Init (const Standard_Real tolerance = 1.0e-06, const Standard_Boolean option1 = Standard_True, const Standard_Boolean option2 = Standard_True, const Standard_Boolean option3 = Standard_True, const Standard_Boolean option4 = Standard_False);
99   
100   //! Loades the context shape.
101   Standard_EXPORT void Load (const TopoDS_Shape& shape);
102   
103   //! Defines the shapes to be sewed or controlled
104   Standard_EXPORT void Add (const TopoDS_Shape& shape);
105   
106   //! Computing
107   //! theProgress - progress indicator of algorithm
108   Standard_EXPORT void Perform (const Message_ProgressRange& theProgress = Message_ProgressRange());
109   
110   //! Gives the sewed shape
111   //! a null shape if nothing constructed
112   //! may be a face, a shell, a solid or a compound
113   Standard_EXPORT const TopoDS_Shape& SewedShape() const;
114   
115   //! set context
116   Standard_EXPORT void SetContext (const Handle(BRepTools_ReShape)& theContext);
117   
118   //! return context
119   Standard_EXPORT const Handle(BRepTools_ReShape)& GetContext() const;
120   
121   //! Gives the number of free edges (edge shared by one face)
122   Standard_EXPORT Standard_Integer NbFreeEdges() const;
123   
124   //! Gives each free edge
125   Standard_EXPORT const TopoDS_Edge& FreeEdge (const Standard_Integer index) const;
126   
127   //! Gives the number of multiple edges
128   //! (edge shared by more than two faces)
129   Standard_EXPORT Standard_Integer NbMultipleEdges() const;
130   
131   //! Gives each multiple edge
132   Standard_EXPORT const TopoDS_Edge& MultipleEdge (const Standard_Integer index) const;
133   
134   //! Gives the number of contigous edges (edge shared by two faces)
135   Standard_EXPORT Standard_Integer NbContigousEdges() const;
136   
137   //! Gives each contigous edge
138   Standard_EXPORT const TopoDS_Edge& ContigousEdge (const Standard_Integer index) const;
139   
140   //! Gives the sections (edge) belonging to a contigous edge
141   Standard_EXPORT const TopTools_ListOfShape& ContigousEdgeCouple (const Standard_Integer index) const;
142   
143   //! Indicates if a section is bound (before use SectionToBoundary)
144   Standard_EXPORT Standard_Boolean IsSectionBound (const TopoDS_Edge& section) const;
145   
146   //! Gives the original edge (free boundary) which becomes the
147   //! the section. Remember that sections constitute  common edges.
148   //! This imformation is important for control because with
149   //! original edge we can find the surface to which the section
150   //! is attached.
151   Standard_EXPORT const TopoDS_Edge& SectionToBoundary (const TopoDS_Edge& section) const;
152   
153   //! Gives the number of degenerated shapes
154   Standard_EXPORT Standard_Integer NbDegeneratedShapes() const;
155   
156   //! Gives each degenerated shape
157   Standard_EXPORT const TopoDS_Shape& DegeneratedShape (const Standard_Integer index) const;
158   
159   //! Indicates if a input shape is degenerated
160   Standard_EXPORT Standard_Boolean IsDegenerated (const TopoDS_Shape& shape) const;
161   
162   //! Indicates if a input shape has been modified
163   Standard_EXPORT Standard_Boolean IsModified (const TopoDS_Shape& shape) const;
164   
165   //! Gives a modifieded shape
166   Standard_EXPORT const TopoDS_Shape& Modified (const TopoDS_Shape& shape) const;
167   
168   //! Indicates if a input subshape has been modified
169   Standard_EXPORT Standard_Boolean IsModifiedSubShape (const TopoDS_Shape& shape) const;
170   
171   //! Gives a modifieded subshape
172   Standard_EXPORT TopoDS_Shape ModifiedSubShape (const TopoDS_Shape& shape) const;
173   
174   //! print the informations
175   Standard_EXPORT void Dump() const;
176   
177   //! Gives the number of deleted faces (faces smallest than tolerance)
178   Standard_EXPORT Standard_Integer NbDeletedFaces() const;
179   
180   //! Gives each deleted face
181   Standard_EXPORT const TopoDS_Face& DeletedFace (const Standard_Integer index) const;
182   
183   //! Gives a modified shape
184   Standard_EXPORT TopoDS_Face WhichFace (const TopoDS_Edge& theEdg, const Standard_Integer index = 1) const;
185   
186   //! Gets same parameter mode.
187     Standard_Boolean SameParameterMode() const;
188   
189   //! Sets same parameter mode.
190     void SetSameParameterMode (const Standard_Boolean SameParameterMode);
191   
192   //! Gives set tolerance.
193     Standard_Real Tolerance() const;
194   
195   //! Sets tolerance
196     void SetTolerance (const Standard_Real theToler);
197   
198   //! Gives set min tolerance.
199     Standard_Real MinTolerance() const;
200   
201   //! Sets min tolerance
202     void SetMinTolerance (const Standard_Real theMinToler);
203   
204   //! Gives set max tolerance
205     Standard_Real MaxTolerance() const;
206   
207   //! Sets max tolerance.
208     void SetMaxTolerance (const Standard_Real theMaxToler);
209   
210   //! Returns mode for sewing faces By default - true.
211     Standard_Boolean FaceMode() const;
212   
213   //! Sets mode for sewing faces By default - true.
214     void SetFaceMode (const Standard_Boolean theFaceMode);
215   
216   //! Returns mode for sewing floating edges By default - false.
217     Standard_Boolean FloatingEdgesMode() const;
218   
219   //! Sets mode for sewing floating edges By default - false.
220   //! Returns mode for cutting floating edges By default - false.
221   //! Sets mode for cutting floating edges By default - false.
222     void SetFloatingEdgesMode (const Standard_Boolean theFloatingEdgesMode);
223   
224   //! Returns mode for accounting of local tolerances
225   //! of edges and vertices during of merging.
226     Standard_Boolean LocalTolerancesMode() const;
227   
228   //! Sets mode for accounting of local tolerances
229   //! of edges and vertices during of merging
230   //! in this case WorkTolerance = myTolerance + tolEdge1+ tolEdg2;
231     void SetLocalTolerancesMode (const Standard_Boolean theLocalTolerancesMode);
232   
233   //! Sets mode for non-manifold sewing.
234     void SetNonManifoldMode (const Standard_Boolean theNonManifoldMode);
235   
236   //! Gets mode for non-manifold sewing.
237   //!
238   //! INTERNAL FUCTIONS ---
239     Standard_Boolean NonManifoldMode() const;
240
241
242
243
244   DEFINE_STANDARD_RTTIEXT(BRepBuilderAPI_Sewing,Standard_Transient)
245
246 protected:
247
248   
249   //! Performs cutting of sections
250   //! theProgress - progress indicator of processing
251   Standard_EXPORT void Cutting (const Message_ProgressRange& theProgress = Message_ProgressRange());
252   
253   Standard_EXPORT void Merging (const Standard_Boolean passage, const Message_ProgressRange& theProgress = Message_ProgressRange());
254   
255   Standard_EXPORT Standard_Boolean IsMergedClosed (const TopoDS_Edge& Edge1, const TopoDS_Edge& Edge2, const TopoDS_Face& fase) const;
256   
257   Standard_EXPORT Standard_Boolean FindCandidates (TopTools_SequenceOfShape& seqSections, TColStd_IndexedMapOfInteger& mapReference, TColStd_SequenceOfInteger& seqCandidates, TColStd_SequenceOfBoolean& seqOrientations);
258   
259   Standard_EXPORT void AnalysisNearestEdges (const TopTools_SequenceOfShape& sequenceSec, TColStd_SequenceOfInteger& seqIndCandidate, TColStd_SequenceOfBoolean& seqOrientations, const Standard_Boolean evalDist = Standard_True);
260   
261   //! Merged nearest edges.
262   Standard_EXPORT Standard_Boolean MergedNearestEdges (const TopoDS_Shape& edge, TopTools_SequenceOfShape& SeqMergedEdge, TColStd_SequenceOfBoolean& SeqMergedOri);
263   
264   Standard_EXPORT void EdgeProcessing (const Message_ProgressRange& theProgress = Message_ProgressRange());
265
266   //! Recompute regularity on merged edges
267   Standard_EXPORT void EdgeRegularity (const Message_ProgressRange& theProgress = Message_ProgressRange());
268   
269   Standard_EXPORT void CreateOutputInformations();
270   
271   //! Defines if surface is U closed.
272   Standard_EXPORT virtual Standard_Boolean IsUClosedSurface (const Handle(Geom_Surface)& surf, const TopoDS_Shape& theEdge, const TopLoc_Location& theloc) const;
273   
274   //! Defines if surface is V closed.
275   Standard_EXPORT virtual Standard_Boolean IsVClosedSurface (const Handle(Geom_Surface)& surf, const TopoDS_Shape& theEdge, const TopLoc_Location& theloc) const;
276   
277
278   //! This method is called from Perform only
279   //! theProgress - progress indicator of processing
280   Standard_EXPORT virtual void FaceAnalysis (const Message_ProgressRange& theProgress = Message_ProgressRange());
281   
282
283   //! This method is called from Perform only
284   Standard_EXPORT virtual void FindFreeBoundaries();
285   
286
287   //! This method is called from Perform only
288   //! theProgress - progress indicator of processing
289   Standard_EXPORT virtual void VerticesAssembling (const Message_ProgressRange& theProgress = Message_ProgressRange());
290   
291
292   //! This method is called from Perform only
293   Standard_EXPORT virtual void CreateSewedShape();
294   
295   //! Get wire from free edges.
296   //! This method is called from EdgeProcessing only
297   Standard_EXPORT virtual void GetFreeWires (TopTools_IndexedMapOfShape& MapFreeEdges,
298                                              TopTools_SequenceOfShape& seqWires);
299   
300
301   //! This method is called from MergingOfSections only
302   Standard_EXPORT virtual void EvaluateAngulars (TopTools_SequenceOfShape& sequenceSec, TColStd_Array1OfBoolean& secForward, TColStd_Array1OfReal& tabAng, const Standard_Integer indRef) const;
303   
304
305   //! This method is called from MergingOfSections only
306   Standard_EXPORT virtual void EvaluateDistances (TopTools_SequenceOfShape& sequenceSec, TColStd_Array1OfBoolean& secForward, TColStd_Array1OfReal& tabAng, TColStd_Array1OfReal& arrLen, TColStd_Array1OfReal& tabMinDist, const Standard_Integer indRef) const;
307   
308
309   //! This method is called from SameParameterEdge only
310   Standard_EXPORT virtual Handle(Geom2d_Curve) SameRange (const Handle(Geom2d_Curve)& CurvePtr, const Standard_Real FirstOnCurve, const Standard_Real LastOnCurve, const Standard_Real RequestedFirst, const Standard_Real RequestedLast) const;
311   
312
313   //! This method is called from SameParameterEdge only
314   Standard_EXPORT virtual void SameParameter (const TopoDS_Edge& edge) const;
315   
316
317   //! This method is called from Merging only
318   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge (const TopoDS_Shape& edge, const TopTools_SequenceOfShape& seqEdges, const TColStd_SequenceOfBoolean& seqForward, TopTools_MapOfShape& mapMerged, const Handle(BRepTools_ReShape)& locReShape);
319   
320
321   //! This method is called from Merging only
322   Standard_EXPORT virtual TopoDS_Edge SameParameterEdge (const TopoDS_Edge& edge1, const TopoDS_Edge& edge2, const TopTools_ListOfShape& listFaces1, const TopTools_ListOfShape& listFaces2, const Standard_Boolean secForward, Standard_Integer& whichSec, const Standard_Boolean firstCall = Standard_True);
323   
324   //! Projects points on curve
325   //! This method is called from Cutting only
326   Standard_EXPORT void ProjectPointsOnCurve (const TColgp_Array1OfPnt& arrPnt, const Handle(Geom_Curve)& Crv, const Standard_Real first, const Standard_Real last, TColStd_Array1OfReal& arrDist, TColStd_Array1OfReal& arrPara, TColgp_Array1OfPnt& arrProj, const Standard_Boolean isConsiderEnds) const;
327   
328   //! Creates cutting vertices on projections
329   //! This method is called from Cutting only
330   Standard_EXPORT virtual void CreateCuttingNodes (const TopTools_IndexedMapOfShape& MapVert, const TopoDS_Shape& bound, const TopoDS_Shape& vfirst, const TopoDS_Shape& vlast, const TColStd_Array1OfReal& arrDist, const TColStd_Array1OfReal& arrPara, const TColgp_Array1OfPnt& arrPnt, TopTools_SequenceOfShape& seqNode, TColStd_SequenceOfReal& seqPara);
331   
332   //! Performs cutting of bound
333   //! This method is called from Cutting only
334   Standard_EXPORT virtual void CreateSections (const TopoDS_Shape& bound, const TopTools_SequenceOfShape& seqNode, const TColStd_SequenceOfReal& seqPara, TopTools_ListOfShape& listEdge);
335   
336   //! Makes all edges from shape same parameter
337   //! if SameParameterMode is equal to Standard_True
338   //! This method is called from Perform only
339   Standard_EXPORT virtual void SameParameterShape();
340
341   Standard_Real myTolerance;
342   Standard_Boolean mySewing;
343   Standard_Boolean myAnalysis;
344   Standard_Boolean myCutting;
345   Standard_Boolean myNonmanifold;
346   TopTools_IndexedDataMapOfShapeShape myOldShapes;
347   TopoDS_Shape mySewedShape;
348   TopTools_IndexedMapOfShape myDegenerated;
349   TopTools_IndexedMapOfShape myFreeEdges;
350   TopTools_IndexedMapOfShape myMultipleEdges;
351   TopTools_IndexedDataMapOfShapeListOfShape myContigousEdges;
352   TopTools_DataMapOfShapeShape myContigSecBound;
353   Standard_Integer myNbShapes;
354   Standard_Integer myNbVertices;
355   Standard_Integer myNbEdges;
356   TopTools_IndexedDataMapOfShapeListOfShape myBoundFaces;
357   TopTools_DataMapOfShapeListOfShape myBoundSections;
358   TopTools_DataMapOfShapeShape mySectionBound;
359   TopTools_IndexedDataMapOfShapeShape myVertexNode;
360   TopTools_IndexedDataMapOfShapeShape myVertexNodeFree;
361   TopTools_DataMapOfShapeListOfShape myNodeSections;
362   TopTools_DataMapOfShapeListOfShape myCuttingNode;
363   TopTools_IndexedMapOfShape myLittleFace;
364   TopoDS_Shape myShape;
365   Handle(BRepTools_ReShape) myReShape;
366
367
368 private:
369
370
371   Standard_Boolean myFaceMode;
372   Standard_Boolean myFloatingEdgesMode;
373   Standard_Boolean mySameParameterMode;
374   Standard_Boolean myLocalToleranceMode;
375   Standard_Real myMinTolerance;
376   Standard_Real myMaxTolerance;
377   TopTools_MapOfShape myMergedEdges;
378
379
380 };
381
382
383 #include <BRepBuilderAPI_Sewing.lxx>
384
385
386
387
388
389 #endif // _BRepBuilderAPI_Sewing_HeaderFile