o3dgcSC3DMCEncoder.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_SC3DMC_ENCODER_H
  21. #define O3DGC_SC3DMC_ENCODER_H
  22. #include "o3dgcCommon.h"
  23. #include "o3dgcBinaryStream.h"
  24. #include "o3dgcIndexedFaceSet.h"
  25. #include "o3dgcSC3DMCEncodeParams.h"
  26. #include "o3dgcTriangleListEncoder.h"
  27. namespace o3dgc
  28. {
  29. //!
  30. template<class T>
  31. class SC3DMCEncoder
  32. {
  33. public:
  34. //! Constructor.
  35. SC3DMCEncoder(void)
  36. {
  37. m_posSize = 0;
  38. m_quantFloatArray = 0;
  39. m_quantFloatArraySize = 0;
  40. m_sizeBufferAC = 0;
  41. m_bufferAC = 0;
  42. m_normals = 0;
  43. m_normalsSize = 0;
  44. m_streamType = O3DGC_STREAM_TYPE_UNKOWN;
  45. };
  46. //! Destructor.
  47. ~SC3DMCEncoder(void)
  48. {
  49. delete [] m_normals;
  50. delete [] m_quantFloatArray;
  51. delete [] m_bufferAC;
  52. }
  53. //!
  54. O3DGCErrorCode Encode(const SC3DMCEncodeParams & params,
  55. const IndexedFaceSet<T> & ifs,
  56. BinaryStream & bstream);
  57. const SC3DMCStats & GetStats() const { return m_stats;}
  58. private:
  59. O3DGCErrorCode EncodeHeader(const SC3DMCEncodeParams & params,
  60. const IndexedFaceSet<T> & ifs,
  61. BinaryStream & bstream);
  62. O3DGCErrorCode EncodePayload(const SC3DMCEncodeParams & params,
  63. const IndexedFaceSet<T> & ifs,
  64. BinaryStream & bstream);
  65. O3DGCErrorCode EncodeFloatArray(const Real * const floatArray,
  66. unsigned long numfloatArray,
  67. unsigned long dimfloatArray,
  68. unsigned long stride,
  69. const Real * const minfloatArray,
  70. const Real * const maxfloatArray,
  71. unsigned long nQBits,
  72. const IndexedFaceSet<T> & ifs,
  73. O3DGCSC3DMCPredictionMode predMode,
  74. BinaryStream & bstream);
  75. O3DGCErrorCode QuantizeFloatArray(const Real * const floatArray,
  76. unsigned long numFloatArray,
  77. unsigned long dimFloatArray,
  78. unsigned long stride,
  79. const Real * const minfloatArray,
  80. const Real * const maxfloatArray,
  81. unsigned long nQBits);
  82. O3DGCErrorCode EncodeIntArray(const long * const intArray,
  83. unsigned long numIntArray,
  84. unsigned long dimIntArray,
  85. unsigned long stride,
  86. const IndexedFaceSet<T> & ifs,
  87. O3DGCSC3DMCPredictionMode predMode,
  88. BinaryStream & bstream);
  89. O3DGCErrorCode ProcessNormals(const IndexedFaceSet<T> & ifs);
  90. TriangleListEncoder<T> m_triangleListEncoder;
  91. long * m_quantFloatArray;
  92. unsigned long m_posSize;
  93. unsigned long m_quantFloatArraySize;
  94. unsigned char * m_bufferAC;
  95. unsigned long m_sizeBufferAC;
  96. SC3DMCPredictor m_neighbors [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
  97. unsigned long m_freqSymbols[O3DGC_SC3DMC_MAX_PREDICTION_SYMBOLS];
  98. unsigned long m_freqPreds [O3DGC_SC3DMC_MAX_PREDICTION_NEIGHBORS];
  99. Vector<long> m_predictors;
  100. Real * m_normals;
  101. unsigned long m_normalsSize;
  102. SC3DMCStats m_stats;
  103. O3DGCStreamType m_streamType;
  104. };
  105. }
  106. #include "o3dgcSC3DMCEncoder.inl" // template implementation
  107. #endif // O3DGC_SC3DMC_ENCODER_H