0029237: Improve performance of Boolean Operations
[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_MapOfPair.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 //! of data structure for the algorithms in the
65 //! Boolean Component such as General Fuse, Boolean operations,
66 //! Section, Maker Volume, Splitter and Cells Builder.<br>
67 //!
68 //! The data structure has the  following contents:<br>
69 //! 1. the arguments of an operation [myArguments];<br>
70 //! 2  the information about arguments/new shapes
71 //! and their sub-shapes (type of the shape,
72 //! bounding box, etc) [myLines];<br>
73 //! 3. each argument shape(and its subshapes)
74 //! has/have own range of indices (rank);<br>
75 //! 4. pave blocks on source edges [myPaveBlocksPool];<br>
76 //! 5. the state of source faces  [myFaceInfoPool];<br>
77 //! 6  the collection of same domain shapes [myShapesSD];<br>
78 //! 7  the collection of interferences  [myInterfTB,
79 //! myInterfVV,..myInterfFF]
80 class BOPDS_DS 
81 {
82 public:
83
84   DEFINE_STANDARD_ALLOC
85
86   
87
88   //! Empty contructor
89   Standard_EXPORT BOPDS_DS();
90 Standard_EXPORT virtual ~BOPDS_DS();
91   
92
93   //! Contructor
94   //! theAllocator - the allocator to manage the memory
95   Standard_EXPORT BOPDS_DS(const BOPCol_BaseAllocator& theAllocator);
96   
97
98   //! Clears the contents
99   Standard_EXPORT void Clear();
100   
101
102   //! Selector
103   Standard_EXPORT const BOPCol_BaseAllocator& Allocator() const;
104   
105
106   //! Modifier
107   //! Sets the arguments [theLS] of an operation
108   Standard_EXPORT void SetArguments (const BOPCol_ListOfShape& theLS);
109   
110
111   //! Selector
112   //! Returns the arguments of an operation
113   Standard_EXPORT const BOPCol_ListOfShape& Arguments() const;
114   
115
116   //! Initializes the data structure for
117   //! the arguments
118   Standard_EXPORT void Init(const Standard_Real theFuzz = Precision::Confusion());
119   
120
121   //! Selector
122   //! Returns the total number of shapes stored
123   Standard_EXPORT Standard_Integer NbShapes() const;
124   
125
126   //! Selector
127   //! Returns the total number of source shapes stored
128   Standard_EXPORT Standard_Integer NbSourceShapes() const;
129   
130
131   //! Selector
132   //! Returns the number of index ranges
133   Standard_EXPORT Standard_Integer NbRanges() const;
134   
135
136   //! Selector
137   //! Returns the index range "i"
138   Standard_EXPORT const BOPDS_IndexRange& Range (const Standard_Integer theIndex) const;
139   
140
141   //! Selector
142   //! Returns the rank of the shape of index "i"
143   Standard_EXPORT Standard_Integer Rank (const Standard_Integer theIndex) const;
144   
145
146   //! Returns true if the shape of index "i" is not
147   //! the source shape/sub-shape
148   Standard_EXPORT Standard_Boolean IsNewShape (const Standard_Integer theIndex) const;
149   
150
151   //! Modifier
152   //! Appends the information about the shape [theSI]
153   //! to the data structure
154   //! Returns the index of theSI in the data structure
155   Standard_EXPORT Standard_Integer Append (const BOPDS_ShapeInfo& theSI);
156   
157
158   //! Modifier
159   //! Appends the default information about the shape [theS]
160   //! to the data structure
161   //! Returns the index of theS in the data structure
162   Standard_EXPORT Standard_Integer Append (const TopoDS_Shape& theS);
163   
164
165   //! Selector
166   //! Returns the information about the shape
167   //! with index theIndex
168   Standard_EXPORT const BOPDS_ShapeInfo& ShapeInfo (const Standard_Integer theIndex) const;
169   
170
171   //! Selector/Modifier
172   //! Returns the information about the shape
173   //! with index theIndex
174   Standard_EXPORT BOPDS_ShapeInfo& ChangeShapeInfo (const Standard_Integer theIndex);
175   
176
177   //! Selector
178   //! Returns the shape
179   //! with index theIndex
180   Standard_EXPORT const TopoDS_Shape& Shape (const Standard_Integer theIndex) const;
181   
182
183   //! Selector
184   //! Returns the index  of the shape theS
185   Standard_EXPORT Standard_Integer Index (const TopoDS_Shape& theS) const;
186   
187
188   //! Selector
189   //! Returns the information about pave blocks on source edges
190   Standard_EXPORT const BOPDS_VectorOfListOfPaveBlock& PaveBlocksPool() const;
191   
192
193   //! Selector/Modifier
194   //! Returns the information about pave blocks on source edges
195   Standard_EXPORT BOPDS_VectorOfListOfPaveBlock& ChangePaveBlocksPool();
196   
197
198   //! Query
199   //! Returns true if the shape with index theIndex has the
200   //! information about pave blocks
201   Standard_EXPORT Standard_Boolean HasPaveBlocks (const Standard_Integer theIndex) const;
202   
203
204   //! Selector
205   //! Returns the pave blocks for the shape with index theIndex
206   Standard_EXPORT const BOPDS_ListOfPaveBlock& PaveBlocks (const Standard_Integer theIndex) const;
207   
208
209   //! Selector/Modifier
210   //! Returns the pave blocks for the shape with index theIndex
211   Standard_EXPORT BOPDS_ListOfPaveBlock& ChangePaveBlocks (const Standard_Integer theIndex);
212   
213
214   //! Update the pave blocks for the all shapes in data structure
215   Standard_EXPORT void UpdatePaveBlocks();
216   
217
218   //! Update the pave block thePB
219   Standard_EXPORT void UpdatePaveBlock (const Handle(BOPDS_PaveBlock)& thePB);
220   
221
222   //! Update the common block theCB
223   Standard_EXPORT void UpdateCommonBlock (const Handle(BOPDS_CommonBlock)& theCB,
224                                           const Standard_Real theFuzz);
225   
226
227   //! Query
228   //! Returns true if the pave block is common block
229   Standard_EXPORT Standard_Boolean IsCommonBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
230   
231
232   //! Selector
233   //! Returns the common block
234   Standard_EXPORT Handle(BOPDS_CommonBlock) CommonBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
235   
236
237   //! Modifier
238   //! Sets the common block <theCB>
239   Standard_EXPORT void SetCommonBlock (const Handle(BOPDS_PaveBlock)& thePB, const Handle(BOPDS_CommonBlock)& theCB);
240   
241
242   //! Selector
243   //! Returns the real first pave block
244   Standard_EXPORT Handle(BOPDS_PaveBlock) RealPaveBlock (const Handle(BOPDS_PaveBlock)& thePB) const;
245   
246
247   //! Query
248   //! Returns true if common block contains more then one pave block
249   Standard_EXPORT Standard_Boolean IsCommonBlockOnEdge (const Handle(BOPDS_PaveBlock)& thePB) const;
250   
251
252   //! Selector
253   //! Returns the information about state of faces
254   Standard_EXPORT const BOPDS_VectorOfFaceInfo& FaceInfoPool() const;
255   
256
257   //! Query
258   //! Returns true if the shape with index theIndex has the
259   //! information about state of face
260   Standard_EXPORT Standard_Boolean HasFaceInfo (const Standard_Integer theIndex) const;
261   
262
263   //! Selector
264   //! Returns the state of face with index theIndex
265   Standard_EXPORT const BOPDS_FaceInfo& FaceInfo (const Standard_Integer theIndex) const;
266   
267
268   //! Selector/Modifier
269   //! Returns the state of face with index theIndex
270   Standard_EXPORT BOPDS_FaceInfo& ChangeFaceInfo (const Standard_Integer theIndex);
271   
272
273   //! Update the state In of face with index theIndex
274   Standard_EXPORT void UpdateFaceInfoIn (const Standard_Integer theIndex);
275   
276
277   //! Update the state On of face with index theIndex
278   Standard_EXPORT void UpdateFaceInfoOn (const Standard_Integer theIndex);
279   
280
281   //! Selector
282   //! Returns the state On
283   //! [theMPB,theMVP] of face with index theIndex
284   Standard_EXPORT void FaceInfoOn (const Standard_Integer theIndex, BOPDS_IndexedMapOfPaveBlock& theMPB, BOPCol_MapOfInteger& theMVP);
285   
286
287   //! Selector
288   //! Returns the state In
289   //! [theMPB,theMVP] of face with index theIndex
290   Standard_EXPORT void FaceInfoIn (const Standard_Integer theIndex, BOPDS_IndexedMapOfPaveBlock& theMPB, BOPCol_MapOfInteger& theMVP);
291   
292
293   //! Selector
294   //! Returns the indices of alone vertices
295   //! for the face with index theIndex
296   Standard_EXPORT void AloneVertices (const Standard_Integer theF, BOPCol_ListOfInteger& theLI) const;
297   
298
299   //! Refine the state On for the all faces having
300   //! state information
301   //!
302   //! ++
303   Standard_EXPORT void RefineFaceInfoOn();
304   
305
306   //! Returns information about ON/IN subshapes of the given faces.
307   //! @param theMVOnIn  the indices of ON/IN vertices from both faces
308   //! @param thePBOnIn  all On/In pave blocks from both faces
309   //! @param theCommonPB  the common pave blocks (that are shared by both faces).
310   Standard_EXPORT void SubShapesOnIn (const Standard_Integer theF1,
311                                       const Standard_Integer theF2,
312                                       BOPCol_MapOfInteger& theMVOnIn,
313                                       BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
314                                       BOPDS_MapOfPaveBlock& theCommonPB) const;
315   
316
317   //! Returns the indices of edges that are  shared
318   //! for the faces with indices theF1, theF2
319   //!
320   //! same domain shapes
321   Standard_EXPORT void SharedEdges (const Standard_Integer theF1, const Standard_Integer theF2, BOPCol_ListOfInteger& theLI, const BOPCol_BaseAllocator& theAllocator);
322   
323
324   //! Selector
325   //! Returns the collection same domain shapes
326   Standard_EXPORT BOPCol_DataMapOfIntegerInteger& ShapesSD();
327   
328
329   //! Modifier
330   //! Adds the information about same domain shapes
331   //! with indices theIndex, theIndexSD
332   Standard_EXPORT void AddShapeSD (const Standard_Integer theIndex, const Standard_Integer theIndexSD);
333   
334
335   //! Query
336   //! Returns true if the shape with index theIndex has the
337   //! same domain shape. In this case theIndexSD will contain
338   //! the index of same domain shape found
339   //!
340   //! interferences
341   Standard_EXPORT Standard_Boolean HasShapeSD (const Standard_Integer theIndex, Standard_Integer& theIndexSD) const;
342   
343
344   //! Selector/Modifier
345   //! Returns the collection of interferences Vertex/Vertex
346     BOPDS_VectorOfInterfVV& InterfVV();
347   
348
349   //! Selector/Modifier
350   //! Returns the collection of interferences Vertex/Edge
351     BOPDS_VectorOfInterfVE& InterfVE();
352   
353
354   //! Selector/Modifier
355   //! Returns the collection of interferences Vertex/Face
356     BOPDS_VectorOfInterfVF& InterfVF();
357   
358
359   //! Selector/Modifier
360   //! Returns the collection of interferences Edge/Edge
361     BOPDS_VectorOfInterfEE& InterfEE();
362   
363
364   //! Selector/Modifier
365   //! Returns the collection of interferences Edge/Face
366     BOPDS_VectorOfInterfEF& InterfEF();
367   
368
369   //! Selector/Modifier
370   //! Returns the collection of interferences Face/Face
371     BOPDS_VectorOfInterfFF& InterfFF();
372   
373
374   //! Selector/Modifier
375   //! Returns the collection of interferences Vertex/Solid
376     BOPDS_VectorOfInterfVZ& InterfVZ();
377   
378
379   //! Selector/Modifier
380   //! Returns the collection of interferences Edge/Solid
381     BOPDS_VectorOfInterfEZ& InterfEZ();
382   
383
384   //! Selector/Modifier
385   //! Returns the collection of interferences Face/Solid
386     BOPDS_VectorOfInterfFZ& InterfFZ();
387   
388
389   //! Selector/Modifier
390   //! Returns the collection of interferences Solid/Solid
391     BOPDS_VectorOfInterfZZ& InterfZZ();
392   
393
394   //! Returns the number of types of the interferences
395     static Standard_Integer NbInterfTypes();
396   
397
398   //! Modifier
399   //! Adds the information about an interference between
400   //! shapes with indices theI1, theI2 to the summary
401   //! table of interferences
402     void AddInterf (const Standard_Integer theI1, const Standard_Integer theI2);
403   
404
405   //! Query
406   //! Returns true if the shape with index theI
407   //! is interferred
408   Standard_EXPORT Standard_Boolean HasInterf (const Standard_Integer theI) const;
409   
410
411   //! Query
412   //! Returns true if the shapes with indices theI1, theI2
413   //! are interferred
414     Standard_Boolean HasInterf (const Standard_Integer theI1, const Standard_Integer theI2) const;
415   
416
417   //! Query
418   //! Returns true if the shape with index theI1 is interfered
419   //! with
420   //! any sub-shape of the shape with index theI2  (theFlag=true)
421   //! all sub-shapes of the shape with index theI2 (theFlag=false)
422   Standard_EXPORT Standard_Boolean HasInterfShapeSubShapes (const Standard_Integer theI1, const Standard_Integer theI2, const Standard_Boolean theFlag = Standard_True) const;
423   
424
425   //! Query
426   //! Returns true if the shapes with indices theI1, theI2
427   //! have interferred sub-shapes
428   Standard_EXPORT Standard_Boolean HasInterfSubShapes (const Standard_Integer theI1, const Standard_Integer theI2) const;
429   
430
431   //! Selector
432   //! Returns the table of interferences
433   //!
434   //! debug
435     const BOPDS_MapOfPair& Interferences() const;
436   
437   Standard_EXPORT void Dump() const;
438   
439   Standard_EXPORT Standard_Boolean IsSubShape (const Standard_Integer theI1, const Standard_Integer theI2);
440   
441   //! Fills theLP with sorted paves
442   //! of the shape with index theIndex
443   Standard_EXPORT void Paves (const Standard_Integer theIndex, BOPDS_ListOfPave& theLP);
444   
445
446   //! Updates tolerance of the sub-shapes of the shape with index <theIndex>.
447   Standard_EXPORT void UpdateEdgeTolerance (const Standard_Integer theIndex,
448                                             const Standard_Real theTolerance,
449                                             const Standard_Real theFuzz = Precision::Confusion());
450
451   //! Update the pave blocks for all shapes in data structure
452   Standard_EXPORT void UpdatePaveBlocksWithSDVertices();
453
454   //! Update the pave block for all shapes in data structure
455   Standard_EXPORT void UpdatePaveBlockWithSDVertices(const Handle(BOPDS_PaveBlock)& thePB);
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   //! Clears information about PaveBlocks for the untouched edges
463   Standard_EXPORT void ReleasePaveBlocks();
464
465   //! Checks if the existing shrunk data of the pave block is still valid.<br>
466   //! The shrunk data may become invalid if e.g. the vertices of the pave block
467   //! have been replaced with the new one with bigger tolerances, or the tolerances
468   //! of the existing vertices have been increased.
469   Standard_EXPORT Standard_Boolean IsValidShrunkData(const Handle(BOPDS_PaveBlock)& thePB);
470
471   //! Computes bounding box <theBox> for the solid with DS-index <theIndex>.
472   //! The flag <theCheckInverted> enables/disables the check of the solid
473   //! for inverted status. By default the solids will be checked.
474   Standard_EXPORT void BuildBndBoxSolid (const Standard_Integer theIndex,
475                                          Bnd_Box& theBox,
476                                          const Standard_Boolean theCheckInverted = Standard_True);
477
478 protected:
479
480   
481
482   //! Initializes the pave blocks for the shape with index theIndex
483   Standard_EXPORT void InitPaveBlocks (const Standard_Integer theIndex);
484
485   //! Initializes the state of face with index theIndex
486   Standard_EXPORT void InitFaceInfo (const Standard_Integer theIndex);
487   
488   Standard_EXPORT void InitShape (const Standard_Integer theIndex, const TopoDS_Shape& theS);
489   
490   Standard_EXPORT Standard_Boolean CheckCoincidence (const Handle(BOPDS_PaveBlock)& thePB1,
491                                                      const Handle(BOPDS_PaveBlock)& thePB2,
492                                                      const Standard_Real theFuzz);
493
494
495   BOPCol_BaseAllocator myAllocator;
496   BOPCol_ListOfShape myArguments;
497   Standard_Integer myNbShapes;
498   Standard_Integer myNbSourceShapes;
499   BOPDS_VectorOfIndexRange myRanges;
500   BOPDS_VectorOfShapeInfo myLines;
501   BOPCol_DataMapOfShapeInteger myMapShapeIndex;
502   BOPDS_VectorOfListOfPaveBlock myPaveBlocksPool;
503   BOPDS_DataMapOfPaveBlockCommonBlock myMapPBCB;
504   BOPDS_VectorOfFaceInfo myFaceInfoPool;
505   BOPCol_DataMapOfIntegerInteger myShapesSD;
506   BOPCol_DataMapOfIntegerListOfInteger myMapVE;
507   BOPDS_MapOfPair myInterfTB;
508   BOPDS_VectorOfInterfVV myInterfVV;
509   BOPDS_VectorOfInterfVE myInterfVE;
510   BOPDS_VectorOfInterfVF myInterfVF;
511   BOPDS_VectorOfInterfEE myInterfEE;
512   BOPDS_VectorOfInterfEF myInterfEF;
513   BOPDS_VectorOfInterfFF myInterfFF;
514   BOPDS_VectorOfInterfVZ myInterfVZ;
515   BOPDS_VectorOfInterfEZ myInterfEZ;
516   BOPDS_VectorOfInterfFZ myInterfFZ;
517   BOPDS_VectorOfInterfZZ myInterfZZ;
518
519
520 private:
521
522
523
524
525
526 };
527
528
529 #include <BOPDS_DS.lxx>
530
531
532
533
534
535 #endif // _BOPDS_DS_HeaderFile