rework on slicing and thresholding

This commit is contained in:
Pavol Rusnak 2011-10-21 21:08:39 +02:00
parent 8039ff529a
commit bc839e5d7c
5 changed files with 75 additions and 67 deletions

View file

@ -4,16 +4,12 @@
#include <qdebug.h>
#include <QMessageBox>
#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());
}

View file

@ -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;
};

View file

@ -44,7 +44,7 @@
<property name="geometry">
<rect>
<x>530</x>
<y>330</y>
<y>350</y>
<width>141</width>
<height>20</height>
</rect>
@ -72,45 +72,6 @@
<string>Save</string>
</property>
</widget>
<widget class="QPushButton" name="pushAxis1">
<property name="geometry">
<rect>
<x>530</x>
<y>160</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>A-P</string>
</property>
</widget>
<widget class="QPushButton" name="pushAxis2">
<property name="geometry">
<rect>
<x>580</x>
<y>160</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>D-V</string>
</property>
</widget>
<widget class="QPushButton" name="pushAxis3">
<property name="geometry">
<rect>
<x>630</x>
<y>160</y>
<width>41</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>L-R</string>
</property>
</widget>
<widget class="QSlider" name="sliderPosition">
<property name="geometry">
<rect>
@ -159,7 +120,7 @@
<number>0</number>
</property>
</widget>
<widget class="QProgressBar" name="progressLoad_2">
<widget class="QProgressBar" name="progressSave">
<property name="geometry">
<rect>
<x>530</x>
@ -172,6 +133,35 @@
<number>0</number>
</property>
</widget>
<widget class="QLabel" name="labelSlice">
<property name="geometry">
<rect>
<x>530</x>
<y>180</y>
<width>141</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Slice:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="checkThreshold">
<property name="geometry">
<rect>
<x>530</x>
<y>330</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>

View file

@ -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];
}

View file

@ -2,8 +2,8 @@
#define VOXELDATA_H
#include <QString>
#define VOXELDATA unsigned char
#include <QImage>
#include <QVector>
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<QImage *> data;
};
#endif