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 | |
15 | #ifndef _BRepMesh_Vertex_HeaderFile |
16 | #define _BRepMesh_Vertex_HeaderFile |
17 | |
7bd071ed |
18 | #include <Standard.hxx> |
19 | #include <Standard_DefineAlloc.hxx> |
20 | #include <Standard_Macro.hxx> |
07bbde45 |
21 | #include <gp_XY.hxx> |
7bd071ed |
22 | #include <BRepMesh_DegreeOfFreedom.hxx> |
07bbde45 |
23 | #include <Precision.hxx> |
fc9b36d6 |
24 | |
25 | //! Light weighted structure representing vertex |
26 | //! of the mesh in parametric space. Vertex could be |
27 | //! associated with 3d point stored in external map. |
28 | class BRepMesh_Vertex |
29 | { |
30 | public: |
31 | |
32 | DEFINE_STANDARD_ALLOC |
33 | |
34 | //! Default constructor |
be5c3602 |
35 | BRepMesh_Vertex() |
fc9b36d6 |
36 | : myLocation3d(0), |
37 | myMovability(BRepMesh_Free) |
38 | { |
39 | } |
40 | |
41 | //! Creates vertex associated with point in 3d space. |
848fa7e3 |
42 | //! @param theUV position of vertex in parametric space. |
43 | //! @param theLocation3d index of 3d point to be associated with vertex. |
44 | //! @param theMovability movability of the vertex. |
be5c3602 |
45 | BRepMesh_Vertex(const gp_XY& theUV, |
46 | const Standard_Integer theLocation3d, |
47 | const BRepMesh_DegreeOfFreedom theMovability) |
fc9b36d6 |
48 | { |
49 | Initialize(theUV, theLocation3d, theMovability); |
50 | } |
51 | |
52 | //! Creates vertex without association with point in 3d space. |
848fa7e3 |
53 | //! @param theU U position of vertex in parametric space. |
54 | //! @param theV V position of vertex in parametric space. |
55 | //! @param theMovability movability of the vertex. |
be5c3602 |
56 | BRepMesh_Vertex(const Standard_Real theU, |
57 | const Standard_Real theV, |
58 | const BRepMesh_DegreeOfFreedom theMovability) |
fc9b36d6 |
59 | : myUV(theU, theV), |
60 | myLocation3d(0), |
61 | myMovability(theMovability) |
62 | {} |
63 | |
64 | //! Initializes vertex associated with point in 3d space. |
848fa7e3 |
65 | //! @param theUV position of vertex in parametric space. |
66 | //! @param theLocation3d index of 3d point to be associated with vertex. |
67 | //! @param theMovability movability of the vertex. |
fc9b36d6 |
68 | inline void Initialize(const gp_XY& theUV, |
69 | const Standard_Integer theLocation3d, |
70 | const BRepMesh_DegreeOfFreedom theMovability) |
71 | { |
72 | myUV = theUV; |
73 | myLocation3d = theLocation3d; |
74 | myMovability = theMovability; |
75 | } |
76 | |
77 | //! Returns position of the vertex in parametric space. |
78 | inline const gp_XY& Coord() const |
79 | { |
80 | return myUV; |
81 | } |
2caff0b3 |
82 | |
83 | //! Returns position of the vertex in parametric space for modification. |
84 | inline gp_XY& ChangeCoord() |
85 | { |
86 | return myUV; |
87 | } |
fc9b36d6 |
88 | |
89 | //! Returns index of 3d point associated with the vertex. |
90 | inline Standard_Integer Location3d() const |
91 | { |
92 | return myLocation3d; |
93 | } |
94 | |
95 | //! Returns movability of the vertex. |
96 | inline BRepMesh_DegreeOfFreedom Movability() const |
97 | { |
98 | return myMovability; |
99 | } |
100 | |
101 | //! Sets movability of the vertex. |
102 | inline void SetMovability(const BRepMesh_DegreeOfFreedom theMovability) |
103 | { |
104 | myMovability = theMovability; |
105 | } |
2b2be3fb |
106 | |
107 | //! Computes a hash code for this vertex, in the range [1, theUpperBound] |
108 | //! @param theUpperBound the upper bound of the range a computing hash code must be within |
109 | //! @return a computed hash code, in the range [1, theUpperBound] |
110 | inline Standard_Integer HashCode(const Standard_Integer theUpperBound) const |
fc9b36d6 |
111 | { |
2b2be3fb |
112 | return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), theUpperBound); |
fc9b36d6 |
113 | } |
114 | |
115 | //! Checks for equality with another vertex. |
848fa7e3 |
116 | //! @param theOther vertex to be checked against this one. |
117 | //! @return TRUE if equal, FALSE if not. |
7bd071ed |
118 | inline Standard_Boolean IsEqual(const BRepMesh_Vertex& theOther) const |
fc9b36d6 |
119 | { |
ceb418e1 |
120 | if (myMovability == BRepMesh_Deleted || |
121 | theOther.myMovability == BRepMesh_Deleted) |
fc9b36d6 |
122 | { |
123 | return Standard_False; |
124 | } |
125 | |
126 | return (myUV.IsEqual(theOther.myUV, Precision::PConfusion())); |
127 | } |
128 | |
129 | //! Alias for IsEqual. |
7bd071ed |
130 | inline Standard_Boolean operator ==(const BRepMesh_Vertex& Other) const |
fc9b36d6 |
131 | { |
132 | return IsEqual(Other); |
133 | } |
134 | |
135 | private: |
136 | |
137 | gp_XY myUV; |
138 | Standard_Integer myLocation3d; |
139 | BRepMesh_DegreeOfFreedom myMovability; |
140 | }; |
141 | |
2b2be3fb |
142 | //! Computes a hash code for the given vertex, in the range [1, theUpperBound] |
143 | //! @param theVertex the vertex which hash code is to be computed |
144 | //! @param theUpperBound the upper bound of the range a computing hash code must be within |
145 | //! @return a computed hash code, in the range [1, theUpperBound] |
146 | inline Standard_Integer HashCode (const BRepMesh_Vertex& theVertex, const Standard_Integer theUpperBound) |
fc9b36d6 |
147 | { |
2b2be3fb |
148 | return theVertex.HashCode (theUpperBound); |
fc9b36d6 |
149 | } |
150 | |
151 | #endif |