7693827d |
1 | //! Created on: 2015-04-24 |
2 | //! Created by: NIKOLAI BUKHALOV |
3 | //! Copyright (c) 2015 OPEN CASCADE SAS |
4 | //! |
5 | //! This file is part of Open CASCADE Technology software library. |
6 | //! |
7 | //! This library is free software; you can redistribute it and/or modify it under |
8 | //! the terms of the GNU Lesser General Public License version 2.1 as published |
9 | //! by the Free Software Foundation, with special exception defined in the file |
10 | //! OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | //! distribution for complete text of the license and disclaimer of any warranty. |
12 | //! |
13 | //! Alternatively, this file may be used under the terms of Open CASCADE |
14 | //! commercial license or contractual agreement. |
15 | |
16 | #ifndef _BRepBuilderAPI_FastSewing_HeaderFile |
17 | #define _BRepBuilderAPI_FastSewing_HeaderFile |
18 | |
19 | #include <Standard_Transient.hxx> |
20 | #include <BRep_Builder.hxx> |
21 | |
22 | #include <NCollection_List.hxx> |
23 | #include <NCollection_Sequence.hxx> |
24 | #include <NCollection_Vector.hxx> |
25 | #include <NCollection_CellFilter.hxx> |
26 | |
27 | #include <TopoDS_Edge.hxx> |
28 | #include <TopoDS_Face.hxx> |
29 | #include <TopoDS_Vertex.hxx> |
30 | #include <TopoDS_Wire.hxx> |
31 | |
7693827d |
32 | |
33 | //! This class performs fast sewing of surfaces (faces). It supposes |
34 | //! that all surfaces are finite and are naturally restricted by their bounds. |
35 | //! Moreover, it supposes that stitched together surfaces have the same parameterization |
36 | //! along common boundaries, therefore it does not perform time-consuming check for |
37 | //! SameParameter property of edges. |
38 | //! |
39 | //! For sewing, use this function as following: |
40 | //! - set tolerance value (default tolerance is 1.E-06) |
41 | //! - add all necessary surfaces (faces) |
42 | //! - check status if adding is correctly completed. |
43 | //! - compute -> Perform |
44 | //! - retrieve the error status if any |
45 | //! - retrieve the resulted shape |
46 | class BRepBuilderAPI_FastSewing : public Standard_Transient |
47 | { |
48 | public: |
49 | typedef unsigned int FS_VARStatuses; |
50 | |
51 | //! Enumeration of result statuses |
52 | //ATTENTION!!! If you add new status, please |
53 | // describe it in GetStatuses() method |
54 | enum FS_Statuses |
55 | { |
56 | FS_OK = 0x00000000, |
57 | FS_Degenerated = 0x00000001, |
58 | FS_FindVertexError = 0x00000002, |
59 | FS_FindEdgeError = 0x00000004, |
60 | FS_FaceWithNullSurface = 0x00000008, |
61 | FS_NotNaturalBoundsFace = 0x00000010, |
62 | FS_InfiniteSurface = 0x00000020, |
63 | FS_EmptyInput = 0x00000040, |
64 | FS_Exception = 0x00000080 |
65 | }; |
66 | |
67 | |
68 | //! Creates an object with tolerance of connexity |
69 | Standard_EXPORT BRepBuilderAPI_FastSewing(const Standard_Real theTolerance = 1.0e-06); |
70 | |
71 | //! Adds faces of a shape |
72 | Standard_EXPORT Standard_Boolean Add(const TopoDS_Shape& theShape); |
73 | |
74 | //! Adds a surface |
75 | Standard_EXPORT Standard_Boolean Add(const Handle(Geom_Surface)& theSurface); |
76 | |
77 | //! Compute resulted shape |
78 | Standard_EXPORT void Perform (void) ; |
79 | |
80 | //! Sets tolerance |
81 | void SetTolerance (const Standard_Real theToler) |
82 | { |
83 | myTolerance = theToler; |
84 | } |
85 | |
86 | //! Returns tolerance |
87 | Standard_Real GetTolerance() const |
88 | { |
89 | return myTolerance; |
90 | } |
91 | |
92 | //! Returns resulted shape |
93 | const TopoDS_Shape& GetResult() const |
94 | { |
95 | return myResShape; |
96 | } |
97 | |
98 | //! Returns list of statuses. Print message if theOS != 0 |
99 | Standard_EXPORT FS_VARStatuses GetStatuses(Standard_OStream* const theOS = 0); |
100 | |
92efcf78 |
101 | DEFINE_STANDARD_RTTIEXT(BRepBuilderAPI_FastSewing,Standard_Transient) |
7693827d |
102 | |
103 | protected: |
104 | class NodeInspector; |
105 | |
106 | Standard_EXPORT void FindVertexes(const Standard_Integer theSurfID, |
107 | NCollection_CellFilter<NodeInspector>& theCells); |
108 | Standard_EXPORT void FindEdges(const Standard_Integer theSurfID); |
109 | Standard_EXPORT void UpdateEdgeInfo(const Standard_Integer theIDPrevVertex, |
110 | const Standard_Integer theIDCurrVertex, |
111 | const Standard_Integer theFaceID, |
112 | const Standard_Integer theIDCurvOnFace); |
113 | Standard_EXPORT void CreateNewEdge( const Standard_Integer theIDPrevVertex, |
114 | const Standard_Integer theIDCurrVertex, |
115 | const Standard_Integer theFaceID, |
116 | const Standard_Integer theIDCurvOnFace); |
117 | |
118 | Standard_EXPORT Standard_Real Compute3DRange(); |
119 | |
120 | //! Sets status. Returns numeric value of the status set |
121 | FS_VARStatuses SetStatus(FS_Statuses theStatus) |
122 | { |
123 | const FS_VARStatuses aStatusID = (FS_VARStatuses)(theStatus); |
124 | myStatusList |= aStatusID; |
125 | return aStatusID; |
126 | } |
127 | |
128 | class FS_Edge; |
129 | |
130 | // Classes FS_Vertex, FS_Face and FS_Edge keep information about |
131 | // relations between resulted members (e.g. which faces share this vertex? etc.) |
132 | |
133 | //! The struct corresponding to a vertex |
134 | struct FS_Vertex |
135 | { |
136 | public: |
137 | FS_Vertex(): myID(-1){}; |
138 | |
139 | //! Creates topological member (vertex) |
140 | void CreateTopologicalVertex(const Standard_Real theToler) |
141 | { |
142 | BRep_Builder aBuilder; |
143 | aBuilder.MakeVertex(myTopoVert, myPnt, theToler); |
144 | } |
145 | |
146 | //! Geometry point of this Vertex |
147 | gp_Pnt myPnt; |
148 | TopoDS_Vertex myTopoVert; |
149 | |
150 | //! List of faces and edges which share this vertex |
151 | NCollection_List<Standard_Integer> myFaces; |
152 | NCollection_List<Standard_Integer> myEdges; |
153 | |
154 | //! Indentifies the place of this Vertex in |
155 | //! BRepBuilderAPI_FastSewing::myVertexVec list |
156 | Standard_Integer myID; |
157 | }; |
158 | |
159 | //! The struct corresponding to an face |
160 | struct FS_Face |
161 | { |
162 | FS_Face(): myID(-1) |
163 | { |
164 | for (Standard_Integer i = 0; i < 4; i++) |
165 | { |
166 | myVertices[i] = -1; |
167 | myEdges[i] = -1; |
168 | } |
169 | }; |
170 | //! Creates topological members (wire and face) |
171 | void CreateTopologicalWire(const NCollection_Vector<FS_Edge>& theEdgeVec, |
172 | const Standard_Real theToler); |
173 | void CreateTopologicalFace(); |
174 | |
175 | //! Sets vertex |
176 | void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID) |
177 | { |
178 | Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3), |
179 | "FS_Face::SetVertex(): OUT of Range"); |
180 | |
181 | myVertices[thePlaceID] = theVertID; |
182 | } |
183 | |
184 | //! Sets edge |
185 | void SetEdge(const Standard_Integer thePlaceID, const Standard_Integer theEdgeID) |
186 | { |
187 | Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3), |
188 | "FS_Face::SetEdge(): OUT of Range"); |
189 | |
190 | myEdges[thePlaceID] = theEdgeID; |
191 | } |
192 | |
193 | TopoDS_Face mySrcFace; |
194 | TopoDS_Wire myWire; |
195 | TopoDS_Face myRetFace; |
196 | |
197 | //! myEdges[i] number of the edge in myEdgeVec |
198 | //! (i==0) <-> (V=Vf); (i==1) <-> (U=Ul); |
199 | //! (i==2) <-> (V=Vl); (i==3) <-> (U=Uf) |
200 | Standard_Integer myEdges[4]; |
201 | //! myVertices[i] is Start point of myEdges[i] |
202 | Standard_Integer myVertices[4]; |
203 | |
204 | //! Indentifies the place of this Face in |
205 | //! BRepBuilderAPI_FastSewing::myFaceVec list |
206 | Standard_Integer myID; |
207 | }; |
208 | |
209 | //! The struct corresponding to a edge |
210 | class FS_Edge |
211 | { |
212 | public: |
213 | FS_Edge(): myID(-1) |
214 | { |
215 | myVertices[0] = -1; |
216 | myVertices[1] = -1; |
217 | } |
218 | |
219 | FS_Edge(const Standard_Integer theIDVert1, const Standard_Integer theIDVert2): myID(-1) |
220 | { |
221 | myVertices[0] = theIDVert1; |
222 | myVertices[1] = theIDVert2; |
223 | }; |
224 | |
225 | //! Creates topological member (TopoDS_Edge) |
226 | void CreateTopologicalEdge( const NCollection_Vector<FS_Vertex>& theVertexVec, |
227 | const NCollection_Vector<FS_Face>& theFaceVec, |
228 | const Standard_Real theTol); |
229 | |
230 | //! Sets vertex |
231 | void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID) |
232 | { |
233 | Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 1), |
234 | "FS_Face::SetVertex(): OUT of Range"); |
235 | |
236 | myVertices[thePlaceID] = theVertID; |
237 | } |
238 | |
239 | Standard_Boolean IsDegenerated() const |
240 | { |
241 | return (myVertices[0] == myVertices[1]); |
242 | } |
243 | |
244 | //! List of faces which are shared with this edge |
245 | //! Value is the index of this shape in myFaceVec array |
246 | NCollection_Sequence<Standard_Integer> myFaces; |
247 | |
248 | //! Indentifies the place of this Edge in |
249 | //! BRepBuilderAPI_FastSewing::myEdgeVec list |
250 | Standard_Integer myID; |
251 | |
252 | TopoDS_Edge myTopoEdge; |
253 | private: |
254 | //! Index of the vertex in myVertexVec array |
255 | Standard_Integer myVertices[2]; |
256 | }; |
257 | |
258 | //! This inspector will find a node nearest to the given point |
259 | //! not far than on the given tolerance |
260 | class NodeInspector: public NCollection_CellFilter_InspectorXYZ |
261 | { |
262 | public: |
263 | typedef Standard_Integer Target; |
264 | |
265 | NodeInspector(const NCollection_Vector<FS_Vertex>& theVec, |
266 | const gp_Pnt& thePnt, const Standard_Real theTol); |
267 | |
268 | Standard_EXPORT NCollection_CellFilter_Action Inspect (const Target theId); |
269 | |
270 | Target GetResult() |
271 | { |
272 | return myResID; |
273 | } |
274 | |
275 | private: |
276 | NodeInspector& operator = (const NodeInspector&); |
277 | const NCollection_Vector<FS_Vertex>& myVecOfVertexes; |
278 | gp_Pnt myPoint; |
279 | Standard_Real mySQToler; |
280 | Target myResID; |
281 | Standard_Boolean myIsFindingEnable; |
282 | }; |
283 | private: |
284 | TopoDS_Shape myResShape; |
285 | |
286 | // myFaceVec, myVertexVec and myEdgeVec lists are filled only once!!!!! |
287 | |
288 | //! Vector of faces |
289 | NCollection_Vector<FS_Face> myFaceVec; |
290 | //! Vector of Vertices |
291 | NCollection_Vector<FS_Vertex> myVertexVec; |
292 | //! Vector of edges |
293 | NCollection_Vector<FS_Edge> myEdgeVec; |
294 | |
295 | //! Tolerance |
296 | Standard_Real myTolerance; |
297 | |
298 | //! Bits of computation status |
299 | FS_VARStatuses myStatusList; |
300 | }; |
301 | |
302 | #endif // _BRepBuilderAPI_FastSewing_HeaderFile |
303 | |
304 | DEFINE_STANDARD_HANDLE(BRepBuilderAPI_FastSewing, Standard_Transient) |