11 #define min_val(VAL_X, VAL_Y) ((VAL_X < VAL_Y) ? VAL_X : VAL_Y)
29 m_fValue = datOther.m_fValue;
32 Voxel(
const float fValue)
42 void SetValue(
const float fValue)
47 float GetValue()
const
52 bool operator==(
const Voxel &datOther)
const
54 return (GetValue() == datOther.GetValue());
57 bool operator!=(
const Voxel &datOther)
const
59 return !(*
this == datOther);
62 bool operator>(
const Voxel &datOther)
const
64 return GetValue() > datOther.GetValue();
67 bool operator>=(
const Voxel &datOther)
const
69 return GetValue() >= datOther.GetValue();
72 bool operator<(
const Voxel &datOther)
const
74 return GetValue() < datOther.GetValue();
77 bool operator<=(
const Voxel &datOther)
const
79 return GetValue() <= datOther.GetValue();
82 const Voxel & operator+=(
const Voxel & datOther)
84 m_fValue += datOther.m_fValue;
88 const Voxel & operator-=(
const Voxel & datOther)
90 m_fValue -= datOther.m_fValue;
94 const Voxel & operator*=(
const float & fOther)
100 const Voxel & operator/=(
const float & fOther)
106 const Voxel operator+(
const Voxel & datOther)
const
108 Voxel voxNew = *
this;
113 const Voxel operator-(
const Voxel & datOther)
const
115 Voxel voxNew = *
this;
120 const Voxel operator*(
const float & fOther)
const
122 Voxel voxNew = *
this;
127 const Voxel operator/(
const float & fOther)
const
129 Voxel voxNew = *
this;
139 Volume() : m_iWidth(1), m_iHeight(1), m_iDepth(1), m_vecVoxels(1)
143 Volume(
const std::string &strFilename) : m_iWidth(1), m_iHeight(1), m_iDepth(1), m_vecVoxels(1)
145 loadRaw(strFilename, 64, 64, 64);
153 const Voxel & Get(
const int iX,
const int iY,
const int iZ)
const
155 return m_vecVoxels[iX + iY*m_iWidth + iZ*m_iWidth*m_iHeight];
158 const Voxel & Get(
const int iIndex)
const
160 return m_vecVoxels[iIndex];
163 const Voxel * Get()
const
165 return &(m_vecVoxels.front());
173 int GetHeight()
const
185 return int(m_vecVoxels.size());
189 void load(
const std::string & strFilename)
191 qDebug() <<
"Loading volume file \'" <<strFilename.c_str() <<
"\'";
194 fp = fopen(strFilename.c_str(),
"rb");
196 std::cerr <<
"+ Error loading file." << std::endl << std::endl;
198 unsigned short uWidth, uHeight, uDepth;
199 fread(&uWidth,
sizeof(
unsigned short),1,fp);
200 fread(&uHeight,
sizeof(
unsigned short),1,fp);
201 fread(&uDepth,
sizeof(
unsigned short),1,fp);
203 m_iWidth = int(uWidth);
204 m_iHeight = int(uHeight);
205 m_iDepth = int(uDepth);
207 std::cout <<
"Dataset size: " << m_iWidth <<
" x " << m_iHeight <<
" x " << m_iDepth << std::endl;
209 const int iSlice = m_iWidth * m_iHeight;
210 const int iSize = iSlice * m_iDepth;
211 m_vecVoxels.resize(iSize);
213 std::vector<unsigned short> vecData;
214 vecData.resize(iSize);
216 fread((
void*)&(vecData.front()),
sizeof(
unsigned short),iSize,fp);
219 std::cout <<
"- File loaded." << std::endl;
221 for (
int k=0;k<m_iDepth;k++) {
222 for (
int j=0;j<m_iHeight;j++) {
223 for (
int i=0;i<m_iWidth;i++) {
225 const float fValue = min_val(1.0f,
float(vecData[i + j*m_iWidth + k*iSlice]) / 4095.0f);
226 m_vecVoxels[i+j*m_iWidth+k*iSlice] = Voxel(fValue);
230 std::cout <<
"\r- Preparing data (" << (k*100) / (m_iDepth-1) <<
"%) ...";
233 std::cout << std::endl <<
"- Data prepared." << std::endl;
237 void loadRaw(
const std::string & strFilename,
const int iWidth,
const int iHeight,
const int iDepth)
239 std::cout <<
"- Loading RAW file '" << strFilename <<
"' ... " << std::endl;
242 fp = fopen(strFilename.c_str(),
"rb");
244 std::cerr <<
"+ Error loading file." << std::endl << std::endl;
252 const int iSlice = m_iWidth * m_iHeight;
253 const int iSize = iSlice * m_iDepth;
255 m_vecVoxels.resize(iSize);
257 std::vector<unsigned short> vecData;
258 vecData.resize(iSize);
260 fread((
void*)&(vecData.front()),
sizeof(
unsigned short),iSize,fp);
263 std::cout <<
"- File loaded." << std::endl;
265 for (
int k=0;k<m_iDepth;k++) {
266 for (
int j=0;j<m_iHeight;j++) {
267 for (
int i=0;i<m_iWidth;i++) {
269 const float fValue = min_val(1.0f,
float(vecData[i + j*m_iWidth + k*iSlice]) / 4095.0f);
270 m_vecVoxels[i+j*m_iWidth+k*iSlice] = Voxel(fValue);
274 std::cout <<
"\r- Preparing data (" << (k*100) / (m_iDepth-1) <<
"%) ...";
277 std::cout << std::endl <<
"- Data prepared." << std::endl;
283 int m_iWidth,m_iHeight,m_iDepth;
284 std::vector<Voxel> m_vecVoxels;