0026106: BRepMesh - revision of data model
[occt.git] / src / BRepMesh / BRepMesh_Vertex.hxx
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
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Macro.hxx>
21 #include <gp_XY.hxx>
22 #include <BRepMesh_DegreeOfFreedom.hxx>
23 #include <Precision.hxx>
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
35   BRepMesh_Vertex()
36     : myLocation3d(0),
37       myMovability(BRepMesh_Free)
38   {
39   }
40   
41   //! Creates vertex associated with point in 3d space.
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.
45   BRepMesh_Vertex(const gp_XY&                   theUV,
46                   const Standard_Integer         theLocation3d,
47                   const BRepMesh_DegreeOfFreedom theMovability)
48   {
49     Initialize(theUV, theLocation3d, theMovability);
50   }
51   
52   //! Creates vertex without association with point in 3d space.
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.
56   BRepMesh_Vertex(const Standard_Real            theU,
57                   const Standard_Real            theV,
58                   const BRepMesh_DegreeOfFreedom theMovability)
59     : myUV(theU, theV),
60       myLocation3d(0),
61       myMovability(theMovability)
62   {}
63
64   //! Initializes vertex associated with point in 3d space.
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.
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   }
82
83   //! Returns position of the vertex in parametric space for modification.
84   inline gp_XY& ChangeCoord()
85   {
86     return myUV;
87   }
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   }
106   
107   //! Returns hash code for this vertex.
108   //! @param theUpper upper index in the container.
109   //! @return hash code.
110   inline Standard_Integer HashCode(const Standard_Integer Upper) const
111   {
112     return ::HashCode(Floor(1e5 * myUV.X()) * Floor(1e5 * myUV.Y()), Upper);
113   }
114   
115   //! Checks for equality with another vertex.
116   //! @param theOther vertex to be checked against this one.
117   //! @return TRUE if equal, FALSE if not.
118   inline Standard_Boolean IsEqual(const BRepMesh_Vertex& theOther) const
119   {
120     if (myMovability          == BRepMesh_Deleted || 
121         theOther.myMovability == BRepMesh_Deleted)
122     {
123       return Standard_False;
124     }
125
126     return (myUV.IsEqual(theOther.myUV, Precision::PConfusion()));
127   }
128
129   //! Alias for IsEqual.
130   inline Standard_Boolean operator ==(const BRepMesh_Vertex& Other) const
131   {
132     return IsEqual(Other);
133   }
134
135 private:
136
137   gp_XY                     myUV;
138   Standard_Integer          myLocation3d;
139   BRepMesh_DegreeOfFreedom  myMovability;
140 };
141
142 inline Standard_Integer HashCode(const BRepMesh_Vertex& me, const Standard_Integer Upper)
143 {
144  return me.HashCode(Upper);
145 }
146
147 #endif