42cf5bc1 |
1 | // Created by: Peter KURNEV |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
7 | // This file is part of Open CASCADE Technology software library. |
8 | // |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
14 | // |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
17 | |
18 | #ifndef _BOPTools_AlgoTools_HeaderFile |
19 | #define _BOPTools_AlgoTools_HeaderFile |
20 | |
21 | #include <Standard.hxx> |
22 | #include <Standard_DefineAlloc.hxx> |
23 | #include <Standard_Handle.hxx> |
24 | |
25 | #include <Standard_Integer.hxx> |
26 | #include <Standard_Real.hxx> |
27 | #include <BOPCol_ListOfShape.hxx> |
28 | #include <Standard_Boolean.hxx> |
29 | #include <TopAbs_ShapeEnum.hxx> |
30 | #include <BOPTools_ListOfCoupleOfShape.hxx> |
98b37659 |
31 | #include <BOPTools_ListOfConnexityBlock.hxx> |
42cf5bc1 |
32 | #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx> |
98b37659 |
33 | #include <BOPCol_ListOfListOfShape.hxx> |
42cf5bc1 |
34 | #include <TopAbs_State.hxx> |
35 | #include <BOPCol_IndexedMapOfShape.hxx> |
36 | #include <BOPCol_BaseAllocator.hxx> |
0d0481c7 |
37 | #include <Precision.hxx> |
42cf5bc1 |
38 | class TopoDS_Vertex; |
39 | class gp_Pnt; |
40 | class IntTools_Curve; |
41 | class TopoDS_Edge; |
42 | class TopoDS_Face; |
43 | class TopoDS_Shape; |
44 | class IntTools_Context; |
45 | class TopoDS_Solid; |
46 | class IntTools_Range; |
47 | class TopoDS_Shell; |
48 | |
49 | |
42cf5bc1 |
50 | class BOPTools_AlgoTools |
51 | { |
52 | public: |
53 | |
54 | DEFINE_STANDARD_ALLOC |
55 | |
56 | |
57 | Standard_EXPORT static Standard_Integer ComputeVV (const TopoDS_Vertex& aV1, const gp_Pnt& aP2, const Standard_Real aTolP2); |
58 | |
0d0481c7 |
59 | Standard_EXPORT static Standard_Integer ComputeVV (const TopoDS_Vertex& aV1, |
60 | const TopoDS_Vertex& aV2, |
61 | const Standard_Real theFuzz = Precision::Confusion()); |
42cf5bc1 |
62 | |
3510db62 |
63 | Standard_EXPORT static void MakeVertex (const BOPCol_ListOfShape& aLV, TopoDS_Vertex& aV); |
42cf5bc1 |
64 | |
65 | Standard_EXPORT static void MakeEdge (const IntTools_Curve& theCurve, const TopoDS_Vertex& theV1, const Standard_Real theT1, const TopoDS_Vertex& theV2, const Standard_Real theT2, const Standard_Real theTolR3D, TopoDS_Edge& theE); |
66 | |
51db0179 |
67 | //! Makes 2d curve of the edge <theE> on the faces <theF1> and <theF2>.<br> |
68 | //! <theContext> - storage for caching the geometrical tools |
69 | Standard_EXPORT static void MakePCurve (const TopoDS_Edge& theE, |
70 | const TopoDS_Face& theF1, |
71 | const TopoDS_Face& theF2, |
72 | const IntTools_Curve& theCurve, |
73 | const Standard_Boolean thePC1, |
74 | const Standard_Boolean thePC2, |
75 | const Handle(IntTools_Context)& theContext = Handle(IntTools_Context)()); |
42cf5bc1 |
76 | |
77 | Standard_EXPORT static void MakeContainer (const TopAbs_ShapeEnum theType, TopoDS_Shape& theShape); |
78 | |
79 | Standard_EXPORT static Standard_Boolean IsHole (const TopoDS_Shape& aW, const TopoDS_Shape& aF); |
80 | |
81 | //! Returns True if the shape theSplit has opposite |
82 | //! direction than theShape |
83 | //! theContext - cashed geometrical tools |
84 | Standard_EXPORT static Standard_Boolean IsSplitToReverse (const TopoDS_Shape& theSplit, const TopoDS_Shape& theShape, Handle(IntTools_Context)& theContext); |
85 | |
86 | //! Returns True if normal direction of the face |
87 | //! theShape is not the same as for the face |
88 | //! theSplit |
89 | //! theContext - cashed geometrical tools |
90 | Standard_EXPORT static Standard_Boolean IsSplitToReverse (const TopoDS_Face& theSplit, const TopoDS_Face& theShape, Handle(IntTools_Context)& theContext); |
91 | |
92 | Standard_EXPORT static Standard_Boolean IsSplitToReverse (const TopoDS_Edge& aE1, const TopoDS_Edge& aE2, Handle(IntTools_Context)& aContext); |
93 | |
0d0481c7 |
94 | Standard_EXPORT static Standard_Boolean AreFacesSameDomain (const TopoDS_Face& theF1, |
95 | const TopoDS_Face& theF2, |
96 | Handle(IntTools_Context)& theContext, |
97 | const Standard_Real theFuzz = Precision::Confusion()); |
42cf5bc1 |
98 | |
99 | Standard_EXPORT static Standard_Boolean CheckSameGeom (const TopoDS_Face& theF1, const TopoDS_Face& theF2, Handle(IntTools_Context)& theContext); |
100 | |
51db0179 |
101 | //! Basing on the normals directions of the faces the method |
102 | //! Defines whether to reverse the second face or not.<br> |
103 | //! <theContext> - storage for caching the geometrical tools |
104 | Standard_EXPORT static Standard_Integer Sense (const TopoDS_Face& theF1, |
105 | const TopoDS_Face& theF2, |
106 | const Handle(IntTools_Context)& theContext = Handle(IntTools_Context)()); |
42cf5bc1 |
107 | |
108 | //! Returns True if the face theFace contains |
109 | //! the edge theEdge but with opposite orientation. |
110 | //! If the method returns True theEdgeOff is the |
111 | //! edge founded |
112 | Standard_EXPORT static Standard_Boolean GetEdgeOff (const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, TopoDS_Edge& theEdgeOff); |
113 | |
114 | //! For the face theFace and its edge theEdge |
115 | //! finds the face suitable to produce shell. |
116 | //! theLCEF - set of faces to search. All faces |
117 | //! from theLCEF must share edge theEdge |
118 | Standard_EXPORT static Standard_Boolean GetFaceOff (const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, BOPTools_ListOfCoupleOfShape& theLCEF, TopoDS_Face& theFaceOff, Handle(IntTools_Context)& theContext); |
119 | |
120 | //! Returns True if the face theFace is inside of the |
121 | //! couple of faces theFace1, theFace2. |
122 | //! The faces theFace, theFace1, theFace2 must |
123 | //! share the edge theEdge |
dde68833 |
124 | //! Return values: |
125 | //! * 0 state is not IN |
126 | //! * 1 state is IN |
127 | //! * 2 state can not be found by the method of angles |
42cf5bc1 |
128 | Standard_EXPORT static Standard_Integer IsInternalFace (const TopoDS_Face& theFace, const TopoDS_Edge& theEdge, const TopoDS_Face& theFace1, const TopoDS_Face& theFace2, Handle(IntTools_Context)& theContext); |
129 | |
130 | //! Returns True if the face theFace is inside of the |
131 | //! appropriate couple of faces (from the set theLF) . |
132 | //! The faces of the set theLF and theFace must |
133 | //! share the edge theEdge |
dde68833 |
134 | //! * 0 state is not IN |
135 | //! * 1 state is IN |
136 | //! * 2 state can not be found by the method of angles |
42cf5bc1 |
137 | Standard_EXPORT static Standard_Integer IsInternalFace (const TopoDS_Face& theFace, const TopoDS_Edge& theEdge, BOPCol_ListOfShape& theLF, Handle(IntTools_Context)& theContext); |
138 | |
139 | //! Returns True if the face theFace is inside the |
140 | //! solid theSolid. |
141 | //! theMEF - Map Edge/Faces for theSolid |
142 | //! theTol - value of precision of computation |
143 | //! theContext- cahed geometrical tools |
dde68833 |
144 | Standard_EXPORT static Standard_Boolean IsInternalFace (const TopoDS_Face& theFace, const TopoDS_Solid& theSolid, BOPCol_IndexedDataMapOfShapeListOfShape& theMEF, const Standard_Real theTol, Handle(IntTools_Context)& theContext); |
42cf5bc1 |
145 | |
146 | //! For the face theFace gets the edge theEdgeOnF |
147 | //! that is the same as theEdge |
148 | //! Returns True if such edge exists |
149 | //! Returns False if there is no such edge |
150 | Standard_EXPORT static Standard_Boolean GetEdgeOnFace (const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, TopoDS_Edge& theEdgeOnF); |
151 | |
152 | //! Computes the 3-D state of the point thePoint |
153 | //! toward solid theSolid. |
154 | //! theTol - value of precision of computation |
155 | //! theContext- cahed geometrical tools |
156 | //! Returns 3-D state. |
157 | Standard_EXPORT static TopAbs_State ComputeState (const gp_Pnt& thePoint, const TopoDS_Solid& theSolid, const Standard_Real theTol, Handle(IntTools_Context)& theContext); |
158 | |
159 | //! Computes the 3-D state of the vertex theVertex |
160 | //! toward solid theSolid. |
161 | //! theTol - value of precision of computation |
162 | //! theContext- cahed geometrical tools |
163 | //! Returns 3-D state. |
164 | Standard_EXPORT static TopAbs_State ComputeState (const TopoDS_Vertex& theVertex, const TopoDS_Solid& theSolid, const Standard_Real theTol, Handle(IntTools_Context)& theContext); |
165 | |
166 | //! Computes the 3-D state of the edge theEdge |
167 | //! toward solid theSolid. |
168 | //! theTol - value of precision of computation |
169 | //! theContext- cahed geometrical tools |
170 | //! Returns 3-D state. |
171 | Standard_EXPORT static TopAbs_State ComputeState (const TopoDS_Edge& theEdge, const TopoDS_Solid& theSolid, const Standard_Real theTol, Handle(IntTools_Context)& theContext); |
172 | |
173 | //! Computes the 3-D state of the face theFace |
174 | //! toward solid theSolid. |
175 | //! theTol - value of precision of computation |
176 | //! theBounds - set of edges of theFace to avoid |
177 | //! theContext- cahed geometrical tools |
178 | //! Returns 3-D state. |
179 | Standard_EXPORT static TopAbs_State ComputeState (const TopoDS_Face& theFace, const TopoDS_Solid& theSolid, const Standard_Real theTol, BOPCol_IndexedMapOfShape& theBounds, Handle(IntTools_Context)& theContext); |
180 | |
181 | //! Computes the 3-D state of the shape theShape |
182 | //! toward solid theSolid. |
183 | //! theTol - value of precision of computation |
184 | //! theContext- cahed geometrical tools |
185 | //! Returns 3-D state. |
186 | Standard_EXPORT static TopAbs_State ComputeStateByOnePoint (const TopoDS_Shape& theShape, const TopoDS_Solid& theSolid, const Standard_Real theTol, Handle(IntTools_Context)& theContext); |
187 | |
188 | //! For the list of faces theLS build block |
189 | //! theLSCB in terms of connexity by edges |
190 | //! theMapAvoid - set of edges to avoid for |
191 | //! the treatment |
192 | Standard_EXPORT static void MakeConnexityBlock (BOPCol_ListOfShape& theLS, BOPCol_IndexedMapOfShape& theMapAvoid, BOPCol_ListOfShape& theLSCB, const BOPCol_BaseAllocator& theAllocator); |
98b37659 |
193 | |
194 | //! For the compound <theS> builds the blocks (compounds) of |
195 | //! elements of type <theElementType> connected through the shapes |
196 | //! of the type <theConnectionType>. |
197 | //! The blocks are stored into the list <theLCB>. |
198 | Standard_EXPORT static void MakeConnexityBlocks(const TopoDS_Shape& theS, |
199 | const TopAbs_ShapeEnum theConnectionType, |
200 | const TopAbs_ShapeEnum theElementType, |
201 | BOPCol_ListOfShape& theLCB); |
202 | |
203 | //! For the compound <theS> builds the blocks (compounds) of |
204 | //! elements of type <theElementType> connected through the shapes |
205 | //! of the type <theConnectionType>. |
206 | //! The blocks are stored into the list of lists <theLCB>. |
207 | //! Returns also the connection map <theConnectionMap>, filled during operation. |
208 | Standard_EXPORT static void MakeConnexityBlocks(const TopoDS_Shape& theS, |
209 | const TopAbs_ShapeEnum theConnectionType, |
210 | const TopAbs_ShapeEnum theElementType, |
211 | BOPCol_ListOfListOfShape& theLCB, |
212 | BOPCol_IndexedDataMapOfShapeListOfShape& theConnectionMap); |
213 | |
214 | //! Makes connexity blocks of elements of the given type with the given type of the |
215 | //! connecting elements. The blocks are checked on regularity (multi-connectivity) |
216 | //! and stored to the list of blocks <theLCB>. |
217 | Standard_EXPORT static void MakeConnexityBlocks(const BOPCol_ListOfShape& theLS, |
218 | const TopAbs_ShapeEnum theConnectionType, |
219 | const TopAbs_ShapeEnum theElementType, |
220 | BOPTools_ListOfConnexityBlock& theLCB); |
77a11d3d |
221 | |
222 | //! Correctly orients edges on the wire |
223 | Standard_EXPORT static void OrientEdgesOnWire (TopoDS_Shape& theWire); |
224 | |
225 | //! Correctly orients faces on the shell |
226 | Standard_EXPORT static void OrientFacesOnShell (TopoDS_Shape& theShell); |
42cf5bc1 |
227 | |
228 | |
229 | //! Provides valid values of tolerances for the shape <theS> |
230 | //! <theTolMax> is max value of the tolerance that can be |
231 | //! accepted for correction. If real value of the tolerance |
232 | //! will be greater than <aTolMax>, the correction does not |
233 | //! perform. |
3510db62 |
234 | Standard_EXPORT static void CorrectTolerances |
235 | (const TopoDS_Shape& theS, |
236 | const BOPCol_IndexedMapOfShape& theMapToAvoid, |
237 | const Standard_Real theTolMax = 0.0001, |
238 | const Standard_Boolean theRunParallel = Standard_False); |
42cf5bc1 |
239 | |
240 | //! Provides valid values of tolerances for the shape <theS> |
241 | //! in terms of BRepCheck_InvalidCurveOnSurface. |
3510db62 |
242 | Standard_EXPORT static void CorrectCurveOnSurface |
243 | (const TopoDS_Shape& theS, |
244 | const BOPCol_IndexedMapOfShape& theMapToAvoid, |
245 | const Standard_Real theTolMax = 0.0001, |
246 | const Standard_Boolean theRunParallel = Standard_False); |
42cf5bc1 |
247 | |
248 | //! Provides valid values of tolerances for the shape <theS> |
249 | //! in terms of BRepCheck_InvalidPointOnCurve. |
3510db62 |
250 | Standard_EXPORT static void CorrectPointOnCurve |
251 | (const TopoDS_Shape& theS, |
252 | const BOPCol_IndexedMapOfShape& theMapToAvoid, |
253 | const Standard_Real theTolMax = 0.0001, |
254 | const Standard_Boolean theRunParallel = Standard_False); |
42cf5bc1 |
255 | |
256 | //! Make a vertex using 3D-point <aP1> and 3D-tolerance value <aTol> |
257 | Standard_EXPORT static void MakeNewVertex (const gp_Pnt& aP1, const Standard_Real aTol, TopoDS_Vertex& aNewVertex); |
258 | |
259 | |
260 | //! Make a vertex using couple of vertices <aV1, aV2> |
261 | Standard_EXPORT static void MakeNewVertex (const TopoDS_Vertex& aV1, const TopoDS_Vertex& aV2, TopoDS_Vertex& aNewVertex); |
262 | |
263 | |
264 | //! Make a vertex in place of intersection between two edges |
265 | //! <aE1, aE2> with parameters <aP1, aP2> |
266 | Standard_EXPORT static void MakeNewVertex (const TopoDS_Edge& aE1, const Standard_Real aP1, const TopoDS_Edge& aE2, const Standard_Real aP2, TopoDS_Vertex& aNewVertex); |
267 | |
268 | |
269 | //! Make a vertex in place of intersection between the edge <aE1> |
270 | //! with parameter <aP1> and the face <aF2> |
271 | Standard_EXPORT static void MakeNewVertex (const TopoDS_Edge& aE1, const Standard_Real aP1, const TopoDS_Face& aF2, TopoDS_Vertex& aNewVertex); |
272 | |
273 | |
274 | //! Compute a 3D-point on the edge <aEdge> at parameter <aPrm> |
275 | Standard_EXPORT static void PointOnEdge (const TopoDS_Edge& aEdge, const Standard_Real aPrm, gp_Pnt& aP); |
56c62737 |
276 | |
277 | //! Makes a copy of <theEdge> with vertices. |
278 | Standard_EXPORT static TopoDS_Edge CopyEdge(const TopoDS_Edge& theEdge); |
42cf5bc1 |
279 | |
280 | //! Make the edge from base edge <aE1> and two vertices <aV1,aV2> |
281 | //! at parameters <aP1,aP2> |
282 | Standard_EXPORT static void MakeSplitEdge (const TopoDS_Edge& aE1, const TopoDS_Vertex& aV1, const Standard_Real aP1, const TopoDS_Vertex& aV2, const Standard_Real aP2, TopoDS_Edge& aNewEdge); |
283 | |
284 | |
285 | //! Make the edge from 3D-Curve <aIC> and two vertices <aV1,aV2> |
286 | //! at parameters <aP1,aP2> |
287 | Standard_EXPORT static void MakeSectEdge (const IntTools_Curve& aIC, const TopoDS_Vertex& aV1, const Standard_Real aP1, const TopoDS_Vertex& aV2, const Standard_Real aP2, TopoDS_Edge& aNewEdge); |
288 | |
289 | |
290 | //! Update the tolerance value for vertex <aV> |
291 | //! taking into account the fact that <aV> lays on |
292 | //! the curve <aIC> |
293 | Standard_EXPORT static void UpdateVertex (const IntTools_Curve& aIC, const Standard_Real aT, const TopoDS_Vertex& aV); |
294 | |
295 | |
296 | //! Update the tolerance value for vertex <aV> |
297 | //! taking into account the fact that <aV> lays on |
298 | //! the edge <aE> |
299 | Standard_EXPORT static void UpdateVertex (const TopoDS_Edge& aE, const Standard_Real aT, const TopoDS_Vertex& aV); |
300 | |
301 | |
302 | //! Update the tolerance value for vertex <aVN> |
303 | //! taking into account the fact that <aVN> should |
304 | //! cover tolerance zone of <aVF> |
305 | Standard_EXPORT static void UpdateVertex (const TopoDS_Vertex& aVF, const TopoDS_Vertex& aVN); |
306 | |
307 | |
308 | //! Correct shrunk range <aSR> taking into account 3D-curve |
309 | //! resolution and corresp. tolerances' values of <aE1>, <aE2> |
310 | Standard_EXPORT static void CorrectRange (const TopoDS_Edge& aE1, const TopoDS_Edge& aE2, const IntTools_Range& aSR, IntTools_Range& aNewSR); |
311 | |
312 | |
313 | //! Correct shrunk range <aSR> taking into account 3D-curve |
314 | //! resolution and corresp. tolerances' values of <aE>, <aF> |
315 | Standard_EXPORT static void CorrectRange (const TopoDS_Edge& aE, const TopoDS_Face& aF, const IntTools_Range& aSR, IntTools_Range& aNewSR); |
316 | |
317 | |
318 | //! Returns TRUE if PaveBlock <aPB> lays on the face <aF>, i.e |
319 | //! the <PB> is IN or ON in 2D of <aF> |
320 | Standard_EXPORT static Standard_Boolean IsBlockInOnFace (const IntTools_Range& aShR, const TopoDS_Face& aF, const TopoDS_Edge& aE, Handle(IntTools_Context)& aContext); |
321 | |
322 | |
01b5b3df |
323 | //! Checks if it is possible to compute shrunk range for the edge <aE> |
324 | //! Flag <theCheckSplittable> defines whether to take into account |
325 | //! the possiblity to split the edge or not. |
326 | Standard_EXPORT static Standard_Boolean IsMicroEdge (const TopoDS_Edge& theEdge, |
327 | const Handle(IntTools_Context)& theContext, |
328 | const Standard_Boolean theCheckSplittable = Standard_True); |
42cf5bc1 |
329 | |
330 | |
331 | //! Corrects tolerance values of the sub-shapes of the shape <theS> if needed. |
3510db62 |
332 | Standard_EXPORT static void CorrectShapeTolerances |
333 | (const TopoDS_Shape& theS, |
334 | const BOPCol_IndexedMapOfShape& theMapToAvoid, |
335 | const Standard_Boolean theRunParallel = Standard_False); |
42cf5bc1 |
336 | |
337 | //! Retutns dimension of the shape <theS>. |
338 | Standard_EXPORT static Standard_Integer Dimension (const TopoDS_Shape& theS); |
339 | |
340 | //! Returns true if the shell <theShell> is open |
341 | Standard_EXPORT static Standard_Boolean IsOpenShell (const TopoDS_Shell& theShell); |
342 | |
343 | //! Returns true if the solid <theSolid> is inverted |
344 | Standard_EXPORT static Standard_Boolean IsInvertedSolid (const TopoDS_Solid& theSolid); |
345 | |
346 | |
347 | //! Computes the necessary value of the tolerance for the edge |
348 | Standard_EXPORT static Standard_Boolean ComputeTolerance (const TopoDS_Face& theFace, const TopoDS_Edge& theEdge, Standard_Real& theMaxDist, Standard_Real& theMaxPar); |
349 | |
350 | |
42cf5bc1 |
351 | protected: |
352 | |
353 | |
42cf5bc1 |
354 | private: |
355 | |
42cf5bc1 |
356 | }; |
357 | |
42cf5bc1 |
358 | #endif // _BOPTools_AlgoTools_HeaderFile |