36 m_fValue = datOther.m_fValue;
39 Voxel(
const float fValue)
49 void SetValue(
const float fValue)
54 const float GetValue()
const
59 const bool operator==(
const Voxel &datOther)
const
61 return (GetValue() == datOther.GetValue());
64 const bool operator!=(
const Voxel &datOther)
const
66 return !(*
this == datOther);
69 const bool operator>(
const Voxel &datOther)
const
71 return GetValue() > datOther.GetValue();
74 const bool operator>=(
const Voxel &datOther)
const
76 return GetValue() >= datOther.GetValue();
79 const bool operator<(
const Voxel &datOther)
const
81 return GetValue() < datOther.GetValue();
84 const bool operator<=(
const Voxel &datOther)
const
86 return GetValue() <= datOther.GetValue();
89 const Voxel & operator+=(
const Voxel & datOther)
91 m_fValue += datOther.m_fValue;
95 const Voxel & operator-=(
const Voxel & datOther)
97 m_fValue -= datOther.m_fValue;
101 const Voxel & operator*=(
const float & fOther)
107 const Voxel & operator/=(
const float & fOther)
113 const Voxel operator+(
const Voxel & datOther)
const
115 Voxel voxNew = *
this;
120 const Voxel operator-(
const Voxel & datOther)
const
122 Voxel voxNew = *
this;
127 const Voxel operator*(
const float & fOther)
const
129 Voxel voxNew = *
this;
134 const Voxel operator/(
const float & fOther)
const
136 Voxel voxNew = *
this;
147 Volume() : m_iWidth(1), m_iHeight(1), m_iDepth(1), m_vecVoxels(1), hist(0)
151 Volume(
const std::string &strFilename) : m_iWidth(1), m_iHeight(1), m_iDepth(1), m_vecVoxels(1), hist(0)
163 const Voxel & Get(
const int iX,
const int iY,
const int iZ)
const
165 return m_vecVoxels[iX + iY*m_iWidth + iZ*m_iWidth*m_iHeight];
168 const Voxel & Get(
const int iIndex)
const
170 return m_vecVoxels[iIndex];
173 const Voxel * Get()
const
175 return &(m_vecVoxels.front());
178 const int GetWidth()
const
183 const int GetHeight()
const
188 const int GetDepth()
const
193 const int GetSize()
const
195 return int(m_vecVoxels.size());
199 double* getHistogram(
int scale) {
206 hist =
new double[4096/scale]();
207 for (
int i = 0; i < GetSize(); i++) {
209 index = (int)floorf(m_vecVoxels[i].GetValue()*4095.0f)/scale;
213 for (
int i = 0; i < (4096/scale); i++) {
214 hist[i] = log(hist[i]);
219 void load(
const std::string & strFilename)
221 cout <<
"- Loading file '" << strFilename <<
"' ... " << endl;
224 fopen_s(&fp,strFilename.c_str(),
"rb");
228 std::cerr <<
"+ Error loading file." << std::endl << endl;
233 char *pFileName = NULL;
234 GetFullPathName(strFilename.c_str(),1024,vcPath,&pFileName);
235 char vcDrive[1024], vcDirectory[1024], vcFilename[1024], vcExtension[1024];
236 _splitpath_s(vcPath,vcDrive,vcDirectory,vcFilename,vcExtension);
237 const std::string strAdditionalFilename = std::string(vcDrive)+std::string(vcDirectory)+std::string(vcFilename)+std::string(
".ini");
239 char vpSpacingX[1024],vpSpacingY[1024],vpSpacingZ[1024];
240 GetPrivateProfileString(
"DatFile",
"oldDat Spacing X",
"1.0",vpSpacingX,256,strAdditionalFilename.c_str());
241 GetPrivateProfileString(
"DatFile",
"oldDat Spacing Y",
"1.0",vpSpacingY,256,strAdditionalFilename.c_str());
242 GetPrivateProfileString(
"DatFile",
"oldDat Spacing Z",
"1.0",vpSpacingZ,256,strAdditionalFilename.c_str());
244 unsigned short uWidth, uHeight, uDepth;
245 fread(&uWidth,
sizeof(
unsigned short),1,fp);
246 fread(&uHeight,
sizeof(
unsigned short),1,fp);
247 fread(&uDepth,
sizeof(
unsigned short),1,fp);
249 m_iWidth = int(uWidth);
250 m_iHeight = int(uHeight);
251 m_iDepth = int(uDepth);
253 const int iSlice = m_iWidth * m_iHeight;
254 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 cout <<
"- File loaded." << endl;
265 for (
int k=0;k<m_iDepth;k++)
267 for (
int j=0;j<m_iHeight;j++)
269 for (
int i=0;i<m_iWidth;i++)
272 const float fValue = min(1.0f,
float(vecData[i + j*m_iWidth + k*iSlice]*16) / 65535.0f);
274 m_vecVoxels[i+j*m_iWidth+k*iSlice] = Voxel(fValue);
277 cout <<
"\r- Preparing data (" << (k*100) / (m_iDepth-1) <<
"%) ...";
280 cout << std::endl <<
"- Data prepared." << endl;
283 cout <<
"Volume dimensions: " << m_iWidth <<
" x " << m_iHeight <<
" x " << m_iDepth << endl;
286 std::vector<Voxel> m_vecVoxels;
291 int m_iWidth,m_iHeight,m_iDepth;