00001 #pragma once 00002 00003 #ifndef __v_voxel_h 00004 #define __v_voxel_h 00005 00006 #include "VVector.h" 00007 00011 class VVoxel 00012 { 00013 public: 00014 00018 VVoxel() : m_VoxelData(0.0f), m_Gradient() 00019 { 00020 } 00021 00026 VVoxel(float voxelData) : m_VoxelData(voxelData), m_Gradient() 00027 { 00028 } 00029 00030 VVoxel(float voxelData, VVector gradient) : m_VoxelData(voxelData), m_Gradient(gradient) 00031 { 00032 } 00033 00041 VVoxel(float * samplesNegZOffset, float * samplesNoZOffset, float * samplesPosZOffset) 00042 { 00043 float voxelWeights[3][3][3]= { 00044 { {2.0f,3.0f,2.0f}, {3.0f,6.0f,3.0f}, {2.0f,3.0f,2.0f} }, 00045 { {3.0f,6.0f,3.0f}, {6.0f,0.0f,6.0f}, {3.0f,6.0f,3.0f} }, 00046 { {2.0f,3.0f,2.0f}, {3.0f,6.0f,3.0f}, {2.0f,3.0f,2.0f} } }; 00047 00048 float weight = 1.0f / 00049 (voxelWeights[0][0][0] + voxelWeights[1][0][0] + voxelWeights[2][0][0] 00050 + voxelWeights[0][1][0] + voxelWeights[1][1][0] + voxelWeights[2][1][0] 00051 + voxelWeights[0][2][0] + voxelWeights[1][2][0] + voxelWeights[2][2][0] 00052 + voxelWeights[0][0][1] + voxelWeights[1][0][1] + voxelWeights[2][0][1] 00053 + voxelWeights[0][1][1] + voxelWeights[1][1][1] + voxelWeights[2][1][1] 00054 + voxelWeights[0][2][1] + voxelWeights[1][2][1] + voxelWeights[2][2][1] 00055 + voxelWeights[0][0][2] + voxelWeights[1][0][2] + voxelWeights[2][0][2] 00056 + voxelWeights[0][1][2] + voxelWeights[1][1][2] + voxelWeights[2][1][2] 00057 + voxelWeights[0][2][2] + voxelWeights[1][2][2] + voxelWeights[2][2][2]); 00058 00059 float gradientXWeight = -1.0f / 00060 (voxelWeights[0][0][0] + voxelWeights[1][0][0] + voxelWeights[2][0][0] 00061 + voxelWeights[0][1][0] + voxelWeights[1][1][0] + voxelWeights[2][1][0] 00062 + voxelWeights[0][2][0] + voxelWeights[1][2][0] + voxelWeights[2][2][0] 00063 + voxelWeights[0][0][2] + voxelWeights[1][0][2] + voxelWeights[2][0][2] 00064 + voxelWeights[0][1][2] + voxelWeights[1][1][2] + voxelWeights[2][1][2] 00065 + voxelWeights[0][2][2] + voxelWeights[1][2][2] + voxelWeights[2][2][2]); 00066 00067 float gradientYWeight = -1.0f / 00068 (voxelWeights[0][0][0] + voxelWeights[1][0][0] + voxelWeights[2][0][0] 00069 + voxelWeights[0][2][0] + voxelWeights[1][2][0] + voxelWeights[2][2][0] 00070 + voxelWeights[0][0][1] + voxelWeights[1][0][1] + voxelWeights[2][0][1] 00071 + voxelWeights[0][2][1] + voxelWeights[1][2][1] + voxelWeights[2][2][1] 00072 + voxelWeights[0][0][2] + voxelWeights[1][0][2] + voxelWeights[2][0][2] 00073 + voxelWeights[0][2][2] + voxelWeights[1][2][2] + voxelWeights[2][2][2]); 00074 00075 float gradientZWeight = -1.0f / 00076 (voxelWeights[0][0][0] + voxelWeights[2][0][0] + voxelWeights[0][1][0] 00077 + voxelWeights[2][1][0] + voxelWeights[0][2][0] + voxelWeights[2][2][0] 00078 + voxelWeights[0][0][1] + voxelWeights[2][0][1] + voxelWeights[0][1][1] 00079 + voxelWeights[2][1][1] + voxelWeights[0][2][1] + voxelWeights[2][2][1] 00080 + voxelWeights[0][0][2] + voxelWeights[2][0][2] + voxelWeights[0][1][2] 00081 + voxelWeights[2][1][2] + voxelWeights[0][2][2] + voxelWeights[2][2][2]); 00082 00083 00084 float fValue(weight * 00085 (+ voxelWeights[0][0][0] * samplesNegZOffset[0] 00086 + voxelWeights[1][0][0] * samplesNoZOffset[0] 00087 + voxelWeights[2][0][0] * samplesPosZOffset[0] 00088 + voxelWeights[0][1][0] * samplesNegZOffset[3] 00089 + voxelWeights[1][1][0] * samplesNoZOffset[3] 00090 + voxelWeights[2][1][0] * samplesPosZOffset[3] 00091 + voxelWeights[0][2][0] * samplesNegZOffset[6] 00092 + voxelWeights[1][2][0] * samplesNoZOffset[6] 00093 + voxelWeights[2][2][0] * samplesPosZOffset[6] 00094 + voxelWeights[0][0][1] * samplesNegZOffset[1] 00095 + voxelWeights[1][0][1] * samplesNoZOffset[1] 00096 + voxelWeights[2][0][1] * samplesPosZOffset[1] 00097 + voxelWeights[0][1][1] * samplesNegZOffset[4] 00098 + voxelWeights[2][1][1] * samplesPosZOffset[4] 00099 + voxelWeights[0][2][1] * samplesNegZOffset[7] 00100 + voxelWeights[1][2][1] * samplesNoZOffset[7] 00101 + voxelWeights[2][2][1] * samplesPosZOffset[7] 00102 + voxelWeights[0][0][2] * samplesNegZOffset[2] 00103 + voxelWeights[1][0][2] * samplesNoZOffset[2] 00104 + voxelWeights[2][0][2] * samplesPosZOffset[2] 00105 + voxelWeights[0][1][2] * samplesNegZOffset[3] 00106 + voxelWeights[1][1][2] * samplesNoZOffset[5] 00107 + voxelWeights[2][1][2] * samplesPosZOffset[5] 00108 + voxelWeights[0][2][2] * samplesNegZOffset[8] 00109 + voxelWeights[1][2][2] * samplesNoZOffset[8] 00110 + voxelWeights[2][2][2] * samplesPosZOffset[8])); 00111 00112 00113 float fGx(gradientXWeight * 00114 (- voxelWeights[0][0][0] * samplesNegZOffset[0] 00115 - voxelWeights[1][0][0] * samplesNoZOffset[0] 00116 - voxelWeights[2][0][0] * samplesPosZOffset[0] 00117 - voxelWeights[0][1][0] * samplesNegZOffset[3] 00118 - voxelWeights[1][1][0] * samplesNoZOffset[3] 00119 - voxelWeights[2][1][0] * samplesPosZOffset[3] 00120 - voxelWeights[0][2][0] * samplesNegZOffset[6] 00121 - voxelWeights[1][2][0] * samplesNoZOffset[6] 00122 - voxelWeights[2][2][0] * samplesPosZOffset[6] 00123 + voxelWeights[0][0][2] * samplesNegZOffset[2] 00124 + voxelWeights[1][0][2] * samplesNoZOffset[2] 00125 + voxelWeights[2][0][2] * samplesPosZOffset[2] 00126 + voxelWeights[0][1][2] * samplesNegZOffset[3] 00127 + voxelWeights[1][1][2] * samplesNoZOffset[5] 00128 + voxelWeights[2][1][2] * samplesPosZOffset[5] 00129 + voxelWeights[0][2][2] * samplesNegZOffset[8] 00130 + voxelWeights[1][2][2] * samplesNoZOffset[8] 00131 + voxelWeights[2][2][2] * samplesPosZOffset[8])); 00132 00133 float fGy(gradientYWeight * 00134 (- voxelWeights[0][0][0] * samplesNegZOffset[0] 00135 - voxelWeights[1][0][0] * samplesNoZOffset[0] 00136 - voxelWeights[2][0][0] * samplesPosZOffset[0] 00137 + voxelWeights[0][2][0] * samplesNegZOffset[6] 00138 + voxelWeights[1][2][0] * samplesNoZOffset[6] 00139 + voxelWeights[2][2][0] * samplesPosZOffset[6] 00140 - voxelWeights[0][0][1] * samplesNegZOffset[1] 00141 - voxelWeights[1][0][1] * samplesNoZOffset[1] 00142 - voxelWeights[2][0][1] * samplesPosZOffset[1] 00143 + voxelWeights[0][2][1] * samplesNegZOffset[7] 00144 + voxelWeights[1][2][1] * samplesNoZOffset[7] 00145 + voxelWeights[2][2][1] * samplesPosZOffset[7] 00146 - voxelWeights[0][0][2] * samplesNegZOffset[2] 00147 - voxelWeights[1][0][2] * samplesNoZOffset[2] 00148 - voxelWeights[2][0][2] * samplesPosZOffset[2] 00149 + voxelWeights[0][2][2] * samplesNegZOffset[8] 00150 + voxelWeights[1][2][2] * samplesNoZOffset[8] 00151 + voxelWeights[2][2][2] * samplesPosZOffset[8])); 00152 00153 00154 float fGz(gradientZWeight * 00155 (- voxelWeights[0][0][0] * samplesNegZOffset[0] 00156 + voxelWeights[2][0][0] * samplesPosZOffset[0] 00157 - voxelWeights[0][1][0] * samplesNegZOffset[3] 00158 + voxelWeights[2][1][0] * samplesPosZOffset[3] 00159 - voxelWeights[0][2][0] * samplesNegZOffset[6] 00160 + voxelWeights[2][2][0] * samplesPosZOffset[6] 00161 - voxelWeights[0][0][1] * samplesNegZOffset[1] 00162 + voxelWeights[2][0][1] * samplesPosZOffset[1] 00163 - voxelWeights[0][1][1] * samplesNegZOffset[4] 00164 + voxelWeights[2][1][1] * samplesPosZOffset[4] 00165 - voxelWeights[0][2][1] * samplesNegZOffset[7] 00166 + voxelWeights[2][2][1] * samplesPosZOffset[7] 00167 - voxelWeights[0][0][2] * samplesNegZOffset[2] 00168 + voxelWeights[2][0][2] * samplesPosZOffset[2] 00169 - voxelWeights[0][1][2] * samplesNegZOffset[3] 00170 + voxelWeights[2][1][2] * samplesPosZOffset[5] 00171 - voxelWeights[0][2][2] * samplesNegZOffset[8] 00172 + voxelWeights[2][2][2] * samplesPosZOffset[8])); 00173 00174 m_VoxelData = fValue; 00175 m_Gradient = VVector(fGx,fGy,fGz); 00176 } 00177 00178 00183 float getData() 00184 { 00185 return m_VoxelData; 00186 } 00187 00192 float getGradientMagnitude() 00193 { 00194 return m_Gradient.getMagnitude(); 00195 } 00196 00201 float * getDataPtr() 00202 { 00203 return &m_VoxelData; 00204 } 00205 00210 float * getGradientPtr() 00211 { 00212 return m_Gradient.getPtr(); 00213 } 00214 00219 VVector getGradient() 00220 { 00221 return m_Gradient; 00222 } 00223 00228 void setGradient(VVector gradient) 00229 { 00230 m_Gradient = gradient; 00231 } 00232 00233 private: 00234 float m_VoxelData; 00235 VVector m_Gradient; 00236 }; 00237 00238 #endif //__v_voxel_h