store images into structure

This commit is contained in:
Pavol Rusnak 2011-10-15 19:43:44 +02:00
parent a0d3dba238
commit 8039ff529a
4 changed files with 29 additions and 7 deletions

View file

@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <qdebug.h>
#include <QMessageBox>
#define BLACK 0xFF000000
#define RED 0xFFFF0000
@ -13,7 +14,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
@ -26,7 +26,13 @@ void MainWindow::on_pushLoad_clicked()
QString filename = QFileDialog::getOpenFileName(this, "Open Image", "", "Series of medical files (*.txt)");
if (filename.isNull()) return;
QFileInfo pathInfo(filename);
vdata.load(pathInfo.path(), pathInfo.fileName());
if (!vdata.load(pathInfo.path(), pathInfo.fileName())) {
QMessageBox("Error", "Error loading data");
} else {
ui->sliderPosition->setMaximum(vdata.getDimZ());
ui->sliderPosition->setValue(vdata.getDimZ()/2);
}
}
/*
@ -124,3 +130,11 @@ void MainWindow::floodfill(QImage &img)
}
*/
void MainWindow::on_sliderPosition_valueChanged(int value)
{
QPixmap pixmap;
scene.clear();
pixmap.convertFromImage(image);
scene.addPixmap(pixmap);
}

View file

@ -20,9 +20,13 @@ public:
private slots:
void on_pushLoad_clicked();
void on_sliderPosition_valueChanged(int value);
private:
Ui::MainWindow *ui;
VoxelData vdata;
QImage img;
QGraphicsScene scene;
};
#endif // MAINWINDOW_H

View file

@ -11,7 +11,7 @@ bool VoxelData::load(QString path, QString filename)
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
QTextStream in(&file);
int i = 0;
int z = 0;
data = new VOXELDATA[512*512*512];
while (!in.atEnd()) {
QString line = in.readLine();
@ -20,10 +20,14 @@ bool VoxelData::load(QString path, QString filename)
img.load(path + "/" + line);
dimx = img.width();
dimy = img.height();
qDebug() << img.format() ;
i++;
for (int x = 0; x < dimx; ++x) {
for (int y = 0; y < dimy; ++y) {
data[ x + y*512 + z*512*512] = img.pixel(x,y) & 0xFF;
}
}
z++;
}
dimz = i;
dimz = z;
file.close();
return true;
}

View file

@ -3,7 +3,7 @@
#include <QString>
#define VOXELDATA char
#define VOXELDATA unsigned char
class VoxelData
{