00001 #ifndef __CVOLVOXELS_H__
00002 #define __CVOLVOXELS_H__
00003
00009 #include <windows.h>
00010 #include <math.h>
00011 #include <string>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <vector>
00015 #include <sstream>
00016 #include "utilityfuncs.h"
00017
00018 class CVoxelValue
00019 {
00020 public:
00021 CVoxelValue() { density = 0; diffuseVal = 0; }
00022 CVoxelValue(float i, float j)
00023 {
00024 density = i;
00025 diffuseVal = j;
00026 }
00027
00028 float density;
00029 float diffuseVal;
00030 };
00031
00032
00039 class CVolVoxels
00040 {
00041 public:
00042
00046 CVolVoxels()
00047 {
00048 _dimX = 0;
00049 _dimY = 0;
00050 _dimZ = 0;
00051
00052 _pVoxelData = 0;
00053 _ptmpVD = 0;
00054 _grad = 0;
00055 }
00056
00057 ~CVolVoxels()
00058 {
00059 Shutdown();
00060 }
00061
00066 void Shutdown()
00067 {
00068 if ( _pVoxelData )
00069 delete[] _pVoxelData;
00070
00071 if ( _grad )
00072 delete[] _grad;
00073
00074 _pVoxelData = 0;
00075 _grad = 0;
00076 _dimX = 0;
00077 _dimY = 0;
00078 _dimZ = 0;
00079 }
00080
00085 void Init( unsigned short * pVoxelData, unsigned short dimX, unsigned short dimY, unsigned short dimZ );
00086
00091 unsigned long GetDimX() { return _dimX; }
00092 unsigned long GetDimY() { return _dimY; }
00093 unsigned long GetDimZ() { return _dimZ; }
00094 unsigned long GetBoundingDim() { return _boundingDim; }
00095
00096 void ResetVolumePtr() { _ptmpVD = _pVoxelData; }
00097
00098 void GotoSliceX(int iSliceNum) { _ptmpVD = _pVoxelData + iSliceNum; }
00099 void GotoSliceY(int iSliceNum) { _ptmpVD = _pVoxelData + _dimX * iSliceNum; }
00100 void GotoSliceZ(int iSliceNum) { _ptmpVD = _pVoxelData + _dimX * _dimY * iSliceNum; }
00101
00102 void UseNextXSlice(int i) { _ptmpVD = _pVoxelData + i; }
00103 void UseNextYSlice(int i) { _ptmpVD = _pVoxelData + i * _dimX; }
00104 void UseNextZSlice(int i) { _ptmpVD = _pVoxelData + i * _dimX * _dimY; }
00105 void UseNextZSlice(int i, int offset) { _ptmpVD = _pVoxelData + i * _dimX;
00106 _ptmpVD += offset * _dimX * _dimY; }
00107
00113 unsigned short NextX() { unsigned short val = (*_ptmpVD); _ptmpVD++; return val; }
00114 unsigned short NextY() { unsigned short val = (*_ptmpVD); _ptmpVD += _dimX; return val; }
00115 unsigned short NextZ() { unsigned short val = (*_ptmpVD); _ptmpVD += _dimX * _dimY; return val; }
00116 unsigned short GetVoxelValue(unsigned i, unsigned j, unsigned k)
00117 {
00118
00119
00120
00121 return (* (_pVoxelData + _dimX * _dimY * k + _dimX * j + i) );
00122 }
00123
00129 float CVolVoxels::GetDensityTriLinear(sPoint3f pos);
00130
00131 unsigned short GetMaxValue();
00132 void ComputeGradient();
00133 void SetGradient(unsigned i, unsigned j, unsigned k, sVector3f grad)
00134 {
00135 (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).x = grad.x;
00136 (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).y = grad.y;
00137 (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).z = grad.z;
00138 }
00139
00140 void GetGradient(unsigned i, unsigned j, unsigned k, sGrad * grad)
00141 {
00142 grad->x = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).x;
00143 grad->y = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).y;
00144 grad->z = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).z;
00145 }
00146
00147 sGrad GetGradient(unsigned i, unsigned j, unsigned k)
00148 {
00149 sGrad grad;
00150
00151 grad.x = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).x;
00152 grad.y = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).y;
00153 grad.z = (* (_grad + _dimX * _dimY * k + _dimX * j + i) ).z;
00154
00155 return grad;
00156 }
00157
00162 void GetGradientTriLinear(float i, float j, float k, sGrad * pGrad);
00163
00164 private:
00165 unsigned long _dimX, _dimY, _dimZ;
00166 unsigned short * _pVoxelData;
00167 unsigned short * _ptmpVD;
00168
00169 unsigned long _boundingDim;
00170 unsigned long _MaxValue;
00171 unsigned long _size;
00172 sGrad * _grad;
00173
00174
00175 };
00176
00177 #endif