0028017: Unexpected result of General Fuse operation
[occt.git] / src / BOPDS / BOPDS_DS.hxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _BOPDS_DS_HeaderFile
16 #define _BOPDS_DS_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <BOPCol_BaseAllocator.hxx>
23 #include <BOPCol_ListOfShape.hxx>
24 #include <Standard_Integer.hxx>
25 #include <BOPDS_VectorOfIndexRange.hxx>
26 #include <BOPDS_VectorOfShapeInfo.hxx>
27 #include <BOPCol_DataMapOfShapeInteger.hxx>
28 #include <BOPDS_VectorOfListOfPaveBlock.hxx>
29 #include <BOPDS_DataMapOfPaveBlockCommonBlock.hxx>
30 #include <BOPDS_VectorOfFaceInfo.hxx>
31 #include <BOPCol_DataMapOfIntegerInteger.hxx>
32 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
33 #include <BOPDS_MapOfPassKey.hxx>
34 #include <BOPDS_VectorOfInterfVV.hxx>
35 #include <BOPDS_VectorOfInterfVE.hxx>
36 #include <BOPDS_VectorOfInterfVF.hxx>
37 #include <BOPDS_VectorOfInterfEE.hxx>
38 #include <BOPDS_VectorOfInterfEF.hxx>
39 #include <BOPDS_VectorOfInterfFF.hxx>
40 #include <BOPDS_VectorOfInterfVZ.hxx>
41 #include <BOPDS_VectorOfInterfEZ.hxx>
42 #include <BOPDS_VectorOfInterfFZ.hxx>
43 #include <BOPDS_VectorOfInterfZZ.hxx>
44 #include <Standard_Real.hxx>
45 #include <Standard_Boolean.hxx>
46 #include <BOPDS_ListOfPaveBlock.hxx>
47 #include <BOPDS_IndexedMapOfPaveBlock.hxx>
48 #include <BOPDS_MapOfPaveBlock.hxx>
49 #include <BOPCol_MapOfInteger.hxx>
50 #include <BOPCol_ListOfInteger.hxx>
51 #include <BOPDS_ListOfPave.hxx>
52 #include <Precision.hxx>
53 class BOPDS_IndexRange;
54 class BOPDS_ShapeInfo;
55 class TopoDS_Shape;
56 class BOPDS_PaveBlock;
57 class BOPDS_CommonBlock;
58 class BOPDS_FaceInfo;
59 class Bnd_Box;
60
61
62
63 //! The class BOPDS_DS provides the control
64 //! the data structure for
65 //! partition and  boolean operation algorithms
66 //!
67 //! The data structure has the  following contents:
68 //! 1. the arguments of an operation [myArguments];
69 //! 2  the information about arguments/new shapes
70 //! and their sub-shapes (type of the shape,
71 //! bounding box, etc) [myLines];
72 //! 3. each argument shape(and its subshapes)
73 //! has/have own range of indices (rank)
74 //! 4. pave blocks on source edges [myPaveBlocksPool];
75 //! 5. the state of source faces  [myFaceInfoPool]
76 //! 6  the collection of same domain shapes [myShapesSD]
77 //! 7  the collection of interferences  [myInterfTB,
78 //! myInterfVV,..myInterfFF]
79 class BOPDS_DS 
80 {
81 public:
82
83   DEFINE_STANDARD_ALLOC
84
85   
86
87   //! Empty contructor
88   Standard_EXPORT BOPDS_DS();
89 Standard_EXPORT virtual ~BOPDS_DS();
90   
91
92   //! Contructor
93   //! theAllocator - the allocator to manage the memory
94   Standard_EXPORT BOPDS_DS(const BOPCol_BaseAllocator& theAllocator);
95   
96
97   //! Clears the contents
98   Standard_EXPORT void Clear();
99   
100
101   //! Selector
102   Standard_EXPORT const BOPCol_BaseAllocator& Allocator() const;
103   
104
105   //! Modifier
106   //! Sets the arguments [theLS] of an operation
107   Standard_EXPORT void SetArguments (const BOPCol_ListOfShape& theLS);
108   
109
110   //! Selector
111   //! Returns the arguments of an operation
112   Standard_EXPORT const BOPCol_ListOfShape& Arguments() const;
113   
114
115   //! Initializes the data structure for
116   //! the arguments
117   Standard_EXPORT void Init(const Standard_Real theFuzz = Precision::Confusion());
118   
119
120   //! Selector
121   //! Returns the total number of shapes stored
122   Standard_EXPORT Standard_Integer NbShapes() const;
123   
124
125   //! Selector
126   //! Returns the total number of source shapes stored
127   Standard_EXPORT Standard_Integer NbSourceShapes() const;
128   
129
130   //! Selector
131   //! Returns the number of index ranges
132   Standard_EXPORT Standard_Integer NbRanges() const;
133   
134
135   //! Selector
136   //! Returns the index range "i"
137   Standard_EXPORT const BOPDS_IndexRange& Range (const Standard_Integer theIndex) const;
138   
139
140   //! Selector
141   //! Returns the rank of the shape of index "i"
142   Standard_EXPORT Standard_Integer Rank (const Standard_Integer theIndex) const;
143   
144
145   //! Returns true if the shape of index "i" is not
146   //! the source shape/sub-shape
147   Standard_EXPORT Standard_Boolean IsNewShape (const Standard_Integer theIndex) const;
148   
149
150   //! Modifier
151   //! Appends the information about the shape [theSI]
152   //! to the data structure
153   //! Returns the index of theSI in the data structure
154   Standard_EXPORT Standard_Integer Append (const BOPDS_ShapeInfo& theSI);
155   
156
157   //! Modifier
158   //! Appends the default information about the shape [theS]
159   //! to the data structure
160   //! Returns the index of theS in the data structure
161   Standard_EXPORT Standard_Integer Append (const TopoDS_Shape& theS);
162   
163
164   //! Selector
165   //! Returns the information about the shape
166   //! with index theIndex
167   Standard_EXPORT const BOPDS_ShapeInfo& ShapeInfo (const Standard_Integer theIndex) const;
168   
169
170   //! Selector/Modifier
171   //! Returns the information about the shape
172   //! with index theIndex
173   Standard_EXPORT BOPDS_ShapeInfo& ChangeShapeInfo (const Standard_Integer theIndex);
174   
175
176   //! Selector
177   //! Returns the shape
178   //! with index theIndex
179   Standard_EXPORT const TopoDS_Shape& Shape (const Standard_Integer theIndex) const;
180   
181
182   //! Selector
183   //! Returns the index  of the shape theS
184   Standard_EXPORT Standard_Integer Index (const TopoDS_Shape& theS) const;
185   
186
187   //! Selector
188   //! Returns the information about pave blocks on source edges
189   Standard_EXPORT const BOPDS_VectorOfListOfPaveBlock& PaveBlocksPool() const;
190   
191
192   //! Selector/Modifier
193   //! Returns the information about pave blocks on source edges
194   Standard_EXPORT BOPDS_VectorOfListOfPaveBlock& ChangePaveBlocksPool();
195   
196
197   //! Query
198   //! Returns true if the shape with index theIndex has the
199   //! information about pave blocks
200   Standard_EXPORT Standard_Boolean HasPaveBlocks (const Standard_Integer theIndex) const;
201   
202
203   //! Selector
204   //! Returns the pave blocks for the shape with index theIndex
205   Standard_EXPORT const BOPDS_ListOfPaveBlock& PaveBlocks (const Standard_Integer theIndex) const;
206   
207
208   //! Selector/Modifier
209   //! Returns the pave blocks for the shape with index theIndex
210   Standard_EXPORT BOPDS_ListOfPaveBlock& ChangePaveBlocks (const Standard_Integer theIndex);
211   
212
213   //! Update the pave blocks for the all shapes in data structure
214   Standard_EXPORT void UpdatePaveBlocks();
215   
216
217   //! Update the pave block thePB
218   Standard_EXPORT void UpdatePaveBlock (const Handle(BOPDS_PaveBlock)& thePB);
219   
220
221   //! Update the common block theCB
222   Standard_EXPORT void UpdateCommonBlock (const Handle(BOPDS_CommonBlock)& theCB,
223                                           const Standard_Real theFuzz);
224   
225
226   //! Query
227   //! Returns true if the pave block is common block
228   Standard_EXPORT Standard_Boolean IsCommonBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
229   
230
231   //! Selector
232   //! Returns the common block
233   Standard_EXPORT Handle(BOPDS_CommonBlock) CommonBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
234   
235
236   //! Modifier
237   //! Sets the common block <theCB>
238   Standard_EXPORT void SetCommonBlock (const Handle(BOPDS_PaveBlock)& thePB, const Handle(BOPDS_CommonBlock)& theCB);
239   
240
241   //! Selector
242   //! Returns the real first pave block
243   Standard_EXPORT Handle(BOPDS_PaveBlock) RealPaveBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
244   
245
246   //! Query
247   //! Returns true if common block contains more then one pave block
248   Standard_EXPORT Standard_Boolean IsCommonBlockOnEdge (const Handle(BOPDS_PaveBlock)& thePB) const;
249   
250
251   //! Selector
252   //! Returns the information about state of faces
253   Standard_EXPORT const BOPDS_VectorOfFaceInfo& FaceInfoPool() const;
254   
255
256   //! Query
257   //! Returns true if the shape with index theIndex has the
258   //! information about state of face
259   Standard_EXPORT Standard_Boolean HasFaceInfo (const Standard_Integer theIndex) const;
260   
261
262   //! Selector
263   //! Returns the state of face with index theIndex
264   Standard_EXPORT const BOPDS_FaceInfo& FaceInfo (const Standard_Integer theIndex) const;
265   
266
267   //! Selector/Modifier
268   //! Returns the state of face with index theIndex
269   Standard_EXPORT BOPDS_FaceInfo& ChangeFaceInfo (const Standard_Integer theIndex);
270   
271
272   //! Update the state In of face with index theIndex
273   Standard_EXPORT void UpdateFaceInfoIn (const Standard_Integer theIndex);
274   
275
276   //! Update the state On of face with index theIndex
277   Standard_EXPORT void UpdateFaceInfoOn (const Standard_Integer theIndex);
278   
279
280   //! Selector
281   //! Returns the state On
282   //! [theMPB,theMVP] of face with index theIndex
283   Standard_EXPORT void FaceInfoOn (const Standard_Integer theIndex, BOPDS_IndexedMapOfPaveBlock& theMPB, BOPCol_MapOfInteger& theMVP);
284   
285
286   //! Selector
287   //! Returns the state In
288   //! [theMPB,theMVP] of face with index theIndex
289   Standard_EXPORT void FaceInfoIn (const Standard_Integer theIndex, BOPDS_IndexedMapOfPaveBlock& theMPB, BOPCol_MapOfInteger& theMVP);
290   
291
292   //! Selector
293   //! Returns the indices of alone vertices
294   //! for the face with index theIndex
295   Standard_EXPORT void AloneVertices (const Standard_Integer theF, BOPCol_ListOfInteger& theLI) const;
296   
297
298   //! Refine the state On for the all faces having
299   //! state information
300   //!
301   //! ++
302   Standard_EXPORT void RefineFaceInfoOn();
303   
304
305   //! Returns information about ON/IN subshapes of the given faces.
306   //! @param theMVOnIn  the indices of ON/IN vertices from both faces
307   //! @param thePBOnIn  all On/In pave blocks from both faces
308   //! @param theCommonPB  the common pave blocks (that are shared by both faces).
309   Standard_EXPORT void SubShapesOnIn (const Standard_Integer theF1,
310                                       const Standard_Integer theF2,
311                                       BOPCol_MapOfInteger& theMVOnIn,
312                                       BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
313                                       BOPDS_MapOfPaveBlock& theCommonPB) const;
314   
315
316   //! Returns the indices of edges that are  shared
317   //! for the faces with indices theF1, theF2
318   //!
319   //! same domain shapes
320   Standard_EXPORT void SharedEdges (const Standard_Integer theF1, const Standard_Integer theF2, BOPCol_ListOfInteger& theLI, const BOPCol_BaseAllocator& theAllocator);
321   
322
323   //! Selector
324   //! Returns the collection same domain shapes
325   Standard_EXPORT BOPCol_DataMapOfIntegerInteger& ShapesSD();
326   
327
328   //! Modifier
329   //! Adds the information about same domain shapes
330   //! with indices theIndex, theIndexSD
331   Standard_EXPORT void AddShapeSD (const Standard_Integer theIndex, const Standard_Integer theIndexSD);
332   
333
334   //! Query
335   //! Returns true if the shape with index theIndex has the
336   //! same domain shape. In this case theIndexSD will contain
337   //! the index of same domain shape found
338   //!
339   //! interferences
340   Standard_EXPORT Standard_Boolean HasShapeSD (const Standard_Integer theIndex, Standard_Integer& theIndexSD) const;
341   
342
343   //! Selector/Modifier
344   //! Returns the collection of interferences Vertex/Vertex
345     BOPDS_VectorOfInterfVV& InterfVV();
346   
347
348   //! Selector/Modifier
349   //! Returns the collection of interferences Vertex/Edge
350     BOPDS_VectorOfInterfVE& InterfVE();
351   
352
353   //! Selector/Modifier
354   //! Returns the collection of interferences Vertex/Face
355     BOPDS_VectorOfInterfVF& InterfVF();
356   
357
358   //! Selector/Modifier
359   //! Returns the collection of interferences Edge/Edge
360     BOPDS_VectorOfInterfEE& InterfEE();
361   
362
363   //! Selector/Modifier
364   //! Returns the collection of interferences Edge/Face
365     BOPDS_VectorOfInterfEF& InterfEF();
366   
367
368   //! Selector/Modifier
369   //! Returns the collection of interferences Face/Face
370     BOPDS_VectorOfInterfFF& InterfFF();
371   
372
373   //! Selector/Modifier
374   //! Returns the collection of interferences Vertex/Solid
375     BOPDS_VectorOfInterfVZ& InterfVZ();
376   
377
378   //! Selector/Modifier
379   //! Returns the collection of interferences Edge/Solid
380     BOPDS_VectorOfInterfEZ& InterfEZ();
381   
382
383   //! Selector/Modifier
384   //! Returns the collection of interferences Face/Solid
385     BOPDS_VectorOfInterfFZ& InterfFZ();
386   
387
388   //! Selector/Modifier
389   //! Returns the collection of interferences Solid/Solid
390     BOPDS_VectorOfInterfZZ& InterfZZ();
391   
392
393   //! Returns the number of types of the interferences
394     static Standard_Integer NbInterfTypes();
395   
396
397   //! Modifier
398   //! Adds the information about an interference between
399   //! shapes with indices theI1, theI2 to the summary
400   //! table of interferences
401     void AddInterf (const Standard_Integer theI1, const Standard_Integer theI2);
402   
403
404   //! Query
405   //! Returns true if the shape with index theI
406   //! is interferred
407   Standard_EXPORT Standard_Boolean HasInterf (const Standard_Integer theI) const;
408   
409
410   //! Query
411   //! Returns true if the shapes with indices theI1, theI2
412   //! are interferred
413     Standard_Boolean HasInterf (const Standard_Integer theI1, const Standard_Integer theI2) const;
414   
415
416   //! Query
417   //! Returns true if the shape with index theI1 is interfered
418   //! with
419   //! any sub-shape of the shape with index theI2  (theFlag=true)
420   //! all sub-shapes of the shape with index theI2 (theFlag=false)
421   Standard_EXPORT Standard_Boolean HasInterfShapeSubShapes (const Standard_Integer theI1, const Standard_Integer theI2, const Standard_Boolean theFlag = Standard_True) const;
422   
423
424   //! Query
425   //! Returns true if the shapes with indices theI1, theI2
426   //! have interferred sub-shapes
427   Standard_EXPORT Standard_Boolean HasInterfSubShapes (const Standard_Integer theI1, const Standard_Integer theI2) const;
428   
429
430   //! Selector
431   //! Returns the table of interferences
432   //!
433   //! debug
434     const BOPDS_MapOfPassKey& Interferences() const;
435   
436   Standard_EXPORT void Dump() const;
437   
438   Standard_EXPORT void SortPaveBlocks (const Handle(BOPDS_CommonBlock)& theCB);
439   
440   Standard_EXPORT Standard_Boolean IsToSort (const Handle(BOPDS_CommonBlock)& theCB, Standard_Integer& theI);
441   
442   Standard_EXPORT Standard_Boolean IsSubShape (const Standard_Integer theI1, const Standard_Integer theI2);
443   
444   //! Fills theLP with sorted paves
445   //! of the shape with index theIndex
446   Standard_EXPORT void Paves (const Standard_Integer theIndex, BOPDS_ListOfPave& theLP);
447   
448
449   //! Updates tolerance of the sub-shapes of the shape with index <theIndex>.
450   Standard_EXPORT void UpdateEdgeTolerance (const Standard_Integer theIndex,
451                                             const Standard_Real theTolerance,
452                                             const Standard_Real theFuzz = Precision::Confusion());
453
454   //! Update the pave blocks for all shapes in data structure
455   Standard_EXPORT void UpdatePaveBlocksWithSDVertices();
456
457   //! Update the pave block of the common block for all shapes in data structure
458   Standard_EXPORT void UpdateCommonBlockWithSDVertices(const Handle(BOPDS_CommonBlock)& theCB);
459
460   Standard_EXPORT void InitPaveBlocksForVertex(const Standard_Integer theNV);
461
462 protected:
463
464   
465
466   //! Initializes the pave blocks for the shape with index theIndex
467   Standard_EXPORT void InitPaveBlocks (const Standard_Integer theIndex);
468
469   //! Update the pave block for all shapes in data structure
470   Standard_EXPORT void UpdatePaveBlockWithSDVertices(const Handle(BOPDS_PaveBlock)& thePB);
471
472   //! Initializes the state of face with index theIndex
473   Standard_EXPORT void InitFaceInfo (const Standard_Integer theIndex);
474   
475   Standard_EXPORT void InitShape (const Standard_Integer theIndex, const TopoDS_Shape& theS);
476   
477   Standard_EXPORT Standard_Boolean CheckCoincidence (const Handle(BOPDS_PaveBlock)& thePB1,
478                                                      const Handle(BOPDS_PaveBlock)& thePB2,
479                                                      const Standard_Real theFuzz);
480   
481
482   //! Computes bouding box <theBox> for the solid with DS-index <theIndex>
483   Standard_EXPORT void BuildBndBoxSolid (const Standard_Integer theIndex, Bnd_Box& theBox);
484
485
486   BOPCol_BaseAllocator myAllocator;
487   BOPCol_ListOfShape myArguments;
488   Standard_Integer myNbShapes;
489   Standard_Integer myNbSourceShapes;
490   BOPDS_VectorOfIndexRange myRanges;
491   BOPDS_VectorOfShapeInfo myLines;
492   BOPCol_DataMapOfShapeInteger myMapShapeIndex;
493   BOPDS_VectorOfListOfPaveBlock myPaveBlocksPool;
494   BOPDS_DataMapOfPaveBlockCommonBlock myMapPBCB;
495   BOPDS_VectorOfFaceInfo myFaceInfoPool;
496   BOPCol_DataMapOfIntegerInteger myShapesSD;
497   BOPCol_DataMapOfIntegerListOfInteger myMapVE;
498   BOPDS_MapOfPassKey myInterfTB;
499   BOPDS_VectorOfInterfVV myInterfVV;
500   BOPDS_VectorOfInterfVE myInterfVE;
501   BOPDS_VectorOfInterfVF myInterfVF;
502   BOPDS_VectorOfInterfEE myInterfEE;
503   BOPDS_VectorOfInterfEF myInterfEF;
504   BOPDS_VectorOfInterfFF myInterfFF;
505   BOPDS_VectorOfInterfVZ myInterfVZ;
506   BOPDS_VectorOfInterfEZ myInterfEZ;
507   BOPDS_VectorOfInterfFZ myInterfFZ;
508   BOPDS_VectorOfInterfZZ myInterfZZ;
509
510
511 private:
512
513
514
515
516
517 };
518
519
520 #include <BOPDS_DS.lxx>
521
522
523
524
525
526 #endif // _BOPDS_DS_HeaderFile