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>
32 class Handle(NCollection_IncAllocator);
33 class Handle(Geom_Surface);
35 //! This class performs fast sewing of surfaces (faces). It supposes
36 //! that all surfaces are finite and are naturally restricted by their bounds.
37 //! Moreover, it supposes that stitched together surfaces have the same parameterization
38 //! along common boundaries, therefore it does not perform time-consuming check for
39 //! SameParameter property of edges.
41 //! For sewing, use this function as following:
42 //! - set tolerance value (default tolerance is 1.E-06)
43 //! - add all necessary surfaces (faces)
44 //! - check status if adding is correctly completed.
45 //! - compute -> Perform
46 //! - retrieve the error status if any
47 //! - retrieve the resulted shape
48 class BRepBuilderAPI_FastSewing : public Standard_Transient
51 typedef unsigned int FS_VARStatuses;
53 //! Enumeration of result statuses
54 //ATTENTION!!! If you add new status, please
55 // describe it in GetStatuses() method
59 FS_Degenerated = 0x00000001,
60 FS_FindVertexError = 0x00000002,
61 FS_FindEdgeError = 0x00000004,
62 FS_FaceWithNullSurface = 0x00000008,
63 FS_NotNaturalBoundsFace = 0x00000010,
64 FS_InfiniteSurface = 0x00000020,
65 FS_EmptyInput = 0x00000040,
66 FS_Exception = 0x00000080
70 //! Creates an object with tolerance of connexity
71 Standard_EXPORT BRepBuilderAPI_FastSewing(const Standard_Real theTolerance = 1.0e-06);
73 //! Adds faces of a shape
74 Standard_EXPORT Standard_Boolean Add(const TopoDS_Shape& theShape);
77 Standard_EXPORT Standard_Boolean Add(const Handle(Geom_Surface)& theSurface);
79 //! Compute resulted shape
80 Standard_EXPORT void Perform (void) ;
83 void SetTolerance (const Standard_Real theToler)
85 myTolerance = theToler;
89 Standard_Real GetTolerance() const
94 //! Returns resulted shape
95 const TopoDS_Shape& GetResult() const
100 //! Returns list of statuses. Print message if theOS != 0
101 Standard_EXPORT FS_VARStatuses GetStatuses(Standard_OStream* const theOS = 0);
103 DEFINE_STANDARD_RTTI(BRepBuilderAPI_FastSewing)
108 Standard_EXPORT void FindVertexes(const Standard_Integer theSurfID,
109 NCollection_CellFilter<NodeInspector>& theCells);
110 Standard_EXPORT void FindEdges(const Standard_Integer theSurfID);
111 Standard_EXPORT void UpdateEdgeInfo(const Standard_Integer theIDPrevVertex,
112 const Standard_Integer theIDCurrVertex,
113 const Standard_Integer theFaceID,
114 const Standard_Integer theIDCurvOnFace);
115 Standard_EXPORT void CreateNewEdge( const Standard_Integer theIDPrevVertex,
116 const Standard_Integer theIDCurrVertex,
117 const Standard_Integer theFaceID,
118 const Standard_Integer theIDCurvOnFace);
120 Standard_EXPORT Standard_Real Compute3DRange();
122 //! Sets status. Returns numeric value of the status set
123 FS_VARStatuses SetStatus(FS_Statuses theStatus)
125 const FS_VARStatuses aStatusID = (FS_VARStatuses)(theStatus);
126 myStatusList |= aStatusID;
132 // Classes FS_Vertex, FS_Face and FS_Edge keep information about
133 // relations between resulted members (e.g. which faces share this vertex? etc.)
135 //! The struct corresponding to a vertex
139 FS_Vertex(): myID(-1){};
141 //! Creates topological member (vertex)
142 void CreateTopologicalVertex(const Standard_Real theToler)
144 BRep_Builder aBuilder;
145 aBuilder.MakeVertex(myTopoVert, myPnt, theToler);
148 //! Geometry point of this Vertex
150 TopoDS_Vertex myTopoVert;
152 //! List of faces and edges which share this vertex
153 NCollection_List<Standard_Integer> myFaces;
154 NCollection_List<Standard_Integer> myEdges;
156 //! Indentifies the place of this Vertex in
157 //! BRepBuilderAPI_FastSewing::myVertexVec list
158 Standard_Integer myID;
161 //! The struct corresponding to an face
166 for (Standard_Integer i = 0; i < 4; i++)
172 //! Creates topological members (wire and face)
173 void CreateTopologicalWire(const NCollection_Vector<FS_Edge>& theEdgeVec,
174 const Standard_Real theToler);
175 void CreateTopologicalFace();
178 void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
180 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
181 "FS_Face::SetVertex(): OUT of Range");
183 myVertices[thePlaceID] = theVertID;
187 void SetEdge(const Standard_Integer thePlaceID, const Standard_Integer theEdgeID)
189 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 3),
190 "FS_Face::SetEdge(): OUT of Range");
192 myEdges[thePlaceID] = theEdgeID;
195 TopoDS_Face mySrcFace;
197 TopoDS_Face myRetFace;
199 //! myEdges[i] number of the edge in myEdgeVec
200 //! (i==0) <-> (V=Vf); (i==1) <-> (U=Ul);
201 //! (i==2) <-> (V=Vl); (i==3) <-> (U=Uf)
202 Standard_Integer myEdges[4];
203 //! myVertices[i] is Start point of myEdges[i]
204 Standard_Integer myVertices[4];
206 //! Indentifies the place of this Face in
207 //! BRepBuilderAPI_FastSewing::myFaceVec list
208 Standard_Integer myID;
211 //! The struct corresponding to a edge
221 FS_Edge(const Standard_Integer theIDVert1, const Standard_Integer theIDVert2): myID(-1)
223 myVertices[0] = theIDVert1;
224 myVertices[1] = theIDVert2;
227 //! Creates topological member (TopoDS_Edge)
228 void CreateTopologicalEdge( const NCollection_Vector<FS_Vertex>& theVertexVec,
229 const NCollection_Vector<FS_Face>& theFaceVec,
230 const Standard_Real theTol);
233 void SetVertex(const Standard_Integer thePlaceID, const Standard_Integer theVertID)
235 Standard_RangeError_Raise_if((thePlaceID < 0) || (thePlaceID > 1),
236 "FS_Face::SetVertex(): OUT of Range");
238 myVertices[thePlaceID] = theVertID;
241 Standard_Boolean IsDegenerated() const
243 return (myVertices[0] == myVertices[1]);
246 //! List of faces which are shared with this edge
247 //! Value is the index of this shape in myFaceVec array
248 NCollection_Sequence<Standard_Integer> myFaces;
250 //! Indentifies the place of this Edge in
251 //! BRepBuilderAPI_FastSewing::myEdgeVec list
252 Standard_Integer myID;
254 TopoDS_Edge myTopoEdge;
256 //! Index of the vertex in myVertexVec array
257 Standard_Integer myVertices[2];
260 //! This inspector will find a node nearest to the given point
261 //! not far than on the given tolerance
262 class NodeInspector: public NCollection_CellFilter_InspectorXYZ
265 typedef Standard_Integer Target;
267 NodeInspector(const NCollection_Vector<FS_Vertex>& theVec,
268 const gp_Pnt& thePnt, const Standard_Real theTol);
270 Standard_EXPORT NCollection_CellFilter_Action Inspect (const Target theId);
278 NodeInspector& operator = (const NodeInspector&);
279 const NCollection_Vector<FS_Vertex>& myVecOfVertexes;
281 Standard_Real mySQToler;
283 Standard_Boolean myIsFindingEnable;
286 TopoDS_Shape myResShape;
288 // myFaceVec, myVertexVec and myEdgeVec lists are filled only once!!!!!
291 NCollection_Vector<FS_Face> myFaceVec;
292 //! Vector of Vertices
293 NCollection_Vector<FS_Vertex> myVertexVec;
295 NCollection_Vector<FS_Edge> myEdgeVec;
298 Standard_Real myTolerance;
300 //! Bits of computation status
301 FS_VARStatuses myStatusList;
304 #endif // _BRepBuilderAPI_FastSewing_HeaderFile
306 DEFINE_STANDARD_HANDLE(BRepBuilderAPI_FastSewing, Standard_Transient)