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