1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BRepMesh_FaceAttribute_HeaderFile
15 #define _BRepMesh_FaceAttribute_HeaderFile
17 #include <Standard.hxx>
18 #include <Standard_Transient.hxx>
19 #include <Standard_Type.hxx>
21 #include <BRepMesh_Status.hxx>
22 #include <BRepMesh.hxx>
23 #include <BRepMesh_DataStructureOfDelaun.hxx>
25 class BRepAdaptor_HSurface;
27 //! Auxiliary class for FastDiscret and FastDiscretFace classes.
28 class BRepMesh_FaceAttribute : public Standard_Transient
32 //! Constructor. Initializes empty attribute.
33 //! @param theBoundaryVertices shared map of shape vertices.
34 //! @param theBoundaryPoints shared discretization points of shape boundaries.
35 Standard_EXPORT BRepMesh_FaceAttribute(
36 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
37 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints);
40 //! @param theFace face the attribute is created for.
41 //! Used for default initialization. Attribute keeps reference
42 //! to the source face with forward orientation.
43 //! @param theBoundaryVertices shared map of shape vertices.
44 //! @param theBoundaryPoints shared discretization points of shape boundaries.
45 //! @param theAdaptiveMin switches on adaptive computation of minimal parametric
46 //! tolerance (if true).
47 Standard_EXPORT BRepMesh_FaceAttribute(
48 const TopoDS_Face& theFace,
49 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
50 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
51 const Standard_Boolean theAdaptiveMin);
54 Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
56 public: //! @name main geometrical properties.
58 //! Returns face's surface.
59 inline const Handle(BRepAdaptor_HSurface)& Surface() const
64 //! Returns True in case if this attribute has already been intialized.
65 inline Standard_Boolean IsInitialized () const
67 return !myFace.IsNull ();
70 //! Initializes this attribute by the given face.
71 Standard_EXPORT void SetFace (
72 const TopoDS_Face& theFace,
73 const Standard_Boolean theAdaptiveMin);
75 //! Returns forward oriented face to be used for calculations.
76 inline const TopoDS_Face& Face() const
81 //! Sets boundary vertices map.
82 inline void SetBoundaryVertices(const BRepMesh::HDMapOfVertexInteger& theVertices)
84 myBoundaryVertices = theVertices;
87 //! Sets boundary points map.
88 inline void SetBoundaryPoints(const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
90 myBoundaryPoints = theBoundaryPoints;
93 //! Returns U tolerance of face calculated regarding its parameters.
94 Standard_EXPORT Standard_Real ToleranceU() const;
96 //! Returns V tolerance of face calculated regarding its parameters.
97 Standard_EXPORT Standard_Real ToleranceV() const;
99 //! Gives face deflection parameter.
100 inline Standard_Real GetDefFace() const
105 //! Sets face deflection.
106 inline void SetDefFace(const Standard_Real theDefFace)
108 myDefFace = theDefFace;
111 //! Gives minimal value in U domain.
112 inline Standard_Real GetUMin() const
117 //! Sets minimal value in U domain.
118 inline void SetUMin(const Standard_Real theUMin)
123 //! Gives minimal value in V domain.
124 inline Standard_Real GetVMin() const
129 //! Sets minimal value in V domain.
130 inline void SetVMin(const Standard_Real theVMin)
135 //! Gives maximal value in U domain.
136 inline Standard_Real GetUMax() const
141 //! Sets maximal value in U domain.
142 inline void SetUMax(const Standard_Real theUMax)
147 //! Gives maximal value in V domain.
148 inline Standard_Real GetVMax() const
153 //! Sets maximal value in V domain.
154 inline void SetVMax(const Standard_Real theVMax)
159 //! Gives value of step in U domain.
160 inline Standard_Real GetDeltaX() const
165 //! Sets value of step in U domain.
166 inline void SetDeltaX(const Standard_Real theDeltaX)
168 myDeltaX = theDeltaX;
171 //! Gives value of step in V domain.
172 inline Standard_Real GetDeltaY() const
177 //! Sets value of step in V domain.
178 inline void SetDeltaY(const Standard_Real theDeltaY)
180 myDeltaY = theDeltaY;
183 //! Sets set of status flags for this face.
184 inline Standard_Integer GetStatus() const
189 //! Sets status flag for this face.
190 inline void SetStatus(const BRepMesh_Status theStatus)
192 myStatus |= theStatus;
195 //! Returns TRUE in case if computed data is valid.
196 inline Standard_Boolean IsValid() const
198 return (myStatus == BRepMesh_NoError || myStatus == BRepMesh_ReMesh);
201 public: //! @name auxiliary structures
203 //! Clear face attribute.
204 Standard_EXPORT void Clear();
206 //! Gives reference to map of internal edges of face.
207 inline BRepMesh::HDMapOfShapePairOfPolygon& ChangeInternalEdges()
209 return myInternalEdges;
212 //! Gives reference to map of 2D points of discretization.
213 inline BRepMesh::HDMapOfIntegerListOfXY& ChangeLocation2D()
218 //! Gives reference to map of 3D points of discretization.
219 inline BRepMesh::HDMapOfIntegerPnt& ChangeSurfacePoints()
221 return mySurfacePoints;
224 //! Gives reference to map of vertices of discretization.
225 inline BRepMesh::HDMapOfVertexInteger& ChangeSurfaceVertices()
227 return mySurfaceVertices;
230 //! Gives reference on map of (vertex, edge) pairs of face.
231 inline BRepMesh::HIMapOfInteger& ChangeVertexEdgeMap()
233 return myVertexEdgeMap;
236 //! Gives Delaunay data structure.
237 inline Handle(BRepMesh_DataStructureOfDelaun)& ChangeStructure()
242 //! Returns classifier.
243 inline BRepMesh::HClassifier& ChangeClassifier()
248 //! Returns mesh nodes calculated for boundaries.
249 inline BRepMesh::HVectorOfVertex& ChangeMeshNodes()
254 public: //! @name Point/Vertex/Node manipulators
256 //! Gives the number of different locations in 3D space.
257 inline Standard_Integer LastPointId() const
259 return (myBoundaryPoints.IsNull() ? 0 : myBoundaryPoints->Extent()) +
260 (mySurfacePoints.IsNull() ? 0 : mySurfacePoints->Extent());
263 //! Gives the 3D location of the vertex.
264 inline const gp_Pnt& GetPoint(const BRepMesh_Vertex& theVertex) const
266 return GetPoint(theVertex.Location3d());
269 //! Gives the 3D location of the vertex.
270 inline const gp_Pnt& GetPoint(const Standard_Integer theIndex) const
272 if (!mySurfacePoints.IsNull() && theIndex > myBoundaryPoints->Extent())
273 return mySurfacePoints->Find(theIndex);
275 return myBoundaryPoints->Find(theIndex);
278 //! Returns index of the given vertex if it exists in cache,
279 //! elsewhere adds it to cache and returns cached index.
280 //! @param theVertexExplorer template parameter intended to transfer
281 //! parameters of vertex to method. Explorer class can implement different
282 //! approaches of extraction of target parameters.
283 //! @param isFillEdgeVertices if TRUE adds vertex to shared map of
284 //! edges vertices, elsewhere adds it map of face vertices.
285 template<class HVertexExplorer>
286 Standard_Integer GetVertexIndex(
287 const HVertexExplorer& theVertexExplorer,
288 const Standard_Boolean isFillEdgeVertices = Standard_False)
290 const TopoDS_Vertex& aVertex = theVertexExplorer->Vertex();
291 Standard_Integer aNewVertexIndex = 0;
292 if (getVertexIndex(aVertex, aNewVertexIndex))
293 return aNewVertexIndex;
295 if (!theVertexExplorer->IsSameUV() ||
296 !getVertexIndex(theVertexExplorer->SameVertex(), aNewVertexIndex))
298 aNewVertexIndex = LastPointId() + 1;
300 BRepMesh::DMapOfIntegerPnt& aPointsMap = isFillEdgeVertices ?
301 *myBoundaryPoints : *mySurfacePoints;
303 aPointsMap.Bind(aNewVertexIndex, theVertexExplorer->Point());
306 BRepMesh::DMapOfVertexInteger& aVertexMap = isFillEdgeVertices ?
307 *myBoundaryVertices : *mySurfaceVertices;
309 aVertexMap.Bind(aVertex, aNewVertexIndex);
311 return aNewVertexIndex;
314 //! Adds node with the given parameters to mesh.
315 //! @param theIndex index of 3D point corresponded to the node.
316 //! @param theUV node position.
317 //! @param theMovability movability of a node.
318 //! @param theNodeIndex index of vertex in mesh structure.
319 //! @param theNodeOnEdgeIndex ordered index of node on the boundary.
320 Standard_EXPORT void AddNode(const Standard_Integer theIndex,
322 const BRepMesh_DegreeOfFreedom theMovability,
323 Standard_Integer& theNodeIndex,
324 Standard_Integer& theNodeOnEdgeIndex);
326 public: //! @name Auxiliary methods
328 //! Scales the given point from real parametric space
329 //! to face basis and otherwise.
330 //! @param thePoint2d point to be scaled.
331 //! @param isToFaceBasis if TRUE converts point to face basis,
332 //! otherwise performs reverse conversion.
333 //! @return scaled point.
334 Standard_EXPORT gp_XY Scale(const gp_XY& thePoint2d,
335 const Standard_Boolean isToFaceBasis);
337 DEFINE_STANDARD_RTTIEXT(BRepMesh_FaceAttribute,Standard_Transient)
341 //! Default constructor.
342 BRepMesh_FaceAttribute();
344 //! Assignment operator.
345 void operator =(const BRepMesh_FaceAttribute& /*theOther*/)
349 //! Initializes internal data structures.
352 //! Computes parametric tolerance of a face regarding the given limits.
353 Standard_Real computeParametricTolerance(
354 const Standard_Real theFirstParam,
355 const Standard_Real theLastParam) const;
357 //! Clears internal data structures local to face.
359 const Standard_Boolean isClearSurfaceDataOnly = Standard_False);
361 //! Returns index of the given vertex if it exists in cache.
362 //! @param theVertex vertex which index should be retrieved.
363 //! @param theVertexIndex index of the given vertex.
364 //! @return TRUE if cached value is found, FALSE elsewhere.
365 Standard_EXPORT Standard_Boolean getVertexIndex(
366 const TopoDS_Vertex& theVertex,
367 Standard_Integer& theVertexIndex) const;
371 Standard_Real myDefFace; //!< Restore face deflection
372 Standard_Real myUMin; //!< Describes minimal value in U domain
373 Standard_Real myUMax; //!< Describes maximal value in U domain
374 Standard_Real myVMin; //!< Describes minimal value in V domain
375 Standard_Real myVMax; //!< Describes maximal value in V domain
376 Standard_Real myDeltaX;
377 Standard_Real myDeltaY;
378 Standard_Real myMinStep;
379 Standard_Integer myStatus;
380 Standard_Boolean myAdaptiveMin;
382 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
383 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
386 Handle(BRepAdaptor_HSurface) mySurface;
387 BRepMesh::HClassifier myClassifier;
389 BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges;
391 BRepMesh::HDMapOfIntegerListOfXY myLocation2D;
392 BRepMesh::HIMapOfInteger myVertexEdgeMap;
394 // This field is intended to keep calculated mesh nodes to prevent
395 // extremely high memory consumption in case if the whole structure is kept.
396 BRepMesh::HVectorOfVertex myMeshNodes;
398 BRepMesh::HDMapOfVertexInteger mySurfaceVertices;
399 BRepMesh::HDMapOfIntegerPnt mySurfacePoints;
400 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
403 DEFINE_STANDARD_HANDLE(BRepMesh_FaceAttribute, Standard_Transient)