Vertex3d.h
上传用户:hcfgz168
上传日期:2011-09-11
资源大小:116k
文件大小:7k
源码类别:

OpenGL

开发平台:

WINDOWS

  1. //********************************************
  2. // Vertex3d.h
  3. // (Part of 3d Toolbox)
  4. //********************************************
  5. // pierre.alliez@cnet.francetelecom.fr
  6. // Created : 10/12/97
  7. // Modified : 29/04/98
  8. //********************************************
  9. #ifndef _VERTEX_3D_
  10. #define _VERTEX_3D_
  11. #include "Object3d.h"
  12. #include "Vector3d.h"
  13. #include "Color.h"
  14. #include "Array3d.h"
  15. class CMesh3d;
  16. class CFace3d;
  17. class CEdge3d;
  18. class CVertex3d : public CObject3d
  19. {
  20. private :
  21. float     m_Coord[3];  // Geometry
  22. CVector3d m_Normal;    // Normal
  23. CColor    m_Color;     // Color
  24. char      m_Flag;      // Flag
  25. void     *m_pBag;    // Any associated structure
  26. // Neighbors (faces and vertices)
  27. CArray3d<CVertex3d> m_ArrayVertexNeighbor;
  28. CArray3d<CFace3d>   m_ArrayFaceNeighbor;
  29. public :
  30. // Constructors
  31. CVertex3d() { m_Flag = 0; Set(0.0f,0.0f,0.0f); }
  32. CVertex3d(CVertex3d &vertex);
  33. CVertex3d(CVertex3d *pVertex);
  34. CVertex3d(CVertex3d *pVertex,CVector3d *pVector);
  35. CVertex3d(const float x,const float y,const float z); 
  36. // Destructor (CArray3d will do the work...)
  37. virtual ~CVertex3d() {}
  38. // Data setting
  39. void Set(const float x,const float y,const float z);
  40. void Set(CVertex3d *pVertex);
  41. void Set(CVertex3d &vertex);
  42. // Moving
  43. void Move(CVector3d &vector,const float ratio);
  44. void Move(CVector3d *pVector,const float ratio = 1.0f);
  45. void Move(const float dx,const float dy,const float dz);
  46. // Per coordinate
  47. void Set(const unsigned int index,const float value) { m_Coord[index] = value;}
  48. void x(const float x) { m_Coord[0] = x; }
  49. void y(const float y) { m_Coord[1] = y; }
  50. void z(const float z) { m_Coord[2] = z; }
  51. // Data access 
  52. float Get(const unsigned int index) { return m_Coord[index];}
  53. float x(void) { return m_Coord[0]; }
  54. float y(void) { return m_Coord[1]; }
  55. float z(void) { return m_Coord[2]; }
  56. // Type
  57. virtual int GetType();
  58. // Color
  59. CColor *GetColor(void) { return &m_Color; }
  60. void SetColor(CColor &color) { m_Color.Set(color); }
  61. // Flag
  62. char GetFlag(void) { return m_Flag; }
  63. void SetFlag(const char flag) { m_Flag = flag; }
  64. int HasNeighborWithFlag(int flag);
  65. int HasNeighborWithFlagButDiff(int flag,CVertex3d *pVertexDiff);
  66. CVertex3d *GetFirstVertexNeighborWithFlag(int flag);
  67. CVertex3d *GetNearestVertexNeighborWithFlag(int flag);
  68. CVertex3d *GetFirstVertexNeighborWithFlagButDiff(int flag,CVertex3d *pVertexDiff);
  69. CVertex3d *GetFirstNeighborWithFlagAndSharingFaceWithFlag(int FlagVertex,int FlagFace);
  70. int DiffFlagsOnNeighboringFaces();
  71. int IsFlagSmallestOnNeighboringFaces(int flag);
  72. int FindVertexNeighborsWhichFlagIsGreater(int flag,CArray3d<CVertex3d> &array);
  73. int FindVertexNeighborsWhichFlagIsSmaller(int flag,CArray3d<CVertex3d> &array);
  74. int NbVertexNeighborWithFlag(int flag);
  75. // Bag, dirty :-(
  76. void SetBag(void *pBag) { m_pBag = pBag; }
  77. void *GetBag() { return m_pBag; }
  78. // Normal
  79. void SetNormal(const float x,const float y,const float z) { m_Normal.Set(x,y,z); }
  80. void SetNormal(CVector3d &vector) { m_Normal.Set(vector); }
  81. CVector3d * GetNormal(void) { return &m_Normal; }
  82. // Operators
  83. CVertex3d operator=(CVertex3d& vertex);
  84. int Diff(CVertex3d *pVertex);
  85. int Equal(CVertex3d *pVertex);
  86. // Vertex neighbors
  87. int  NbVertexNeighbor(void);
  88. void AddNeighbor(CVertex3d *pVertex);
  89. void AddNeighborNoCheck(CVertex3d *pVertex);
  90. int  HasNeighbor(CVertex3d *pVertex) { return m_ArrayVertexNeighbor.Has(pVertex); }
  91. int  RemoveNeighbor(CVertex3d *pVertex);
  92. void RemoveAllVertexNeighbor(void);
  93. void UpdateNeighborRecursive(CVertex3d *pVertexOld,CVertex3d *pVertexNew);
  94. int  UpdateNeighbor(CVertex3d *pVertexOld,CVertex3d *pVertexNew);
  95. int FindFaceAroundContainVertex(CVertex3d *pVertex,CArray3d<CFace3d> &ArrayFace);
  96. CVertex3d *GetVertexNeighbor(const unsigned int index) {return m_ArrayVertexNeighbor[index];}
  97. CArray3d<CVertex3d> *GetArrayVertexNeighbor() { return &m_ArrayVertexNeighbor; }
  98. // Face neighbors
  99. int  NbFaceNeighbor(void);
  100. void AddNeighbor(CFace3d *pFace);
  101. int  RemoveNeighbor(CFace3d *pFace);
  102. void RemoveAllFaceNeighbor(void);
  103. int  HasNeighbor(CFace3d *pFace) { return m_ArrayFaceNeighbor.Has(pFace); }
  104. CFace3d *GetFaceNeighbor(const unsigned int index) { return m_ArrayFaceNeighbor[index]; }
  105. CArray3d<CFace3d> *GetArrayFaceNeighbor() { return &m_ArrayFaceNeighbor; }
  106. // Face sharing
  107. int FindSharingFaces(CVertex3d *pVertex,CArray3d<CFace3d> &array);
  108. // Area
  109. double GetMeanAreaAround();
  110. double GetMinAreaAround();
  111. // Distance
  112. double GetMeanLengthEdgeAround();
  113. // Curve
  114. double GetMeanCurveAround();
  115. double GetSumCurveAround();
  116. double GetMaxCurveAround();
  117. double GetMaxAngleAround();
  118. double GetMaxCurveAroundAndNeighbors();
  119. // Precision
  120. void ReplaceOnGrid(float threshold);
  121. // Boundaries
  122. int IsOnBoundary();
  123. // Count sharp edges around vertex
  124. int NbSharpEdge(const double threshold = 0.5);
  125. // Normals's 
  126. int NormalSum(double *pSum);
  127. int NormalMax(double *pMax);
  128. // Debug
  129. void Trace();
  130. // OpenGL highlighting
  131. void glDrawHighlight(const float radius,const float RadiusNeighbor,
  132.                    unsigned char *ColorVertex,CMesh3d *pMesh = NULL,
  133.  unsigned char *ColorNeightbor = NULL);
  134. virtual int glDraw();
  135. void glDraw(const float radius,unsigned char *ColorVertex,CMesh3d *pMesh = NULL);
  136. };
  137. // Constructor
  138. inline CVertex3d::CVertex3d(CVertex3d &vertex)
  139. {
  140. m_Coord[0] = vertex.x();
  141. m_Coord[1] = vertex.y();
  142. m_Coord[2] = vertex.z();
  143. m_Flag = 0;
  144. }
  145. // Constructor
  146. inline CVertex3d::CVertex3d(CVertex3d *pVertex)
  147. {
  148. m_Coord[0] = pVertex->x();
  149. m_Coord[1] = pVertex->y();
  150. m_Coord[2] = pVertex->z();
  151. m_Flag = 0;
  152. }
  153. // Constructor
  154. inline CVertex3d::CVertex3d(CVertex3d *pVertex,CVector3d *pVector)
  155. {
  156. m_Coord[0] = pVertex->x() + pVector->x();
  157. m_Coord[1] = pVertex->y() + pVector->y();
  158. m_Coord[2] = pVertex->z() + pVector->z();
  159. m_Flag = 0;
  160. }
  161. // Constructor
  162. inline CVertex3d::CVertex3d(const float x,const float y,const float z) 
  163. {
  164. m_Coord[0] = x; 
  165. m_Coord[1] = y; 
  166. m_Coord[2] = z; 
  167. m_Flag = 0;
  168. }
  169. // Setting
  170. inline void CVertex3d::Set(const float x,const float y,const float z)
  171. {
  172. m_Coord[0] = x;
  173. m_Coord[1] = y;
  174. m_Coord[2] = z;
  175. }
  176. // Setting
  177. inline void CVertex3d::Set(CVertex3d *pVertex)
  178. {
  179. m_Coord[0] = pVertex->x();
  180. m_Coord[1] = pVertex->y();
  181. m_Coord[2] = pVertex->z();
  182. }
  183. // Setting
  184. inline void CVertex3d::Set(CVertex3d &vertex)
  185. {
  186. m_Coord[0] = vertex.x();
  187. m_Coord[1] = vertex.y();
  188. m_Coord[2] = vertex.z();
  189. }
  190. // Moving
  191. inline void CVertex3d::Move(const float dx,
  192. const float dy,
  193. const float dz)
  194. {
  195. m_Coord[0] += dx;
  196. m_Coord[1] += dy;
  197. m_Coord[2] += dz;
  198. }
  199. // Moving
  200. inline void CVertex3d::Move(CVector3d *pVector,
  201. float ratio)
  202. {
  203. m_Coord[0] += ratio * pVector->x();
  204. m_Coord[1] += ratio * pVector->y();
  205. m_Coord[2] += ratio * pVector->z();
  206. }
  207. // Moving
  208. inline void CVertex3d::Move(CVector3d &vector,
  209. float ratio)
  210. {
  211. m_Coord[0] += ratio * vector.x();
  212. m_Coord[1] += ratio * vector.y();
  213. m_Coord[2] += ratio * vector.z();
  214. }
  215. #endif // _VERTEX_3D_