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

OpenGL

开发平台:

WINDOWS

  1. //********************************************
  2. // Mesh3d.h
  3. // class CMesh3d
  4. //********************************************
  5. // A mesh : simplicial complex
  6. // + Array of vertex
  7. // + Array of faces
  8. // + Binding infos
  9. //********************************************
  10. // pierre.alliez@cnet.francetelecom.fr
  11. // Created : 15/01/98
  12. // Modified : 07/07/98
  13. //********************************************
  14. #ifndef _MESH_3D_
  15. #define _MESH_3D_
  16. #include "Array3d.h"
  17. #include "Vertex3d.h"
  18. #include "Face3d.h"
  19. #include "Vector3d.h"
  20. #include "Material.h"
  21. #include "Transform.h"
  22. class CColorRamp;
  23. class CTexture;
  24. class CMesh3d : public CObject3d
  25. {
  26. friend class CParserVrml;
  27. private :
  28. // Datas
  29. CArray3d<CVertex3d> m_ArrayVertex;
  30. CArray3d<CFace3d>   m_ArrayFace;
  31. CTransform m_Transform;
  32. CString m_Name;
  33. // Apparence & texture
  34. CMaterial m_Material; // material
  35. int m_NormalBinding;  // normals defined at vertices or faces ? (Gouraud)
  36. int m_ColorBinding;   // colors defined at vertices or faces ? (Gouraud)
  37. // Texture
  38. int m_IndexTexture;   // which texture in SceneGraph ? (-1 : no texture)
  39. float *m_pTextureCoordinate;
  40. int *m_pTextureCoordinateIndex;
  41. // OpenGL-specific
  42. unsigned int m_ListOpenGL;
  43. unsigned int m_ListDone;
  44. int m_Modified;
  45. int m_Show;
  46. public :
  47. // Constructor
  48. CMesh3d();
  49. virtual ~CMesh3d();
  50. // Datas
  51. void Free();
  52. virtual int GetType();
  53. int IsValid();
  54. void Copy(CMesh3d *pMesh);
  55. // Faces
  56. int NbFace() { return m_ArrayFace.GetSize(); }
  57. CFace3d *GetFace(int index) { return m_ArrayFace[index]; }
  58. void AddFace(CFace3d *pFace) { m_ArrayFace.Add(pFace); }
  59. void SetNbFace(int NbFace) { m_ArrayFace.SetSize(NbFace); }
  60. CArray3d<CFace3d> *GetArrayFace() { return &m_ArrayFace; }
  61. int Has(CFace3d *pFace) { return m_ArrayFace.Has(pFace); }
  62. int FindFace(CFace3d *pFace); // even in neighborign faces
  63. // Flags
  64. void SetFlagOnFaces(int flag);
  65. void SetFlagOnVertices(int flag);
  66. CVertex3d *GetFirstVertexWithFlag(int flag);
  67. int GetMaxFlagOnFaces();
  68. int FindSmallestFlagOnVerticesDiffThan(int flag,int *pFounded);
  69. int FindFlagOnVerticesDiffThan(int flag);
  70. CVertex3d *GetAnyVertexWithFlagRootPrefered(int flag);
  71. // Vertices
  72. int NbVertex() { return m_ArrayVertex.GetSize(); }
  73. void SetNbVertex(int NbVertex)  { m_ArrayVertex.SetSize(NbVertex); }
  74. CArray3d<CVertex3d> *GetArrayVertex() { return &m_ArrayVertex; }
  75. void AddVertex(CVertex3d *pVertex) { m_ArrayVertex.Add(pVertex); }
  76. int DeleteVertex(CVertex3d *pVertex);
  77. int DeleteVertex(int index);
  78. int DeleteFaceNbNeighbors(int NbNeighbor);
  79. CVertex3d *GetVertex(int index) {return m_ArrayVertex[index];}
  80. int Has(CVertex3d *pVertex) { return m_ArrayVertex.Has(pVertex); }
  81. // Edges
  82. float GetMeanLengthEdge();
  83. // Name
  84. CString GetName(void) { return m_Name; } 
  85. void SetName(CString &string) { m_Name = string; } 
  86. // I/O
  87. int WriteFile(CStdioFile &file);
  88. int WriteFileRaw(CFile &file);
  89. // Transform
  90. void SetTransform(CTransform &transform) { m_Transform.Copy(transform); }
  91. CTransform *GetTransform(void) { return &m_Transform; }
  92. // Range
  93. void Range(int coord,float *min,float *max); 
  94. void Range(int coord,float min,float max); 
  95. void Offset(int coord,float offset);
  96. void Scale(int coord,float scale);
  97. void Move(float dx,float dy,float dz);
  98. // Predefined
  99. int GenerateMap(int line,int col,float min,float max);
  100. int GenerateBox(float dx,float dy,float dz);
  101. int GenerateMap(CTexture *pTexture,int width,int height,int FlagColor = 1);
  102. // OpenGL
  103. virtual int glBuildList();
  104. virtual int glDraw();
  105. void Show(int flag) { m_Show = flag; }
  106. // Debug
  107. void Trace();
  108. // Adjacency 
  109. int BuildAdjacency();
  110. // Processing
  111. int IndexFrom(CFace3d *pFace);
  112. int IndexFrom(CVertex3d *pVertex);
  113. // Modif
  114. void SetModified(int flag = 1) { m_Modified = flag; }
  115. int GetModified() { return m_Modified; }
  116. // Vertex removal
  117. int VertexRemoval(CVertex3d *pV);
  118. int VertexRemoval();
  119. // Search
  120. int FindVertex(CVertex3d *pVertex);
  121. // Normals
  122. int CalculateNormalPerVertex(void);
  123. int CalculateNormalPerFace(void);
  124. void SetNormalBinding(int type);
  125. int GetNormalBinding(void);
  126. CVectorSet3d *GetVectorSetNormalPerFace(void); // alloc on the global heap
  127. // Adjacency
  128. void Rebuild();
  129. // Distance
  130. double SquareDistanceToVertex(CVertex3d *pVertex,CVertex3d **pVertexRef);
  131. double SquareDistanceToFace(CVertex3d *pVertex,CVertex3d *pVertexRef,CFace3d **ppFaceRef);
  132. // Sharp edges
  133. int ColorSharpEdge(float threshold,CColor &color);
  134. CVectorSet3d *GetSharpEdges(float threshold);
  135. // Strings
  136. CVectorSet3d *GetStringBetweenVertices();
  137. // Color
  138. void SetColorBinding(int type);
  139. void SetColor(CColor &color);
  140. int GetColorBinding(void);
  141. // Material
  142. CMaterial *GetMaterial() { return &m_Material; }
  143. void SetMaterial(CMaterial *pMaterial) { m_Material.Copy(pMaterial); }
  144. // Texture
  145. int GetTextureIndex() { return m_IndexTexture; }
  146. // Subdivision
  147. int SubdivisionLoop(int MoveOnBundary = 1); // Charles Loop (1987)
  148. int Subdivision(void); 
  149. float Alpha(int n);
  150. // Smoothing
  151. int Smooth(int MoveOnBundary = 1);
  152. // Coloring (curvature, compacity, etc...)
  153. void ColorCurvature(CColorRamp *pRamp);
  154. void ColorNormalSpace(CColorRamp *pRamp);
  155. void ColorCompacity(CColorRamp *pRamp);
  156. void ColorFacesFromFlagPastels();
  157. void ColorFacesFromFlagGrey();
  158. // Intersection
  159. int NearestIntersectionWithLine(CVertex3d *pV0,CVertex3d *pV1,CVertex3d *pVertexResult,
  160.                               CFace3d **ppFaceResult,int *pNbFaceVisited);
  161. // Area
  162. double GetMinArea(CFace3d **ppFace = NULL);
  163. double GetMeanArea();
  164. };
  165. #endif // _MESH_3D_