00001 #include "Volume.h"
00002 #include <QtDebug>
00003 #include <QFileDialog>
00004 #include <QMessageBox>
00005
00006 Volume::Volume() : width(1), height(1), depth(1), voxels(1), histogramm(1), heightHist(0)
00007 {
00008
00009 };
00010
00011 Volume::~Volume(void)
00012 {
00013 };
00014
00015 const int Volume::getWidth() const
00016 {
00017 return width;
00018 };
00019
00020 const int Volume::getHeight() const
00021 {
00022 return height;
00023 };
00024
00025 const int Volume::getDepth() const
00026 {
00027 return depth;
00028 };
00029
00030 const int Volume::getSize() const
00031 {
00032 return int(voxels.size());
00033 };
00034
00035 const unsigned short* Volume::getData() const
00036 {
00037 return &(voxels.front());
00038 }
00039
00040 const std::vector<unsigned int>* Volume::getHistogramm() const
00041 {
00042 return &histogramm;
00043 }
00044
00045 const unsigned int Volume::getHistHeight() const
00046 {
00047 return heightHist;
00048 }
00049
00050 const int Volume::getDataRange() const
00051 {
00052 return 4096;
00053 }
00054
00055 void Volume::loadDatFile()
00056 {
00057 QString fileName = QFileDialog::getOpenFileName(0,
00058 "Load Data", curDir,
00059 "Vis Data (*.dat);;All Files (*)");
00060 if(fileName!=0) {
00061 curDir = fileName;
00062 qDebug() << "Pfad vom File: " << fileName.toStdString().c_str();
00063 loadDatFile(fileName.toStdString().c_str());
00064 }
00065 }
00066
00067 void Volume::loadDatFile(const std::string &fileName)
00068 {
00069 qDebug() << "- Loading file '" << fileName.c_str() << "' ... ";
00070 FILE *file = NULL;
00071
00072 fopen_s(&file, fileName.c_str(), "rb");
00073
00074 if(!file)
00075 {
00076 QMessageBox::information(0, "Unable to load file", "");
00077 }
00078 else
00079 {
00080 unsigned short tempShort;
00081
00082 fread(&tempShort, sizeof(unsigned short), 1, file);
00083 width = int(tempShort);
00084 fread(&tempShort, sizeof(unsigned short), 1, file);
00085 height = int(tempShort);
00086 fread(&tempShort, sizeof(unsigned short), 1, file);
00087 depth = int(tempShort);
00088
00089 int size;
00090
00091 histogramm.resize(4096);
00092 for(unsigned int j=0;j<histogramm.size();j++) {
00093 histogramm[j] = 0;
00094 }
00095
00096 if(width % 2)
00097 {
00098 int realWidth = width;
00099 width = realWidth + realWidth % 2;
00100 size = width * height * depth;
00101 voxels.resize(size);
00102
00103 unsigned short *voxelPointer = &(voxels.front());
00104 for(int i = 0;i < height * depth;++i) {
00105 fread(voxelPointer + i * width, sizeof(unsigned short), realWidth, file);
00106 voxelPointer[i * width + realWidth] = 0;
00107 }
00108 }
00109 else
00110 {
00111 size = width * height * depth;
00112 voxels.resize(size);
00113 fread((void*)&(voxels.front()), sizeof(unsigned short), size, file);
00114 }
00115 fclose(file);
00116
00117 for(int i = 0;i < size;++i)
00118 {
00119 histogramm[voxels[i]]++;
00120 voxels[i] <<= 4;
00121 }
00122
00123 heightHist = 0;
00124 for(unsigned int k = 0;k <histogramm.size();k++)
00125 {
00126 if(heightHist<histogramm[k])
00127 {
00128 heightHist = histogramm[k];
00129 }
00130 }
00131
00132 qDebug() << "- File loaded. Size: " << width << height << depth;
00133
00134 emit loadedDatFile(this);
00135 QString temp = QString(fileName.c_str());
00136 QStringList tempList = temp.split("/");
00137 emit loadedDatFileName(tempList.last());
00138 }
00139 }