fc9b36d6 |
1 | // Copyright (c) 2013 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _BRepMesh_FastDiscret_HeaderFile |
15 | #define _BRepMesh_FastDiscret_HeaderFile |
16 | |
17 | #include <Standard.hxx> |
18 | #include <Standard_DefineHandle.hxx> |
19 | #include <BRepMesh_FastDiscret.hxx> |
20 | #include <BRepMesh_DataStructureOfDelaun.hxx> |
21 | #include <TColStd_IndexedMapOfInteger.hxx> |
22 | #include <BRepMesh_Status.hxx> |
23 | #include <TopTools_DataMapOfShapeReal.hxx> |
24 | #include <TopTools_ListOfShape.hxx> |
25 | #include <TopTools_MutexForShapeProvider.hxx> |
26 | #include <Standard_Transient.hxx> |
27 | #include <Handle_BRepAdaptor_HSurface.hxx> |
28 | #include <Handle_Geom2d_Curve.hxx> |
29 | #include <BRepMesh_Delaun.hxx> |
30 | #include <TopAbs_ShapeEnum.hxx> |
31 | #include <BRepMesh_Triangle.hxx> |
32 | #include <BRepMesh_FaceAttribute.hxx> |
848fa7e3 |
33 | #include <BRepMesh.hxx> |
ceb418e1 |
34 | #include <TColgp_Array1OfPnt.hxx> |
35 | #include <BRep_Tool.hxx> |
36 | #include <BRepMesh_ShapeTool.hxx> |
37 | #include <TopoDS_Vertex.hxx> |
38 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
fc9b36d6 |
39 | |
40 | class BRepMesh_DataStructureOfDelaun; |
41 | class Bnd_Box; |
42 | class TopoDS_Shape; |
43 | class TopoDS_Face; |
fc9b36d6 |
44 | class TopoDS_Edge; |
45 | class BRepAdaptor_HSurface; |
46 | class Geom2d_Curve; |
fc9b36d6 |
47 | class BRepMesh_Edge; |
48 | class BRepMesh_Vertex; |
49 | class gp_Pnt; |
50 | class BRepMesh_FaceAttribute; |
51 | class TopTools_DataMapOfShapeReal; |
52 | |
53 | |
54 | //! Algorithm to mesh a shape with respect of the <br> |
55 | //! frontier the deflection and by option the shared <br> |
56 | //! components. <br> |
57 | class BRepMesh_FastDiscret : public Standard_Transient |
58 | { |
59 | public: |
60 | |
61 | Standard_EXPORT BRepMesh_FastDiscret(const Standard_Real defle, |
62 | const Standard_Real angle, |
63 | const Bnd_Box& B, |
64 | const Standard_Boolean withShare = Standard_True, |
65 | const Standard_Boolean inshape = Standard_False, |
66 | const Standard_Boolean relative = Standard_False, |
67 | const Standard_Boolean shapetrigu = Standard_False, |
68 | const Standard_Boolean isInParallel = Standard_False); |
69 | |
70 | //! if the boolean <relative> is True, the <br> |
71 | //! deflection used for the polygonalisation of <br> |
72 | //! each edge will be <defle> * Size of Edge. <br> |
73 | //! the deflection used for the faces will be the maximum <br> |
74 | //! deflection of their edges. <br> |
75 | //! <br> |
76 | //! if <shapetrigu> is True, the triangulation, if exists <br> |
77 | //! with a correct deflection, can be used to re-triangulate <br> |
78 | //! the shape. <br> |
79 | //! <br> |
80 | //! if <inshape> is True, the calculated <br> |
81 | //! triangulation will be stored in the shape. <br> |
82 | Standard_EXPORT BRepMesh_FastDiscret(const TopoDS_Shape& shape, |
83 | const Standard_Real defle, |
84 | const Standard_Real angle, |
85 | const Bnd_Box& B, |
86 | const Standard_Boolean withShare = Standard_True, |
87 | const Standard_Boolean inshape = Standard_False, |
88 | const Standard_Boolean relative = Standard_False, |
89 | const Standard_Boolean shapetrigu = Standard_False, |
90 | const Standard_Boolean isInParallel = Standard_False); |
91 | |
ceb418e1 |
92 | //! Build triangulation on the whole shape. |
fc9b36d6 |
93 | Standard_EXPORT void Perform(const TopoDS_Shape& shape); |
94 | |
ceb418e1 |
95 | //! Record a face for further processing. |
96 | //! @return status flags collected during discretization |
97 | //! of boundaries of the given face. |
98 | Standard_EXPORT Standard_Integer Add(const TopoDS_Face& face); |
fc9b36d6 |
99 | |
ceb418e1 |
100 | //! Triangulate a face previously recorded for |
101 | //! processing by call to Add(). Can be executed in |
102 | //! parallel threads. |
fc9b36d6 |
103 | Standard_EXPORT void Process(const TopoDS_Face& face) const; |
104 | |
105 | void operator ()(const TopoDS_Face& face) const |
106 | { |
107 | Process(face); |
108 | } |
109 | |
fc9b36d6 |
110 | //! Request algorithm to launch in multiple threads <br> |
111 | //! to improve performance (should be supported by plugin). <br> |
ceb418e1 |
112 | inline void SetParallel(const Standard_Boolean theInParallel) |
113 | { |
114 | myInParallel = theInParallel; |
115 | } |
fc9b36d6 |
116 | |
117 | //! Returns the multi-threading usage flag. <br> |
ceb418e1 |
118 | inline Standard_Boolean IsParallel() const |
fc9b36d6 |
119 | { |
ceb418e1 |
120 | return myInParallel; |
fc9b36d6 |
121 | } |
ceb418e1 |
122 | |
fc9b36d6 |
123 | //! returns the deflection value. <br> |
124 | inline Standard_Real GetDeflection() const |
125 | { |
126 | return myDeflection; |
127 | } |
128 | |
129 | //! returns the deflection value. <br> |
130 | inline Standard_Real GetAngle() const |
131 | { |
132 | return myAngle; |
133 | } |
134 | |
135 | inline Standard_Boolean WithShare() const |
136 | { |
137 | return myWithShare; |
138 | } |
139 | |
140 | inline Standard_Boolean InShape() const |
141 | { |
142 | return myInshape; |
143 | } |
144 | |
145 | inline Standard_Boolean ShapeTrigu() const |
146 | { |
147 | return myShapetrigu; |
148 | } |
149 | |
ceb418e1 |
150 | Standard_EXPORT void InitSharedFaces(const TopoDS_Shape& theShape); |
fc9b36d6 |
151 | |
ceb418e1 |
152 | inline const TopTools_IndexedDataMapOfShapeListOfShape& SharedFaces() const |
fc9b36d6 |
153 | { |
ceb418e1 |
154 | return mySharedFaces; |
fc9b36d6 |
155 | } |
156 | |
ceb418e1 |
157 | //! Gives face attribute. |
158 | Standard_EXPORT Standard_Boolean GetFaceAttribute |
159 | ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const; |
160 | |
161 | //! Remove face attribute as useless to free locate memory. |
162 | Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace ); |
163 | |
164 | //! Returns number of boundary 3d points. |
165 | inline Standard_Integer NbBoundaryPoints() const |
166 | { |
848fa7e3 |
167 | return myBoundaryPoints->Extent(); |
ceb418e1 |
168 | } |
fc9b36d6 |
169 | |
170 | DEFINE_STANDARD_RTTI(BRepMesh_FastDiscret) |
171 | |
ceb418e1 |
172 | private: |
173 | |
174 | //! Auxiliary class used to extract geometrical parameters of TopoDS_Vertex. |
175 | class TopoDSVExplorer |
176 | { |
177 | public: |
178 | TopoDSVExplorer( |
179 | const TopoDS_Vertex& theVertex, |
180 | const Standard_Boolean isSameUV, |
181 | const TopoDS_Vertex& theSameVertex) |
182 | : myVertex(theVertex), |
183 | myIsSameUV(isSameUV), |
184 | mySameVertex(theSameVertex) |
185 | { |
186 | } |
187 | |
188 | const TopoDS_Vertex& Vertex() const |
189 | { |
190 | return myVertex; |
191 | } |
192 | |
193 | Standard_Boolean IsSameUV() const |
194 | { |
195 | return myIsSameUV; |
196 | } |
197 | |
198 | const TopoDS_Vertex& SameVertex() const |
199 | { |
200 | return mySameVertex; |
201 | } |
202 | |
203 | virtual gp_Pnt Point() const |
204 | { |
205 | return BRep_Tool::Pnt(myVertex); |
206 | } |
207 | |
208 | private: |
209 | |
210 | void operator =(const TopoDSVExplorer& /*theOther*/) |
211 | { |
212 | } |
213 | |
214 | private: |
215 | const TopoDS_Vertex& myVertex; |
216 | Standard_Boolean myIsSameUV; |
217 | const TopoDS_Vertex& mySameVertex; |
218 | }; |
219 | |
220 | |
221 | //! Auxiliary class used to extract polygonal parameters of TopoDS_Vertex. |
222 | class PolyVExplorer : public TopoDSVExplorer |
223 | { |
224 | public: |
225 | PolyVExplorer( |
226 | const TopoDS_Vertex& theVertex, |
227 | const Standard_Boolean isSameUV, |
228 | const TopoDS_Vertex& theSameVertex, |
229 | const Standard_Integer theVertexIndex, |
230 | const TColgp_Array1OfPnt& thePolygon, |
231 | const TopLoc_Location& theLoc) |
232 | : TopoDSVExplorer(theVertex, isSameUV, theSameVertex), |
233 | myVertexIndex(theVertexIndex), |
234 | myPolygon(thePolygon), |
235 | myLoc(theLoc) |
236 | { |
237 | } |
238 | |
239 | virtual gp_Pnt Point() const |
240 | { |
241 | return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc); |
242 | } |
243 | |
244 | private: |
245 | |
246 | void operator =(const PolyVExplorer& /*theOther*/) |
247 | { |
248 | } |
249 | |
250 | private: |
251 | Standard_Integer myVertexIndex; |
252 | const TColgp_Array1OfPnt& myPolygon; |
253 | const TopLoc_Location myLoc; |
254 | }; |
255 | |
256 | //! Structure keeps common parameters of edge |
257 | //! used for tessellation. |
258 | struct EdgeAttributes |
259 | { |
848fa7e3 |
260 | TopoDS_Vertex FirstVertex; |
261 | TopoDS_Vertex LastVertex; |
ceb418e1 |
262 | |
848fa7e3 |
263 | Standard_Real FirstParam; |
264 | Standard_Real LastParam; |
ceb418e1 |
265 | |
848fa7e3 |
266 | gp_Pnt2d FirstUV; |
267 | gp_Pnt2d LastUV; |
ceb418e1 |
268 | |
848fa7e3 |
269 | Standard_Boolean IsSameUV; |
270 | Standard_Real MinDist; |
ceb418e1 |
271 | |
848fa7e3 |
272 | NCollection_Handle<TopoDSVExplorer> FirstVExtractor; |
273 | NCollection_Handle<TopoDSVExplorer> LastVExtractor; |
ceb418e1 |
274 | }; |
275 | |
276 | //! Structure keeps geometrical parameters of edge's PCurve. |
277 | //! Used for caching. |
278 | struct EdgePCurve |
279 | { |
280 | Handle(Geom2d_Curve) Curve2d; |
281 | Standard_Real FirstParam; |
282 | Standard_Real LastParam; |
283 | }; |
284 | |
285 | //! Fills structure of by attributes of the given edge. |
286 | //! @return TRUE on success, FALSE elsewhere. |
287 | Standard_Boolean getEdgeAttributes( |
288 | const TopoDS_Edge& theEdge, |
289 | const EdgePCurve& thePCurve, |
290 | const Standard_Real theDefEdge, |
291 | EdgeAttributes& theAttributes) const; |
292 | |
293 | //! Registers end vertices of the edge in mesh data |
294 | //! structure of currently processed face. |
295 | void registerEdgeVertices( |
296 | EdgeAttributes& theAttributes, |
297 | Standard_Integer& ipf, |
298 | Standard_Integer& ivf, |
299 | Standard_Integer& isvf, |
300 | Standard_Integer& ipl, |
301 | Standard_Integer& ivl, |
302 | Standard_Integer& isvl); |
303 | |
304 | //! Adds tessellated representation of the given edge to |
305 | //! mesh data structure of currently processed face. |
306 | void add(const TopoDS_Edge& theEdge, |
307 | const EdgePCurve& theCurve2D, |
308 | const Standard_Real theEdgeDeflection); |
309 | |
310 | //! Updates tessellated representation of the given edge. |
311 | //! If edge already has a polygon which deflection satisfies |
312 | //! the given value, retrieves tessellation from polygon. |
313 | //! Computes tessellation using edge's geometry elsewhere. |
314 | void update( |
315 | const TopoDS_Edge& theEdge, |
316 | const Handle(Geom2d_Curve)& theCurve2D, |
317 | const Standard_Real theEdgeDeflection, |
318 | EdgeAttributes& theAttributes); |
319 | |
320 | //! Adds new link to the mesh data structure. |
321 | //! Movability of the link and order of nodes depend on orientation parameter. |
322 | void addLinkToMesh(const Standard_Integer theFirstNodeId, |
323 | const Standard_Integer theLastNodeId, |
324 | const TopAbs_Orientation theOrientation); |
325 | |
326 | //! Stores polygonal model of the given edge. |
327 | //! @param theEdge edge which polygonal model is stored. |
328 | //! @param thePolygon polygonal model of the edge. |
329 | //! @param theDeflection deflection with which polygonalization is performed. |
330 | //! This value is stored inside the polygon. |
331 | void storePolygon( |
332 | const TopoDS_Edge& theEdge, |
333 | Handle(Poly_PolygonOnTriangulation)& thePolygon, |
334 | const Standard_Real theDeflection); |
335 | |
336 | //! Caches polygonal model of the given edge to be used in further. |
337 | //! @param theEdge edge which polygonal data is stored. |
338 | //! @param thePolygon shared polygonal data of the edge. |
339 | //! @param theDeflection deflection with which polygonalization is performed. |
340 | //! This value is stored inside the polygon. |
341 | void storePolygonSharedData( |
342 | const TopoDS_Edge& theEdge, |
343 | Handle(Poly_PolygonOnTriangulation)& thePolygon, |
344 | const Standard_Real theDeflection); |
fc9b36d6 |
345 | |
346 | private: |
347 | |
848fa7e3 |
348 | TopoDS_Face myFace; |
349 | Standard_Real myAngle; |
350 | Standard_Real myDeflection; |
351 | Standard_Real myDtotale; |
352 | Standard_Boolean myWithShare; |
353 | Standard_Boolean myInParallel; |
354 | BRepMesh::DMapOfShapePairOfPolygon myEdges; |
355 | BRepMesh::DMapOfFaceAttribute myAttributes; |
356 | Standard_Boolean myRelative; |
357 | Standard_Boolean myShapetrigu; |
358 | Standard_Boolean myInshape; |
359 | TopTools_DataMapOfShapeReal myMapdefle; |
ceb418e1 |
360 | |
361 | // Data shared for whole shape |
848fa7e3 |
362 | BRepMesh::HDMapOfVertexInteger myBoundaryVertices; |
363 | BRepMesh::HDMapOfIntegerPnt myBoundaryPoints; |
ceb418e1 |
364 | |
365 | // Fast access to attributes of current face |
848fa7e3 |
366 | Handle(BRepMesh_FaceAttribute) myAttribute; |
848fa7e3 |
367 | BRepMesh::HIMapOfInteger myVertexEdgeMap; |
368 | BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges; |
369 | TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces; |
fc9b36d6 |
370 | }; |
371 | |
372 | DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient) |
373 | |
374 | #endif |