o3dgcIndexedFaceSet.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #ifndef O3DGC_INDEXED_FACE_SET_H
  21. #define O3DGC_INDEXED_FACE_SET_H
  22. #include "o3dgcCommon.h"
  23. namespace o3dgc
  24. {
  25. template<class T>
  26. class IndexedFaceSet
  27. {
  28. public:
  29. //! Constructor.
  30. IndexedFaceSet(void)
  31. {
  32. memset(this, 0, sizeof(IndexedFaceSet));
  33. m_ccw = true;
  34. m_solid = true;
  35. m_convex = true;
  36. m_isTriangularMesh = true;
  37. m_creaseAngle = 30;
  38. };
  39. //! Destructor.
  40. ~IndexedFaceSet(void) {};
  41. unsigned long GetNCoordIndex() const { return m_nCoordIndex ;}
  42. // only coordIndex is supported
  43. unsigned long GetNCoord() const { return m_nCoord ;}
  44. unsigned long GetNNormal() const { return m_nNormal ;}
  45. unsigned long GetNFloatAttribute(unsigned long a) const
  46. {
  47. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  48. return m_nFloatAttribute[a];
  49. }
  50. unsigned long GetNIntAttribute(unsigned long a) const
  51. {
  52. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  53. return m_nIntAttribute[a];
  54. }
  55. unsigned long GetNumFloatAttributes() const { return m_numFloatAttributes;}
  56. unsigned long GetNumIntAttributes() const { return m_numIntAttributes ;}
  57. const Real * const GetCoordMin () const { return m_coordMin;}
  58. const Real * const GetCoordMax () const { return m_coordMax;}
  59. const Real * const GetNormalMin () const { return m_normalMin;}
  60. const Real * const GetNormalMax () const { return m_normalMax;}
  61. Real GetCoordMin (int j) const { return m_coordMin[j] ;}
  62. Real GetCoordMax (int j) const { return m_coordMax[j] ;}
  63. Real GetNormalMin (int j) const { return m_normalMin[j] ;}
  64. Real GetNormalMax (int j) const { return m_normalMax[j] ;}
  65. const O3DGCIFSFloatAttributeType GetFloatAttributeType(unsigned long a) const
  66. {
  67. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  68. return m_typeFloatAttribute[a];
  69. }
  70. const O3DGCIFSIntAttributeType GetIntAttributeType(unsigned long a) const
  71. {
  72. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  73. return m_typeIntAttribute[a];
  74. }
  75. const unsigned long GetFloatAttributeDim(unsigned long a) const
  76. {
  77. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  78. return m_dimFloatAttribute[a];
  79. }
  80. unsigned long GetIntAttributeDim(unsigned long a) const
  81. {
  82. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  83. return m_dimIntAttribute[a];
  84. }
  85. const Real * const GetFloatAttributeMin(unsigned long a) const
  86. {
  87. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  88. return &(m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
  89. }
  90. const Real * const GetFloatAttributeMax(unsigned long a) const
  91. {
  92. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  93. return &(m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES]);
  94. }
  95. Real GetFloatAttributeMin(unsigned long a, unsigned long dim) const
  96. {
  97. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  98. assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
  99. return m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
  100. }
  101. Real GetFloatAttributeMax(unsigned long a, unsigned long dim) const
  102. {
  103. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  104. assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
  105. return m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim];
  106. }
  107. Real GetCreaseAngle() const { return m_creaseAngle ;}
  108. bool GetCCW() const { return m_ccw ;}
  109. bool GetSolid() const { return m_solid ;}
  110. bool GetConvex() const { return m_convex ;}
  111. bool GetIsTriangularMesh() const { return m_isTriangularMesh;}
  112. const unsigned long * const GetIndexBufferID() const { return m_indexBufferID ;}
  113. const T * const GetCoordIndex() const { return m_coordIndex;}
  114. T * const GetCoordIndex() { return m_coordIndex;}
  115. Real * const GetCoord() const { return m_coord ;}
  116. Real * const GetNormal() const { return m_normal ;}
  117. Real * const GetFloatAttribute(unsigned long a) const
  118. {
  119. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  120. return m_floatAttribute[a];
  121. }
  122. long * const GetIntAttribute(unsigned long a) const
  123. {
  124. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  125. return m_intAttribute[a] ;
  126. }
  127. // only coordIndex is supported
  128. void SetNNormalIndex(unsigned long) {}
  129. void SetNTexCoordIndex(unsigned long) {}
  130. void SetNFloatAttributeIndex(int, unsigned long) {}
  131. void SetNIntAttributeIndex (int, unsigned long) {}
  132. // per triangle attributes not supported
  133. void SetNormalPerVertex(bool) {}
  134. void SetColorPerVertex(bool) {}
  135. void SetFloatAttributePerVertex(int, bool){}
  136. void SetIntAttributePerVertex (int, bool){}
  137. void SetNCoordIndex (unsigned long nCoordIndex) { m_nCoordIndex = nCoordIndex;}
  138. void SetNCoord (unsigned long nCoord) { m_nCoord = nCoord ;}
  139. void SetNNormal (unsigned long nNormal) { m_nNormal = nNormal ;}
  140. void SetNumFloatAttributes(unsigned long numFloatAttributes)
  141. {
  142. assert(numFloatAttributes < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  143. m_numFloatAttributes = numFloatAttributes;
  144. }
  145. void SetNumIntAttributes (unsigned long numIntAttributes)
  146. {
  147. assert(numIntAttributes < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  148. m_numIntAttributes = numIntAttributes;
  149. }
  150. void SetCreaseAngle (Real creaseAngle) { m_creaseAngle = creaseAngle ;}
  151. void SetCCW (bool ccw) { m_ccw = ccw ;}
  152. void SetSolid (bool solid) { m_solid = solid ;}
  153. void SetConvex (bool convex) { m_convex = convex ;}
  154. void SetIsTriangularMesh (bool isTriangularMesh) { m_isTriangularMesh = isTriangularMesh;}
  155. void SetCoordMin (int j, Real min) { m_coordMin[j] = min;}
  156. void SetCoordMax (int j, Real max) { m_coordMax[j] = max;}
  157. void SetNormalMin (int j, Real min) { m_normalMin[j] = min;}
  158. void SetNormalMax (int j, Real max) { m_normalMax[j] = max;}
  159. void SetNFloatAttribute(unsigned long a, unsigned long nFloatAttribute)
  160. {
  161. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  162. m_nFloatAttribute[a] = nFloatAttribute;
  163. }
  164. void SetNIntAttribute(unsigned long a, unsigned long nIntAttribute)
  165. {
  166. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  167. m_nIntAttribute[a] = nIntAttribute;
  168. }
  169. void SetFloatAttributeDim(unsigned long a, unsigned long d)
  170. {
  171. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  172. m_dimFloatAttribute[a] = d;
  173. }
  174. void SetIntAttributeDim(unsigned long a, unsigned long d)
  175. {
  176. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  177. m_dimIntAttribute[a] = d;
  178. }
  179. void SetFloatAttributeType(unsigned long a, O3DGCIFSFloatAttributeType t)
  180. {
  181. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  182. m_typeFloatAttribute[a] = t;
  183. }
  184. void SetIntAttributeType(unsigned long a, O3DGCIFSIntAttributeType t)
  185. {
  186. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  187. m_typeIntAttribute[a] = t;
  188. }
  189. void SetFloatAttributeMin(unsigned long a, unsigned long dim, Real min)
  190. {
  191. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  192. assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
  193. m_minFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = min;
  194. }
  195. void SetFloatAttributeMax(unsigned long a, unsigned long dim, Real max)
  196. {
  197. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  198. assert(dim < O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES);
  199. m_maxFloatAttribute[a * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES + dim] = max;
  200. }
  201. void SetIndexBufferID (unsigned long * const indexBufferID) { m_indexBufferID = indexBufferID;}
  202. void SetCoordIndex (T * const coordIndex) { m_coordIndex = coordIndex;}
  203. void SetCoord (Real * const coord ) { m_coord = coord ;}
  204. void SetNormal (Real * const normal ) { m_normal = normal ;}
  205. void SetFloatAttribute (unsigned long a, Real * const floatAttribute)
  206. {
  207. assert(a < O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES);
  208. m_floatAttribute[a] = floatAttribute;
  209. }
  210. void SetIntAttribute (unsigned long a, long * const intAttribute)
  211. {
  212. assert(a < O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES);
  213. m_intAttribute[a] = intAttribute ;
  214. }
  215. void ComputeMinMax(O3DGCSC3DMCQuantizationMode quantMode);
  216. private:
  217. // triangles list
  218. unsigned long m_nCoordIndex;
  219. T * m_coordIndex;
  220. unsigned long * m_indexBufferID;
  221. // coord, normals, texcoord and color
  222. unsigned long m_nCoord;
  223. unsigned long m_nNormal;
  224. Real m_coordMin [3];
  225. Real m_coordMax [3];
  226. Real m_normalMin [3];
  227. Real m_normalMax [3];
  228. Real * m_coord;
  229. Real * m_normal;
  230. // other attributes
  231. unsigned long m_numFloatAttributes;
  232. unsigned long m_numIntAttributes;
  233. O3DGCIFSFloatAttributeType m_typeFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
  234. O3DGCIFSIntAttributeType m_typeIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
  235. unsigned long m_nFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
  236. unsigned long m_nIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
  237. unsigned long m_dimFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
  238. unsigned long m_dimIntAttribute [O3DGC_SC3DMC_MAX_NUM_INT_ATTRIBUTES ];
  239. Real m_minFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
  240. Real m_maxFloatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES * O3DGC_SC3DMC_MAX_DIM_ATTRIBUTES];
  241. Real * m_floatAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
  242. long * m_intAttribute [O3DGC_SC3DMC_MAX_NUM_FLOAT_ATTRIBUTES];
  243. // mesh info
  244. Real m_creaseAngle;
  245. bool m_ccw;
  246. bool m_solid;
  247. bool m_convex;
  248. bool m_isTriangularMesh;
  249. };
  250. }
  251. #include "o3dgcIndexedFaceSet.inl" // template implementation
  252. #endif // O3DGC_INDEXED_FACE_SET_H