1 //! Created on: 2015-04-24
2 //! Created by: NIKOLAI BUKHALOV
3 //! Copyright (c) 2015 OPEN CASCADE SAS
5 //! This file is part of Open CASCADE Technology software library.
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.
13 //! Alternatively, this file may be used under the terms of Open CASCADE
14 //! commercial license or contractual agreement.
16 #ifndef _BRepBuilderAPI_FastSewing_HeaderFile
17 #define _BRepBuilderAPI_FastSewing_HeaderFile
19 #include <Standard_Transient.hxx>
20 #include <BRep_Builder.hxx>
22 #include <NCollection_List.hxx>
23 #include <NCollection_Sequence.hxx>
24 #include <NCollection_Vector.hxx>
25 #include <NCollection_CellFilter.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Face.hxx>
29 #include <TopoDS_Vertex.hxx>
30 #include <TopoDS_Wire.hxx>
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.
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
49 typedef unsigned int FS_VARStatuses;
51 //! Enumeration of result statuses
52 //ATTENTION!!! If you add new status, please
53 // describe it in GetStatuses() method
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
68 //! Creates an object with tolerance of connexity
69 Standard_EXPORT BRepBuilderAPI_FastSewing(const Standard_Real theTolerance = 1.0e-06);
71 //! Adds faces of a shape
72 Standard_EXPORT Standard_Boolean Add(const TopoDS_Shape& theShape);
75 Standard_EXPORT Standard_Boolean Add(const Handle(Geom_Surface)& theSurface);
77 //! Compute resulted shape
78 Standard_EXPORT void Perform (void) ;
81 void SetTolerance (const Standard_Real theToler)
83 myTolerance = theToler;
87 Standard_Real GetTolerance() const
92 //! Returns resulted shape
93 const TopoDS_Shape& GetResult() const
98 //! Returns list of statuses. Print message if theOS != 0
99 Standard_EXPORT FS_VARStatuses GetStatuses(Standard_OStream* const theOS = 0);
101 DEFINE_STANDARD_RTTIEXT(BRepBuilderAPI_FastSewing,Standard_Transient)
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);
118 Standard_EXPORT Standard_Real Compute3DRange();
120 //! Sets status. Returns numeric value of the status set
121 FS_VARStatuses SetStatus(FS_Statuses theStatus)
123 const FS_VARStatuses aStatusID = (FS_VARStatuses)(theStatus);
124 myStatusList |= aStatusID;
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.)
133 //! The struct corresponding to a vertex
137 FS_Vertex(): myID(-1){};
139 //! Creates topological member (vertex)
140 void CreateTopologicalVertex(const Standard_Real theToler)
142 BRep_Builder aBuilder;
143 aBuilder.MakeVertex(myTopoVert, myPnt, theToler);
146 //! Geometry point of this Vertex
148 TopoDS_Vertex myTopoVert;
150 //! List of faces and edges which share this vertex
151 NCollection_List<Standard_Integer> myFaces;
152 NCollection_List<Standard_Integer> myEdges;
154 //! Indentifies the place of this Vertex in
155 //! BRepBuilderAPI_FastSewing::myVertexVec list
156 Standard_Integer myID;
159 //! The struct corresponding to an face
164 for (Standard_Integer i = 0; i < 4; i++)
170 //! Creates topological members (wire and face)
171 void CreateTopologicalWire(const NCollection_Vector<FS_Edge>& theEdgeVec,
172 const Standard_Real theToler);
173 void CreateTopologicalFace();
176 void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
178 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
179 "FS_Face::SetVertex(): OUT of Range");
181 myVertices[thePlaceID] = theVertID;
185 void SetEdge(const Standard_Integer thePlaceID, const Standard_Integer theEdgeID)
187 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
188 "FS_Face::SetEdge(): OUT of Range");
190 myEdges[thePlaceID] = theEdgeID;
193 TopoDS_Face mySrcFace;
195 TopoDS_Face myRetFace;
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];
204 //! Indentifies the place of this Face in
205 //! BRepBuilderAPI_FastSewing::myFaceVec list
206 Standard_Integer myID;
209 //! The struct corresponding to a edge
219 FS_Edge(const Standard_Integer theIDVert1, const Standard_Integer theIDVert2): myID(-1)
221 myVertices[0] = theIDVert1;
222 myVertices[1] = theIDVert2;
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);
231 void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
233 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 1),
234 "FS_Face::SetVertex(): OUT of Range");
236 myVertices[thePlaceID] = theVertID;
239 Standard_Boolean IsDegenerated() const
241 return (myVertices[0] == myVertices[1]);
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;
248 //! Indentifies the place of this Edge in
249 //! BRepBuilderAPI_FastSewing::myEdgeVec list
250 Standard_Integer myID;
252 TopoDS_Edge myTopoEdge;
254 //! Index of the vertex in myVertexVec array
255 Standard_Integer myVertices[2];
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
263 typedef Standard_Integer Target;
265 NodeInspector(const NCollection_Vector<FS_Vertex>& theVec,
266 const gp_Pnt& thePnt, const Standard_Real theTol);
268 Standard_EXPORT NCollection_CellFilter_Action Inspect (const Target theId);
276 NodeInspector& operator = (const NodeInspector&);
277 const NCollection_Vector<FS_Vertex>& myVecOfVertexes;
279 Standard_Real mySQToler;
281 Standard_Boolean myIsFindingEnable;
284 TopoDS_Shape myResShape;
286 // myFaceVec, myVertexVec and myEdgeVec lists are filled only once!!!!!
289 NCollection_Vector<FS_Face> myFaceVec;
290 //! Vector of Vertices
291 NCollection_Vector<FS_Vertex> myVertexVec;
293 NCollection_Vector<FS_Edge> myEdgeVec;
296 Standard_Real myTolerance;
298 //! Bits of computation status
299 FS_VARStatuses myStatusList;
302 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_FastSewing, Standard_Transient)
304 #endif // _BRepBuilderAPI_FastSewing_HeaderFile