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_DefineHandle.hxx>
21 #include <BRepMesh_Status.hxx>
22 #include <BRepMesh.hxx>
23 #include <BRepMesh_DataStructureOfDelaun.hxx>
24 #include <Handle_BRepAdaptor_HSurface.hxx>
26 class BRepAdaptor_HSurface;
28 //! Auxiliary class for FastDiscret and FastDiscretFace classes.
29 class BRepMesh_FaceAttribute : public Standard_Transient
33 //! Default constructor.
34 Standard_EXPORT BRepMesh_FaceAttribute();
37 //! @param theFace face the attribute is created for.
38 //! Used for default initialization. Attribute keeps reference
39 //! to the source face with forward orientation.
40 //! @param theBoundaryVertices shared map of shape vertices.
41 //! @param theBoundaryPoints shared discretization points of shape boundaries.
42 Standard_EXPORT BRepMesh_FaceAttribute(
43 const TopoDS_Face& theFace,
44 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
45 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints);
48 Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
50 public: //! @name main geometrical properties.
52 //! Returns face's surface.
53 inline const Handle(BRepAdaptor_HSurface)& Surface() const
58 //! Sets reference face.
59 inline void SetFace(const TopoDS_Face& theFace)
64 //! Returns forward oriented face to be used for calculations.
65 inline const TopoDS_Face& Face() const
70 //! Sets boundary vertices map.
71 inline void SetBoundaryVertices(const BRepMesh::HDMapOfVertexInteger& theVertices)
73 myBoundaryVertices = theVertices;
76 //! Sets boundary points map.
77 inline void SetBoundaryPoints(const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
79 myBoundaryPoints = theBoundaryPoints;
82 //! Returns U tolerance of face calculated regarding its parameters.
83 Standard_EXPORT Standard_Real ToleranceU() const;
85 //! Returns V tolerance of face calculated regarding its parameters.
86 Standard_EXPORT Standard_Real ToleranceV() const;
88 //! Gives face deflection parameter.
89 inline Standard_Real GetDefFace() const
94 //! Sets face deflection.
95 inline void SetDefFace(const Standard_Real theDefFace)
97 myDefFace = theDefFace;
100 //! Gives minimal value in U domain.
101 inline Standard_Real GetUMin() const
106 //! Sets minimal value in U domain.
107 inline void SetUMin(const Standard_Real theUMin)
112 //! Gives minimal value in V domain.
113 inline Standard_Real GetVMin() const
118 //! Sets minimal value in V domain.
119 inline void SetVMin(const Standard_Real theVMin)
124 //! Gives maximal value in U domain.
125 inline Standard_Real GetUMax() const
130 //! Sets maximal value in U domain.
131 inline void SetUMax(const Standard_Real theUMax)
136 //! Gives maximal value in V domain.
137 inline Standard_Real GetVMax() const
142 //! Sets maximal value in V domain.
143 inline void SetVMax(const Standard_Real theVMax)
148 //! Gives value of step in U domain.
149 inline Standard_Real GetDeltaX() const
154 //! Sets value of step in U domain.
155 inline void SetDeltaX(const Standard_Real theDeltaX)
157 myDeltaX = theDeltaX;
160 //! Gives value of step in V domain.
161 inline Standard_Real GetDeltaY() const
166 //! Sets value of step in V domain.
167 inline void SetDeltaY(const Standard_Real theDeltaY)
169 myDeltaY = theDeltaY;
172 //! Sets set of status flags for this face.
173 inline Standard_Integer GetStatus() const
178 //! Sets status flag for this face.
179 inline void SetStatus(const BRepMesh_Status theStatus)
181 myStatus |= theStatus;
184 //! Returns TRUE in case if computed data is valid.
185 inline Standard_Boolean IsValid() const
187 return (myStatus == BRepMesh_NoError || myStatus == BRepMesh_ReMesh);
190 public: //! @name auxiliary structures
192 //! Resets mesh data structure.
193 //! @returns reset data structure.
194 Standard_EXPORT Handle(BRepMesh_DataStructureOfDelaun)& ResetStructure();
196 //! Gives reference to map of internal edges of face.
197 inline BRepMesh::HDMapOfShapePairOfPolygon& ChangeInternalEdges()
199 return myInternalEdges;
202 //! Gives reference to map of 2D points of discretization.
203 inline BRepMesh::DMapOfIntegerListOfXY& ChangeLocation2D()
208 //! Gives reference to map of 3D points of discretization.
209 inline BRepMesh::HDMapOfIntegerPnt& ChangeSurfacePoints()
211 return mySurfacePoints;
214 //! Gives reference on map of (vertex, edge) pairs of face.
215 inline BRepMesh::HIMapOfInteger& ChangeVertexEdgeMap()
217 return myVertexEdgeMap;
220 //! Gives Delaunay data structure.
221 inline Handle(BRepMesh_DataStructureOfDelaun)& ChangeStructure()
226 //! Returns classifier.
227 inline BRepMesh::HClassifier& ChangeClassifier()
232 public: //! @name Point/Vertex/Node manipulators
234 //! Gives the number of different locations in 3D space.
235 inline Standard_Integer LastPointId() const
237 return (myBoundaryPoints.IsNull() ? 0 : myBoundaryPoints->Extent())
238 + mySurfacePoints->Extent();
241 //! Gives the 3D location of the vertex.
242 inline const gp_Pnt& GetPoint(const BRepMesh_Vertex& theVertex) const
244 return GetPoint(theVertex.Location3d());
247 //! Gives the 3D location of the vertex.
248 inline const gp_Pnt& GetPoint(const Standard_Integer theIndex) const
250 if (myBoundaryPoints.IsNull() || theIndex > myBoundaryPoints->Extent())
251 return mySurfacePoints->Find(theIndex);
253 return myBoundaryPoints->Find(theIndex);
256 //! Returns index of the given vertex if it exists in cache,
257 //! elsewhere adds it to cache and returns cached index.
258 //! @param theVertexExplorer template parameter intended to transfer
259 //! parameters of vertex to method. Explorer class can implement different
260 //! approaches of extraction of target parameters.
261 //! @param isFillEdgeVertices if TRUE adds vertex to shared map of
262 //! edges vertices, elsewhere adds it map of face vertices.
263 template<class HVertexExplorer>
264 Standard_Integer GetVertexIndex(
265 const HVertexExplorer& theVertexExplorer,
266 const Standard_Boolean isFillEdgeVertices = Standard_False)
268 const TopoDS_Vertex& aVertex = theVertexExplorer->Vertex();
269 Standard_Integer aNewVertexIndex = 0;
270 if (getVertexIndex(aVertex, aNewVertexIndex))
271 return aNewVertexIndex;
273 if (!theVertexExplorer->IsSameUV() ||
274 !getVertexIndex(theVertexExplorer->SameVertex(), aNewVertexIndex))
276 aNewVertexIndex = LastPointId() + 1;
278 BRepMesh::DMapOfIntegerPnt& aPointsMap = isFillEdgeVertices ?
279 *myBoundaryPoints : *mySurfacePoints;
281 aPointsMap.Bind(aNewVertexIndex, theVertexExplorer->Point());
284 BRepMesh::DMapOfVertexInteger& aVertexMap = isFillEdgeVertices ?
285 *myBoundaryVertices : mySurfaceVertices;
287 aVertexMap.Bind(aVertex, aNewVertexIndex);
289 return aNewVertexIndex;
292 //! Adds node with the given parameters to mesh.
293 //! @param theIndex index of 3D point corresponded to the node.
294 //! @param theUV node position.
295 //! @param theMovability movability of a node.
296 //! @param theNodeIndex index of vertex in mesh structure.
297 //! @param theNodeOnEdgeIndex ordered index of node on the boundary.
298 Standard_EXPORT void AddNode(const Standard_Integer theIndex,
300 const BRepMesh_DegreeOfFreedom theMovability,
301 Standard_Integer& theNodeIndex,
302 Standard_Integer& theNodeOnEdgeIndex);
304 public: //! @name Auxiliary methods
306 //! Scales the given point from real parametric space
307 //! to face basis and otherwise.
308 //! @param thePoint2d point to be scaled.
309 //! @param isToFaceBasis if TRUE converts point to face basis,
310 //! otherwise performs reverse conversion.
311 //! @return scaled point.
312 Standard_EXPORT gp_XY Scale(const gp_XY& thePoint2d,
313 const Standard_Boolean isToFaceBasis);
315 DEFINE_STANDARD_RTTI(BRepMesh_FaceAttribute)
319 //! Assignment operator.
320 void operator =(const BRepMesh_FaceAttribute& /*theOther*/)
324 //! Initializes internal data structures.
327 //! Computes parametric tolerance of a face regarding the given limits.
328 Standard_Real computeParametricTolerance(
329 const Standard_Real theFirstParam,
330 const Standard_Real theLastParam) const;
332 //! Clears internal data structures local to face.
335 //! Returns index of the given vertex if it exists in cache.
336 //! @param theVertex vertex which index should be retrieved.
337 //! @param theVertexIndex index of the given vertex.
338 //! @return TRUE if cached value is found, FALSE elsewhere.
339 Standard_EXPORT Standard_Boolean getVertexIndex(
340 const TopoDS_Vertex& theVertex,
341 Standard_Integer& theVertexIndex) const;
345 Standard_Real myDefFace; //!< Restore face deflection
346 Standard_Real myUMin; //!< Describes minimal value in U domain
347 Standard_Real myUMax; //!< Describes maximal value in U domain
348 Standard_Real myVMin; //!< Describes minimal value in V domain
349 Standard_Real myVMax; //!< Describes maximal value in V domain
350 Standard_Real myDeltaX;
351 Standard_Real myDeltaY;
352 Standard_Integer myStatus;
354 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
355 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
358 Handle(BRepAdaptor_HSurface) mySurface;
359 BRepMesh::DMapOfVertexInteger mySurfaceVertices;
360 BRepMesh::HDMapOfIntegerPnt mySurfacePoints;
362 BRepMesh::DMapOfIntegerListOfXY myLocation2D;
363 BRepMesh::HIMapOfInteger myVertexEdgeMap;
364 BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges;
366 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
367 BRepMesh::HClassifier myClassifier;
368 Handle(NCollection_IncAllocator) myAllocator;
371 DEFINE_STANDARD_HANDLE(BRepMesh_FaceAttribute, Standard_Transient)