diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index e526d6a..61dbf0f 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -4,16 +4,12 @@ #include #include -#define BLACK 0xFF000000 -#define RED 0xFFFF0000 -#define WHITE 0xFFFFFFFF -#define BLUE 0xFF0000FF - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + ui->graphicsView->setScene(&scene); } MainWindow::~MainWindow() @@ -27,12 +23,11 @@ void MainWindow::on_pushLoad_clicked() if (filename.isNull()) return; QFileInfo pathInfo(filename); if (!vdata.load(pathInfo.path(), pathInfo.fileName())) { - QMessageBox("Error", "Error loading data"); + qDebug() << "Error loading data"; } else { - ui->sliderPosition->setMaximum(vdata.getDimZ()); + ui->sliderPosition->setMaximum(vdata.getDimZ()-1); ui->sliderPosition->setValue(vdata.getDimZ()/2); } - } /* @@ -134,7 +129,31 @@ void MainWindow::floodfill(QImage &img) void MainWindow::on_sliderPosition_valueChanged(int value) { QPixmap pixmap; + if (ui->checkThreshold->checkState() != Qt::Unchecked) { + int threshold = ui->sliderThreshold->value(); + QImage *img = new QImage(*vdata.getSlice(value)); + for (int x = 0; x < img->width(); ++x) { + for (int y = 0; y < img->height(); ++y) { + img->setPixel(x,y, ((img->pixel(x,y) & 0xFF) > threshold) ? 255 : 0); + } + } + pixmap.convertFromImage(*img); + delete img; + } else { + pixmap.convertFromImage(*vdata.getSlice(value)); + } scene.clear(); - pixmap.convertFromImage(image); scene.addPixmap(pixmap); } + +void MainWindow::on_sliderThreshold_valueChanged(int value) +{ + if (ui->checkThreshold->checkState() != Qt::Unchecked) { + on_sliderPosition_valueChanged(ui->sliderPosition->value()); + } +} + +void MainWindow::on_checkThreshold_clicked() +{ + on_sliderPosition_valueChanged(ui->sliderPosition->value()); +} diff --git a/qt/mainwindow.h b/qt/mainwindow.h index 0992c41..7248f77 100644 --- a/qt/mainwindow.h +++ b/qt/mainwindow.h @@ -22,10 +22,13 @@ private slots: void on_sliderPosition_valueChanged(int value); + void on_sliderThreshold_valueChanged(int value); + + void on_checkThreshold_clicked(); + private: Ui::MainWindow *ui; VoxelData vdata; - QImage img; QGraphicsScene scene; }; diff --git a/qt/mainwindow.ui b/qt/mainwindow.ui index 8a2330c..76410a2 100644 --- a/qt/mainwindow.ui +++ b/qt/mainwindow.ui @@ -44,7 +44,7 @@ 530 - 330 + 350 141 20 @@ -72,45 +72,6 @@ Save - - - - 530 - 160 - 41 - 31 - - - - A-P - - - - - - 580 - 160 - 41 - 31 - - - - D-V - - - - - - 630 - 160 - 41 - 31 - - - - L-R - - @@ -159,7 +120,7 @@ 0 - + 530 @@ -172,6 +133,35 @@ 0 + + + + 530 + 180 + 141 + 21 + + + + Slice: + + + Qt::AlignCenter + + + + + + 530 + 330 + 141 + 20 + + + + Active + + diff --git a/qt/voxeldata.cpp b/qt/voxeldata.cpp index 8a1c8da..6a1bdea 100644 --- a/qt/voxeldata.cpp +++ b/qt/voxeldata.cpp @@ -6,28 +6,23 @@ bool VoxelData::load(QString path, QString filename) { + data.clear(); qDebug() << "Processing " + path + "/" + filename + " ..."; QFile file(path + "/" + filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return false; QTextStream in(&file); - int z = 0; - data = new VOXELDATA[512*512*512]; while (!in.atEnd()) { QString line = in.readLine(); - QImage img; qDebug() << "Loading " + line + " ..."; - img.load(path + "/" + line); - dimx = img.width(); - dimy = img.height(); - 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++; + data.push_back(new QImage(path + "/" + line)); } - dimz = z; + dimz = data.size(); file.close(); return true; } + +const QImage *VoxelData::getSlice(int z) +{ + return data[z]; +} diff --git a/qt/voxeldata.h b/qt/voxeldata.h index 82b4126..c1dfd49 100644 --- a/qt/voxeldata.h +++ b/qt/voxeldata.h @@ -2,8 +2,8 @@ #define VOXELDATA_H #include - -#define VOXELDATA unsigned char +#include +#include class VoxelData { @@ -12,9 +12,10 @@ public: inline int getDimY() { return dimy; } inline int getDimZ() { return dimz; } bool load(QString path, QString filename); + const QImage *getSlice(int z); private: int dimx, dimy, dimz; - VOXELDATA *data; + QVector data; }; #endif