0028187: Add possibility to avoid creation of Internal parts in the result of Volume...
[occt.git] / src / BOPAlgo / BOPAlgo_CellsBuilder.hxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2015 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
16 #ifndef _BOPAlgo_CellsBuilder_HeaderFile
17 #define _BOPAlgo_CellsBuilder_HeaderFile
18
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <TopoDS_Shape.hxx>
23
24 #include <TopAbs_ShapeEnum.hxx>
25
26 #include <BOPAlgo_Builder.hxx>
27
28 #include <BOPCol_ListOfShape.hxx>
29 #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
30 #include <BOPCol_DataMapOfIntegerListOfShape.hxx>
31 #include <BOPCol_DataMapOfShapeInteger.hxx>
32 #include <BOPCol_DataMapOfShapeShape.hxx>
33
34 //!
35 //! The algorithm is based on the General Fuse algorithm (GFA). The result of 
36 //! GFA is all split parts of the Arguments.
37 //! 
38 //! The purpose of this algorithm is to provide the result with the content of:
39 //! 1. Cells (parts) defined by the user;
40 //! 2. Internal boundaries defined by the user.
41 //! 
42 //! In other words the algorithm should provide the possibility for the user
43 //! to add or remove any part to (from) result and remove any internal boundaries
44 //! between parts.
45 //! 
46 //! Requirements for the Data:
47 //! All the requirements of GFA for the DATA are inherited in this algorithm.
48 //! Plus all the arguments should have the same dimension.
49 //!
50 //! Results:
51 //! The result of the algorithm is compound containing selected parts of 
52 //! the basic type (VERTEX, EDGE, FACE or SOLID). The default result
53 //! is empty compound. It is possible to add any split part to the result
54 //! by using the methods AddToRessult() and AddAllToResult().
55 //! It is also possible to remove any part from the result by using methods 
56 //! RemoveFromResult() and RemoveAllFromResult().
57 //! The method RemoveAllFromResult() is also suitable for clearing the result.
58 //!
59 //! To remove Internal boundaries it is necessary to set the same material to the 
60 //! parts between which the boundaries should be removed and call the method 
61 //! RemoveInternalBoundaries(). The material should not be equal to 0, as this is 
62 //! default material value. The boundaries between parts with this value 
63 //! will not be removed.
64 //! One part cannot be added with the different materials.
65 //! It is also possible to remove the boundaries during combining the result.
66 //! To do this it is necessary to set the material for parts (not equal to 0)
67 //! and set the flag bUpdate to TRUE. 
68 //! BUT for the arguments of the types FACE or EDGE it is recommended
69 //! to remove the boundaries in the end when the result is completely built.
70 //! It will help to avoid self-intersections in the result.
71 //!
72 //! It is possible to create typed Containers from the parts added to result by using
73 //! method MakeContainers(). The type of the containers will depend on the type of 
74 //! the arguments: WIRES for EEDGE, SHELLS for FACES and COMPSOLIDS for SOLIDS.
75 //! The result will be compound containing containers.
76 //! Adding of the parts to such result will not update containers. The result 
77 //! compound will contain the containers and new added parts (of basic type).
78 //! Removing of the parts from such result may affect some containers if the 
79 //! the parts that should be removed is in container. In this case this container
80 //! will be rebuilt without that part.
81 //!
82 //! History:
83 //! The algorithm supports history information for basic types of the shapes -
84 //! VERTEX, EDGE, FACE. This information available through the methods 
85 //! IsDeleted() and Modified(). In DRAW Test Harness it is available through the same 
86 //! commands as for Boolean Operations (bmodified, bgenerated and bisdeleted).
87 //! There could be Generated shapes only after removing of the internal boundaries
88 //! between faces and edges, i.e. after using ShapeUpgrade_UnifySameDomain tool.
89 //! 
90 //! Examples:
91 //! 1. API
92 //! BOPAlgo_CellsBuilder aCBuilder;
93 //! BOPCol_ListOfShape aLS = ...; // arguments
94 //! /* parallel or single mode (the default value is FALSE)*/
95 //! Standard_Boolean bRunParallel = Standard_False; 
96 //! /* fuzzy option (default value is 0)*/
97 //! Standard_Real aTol = 0.0; 
98 //! //
99 //! aCBuilder.SetArguments(aLS);
100 //! aCBuilder.SetRunParallel(bRunParallel);
101 //! aCBuilder.SetFuzzyValue(aTol);
102 //! //
103 //! aCBuilder.Perform();
104 //! if (aCBuilder.ErrorStatus()) { // check error status
105 //!   return;
106 //! }
107 //! /* empty compound, as nothing has been added yet */
108 //! const TopoDS_Shape& aRes = aCBuilder.Shape(); 
109 //! /* all split parts */
110 //! const TopoDS_Shape& aRes = aCBuilder.GetAllParts();
111 //! //
112 //! BOPCol_ListOfShape aLSToTake = ...; // parts of these arguments will be taken into result
113 //! BOPCol_ListOfShape aLSToAvoid = ...; // parts of these arguments will not be taken into result
114 //! //
115 //! /* defines the material common for the cells, i.e. 
116 //!    the boundaries between cells with the same material
117 //!    will be removed. 
118 //!    By default it is set to 0. Thus, to remove some boundary 
119 //!    the value of this variable should not be equal to 0 */
120 //! Standard_Integer iMaterial = ...; 
121 //! /* defines whether to update the result right now or not */
122 //! Standard_Boolean bUpdate = ...;
123 //! // adding to result
124 //! aCBuilder.AddToResult(aLSToTake, aLSToAvoid, iMaterial, bUpdate);
125 //! aR = aCBuilder.Shape(); // the result
126 //! // removing of the boundaries
127 //! aCBuilder.RemoveInternalBoundaries();
128 //! 
129 //! // removing from result
130 //! aCBuilder.AddAllToResult();
131 //! aCBuilder.RemoveFromResult(aLSToTake, aLSToAvoid);
132 //! aR = aCBuilder.Shape(); // the result
133 //! 
134 //! 
135 //! 2. DRAW Test Harness
136 //! psphere s1 15
137 //! psphere s2 15
138 //! psphere s3 15
139 //! ttranslate s1 0 0 10
140 //! ttranslate s2 20 0 10
141 //! ttranslate s3 10 0 0 
142 //! 
143 //! bclearobjects; bcleartools
144 //! baddobjects s1 s2 s3
145 //! bfillds
146 //! # rx will contain all split parts
147 //! bcbuild rx 
148 //! # add to result the part that is common for all three spheres
149 //! bcadd res s1 1 s2 1 s3 1 -m 1
150 //! # add to result the part that is common only for first and third shperes
151 //! bcadd res s1 1 s2 0 s3 1 -m 1
152 //! # remove internal boundaries
153 //! bcremoveint res
154 //!
155
156
157 class BOPAlgo_CellsBuilder : public BOPAlgo_Builder
158 {
159  public:
160
161   DEFINE_STANDARD_ALLOC
162
163   Standard_EXPORT BOPAlgo_CellsBuilder();
164
165   Standard_EXPORT BOPAlgo_CellsBuilder(const Handle(NCollection_BaseAllocator)& theAllocator);
166
167   Standard_EXPORT virtual ~BOPAlgo_CellsBuilder();
168
169   //! Redefined method Clear - clears the contents.
170   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
171
172   //! Adding the parts to result.
173   //! The parts are defined by two lists of shapes.
174   //! <theLSToTake> defines the arguments which parts should be taken into result;
175   //! <theLSToAvoid> defines the arguments which parts should not be taken into result;
176   //! To be taken into result the part must be IN for all shapes from the list
177   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>. 
178   //! 
179   //! To remove internal boundaries between any cells in the result 
180   //! <theMaterial> variable should be used. The boundaries between 
181   //! cells with the same material will be removed. Default value is 0. 
182   //! Thus, to remove any boundary the value of this variable should not be equal to 0.
183   //! <theUpdate> parameter defines whether to remove boundaries now or not
184   Standard_EXPORT void AddToResult(const BOPCol_ListOfShape& theLSToTake,
185                                    const BOPCol_ListOfShape& theLSToAvoid,
186                                    const Standard_Integer theMaterial = 0,
187                                    const Standard_Boolean theUpdate = Standard_False);
188
189   //! Add all split parts to result
190   //! <theMaterial> defines the removal of internal boundaries;
191   //! <theUpdate> parameter defines whether to remove boundaries now or not.
192   Standard_EXPORT void AddAllToResult(const Standard_Integer theMaterial = 0,
193                                       const Standard_Boolean theUpdate = Standard_False);
194
195   //! Removing the parts from result.
196   //! The parts are defined by two lists of shapes.
197   //! <theLSToTake> defines the arguments which parts should be removed from result;
198   //! <theLSToAvoid> defines the arguments which parts should not be removed from result.
199   //! To be removed from the result the part must be IN for all shapes from the list
200   //! <theLSToTake> and must be OUT of all shapes from the list <theLSToAvoid>.
201   Standard_EXPORT void RemoveFromResult(const BOPCol_ListOfShape& theLSToTake,
202                                         const BOPCol_ListOfShape& theLSToAvoid);
203
204   //! Remove all parts from result.
205   Standard_EXPORT void RemoveAllFromResult();
206
207   //! Removes internal boundaries between cells with the same material.
208   Standard_EXPORT void RemoveInternalBoundaries();
209
210   //! Get all split parts.
211   Standard_EXPORT const TopoDS_Shape& GetAllParts() const;
212
213   //! Makes the Containers of proper type from the parts added to result.
214   Standard_EXPORT void MakeContainers();
215
216   //! Returns the list of shapes generated from the shape theS.
217   Standard_EXPORT virtual const TopTools_ListOfShape& Generated(const TopoDS_Shape& theS) Standard_OVERRIDE;
218   
219   //! Returns true if the shape theS has been deleted.
220   Standard_EXPORT virtual Standard_Boolean IsDeleted (const TopoDS_Shape& theS) Standard_OVERRIDE;
221   
222  protected:
223
224   //! Redefined method Prepare - no need to prepare history 
225   //! information on the default result as it is empty compound.
226   Standard_EXPORT virtual void Prepare() Standard_OVERRIDE;
227
228   //! Redefined method CheckData() - additional check for the arguments 
229   //! to be of the same dimension.
230   Standard_EXPORT virtual void CheckData() Standard_OVERRIDE;
231
232   //! Redefined method PerformInternal1 - makes all split parts, 
233   //! nullifies the result <myShape>, and index all parts.
234   Standard_EXPORT virtual void PerformInternal1 (const BOPAlgo_PaveFiller& thePF) Standard_OVERRIDE;
235
236   //! Saves all split parts in myAllParts.
237   Standard_EXPORT void TakeAllParts();
238
239   //! Indexes the parts for quick access to the arguments.
240   Standard_EXPORT void IndexParts();
241
242   //! Looking for the parts defined by two lists.
243   Standard_EXPORT void FindParts(const BOPCol_ListOfShape& theLSToTake,
244                                  const BOPCol_ListOfShape& theLSToAvoid,
245                                  BOPCol_ListOfShape& theParts);
246
247   //! Removes internal boundaries between cells with the same material.
248   Standard_EXPORT Standard_Integer RemoveInternals(const BOPCol_ListOfShape& theLS,
249                                                    BOPCol_ListOfShape& theLSNew);
250
251   // fields
252   TopAbs_ShapeEnum myType;
253   TopoDS_Shape myAllParts;
254   BOPCol_IndexedDataMapOfShapeListOfShape myIndex;
255   BOPCol_DataMapOfIntegerListOfShape myMaterials;
256   BOPCol_DataMapOfShapeInteger myShapeMaterial;
257   BOPCol_DataMapOfShapeShape myMapGenerated;
258
259  private:
260
261 };
262
263 #endif //_BOPAlgo_CellsBuilder_HeaderFile