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