0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / BRepMesh / BRepMesh_FaceAttribute.hxx
CommitLineData
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_FaceAttribute_HeaderFile
15#define _BRepMesh_FaceAttribute_HeaderFile
16
17#include <Standard.hxx>
ceb418e1 18#include <Standard_Transient.hxx>
ec357c5c 19#include <Standard_Type.hxx>
ceb418e1 20
21#include <BRepMesh_Status.hxx>
848fa7e3 22#include <BRepMesh.hxx>
ceb418e1 23#include <BRepMesh_DataStructureOfDelaun.hxx>
24#include <Handle_BRepAdaptor_HSurface.hxx>
fc9b36d6 25
ceb418e1 26class BRepAdaptor_HSurface;
fc9b36d6 27
ceb418e1 28//! Auxiliary class for FastDiscret and FastDiscretFace classes.
fc9b36d6 29class BRepMesh_FaceAttribute : public Standard_Transient
30{
31public:
32
848fa7e3 33 //! Default constructor.
34 Standard_EXPORT BRepMesh_FaceAttribute();
35
ceb418e1 36 //! Constructor.
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(
848fa7e3 43 const TopoDS_Face& theFace,
44 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
45 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints);
ceb418e1 46
47 //! Destructor.
848fa7e3 48 Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
ceb418e1 49
50public: //! @name main geometrical properties.
51
52 //! Returns face's surface.
53 inline const Handle(BRepAdaptor_HSurface)& Surface() const
54 {
55 return mySurface;
56 }
57
848fa7e3 58 //! Sets reference face.
59 inline void SetFace(const TopoDS_Face& theFace)
60 {
61 myFace = theFace;
62 }
63
ceb418e1 64 //! Returns forward oriented face to be used for calculations.
65 inline const TopoDS_Face& Face() const
66 {
67 return myFace;
68 }
69
848fa7e3 70 //! Sets boundary vertices map.
71 inline void SetBoundaryVertices(const BRepMesh::HDMapOfVertexInteger& theVertices)
ceb418e1 72 {
848fa7e3 73 myBoundaryVertices = theVertices;
ceb418e1 74 }
75
848fa7e3 76 //! Sets boundary points map.
77 inline void SetBoundaryPoints(const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
ceb418e1 78 {
848fa7e3 79 myBoundaryPoints = theBoundaryPoints;
ceb418e1 80 }
81
848fa7e3 82 //! Returns U tolerance of face calculated regarding its parameters.
83 Standard_EXPORT Standard_Real ToleranceU() const;
84
85 //! Returns V tolerance of face calculated regarding its parameters.
86 Standard_EXPORT Standard_Real ToleranceV() const;
87
ceb418e1 88 //! Gives face deflection parameter.
89 inline Standard_Real GetDefFace() const
90 {
91 return myDefFace;
92 }
93
94 //! Sets face deflection.
95 inline void SetDefFace(const Standard_Real theDefFace)
96 {
97 myDefFace = theDefFace;
98 }
99
100 //! Gives minimal value in U domain.
101 inline Standard_Real GetUMin() const
102 {
103 return myUMin;
104 }
105
106 //! Sets minimal value in U domain.
107 inline void SetUMin(const Standard_Real theUMin)
108 {
109 myUMin = theUMin;
110 }
111
112 //! Gives minimal value in V domain.
113 inline Standard_Real GetVMin() const
114 {
115 return myVMin;
116 }
117
118 //! Sets minimal value in V domain.
119 inline void SetVMin(const Standard_Real theVMin)
120 {
121 myVMin = theVMin;
122 }
123
124 //! Gives maximal value in U domain.
125 inline Standard_Real GetUMax() const
126 {
127 return myUMax;
128 }
129
130 //! Sets maximal value in U domain.
131 inline void SetUMax(const Standard_Real theUMax)
132 {
133 myUMax = theUMax;
134 }
135
136 //! Gives maximal value in V domain.
137 inline Standard_Real GetVMax() const
fc9b36d6 138 {
ceb418e1 139 return myVMax;
fc9b36d6 140 }
141
ceb418e1 142 //! Sets maximal value in V domain.
143 inline void SetVMax(const Standard_Real theVMax)
fc9b36d6 144 {
ceb418e1 145 myVMax = theVMax;
fc9b36d6 146 }
147
ceb418e1 148 //! Gives value of step in U domain.
149 inline Standard_Real GetDeltaX() const
fc9b36d6 150 {
ceb418e1 151 return myDeltaX;
fc9b36d6 152 }
153
ceb418e1 154 //! Sets value of step in U domain.
155 inline void SetDeltaX(const Standard_Real theDeltaX)
fc9b36d6 156 {
ceb418e1 157 myDeltaX = theDeltaX;
fc9b36d6 158 }
159
ceb418e1 160 //! Gives value of step in V domain.
161 inline Standard_Real GetDeltaY() const
fc9b36d6 162 {
ceb418e1 163 return myDeltaY;
fc9b36d6 164 }
165
ceb418e1 166 //! Sets value of step in V domain.
167 inline void SetDeltaY(const Standard_Real theDeltaY)
fc9b36d6 168 {
ceb418e1 169 myDeltaY = theDeltaY;
fc9b36d6 170 }
171
ceb418e1 172 //! Sets set of status flags for this face.
173 inline Standard_Integer GetStatus() const
fc9b36d6 174 {
ceb418e1 175 return myStatus;
fc9b36d6 176 }
177
ceb418e1 178 //! Sets status flag for this face.
179 inline void SetStatus(const BRepMesh_Status theStatus)
fc9b36d6 180 {
ceb418e1 181 myStatus |= theStatus;
fc9b36d6 182 }
183
ceb418e1 184 //! Returns TRUE in case if computed data is valid.
185 inline Standard_Boolean IsValid() const
fc9b36d6 186 {
ceb418e1 187 return (myStatus == BRepMesh_NoError || myStatus == BRepMesh_ReMesh);
fc9b36d6 188 }
189
ceb418e1 190public: //! @name auxiliary structures
191
fcf15f5c 192 //! Clear face attribute.
2caff0b3 193 Standard_EXPORT void Clear();
ceb418e1 194
195 //! Gives reference to map of internal edges of face.
848fa7e3 196 inline BRepMesh::HDMapOfShapePairOfPolygon& ChangeInternalEdges()
fc9b36d6 197 {
ceb418e1 198 return myInternalEdges;
fc9b36d6 199 }
200
ceb418e1 201 //! Gives reference to map of 2D points of discretization.
2caff0b3 202 inline BRepMesh::HDMapOfIntegerListOfXY& ChangeLocation2D()
ceb418e1 203 {
204 return myLocation2D;
205 }
206
207 //! Gives reference to map of 3D points of discretization.
848fa7e3 208 inline BRepMesh::HDMapOfIntegerPnt& ChangeSurfacePoints()
ceb418e1 209 {
210 return mySurfacePoints;
211 }
212
2caff0b3 213 //! Gives reference to map of vertices of discretization.
214 inline BRepMesh::HDMapOfVertexInteger& ChangeSurfaceVertices()
215 {
216 return mySurfaceVertices;
217 }
218
ceb418e1 219 //! Gives reference on map of (vertex, edge) pairs of face.
848fa7e3 220 inline BRepMesh::HIMapOfInteger& ChangeVertexEdgeMap()
ceb418e1 221 {
222 return myVertexEdgeMap;
223 }
224
225 //! Gives Delaunay data structure.
226 inline Handle(BRepMesh_DataStructureOfDelaun)& ChangeStructure()
227 {
228 return myStructure;
229 }
230
231 //! Returns classifier.
848fa7e3 232 inline BRepMesh::HClassifier& ChangeClassifier()
ceb418e1 233 {
234 return myClassifier;
235 }
236
2caff0b3 237 //! Returns mesh nodes calculated for boundaries.
238 inline BRepMesh::HVectorOfVertex& ChangeMeshNodes()
239 {
240 return myMeshNodes;
241 }
242
ceb418e1 243public: //! @name Point/Vertex/Node manipulators
244
245 //! Gives the number of different locations in 3D space.
246 inline Standard_Integer LastPointId() const
247 {
2caff0b3 248 return (myBoundaryPoints.IsNull() ? 0 : myBoundaryPoints->Extent()) +
249 (mySurfacePoints.IsNull() ? 0 : mySurfacePoints->Extent());
ceb418e1 250 }
251
252 //! Gives the 3D location of the vertex.
253 inline const gp_Pnt& GetPoint(const BRepMesh_Vertex& theVertex) const
254 {
255 return GetPoint(theVertex.Location3d());
256 }
257
258 //! Gives the 3D location of the vertex.
259 inline const gp_Pnt& GetPoint(const Standard_Integer theIndex) const
260 {
2caff0b3 261 if (!mySurfacePoints.IsNull() && theIndex > myBoundaryPoints->Extent())
ceb418e1 262 return mySurfacePoints->Find(theIndex);
263
848fa7e3 264 return myBoundaryPoints->Find(theIndex);
ceb418e1 265 }
266
267 //! Returns index of the given vertex if it exists in cache,
268 //! elsewhere adds it to cache and returns cached index.
269 //! @param theVertexExplorer template parameter intended to transfer
270 //! parameters of vertex to method. Explorer class can implement different
271 //! approaches of extraction of target parameters.
272 //! @param isFillEdgeVertices if TRUE adds vertex to shared map of
273 //! edges vertices, elsewhere adds it map of face vertices.
274 template<class HVertexExplorer>
275 Standard_Integer GetVertexIndex(
276 const HVertexExplorer& theVertexExplorer,
277 const Standard_Boolean isFillEdgeVertices = Standard_False)
278 {
279 const TopoDS_Vertex& aVertex = theVertexExplorer->Vertex();
280 Standard_Integer aNewVertexIndex = 0;
281 if (getVertexIndex(aVertex, aNewVertexIndex))
282 return aNewVertexIndex;
283
284 if (!theVertexExplorer->IsSameUV() ||
285 !getVertexIndex(theVertexExplorer->SameVertex(), aNewVertexIndex))
286 {
287 aNewVertexIndex = LastPointId() + 1;
288
848fa7e3 289 BRepMesh::DMapOfIntegerPnt& aPointsMap = isFillEdgeVertices ?
290 *myBoundaryPoints : *mySurfacePoints;
ceb418e1 291
292 aPointsMap.Bind(aNewVertexIndex, theVertexExplorer->Point());
293 }
294
848fa7e3 295 BRepMesh::DMapOfVertexInteger& aVertexMap = isFillEdgeVertices ?
2caff0b3 296 *myBoundaryVertices : *mySurfaceVertices;
ceb418e1 297
298 aVertexMap.Bind(aVertex, aNewVertexIndex);
299
300 return aNewVertexIndex;
301 }
302
303 //! Adds node with the given parameters to mesh.
304 //! @param theIndex index of 3D point corresponded to the node.
305 //! @param theUV node position.
306 //! @param theMovability movability of a node.
307 //! @param theNodeIndex index of vertex in mesh structure.
308 //! @param theNodeOnEdgeIndex ordered index of node on the boundary.
309 Standard_EXPORT void AddNode(const Standard_Integer theIndex,
310 const gp_XY& theUV,
311 const BRepMesh_DegreeOfFreedom theMovability,
312 Standard_Integer& theNodeIndex,
313 Standard_Integer& theNodeOnEdgeIndex);
314
315public: //! @name Auxiliary methods
316
317 //! Scales the given point from real parametric space
318 //! to face basis and otherwise.
319 //! @param thePoint2d point to be scaled.
320 //! @param isToFaceBasis if TRUE converts point to face basis,
321 //! otherwise performs reverse conversion.
322 //! @return scaled point.
323 Standard_EXPORT gp_XY Scale(const gp_XY& thePoint2d,
324 const Standard_Boolean isToFaceBasis);
fc9b36d6 325
ec357c5c 326 DEFINE_STANDARD_RTTI(BRepMesh_FaceAttribute, Standard_Transient)
fc9b36d6 327
ceb418e1 328private:
329
330 //! Assignment operator.
331 void operator =(const BRepMesh_FaceAttribute& /*theOther*/)
332 {
333 }
334
848fa7e3 335 //! Initializes internal data structures.
336 void init();
337
ceb418e1 338 //! Computes parametric tolerance of a face regarding the given limits.
339 Standard_Real computeParametricTolerance(
340 const Standard_Real theFirstParam,
341 const Standard_Real theLastParam) const;
342
343 //! Clears internal data structures local to face.
fcf15f5c 344 void clearLocal(
345 const Standard_Boolean isClearSurfaceDataOnly = Standard_False);
ceb418e1 346
347 //! Returns index of the given vertex if it exists in cache.
348 //! @param theVertex vertex which index should be retrieved.
349 //! @param theVertexIndex index of the given vertex.
350 //! @return TRUE if cached value is found, FALSE elsewhere.
351 Standard_EXPORT Standard_Boolean getVertexIndex(
352 const TopoDS_Vertex& theVertex,
353 Standard_Integer& theVertexIndex) const;
354
355private:
356
357 Standard_Real myDefFace; //!< Restore face deflection
358 Standard_Real myUMin; //!< Describes minimal value in U domain
359 Standard_Real myUMax; //!< Describes maximal value in U domain
360 Standard_Real myVMin; //!< Describes minimal value in V domain
361 Standard_Real myVMax; //!< Describes maximal value in V domain
362 Standard_Real myDeltaX;
363 Standard_Real myDeltaY;
364 Standard_Integer myStatus;
365
848fa7e3 366 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
367 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
ceb418e1 368
369 TopoDS_Face myFace;
370 Handle(BRepAdaptor_HSurface) mySurface;
2caff0b3 371 BRepMesh::HClassifier myClassifier;
ceb418e1 372
848fa7e3 373 BRepMesh::HDMapOfShapePairOfPolygon myInternalEdges;
ceb418e1 374
2caff0b3 375 BRepMesh::HDMapOfIntegerListOfXY myLocation2D;
376 BRepMesh::HIMapOfInteger myVertexEdgeMap;
377
378 // This field is intended to keep calculated mesh nodes to prevent
379 // extremely high memory consumption in case if the whole structure is kept.
380 BRepMesh::HVectorOfVertex myMeshNodes;
381
382 BRepMesh::HDMapOfVertexInteger mySurfaceVertices;
383 BRepMesh::HDMapOfIntegerPnt mySurfacePoints;
ceb418e1 384 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
fc9b36d6 385};
386
387DEFINE_STANDARD_HANDLE(BRepMesh_FaceAttribute, Standard_Transient)
388
389#endif