From 8039ff529a6b13cd9643a6120d24deeac50b10ee Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 15 Oct 2011 19:43:44 +0200 Subject: [PATCH] store images into structure --- qt/mainwindow.cpp | 18 ++++++++++++++++-- qt/mainwindow.h | 4 ++++ qt/voxeldata.cpp | 12 ++++++++---- qt/voxeldata.h | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 051c320..e526d6a 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -2,6 +2,7 @@ #include "ui_mainwindow.h" #include #include +#include #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); +} diff --git a/qt/mainwindow.h b/qt/mainwindow.h index 076e1e0..0992c41 100644 --- a/qt/mainwindow.h +++ b/qt/mainwindow.h @@ -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 diff --git a/qt/voxeldata.cpp b/qt/voxeldata.cpp index 6ae8042..8a1c8da 100644 --- a/qt/voxeldata.cpp +++ b/qt/voxeldata.cpp @@ -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; } diff --git a/qt/voxeldata.h b/qt/voxeldata.h index e2b1c28..82b4126 100644 --- a/qt/voxeldata.h +++ b/qt/voxeldata.h @@ -3,7 +3,7 @@ #include -#define VOXELDATA char +#define VOXELDATA unsigned char class VoxelData {