NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkBasicTriangle.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 niftkBasicTriangle_h
16 #define niftkBasicTriangle_h
17 
18 #include <assert.h>
19 #include <iostream>
20 #include "niftkCoreExports.h"
21 #include "niftkBasicVec3D.h"
22 
23 namespace niftk
24 {
25 
26 class BasicVertex;
27 class BasicMesh;
28 
33 
34 class NIFTKCORE_EXPORT BasicTriangle
35 {
36 public:
38  BasicTriangle();
40  BasicTriangle(int v1, int v2, int v3);
42  BasicTriangle(BasicMesh* mp, int v1, int v2, int v3);
43 
45  virtual ~BasicTriangle();
46 
49 
51  BasicTriangle& operator=(const BasicTriangle& t);
52 
54  bool operator==(const BasicTriangle& t);
55 
57  friend std::ostream& operator<<(std::ostream& os, const BasicTriangle& to);
58 
60  void ChangeMesh(BasicMesh* mp) { m_Mesh = mp; }
61 
63  bool IsActive() const { return m_Active; }
65  void SetActive(bool b) { m_Active = b; }
67  bool HasVertex(int vi);
68 
71  void ChangeVertex(int vFrom, int vTo);
72 
74  void GetVertIndices(int& v1, int& v2, int& v3);
75 
77  const float* GetVert1CoordArray();
79  const float* GetVert2CoordArray();
81  const float* GetVert3CoordArray();
82 
84  const BasicVec3D& GetVert1Coords() const;
86  const BasicVec3D& GetVert2Coords() const;
88  const BasicVec3D& GetVert3Coords() const;
89 
91  const BasicVertex& GetVert1() const;
93  const BasicVertex& GetVert2() const;
95  const BasicVertex& GetVert3() const;
96 
98  const float* GetVert1NormalArray();
100  const float* GetVert2NormalArray();
102  const float* GetVert3NormalArray();
103 
105  const BasicVec3D& GetVert1Normal() const;
107  const BasicVec3D& GetVert2Normal() const;
109  const BasicVec3D& GetVert3Normal() const;
110 
111  //****************************************
113  void SetTriNormal(BasicVec3D triNorm) { m_TriNormal = triNorm; }
115  const BasicVec3D & GetTriNormal() const { return m_TriNormal; }
117  float* GetTriNormalArray();
118 
120  float GetTriNormalX() { return m_TriNormal.GetX(); }
122  float GetTriNormalY() { return m_TriNormal.GetY(); }
124  float GetTriNormalZ() { return m_TriNormal.GetZ(); }
125 
127  void SetTriNormalX(float nx) { m_TriNormal.SetX(nx); }
129  void SetTriNormalY(float ny) { m_TriNormal.SetY(ny); }
131  void SetTriNormalZ(float nz) { m_TriNormal.SetZ(nz); }
132 
134  void CalcNormal();
135 
137  float CalcArea();
138 
140  int GetVertIndex(int which);
142  void SetVertIndex(int which, int indexVal);
143 
145  int GetVert1Index() const { return m_Vert1; }
147  int GetVert2Index() const { return m_Vert2; }
149  int GetVert3Index() const { return m_Vert3; }
150 
152  void SetVert1Index(int v1) { m_Vert1 = v1; }
154  void SetVert2Index(int v2) { m_Vert2 = v2; }
156  void SetVert3Index(int v3) { m_Vert3 = v3; }
157 
159  int GetIndex() const { return m_Index; }
161  void SetIndex(int i) { m_Index = i; }
162 
164  float GetDParam() const { return m_DParam; }
166  void SetDParam(float d) { m_DParam = d; }
167 
168 protected:
169 
170  int m_Vert1; // index of the first member vertex
171  int m_Vert2; // index of the second member vertex
172  int m_Vert3; // index of the third member vertex
173 
174  BasicVec3D m_TriNormal; // normal to plane
175  mutable float m_TriNormalArray[3]; //used for returning values
176 
177  // This parameter is the "d" in the
178  // plane equation ax + by + cz + d = 0
179  // The plane equation of this BasicTriangle is used
180  float m_DParam;
181  bool m_Active; // active flag
182  BasicMesh * m_Mesh; // pointer to the mesh structure that holds the current triangle
183  int m_Index; // index in list of BasicTriangles w/in mesh
184 };
185 
186 }
187 
188 #endif
float GetDParam() const
Returns the'd' is from the plane equation ax + by + cz + d = 0.
Definition: niftkBasicTriangle.h:164
float m_DParam
Definition: niftkBasicTriangle.h:180
void SetTriNormal(BasicVec3D triNorm)
Sets the triangle normal (as Vec3D)
Definition: niftkBasicTriangle.h:113
bool operator==(niftk::BasicVertex const &x, niftk::BasicVertex const &y)
Definition: niftkMeshSmoother.cxx:31
void SetTriNormalX(float nx)
Sets the X component of the triangle normal.
Definition: niftkBasicTriangle.h:127
int GetVert1Index() const
Returns the index of the first member vertex.
Definition: niftkBasicTriangle.h:145
GLfloat GLfloat v1
Definition: glew.h:1836
int m_Vert2
Definition: niftkBasicTriangle.h:171
GLfloat GLfloat GLfloat v2
Definition: glew.h:1840
bool IsActive() const
Returns true if the triangle active, false if it was removed from the mesh.
Definition: niftkBasicTriangle.h:63
int m_Index
Definition: niftkBasicTriangle.h:183
const BasicVec3D & GetTriNormal() const
Gets const refernece to the triangle normal (as Vec3D)
Definition: niftkBasicTriangle.h:115
GLdouble GLdouble t
Definition: glew.h:1382
std::ostream & operator<<(std::ostream &os, const CSVRow &data)
Definition: niftkCSVRow.h:89
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
float GetTriNormalY()
Gets the Y component of the triangle normal.
Definition: niftkBasicTriangle.h:122
int GetVert2Index() const
Returns the index of the second member vertex.
Definition: niftkBasicTriangle.h:147
int m_Vert1
Definition: niftkBasicTriangle.h:170
int m_Vert3
Definition: niftkBasicTriangle.h:172
BasicMesh * m_Mesh
Definition: niftkBasicTriangle.h:182
void SetVert1Index(int v1)
Sets the index of the first member vertex.
Definition: niftkBasicTriangle.h:152
void SetVert3Index(int v3)
Sets the index of the third member vertex.
Definition: niftkBasicTriangle.h:156
Simple vertex implementation that is used in the Surface Extraction and surface smoothing and decimat...
Definition: niftkBasicVertex.h:77
int GetVert3Index() const
Returns the index of the third member vertex.
Definition: niftkBasicTriangle.h:149
void SetTriNormalZ(float nz)
Sets the Z component of the triangle normal.
Definition: niftkBasicTriangle.h:131
void SetVert2Index(int v2)
Sets the index of the second member vertex.
Definition: niftkBasicTriangle.h:154
void SetIndex(int i)
Sets the index of the current triangle.
Definition: niftkBasicTriangle.h:161
bool m_Active
Definition: niftkBasicTriangle.h:181
GLfloat GLfloat GLfloat GLfloat nx
Definition: glew.h:14135
GLhalf GLhalf nz
Definition: glew.h:11437
Simple mesh implementation that is used in the Surface Extraction and surface smoothing and decimatio...
Definition: niftkBasicMesh.h:31
void ChangeMesh(BasicMesh *mp)
Changes the mesh pointer to the specified one.
Definition: niftkBasicTriangle.h:60
float GetTriNormalZ()
Gets the Z component of the triangle normal.
Definition: niftkBasicTriangle.h:124
int GetIndex() const
Returns the index of the current triangle.
Definition: niftkBasicTriangle.h:159
Simple triangle implementation that is used in the Surface Extraction and surface smoothing and decim...
Definition: niftkBasicTriangle.h:34
GLhalf ny
Definition: glew.h:11437
GLfloat GLfloat GLfloat GLfloat v3
Definition: glew.h:1844
void SetTriNormalY(float ny)
Sets the Y component of the triangle normal.
Definition: niftkBasicTriangle.h:129
Simple 3D Vector implementation that is used in the Surface Extraction and surface smoothing and deci...
Definition: niftkBasicVec3D.h:30
void SetDParam(float d)
Sets the'd' parameter of the plane equation ax + by + cz + d = 0.
Definition: niftkBasicTriangle.h:166
BasicVec3D m_TriNormal
Definition: niftkBasicTriangle.h:174
float GetTriNormalX()
Gets the X component of the triangle normal.
Definition: niftkBasicTriangle.h:120
Definition: niftkExceptionObject.h:21
void SetActive(bool b)
Sets the active status of the triangle. False = triangle was removed.
Definition: niftkBasicTriangle.h:65