d9ca2e0c |
1 | // Created by: Eugeny MALTCHIKOV |
2 | // Copyright (c) 2018 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 _BOPAlgo_RemoveFeatures_HeaderFile |
16 | #define _BOPAlgo_RemoveFeatures_HeaderFile |
17 | |
18 | #include <Standard.hxx> |
19 | #include <Standard_DefineAlloc.hxx> |
20 | #include <Standard_Handle.hxx> |
21 | |
948fe6ca |
22 | #include <BOPAlgo_BuilderShape.hxx> |
d9ca2e0c |
23 | #include <BRepTools_History.hxx> |
24 | #include <TopoDS_Shape.hxx> |
25 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
26 | #include <TopTools_IndexedMapOfShape.hxx> |
27 | #include <TopTools_ListOfShape.hxx> |
28 | #include <TopTools_MapOfShape.hxx> |
29 | |
30 | //! The RemoveFeatures algorithm is intended for reconstruction of |
31 | //! the shape by removal of the unwanted parts from it. These parts can |
32 | //! be holes, protrusions, spikes, fillets etc. |
33 | //! The shape itself is not modified, the new shape is built in |
34 | //! the result. |
35 | //! |
36 | //! Currently, only the shapes of type SOLID, COMPSOLID, and |
37 | //! COMPOUND of Solids are supported. And only the FACEs can be |
38 | //! removed from the shape. |
39 | //! |
40 | //! On the input the algorithm accepts the shape itself and the |
41 | //! faces which have to be removed. It does not matter how the faces |
42 | //! are given. It could be the separate faces or the collections of faces. |
43 | //! The faces should belong to the initial shape, and those that |
44 | //! do not belong will be ignored. |
45 | //! Before reconstructing the shape, the algorithm will sort all |
46 | //! the given faces on the connected blocks (features). |
47 | //! |
48 | //! The features will be removed from the shape one by one. |
49 | //! It will allow removing all possible features even if there |
50 | //! were problems with the removal of some of them. |
51 | //! |
52 | //! The removed feature is filled by the extension of the faces adjacent |
53 | //! to the feature. In general, the algorithm of removing of the single |
54 | //! feature from the shape looks as follows: |
55 | //! - Find the faces adjacent to the feature; |
56 | //! - Extend the adjacent faces to cover the feature; |
57 | //! - Trim the extended faces by the bounds of original face |
58 | //! (except for bounds common with the feature), so it will cover |
59 | //! the feature only; |
60 | //! - Rebuild the solids with reconstructed adjacent faces |
61 | //! avoiding the faces from the feature. |
62 | //! |
63 | //! If the removal is successful, the result is overwritten with the |
64 | //! new shape and the next feature is treated. Otherwise, the warning |
65 | //! will be given. |
66 | //! |
67 | //! The algorithm has the following options: |
68 | //! - History support; |
69 | //! |
70 | //! and the options available from base class: |
71 | //! - Error/Warning reporting system; |
72 | //! - Parallel processing mode. |
73 | //! |
74 | //! Please note that the other options of the base class are not supported |
75 | //! here and will have no effect. |
76 | //! |
77 | //! <b>History support</b> allows tracking modification of the input shape |
78 | //! in terms of Modified, IsDeleted and Generated. The history is |
79 | //! available through the methods of the history tool *BRepTools_History*, |
80 | //! which can be accessed here through the method *History()*. |
81 | //! By default, the history is collected, but it is possible to disable it |
948fe6ca |
82 | //! using the method *SetToFillHistory(false)*; |
d9ca2e0c |
83 | //! |
84 | //! <b>Error/Warning reporting system</b> - allows obtaining the extended overview |
85 | //! of the Errors/Warnings occurred during the operation. As soon as any error |
86 | //! appears the algorithm stops working. The warnings allow continuing the job, |
87 | //! informing the user that something went wrong. |
88 | //! The algorithm returns the following errors/warnings: |
89 | //! - *BOPAlgo_AlertTooFewArguments* - the error alert is given if the input |
90 | //! shape does not contain any solids; |
91 | //! - *BOPAlgo_AlertUnsupportedType* - the warning alert is given if the input |
92 | //! shape contains not only solids, but also other shapes; |
93 | //! - *BOPAlgo_AlertNoFacesToRemove* - the error alert is given in case |
94 | //! there are no faces to remove from the shape (nothing to do); |
95 | //! - *BOPAlgo_AlertUnableToRemoveTheFeature* - the warning alert is given to |
96 | //! inform the user the removal of the feature is not possible. The algorithm |
97 | //! will still try to remove the other features; |
98 | //! - *BOPAlgo_AlertRemoveFeaturesFailed* - the error alert is given in case if |
99 | //! the operation was aborted by the unknown reason. |
100 | //! |
101 | //! <b>Parallel processing mode</b> - allows running the algorithm in parallel mode |
102 | //! obtaining the result faster. |
103 | //! |
104 | //! The algorithm has certain limitations: |
105 | //! - Intersection of the connected faces adjacent to the feature should not be empty. |
106 | //! It means, that such faces should not be tangent to each other. |
107 | //! If the intersection of the adjacent faces will be empty, the algorithm will |
108 | //! be unable to trim the faces correctly and, most likely, the feature will not be removed. |
109 | //! - The algorithm does not process the INTERNAL parts of the solids, they are simply |
110 | //! removed during reconstruction. |
111 | //! |
112 | //! Note that for successful removal of the feature, the extended faces adjacent |
113 | //! to the feature should cover the feature completely, otherwise the solids will |
114 | //! not be rebuild. |
115 | //! |
116 | //! Here is the example of usage of the algorithm: |
117 | //! ~~~~ |
118 | //! TopoDS_Shape aSolid = ...; // Input shape to remove the features from |
119 | //! TopTools_ListOfShape aFaces = ...; // Faces to remove from the shape |
120 | //! Standard_Boolean bRunParallel = ...; // Parallel processing mode |
121 | //! Standard_Boolean isHistoryNeeded = ...; // History support |
122 | //! |
123 | //! BOPAlgo_RemoveFeatures aRF; // Feature removal algorithm |
124 | //! aRF.SetShape(aSolid); // Set the shape |
125 | //! aRF.AddFacesToRemove(aFaces); // Add faces to remove |
126 | //! aRF.SetRunParallel(bRunParallel); // Define the processing mode (parallel or single) |
948fe6ca |
127 | //! aRF.SetToFillHistory(isHistoryNeeded); // Define whether to track the shapes modifications |
d9ca2e0c |
128 | //! aRF.Perform(); // Perform the operation |
129 | //! if (aRF.HasErrors()) // Check for the errors |
130 | //! { |
131 | //! // error treatment |
132 | //! return; |
133 | //! } |
134 | //! if (aRF.HasWarnings()) // Check for the warnings |
135 | //! { |
136 | //! // warnings treatment |
137 | //! } |
138 | //! const TopoDS_Shape& aResult = aRF.Shape(); // Result shape |
139 | //! ~~~~ |
140 | //! |
141 | //! The algorithm preserves the type of the input shape in the result shape. Thus, |
142 | //! if the input shape is a COMPSOLID, the resulting solids will also be put into a COMPSOLID. |
143 | //! |
144 | //! When all possible features are removed, the shape is simplified by |
145 | //! removing extra edges and vertices, created during operation, from the result shape. |
146 | //! |
948fe6ca |
147 | class BOPAlgo_RemoveFeatures: public BOPAlgo_BuilderShape |
d9ca2e0c |
148 | { |
149 | public: |
150 | DEFINE_STANDARD_ALLOC |
151 | |
152 | public: //! @name Constructors |
153 | |
154 | //! Empty constructor |
155 | BOPAlgo_RemoveFeatures() |
156 | : |
948fe6ca |
157 | BOPAlgo_BuilderShape() |
158 | {} |
d9ca2e0c |
159 | |
160 | |
161 | public: //! @name Setting input data for the algorithm |
162 | |
163 | //! Sets the shape for processing. |
164 | //! @param theShape [in] The shape to remove the faces from. |
165 | //! It should either be the SOLID, COMPSOLID or COMPOUND of Solids. |
166 | void SetShape(const TopoDS_Shape& theShape) |
167 | { |
168 | myInputShape = theShape; |
169 | } |
170 | |
171 | //! Returns the input shape |
172 | const TopoDS_Shape& InputShape() const |
173 | { |
174 | return myInputShape; |
175 | } |
176 | |
177 | //! Adds the face to remove from the input shape. |
178 | //! @param theFace [in] The shape to extract the faces for removal. |
179 | void AddFaceToRemove(const TopoDS_Shape& theFace) |
180 | { |
181 | myFacesToRemove.Append(theFace); |
182 | } |
183 | |
184 | //! Adds the faces to remove from the input shape. |
185 | //! @param theFaces [in] The list of shapes to extract the faces for removal. |
186 | void AddFacesToRemove(const TopTools_ListOfShape& theFaces) |
187 | { |
188 | TopTools_ListIteratorOfListOfShape it(theFaces); |
189 | for (; it.More(); it.Next()) |
190 | myFacesToRemove.Append(it.Value()); |
191 | } |
192 | |
193 | //! Returns the list of faces which have been requested for removal |
194 | //! from the input shape. |
195 | const TopTools_ListOfShape& FacesToRemove() const |
196 | { |
197 | return myFacesToRemove; |
198 | } |
199 | |
200 | |
201 | public: //! @name Performing the operation |
202 | |
203 | //! Performs the operation |
948fe6ca |
204 | Standard_EXPORT virtual void Perform() Standard_OVERRIDE; |
d9ca2e0c |
205 | |
206 | |
207 | public: //! @name Clearing the contents of the algorithm |
208 | |
209 | //! Clears the contents of the algorithm from previous run, |
210 | //! allowing reusing it for following removals. |
948fe6ca |
211 | virtual void Clear() Standard_OVERRIDE |
d9ca2e0c |
212 | { |
948fe6ca |
213 | BOPAlgo_BuilderShape::Clear(); |
d9ca2e0c |
214 | myInputShape.Nullify(); |
215 | myShape.Nullify(); |
216 | myFacesToRemove.Clear(); |
217 | myFeatures.Clear(); |
218 | myInputsMap.Clear(); |
d9ca2e0c |
219 | } |
220 | |
221 | |
222 | protected: //! @name Protected methods performing the removal |
223 | |
224 | //! Checks the input data on validity for the algorithm: |
225 | //! - The input shape must be either a SOLID, COMPSOLID or COMPOUND of Solids. |
226 | //! If the input shape is not a solid, the method looks for the solids |
227 | //! in <myInputShape> and uses only them. All other shapes are simply removed. |
228 | //! If no solids were found, the Error of unsupported type is returned. |
948fe6ca |
229 | Standard_EXPORT virtual void CheckData() Standard_OVERRIDE; |
d9ca2e0c |
230 | |
231 | //! Prepares the faces to remove: |
232 | //! - Gets only faces contained in the input solids; |
233 | //! - Builds connected blocks of faces creating separate features to remove. |
234 | Standard_EXPORT void PrepareFeatures(); |
235 | |
236 | //! Removes the features and fills the created gaps by extension of the adjacent faces. |
237 | //! Processes each feature separately. |
238 | Standard_EXPORT void RemoveFeatures(); |
239 | |
240 | //! Remove the single feature from the shape. |
241 | //! @param theFeature [in] The feature to remove; |
242 | //! @param theSolids [in] The solids to be reconstructed after feature removal; |
243 | //! @param theFeatureFacesMap [in] The map of feature faces; |
244 | //! @param theHasAdjacentFaces [in] Shows whether the adjacent faces have been |
245 | //! found for the feature or not; |
246 | //! @param theAdjFaces [in] The reconstructed adjacent faces covering the feature; |
247 | //! @param theAdjFacesHistory [in] The history of the adjacent faces reconstruction; |
248 | //! @param theSolidsHistoryNeeded [in] Defines whether the history of solids |
249 | //! modifications should be tracked or not. |
250 | Standard_EXPORT void RemoveFeature(const TopoDS_Shape& theFeature, |
251 | const TopTools_IndexedMapOfShape& theSolids, |
252 | const TopTools_MapOfShape& theFeatureFacesMap, |
253 | const Standard_Boolean theHasAdjacentFaces, |
254 | const TopTools_IndexedDataMapOfShapeListOfShape& theAdjFaces, |
255 | const Handle(BRepTools_History)& theAdjFacesHistory, |
256 | const Standard_Boolean theSolidsHistoryNeeded); |
257 | |
258 | //! Updates history with the removed features |
259 | Standard_EXPORT void UpdateHistory(); |
260 | |
261 | //! Simplifies the result by removing extra edges and vertices created |
262 | //! during removal of the features. |
263 | Standard_EXPORT void SimplifyResult(); |
264 | |
265 | //! Post treatment - restore the type of the initial shape |
266 | Standard_EXPORT void PostTreat(); |
267 | |
268 | protected: //! @name Fields |
269 | |
270 | // Inputs |
271 | TopoDS_Shape myInputShape; //!< Input shape |
272 | TopTools_ListOfShape myFacesToRemove; //!< Faces to remove |
d9ca2e0c |
273 | |
274 | // Intermediate |
275 | TopTools_ListOfShape myFeatures; //!< List of not connected features to remove |
276 | //! (each feature is a compound of faces) |
277 | TopTools_IndexedMapOfShape myInputsMap; //!< Map of all sub-shapes of the input shape |
d9ca2e0c |
278 | }; |
279 | |
280 | #endif // _BOPAlgo_RemoveFeatures_HeaderFile |