NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkBasicVertex.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3 NifTK: A software platform for medical image computing.
4 
5 Copyright (c) University College London (UCL). All rights reserved.
6 
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE.
10 
11 See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkBasicVertex_h
16 #define niftkBasicVertex_h
17 
18 #include <set>
19 
20 #include "niftkBasicVec3D.h"
21 #include "niftkCoreExports.h"
22 
23 namespace niftk
24 {
25 
26 class BasicMesh;
27 
28 // Used to store an edge -- two vertices which have only one
29 // triangle in common form an edge of the mesh.
30 struct Border
31 {
32  int vert1;
33  int vert2;
34  int triIndex;
35 
36  // We need operator< because it's used by the STL's set<> to determine equality
37  // (if (not a<b) and (not b>a) then a is equal to b)
38  bool operator <(const Border& b) const
39  {
40  int v1, v2, b1, b2;
41 
42  // make sure the smaller vert index is always first.
43  if (vert1 < vert2)
44  {
45  v1 = vert1; v2 = vert2;
46  }
47  else
48  {
49  v1 = vert2; v2 = vert1;
50  }
51 
52  if (b.vert1 < b.vert2)
53  {
54  b1 = b.vert1; b2 = b.vert2;
55  }
56  else
57  {
58  b1 = b.vert2; b2 = b.vert1;
59  }
60 
61  if (v1 < b1)
62  return true;
63 
64  if (v1 > b1)
65  return false;
66 
67  return (v2 < b2); // v1 == b1
68  }
69 };
70 
77 class NIFTKCORE_EXPORT BasicVertex
78 {
79 
80 public:
82  BasicVertex();
84  BasicVertex(float x1, float y1, float z1);
86  BasicVertex(float av[3]);
88  BasicVertex(float av[3], float vn[3]);
89 
91  BasicVertex(const BasicVertex& v);
92 
94  virtual ~BasicVertex();
95 
97  BasicVertex& operator=(const BasicVertex& v);
99  BasicVertex& operator=(const float av[3]);
100 
102  bool operator==(const BasicVertex& v);
104  bool operator!=(const BasicVertex& v);
105 
107  bool operator<(const BasicVertex &right) const;
109  bool operator>(const BasicVertex &right) const;
110 
112  friend std::ostream& operator<<(std::ostream& , const BasicVertex& );
113 
115  void SetCoords(const BasicVec3D& v) { m_Coords = v; };
117  inline BasicVec3D& GetCoords() { return m_Coords; }
119  inline const BasicVec3D& GetCoords() const { return m_Coords; }
121  const float* GetCoordArray() const;
122 
124  void SetCoordX(float x) { m_Coords.SetX(x); }
126  void SetCoordY(float y) { m_Coords.SetY(y); }
128  void SetCoordZ(float z) { m_Coords.SetZ(z); }
129 
131  float GetCoordX() { return m_Coords.GetX(); }
133  float GetCoordY() { return m_Coords.GetY(); }
135  float GetCoordZ() { return m_Coords.GetZ(); }
136 
138  const float GetCoordX() const { return m_Coords.GetX(); }
140  const float GetCoordY() const { return m_Coords.GetY(); }
142  const float GetCoordZ() const { return m_Coords.GetZ(); }
143 
145  void SetNormal(const BasicVec3D& vn) { m_Normal = vn; };
147  inline BasicVec3D& GetNormal() { return m_Normal; };
149  inline const BasicVec3D& GetNormal() const { return m_Normal; };
151  const float* GetNormalArray() const;
152 
154  void SetNormalX(float x) { m_Normal.SetX(x); }
156  void SetNormalY(float y) { m_Normal.SetY(y); }
158  void SetNormalZ(float z) { m_Normal.SetZ(z); }
159 
161  float GetNormalX() { return m_Normal.GetX(); }
163  float GetNormalY() { return m_Normal.GetY(); }
165  float GetNormalZ() { return m_Normal.GetZ(); }
166 
168  const float GetNormalX() const { return m_Normal.GetX(); }
170  const float GetNormalY() const { return m_Normal.GetY(); }
172  const float GetNormalZ() const { return m_Normal.GetZ(); }
173 
175  void AddVertNeighbor(int v) { m_VertNeighbors.insert(v); }
176 
178  unsigned RemoveVertNeighbor(int v) { return m_VertNeighbors.erase(v); }
179 
181  void AddTriNeighbor(int t) { m_TriNeighbors.insert(t); }
182 
184  unsigned RemoveTriNeighbor(int t) { return m_TriNeighbors.erase(t); }
185 
187  const std::set<int>& GetVertNeighbors() const { return m_VertNeighbors; }
188  // \brief Get the whole set of vertex neighbours
189  std::set<int>& GetVertNeighbors() { return m_VertNeighbors; }
190 
192  const std::set<int>& GetTriNeighbors() const { return m_TriNeighbors; }
194  std::set<int>& GetTriNeighbors() { return m_TriNeighbors; }
195 
197  bool HasVertNeighbor(int v) const { return (m_VertNeighbors.find(v) != m_VertNeighbors.end()); }
199  bool HasTriNeighbor(int t) const { return (m_TriNeighbors.find(t) != m_TriNeighbors.end()); }
200 
202  double GetEdgeRemoveCost() { return m_Cost; };
204  void SetEdgeRemoveCost(double f) { m_Cost = f; };
205 
207  int GetMinCostEdgeVert() const { return m_MinCostNeighbor; };
209  void SetMinCostEdgeVert(int i) { m_MinCostNeighbor = i; }
210 
212  double GetCost() const { return m_Cost; }
213 
215  int GetIndex() const { return m_Index; }
217  void SetIndex(int i) { m_Index = i; }
218 
220  inline bool IsActive() const { return m_Active; }
222  inline void SetActive(bool b) { m_Active = b; }
223 
227  bool IsBorder(BasicMesh& m);
228 
233  void GetAllBorderEdges(std::set<Border> &borderSet, BasicMesh& m);
234 
237  void CalcQuadric(BasicMesh& m, bool bUseTriArea); // calculate the 4x4 Quadric matrix
239  void GetQuadric(double Qret[4][4]);
241  void SetQuadric(double Qnew[4][4]);
242 
244  double GetQuadricSummedTriArea() { return m_QuadricTriArea; };
246  void SetQuadricSummedTriArea(double newArea) { m_QuadricTriArea = newArea; };
247 
248 private:
251  void InitQuadric();
252 
253 private:
254  BasicVec3D m_Coords; // X, Y, Z position of this vertex
255  BasicVec3D m_Normal; // vertex normal, used for Gouraud shading
256 
257  std::set<int> m_VertNeighbors; // connected to this vertex via an edge
258  std::set<int> m_TriNeighbors; // triangles of which this vertex is a part
259 
260  bool m_Active; // false if vertex has been removed
261 
262  double m_Cost; // cost of removing this vertex from Progressive Mesh
263  int m_MinCostNeighbor; // index of vertex at other end of the min. cost edge
264 
265  int m_Index;
266  double m_QuadricError[4][4]; // Used for Quadric error cost.
267  double m_QuadricTriArea; // summed area of triangles used to compute quadrics
268 
269  mutable float m_V[3]; //mutable floats used for returning values
270  mutable float m_VN[3]; //mutable floats used for returning values
271 };
272 
273 }
274 
275 #endif
float GetCoordZ()
Get Z coordinate of the vertex.
Definition: niftkBasicVertex.h:135
bool HasTriNeighbor(int t) const
Check is vertex has a certain triangle neighbour.
Definition: niftkBasicVertex.h:199
GLdouble GLdouble z
Definition: glew.h:1543
float GetNormalZ()
Get Z coordinate of the vertex normal.
Definition: niftkBasicVertex.h:165
const float GetCoordZ() const
Get Z coordinate of the vertex - const.
Definition: niftkBasicVertex.h:142
bool IsActive() const
Returns the flag value that indicates if the vertex is active (true) or it was removed (false) from t...
Definition: niftkBasicVertex.h:220
const float GetNormalZ() const
Get Z coordinate of the vertex normal - const.
Definition: niftkBasicVertex.h:172
const float GetNormalX() const
Get X coordinate of the vertex normal - const.
Definition: niftkBasicVertex.h:168
int GetIndex() const
Get index of the current vertex.
Definition: niftkBasicVertex.h:215
int GetMinCostEdgeVert() const
Returns the index of the vertex that is at other end of the min. cost edge (used in mesh simplificati...
Definition: niftkBasicVertex.h:207
const std::set< int > & GetTriNeighbors() const
Get the whole set of triangle neighbours - const.
Definition: niftkBasicVertex.h:192
bool operator==(niftk::BasicVertex const &x, niftk::BasicVertex const &y)
Definition: niftkMeshSmoother.cxx:31
float GetCoordX()
Get X coordinate of the vertex.
Definition: niftkBasicVertex.h:131
void AddVertNeighbor(int v)
Add neighbor - a vertex that is connected by an edge.
Definition: niftkBasicVertex.h:175
GLfloat GLfloat v1
Definition: glew.h:1836
unsigned RemoveTriNeighbor(int t)
Remove triangle if it no longer uses this vertex.
Definition: niftkBasicVertex.h:184
bool operator<(const GoldStandardPoint &GSP1, const GoldStandardPoint &GSP2)
Definition: mitkOpenCVPointTypes.cxx:125
const BasicVec3D & GetNormal() const
Get normal as 3D vector - const.
Definition: niftkBasicVertex.h:149
GLfloat GLfloat GLfloat v2
Definition: glew.h:1840
void SetEdgeRemoveCost(double f)
Sets the edge remove costs that is used in mesh simplification.
Definition: niftkBasicVertex.h:204
int vert1
Definition: niftkBasicVertex.h:32
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1236
unsigned RemoveVertNeighbor(int v)
Remove a vertex which is no longer connected by an edge.
Definition: niftkBasicVertex.h:178
void SetNormalY(float y)
Set Y coordinate of the vertex normal individually.
Definition: niftkBasicVertex.h:156
std::set< int > & GetVertNeighbors()
Definition: niftkBasicVertex.h:189
GLdouble GLdouble t
Definition: glew.h:1382
int vert2
Definition: niftkBasicVertex.h:33
std::ostream & operator<<(std::ostream &os, const CSVRow &data)
Definition: niftkCSVRow.h:89
void SetCoords(const BasicVec3D &v)
Set coordinates as 3D vector.
Definition: niftkBasicVertex.h:115
float GetCoordY()
Get Y coordinate of the vertex.
Definition: niftkBasicVertex.h:133
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
void SetCoordY(float y)
Set Y coordinate of the vertex individually.
Definition: niftkBasicVertex.h:126
bool HasVertNeighbor(int v) const
Check is vertex has a certain vertex neighbour.
Definition: niftkBasicVertex.h:197
float GetNormalX()
Get X coordinate of the vertex normal.
Definition: niftkBasicVertex.h:161
const GLdouble * v
Definition: glew.h:1375
void SetCoordZ(float z)
Set Z coordinate of the vertex individually.
Definition: niftkBasicVertex.h:128
bool operator<(const Border &b) const
Definition: niftkBasicVertex.h:38
float GetNormalY()
Get Y coordinate of the vertex normal.
Definition: niftkBasicVertex.h:163
double GetCost() const
Returns the cost of removing this vertex from the mesh.
Definition: niftkBasicVertex.h:212
void SetNormal(const BasicVec3D &vn)
Set normal as 3D vector.
Definition: niftkBasicVertex.h:145
void SetCoordX(float x)
Set X coordinate of the vertex individually.
Definition: niftkBasicVertex.h:124
Simple vertex implementation that is used in the Surface Extraction and surface smoothing and decimat...
Definition: niftkBasicVertex.h:77
const float GetCoordX() const
Get X coordinate of the vertex - const.
Definition: niftkBasicVertex.h:138
void SetMinCostEdgeVert(int i)
Sets the index of the vertex that is at other end of the min. cost edge (used in mesh simplification)...
Definition: niftkBasicVertex.h:209
double GetQuadricSummedTriArea()
Gets the quadric cost function summed over the triangle area.
Definition: niftkBasicVertex.h:244
std::set< int > & GetTriNeighbors()
Get the whole set of triangle neighbours.
Definition: niftkBasicVertex.h:194
GLint GLint GLint GLint GLint x
Definition: glew.h:1236
void SetActive(bool b)
Sets a flag the flag that indicates if the vertex is active (true) or it was removed (false) from the...
Definition: niftkBasicVertex.h:222
const float GetCoordY() const
Get Y coordinate of the vertex - const.
Definition: niftkBasicVertex.h:140
void SetQuadricSummedTriArea(double newArea)
Sets the quadric cost function summed over the triangle area.
Definition: niftkBasicVertex.h:246
const std::set< int > & GetVertNeighbors() const
Get the whole set of vertex neighbours - const.
Definition: niftkBasicVertex.h:187
Simple mesh implementation that is used in the Surface Extraction and surface smoothing and decimatio...
Definition: niftkBasicMesh.h:31
const GLdouble * m
Definition: glew.h:7887
void AddTriNeighbor(int t)
Add a triangle neighbor - a triangle which uses this vertex.
Definition: niftkBasicVertex.h:181
void SetNormalZ(float z)
Set Z coordinate of the vertex normal individually.
Definition: niftkBasicVertex.h:158
double GetEdgeRemoveCost()
Returns the edge remove costs that is used in mesh simplification.
Definition: niftkBasicVertex.h:202
BasicVec3D & GetNormal()
Get normal as 3D vector.
Definition: niftkBasicVertex.h:147
const BasicVec3D & GetCoords() const
Set coordinates as 3D vector - const.
Definition: niftkBasicVertex.h:119
void SetNormalX(float x)
Set X coordinate of the vertex normal individually.
Definition: niftkBasicVertex.h:154
Definition: niftkBasicVertex.h:30
Simple 3D Vector implementation that is used in the Surface Extraction and surface smoothing and deci...
Definition: niftkBasicVec3D.h:30
BasicVec3D & GetCoords()
Get coordinates as 3D vector.
Definition: niftkBasicVertex.h:117
const float GetNormalY() const
Get Y coordinate of the vertex normal - const.
Definition: niftkBasicVertex.h:170
Definition: niftkExceptionObject.h:21
void SetIndex(int i)
Set index of the current vertex.
Definition: niftkBasicVertex.h:217
int triIndex
Definition: niftkBasicVertex.h:34
GLclampf f
Definition: glew.h:3136