This commit is contained in:
Pavol Rusnak 2011-10-15 19:02:14 +02:00
commit a0d3dba238
827 changed files with 1224 additions and 0 deletions

2
qt/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.pro.user
_build

11
qt/main.cpp Normal file
View file

@ -0,0 +1,11 @@
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

126
qt/mainwindow.cpp Normal file
View file

@ -0,0 +1,126 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <qdebug.h>
#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);
}
MainWindow::~MainWindow()
{
delete ui;
}
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());
}
/*
void MainWindow::on_sliderThreshold_valueChanged(int value)
{
thresholdimage = shownimage;
for (int x = 0; x < shownimage.width(); ++x) {
for (int y = 0; y < shownimage.height(); ++y) {
int pval = shownimage.pixel(x, y) & 0xFF;
if (pval > value) {
thresholdimage.setPixel(x, y, WHITE);
} else {
thresholdimage.setPixel(x, y, BLACK);
}
}
}
scene.clear();
pixmap.convertFromImage(thresholdimage);
scene.addPixmap(pixmap);
}
*/
/*
void MainWindow::on_pushFill_clicked()
{
fillupimage = thresholdimage;
for (int x = 0; x < fillupimage.width(); ++x) {
for (int y = 0; y < fillupimage.height(); ++y) {
fillupimage.setPixel(x, y, BLACK);
}
}
for (int x = 0; x < thresholdimage.width()-1; ++x) {
for (int y = 0; y < thresholdimage.height()-1; ++y) {
int pval1 = thresholdimage.pixel(x, y) & 0xFF;
int pval2 = thresholdimage.pixel(x+1, y) & 0xFF;
int pval3 = thresholdimage.pixel(x, y+1) & 0xFF;
int pval4 = thresholdimage.pixel(x+1, y+1) & 0xFF;
int cnt = 0;
if (pval1 > 128) cnt++;
if (pval2 > 128) cnt++;
if (pval3 > 128) cnt++;
if (pval4 > 128) cnt++;
if (cnt < 4 && cnt > 1) {
for (int a = -3; a <= +3; ++a) {
for (int b = -3; b <= +3; ++b) {
if (abs(a) + abs(b) < 6) {
fillupimage.setPixel(x+a, y+b, WHITE);
}
}
}
}
}
}
floodfill(fillupimage);
for (int x = 0; x < fillupimage.width(); ++x) {
for (int y = 0; y < fillupimage.height(); ++y) {
if (fillupimage.pixel(x, y) == RED) {
fillupimage.setPixel(x, y, BLACK);
} else {
fillupimage.setPixel(x, y, WHITE);
}
}
}
scene.clear();
pixmap.convertFromImage(fillupimage);
scene.addPixmap(pixmap);
}
void MainWindow::floodfill(QImage &img)
{
QVector<QPoint> q;
q.push_back(QPoint(0,0));
while (!q.isEmpty()) {
QPoint p = q.last(); q.pop_back();
bool shouldBeRed = true;
for (int i = -1; i <= 1; ++i) {
for (int j = -1; j <= 1; ++j) {
if (i != 0 && j != 0 && img.valid(p.x()+i, p.y()+j) && img.pixel(p.x()+i, p.y()+j) == WHITE) shouldBeRed = false;
}
}
img.setPixel(p.x(),p.y(), shouldBeRed ? RED : BLUE);
if (p.x() > 0 && img.pixel(p.x()-1,p.y()) == BLACK) q.push_back(QPoint(p.x()-1,p.y()));
if (p.y() > 0 && img.pixel(p.x(),p.y()-1) == BLACK) q.push_back(QPoint(p.x(),p.y()-1));
if (p.x() < img.width()-1 && img.pixel(p.x()+1,p.y()) == BLACK) q.push_back(QPoint(p.x()+1,p.y()));
if (p.y() < img.height()-1 && img.pixel(p.x(),p.y()+1) == BLACK) q.push_back(QPoint(p.x(),p.y()+1));
}
}
*/

28
qt/mainwindow.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsScene>
#include "voxeldata.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushLoad_clicked();
private:
Ui::MainWindow *ui;
VoxelData vdata;
};
#endif // MAINWINDOW_H

180
qt/mainwindow.ui Normal file
View file

@ -0,0 +1,180 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>675</width>
<height>535</height>
</rect>
</property>
<property name="windowTitle">
<string>MediRap</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QGraphicsView" name="graphicsView">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>514</width>
<height>514</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
<widget class="QPushButton" name="pushLoad">
<property name="geometry">
<rect>
<x>530</x>
<y>10</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
<widget class="QSlider" name="sliderThreshold">
<property name="geometry">
<rect>
<x>530</x>
<y>330</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>128</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QPushButton" name="pushSave">
<property name="geometry">
<rect>
<x>530</x>
<y>460</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="text">
<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>
<x>530</x>
<y>200</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>128</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="labelThreshold">
<property name="geometry">
<rect>
<x>530</x>
<y>310</y>
<width>141</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Threshold:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QProgressBar" name="progressLoad">
<property name="geometry">
<rect>
<x>530</x>
<y>50</y>
<width>141</width>
<height>23</height>
</rect>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
<widget class="QProgressBar" name="progressLoad_2">
<property name="geometry">
<rect>
<x>530</x>
<y>500</y>
<width>141</width>
<height>23</height>
</rect>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

11
qt/medirap.pro Normal file
View file

@ -0,0 +1,11 @@
QT += core gui
TARGET = medirap
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp voxeldata.cpp
HEADERS += mainwindow.h voxeldata.h
FORMS += mainwindow.ui

29
qt/voxeldata.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "voxeldata.h"
#include <QFile>
#include <QImage>
#include <QTextStream>
#include <QDebug>
bool VoxelData::load(QString path, QString filename)
{
qDebug() << "Processing " + path + "/" + filename + " ...";
QFile file(path + "/" + filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
QTextStream in(&file);
int i = 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();
qDebug() << img.format() ;
i++;
}
dimz = i;
file.close();
return true;
}

20
qt/voxeldata.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef VOXELDATA_H
#define VOXELDATA_H
#include <QString>
#define VOXELDATA char
class VoxelData
{
public:
inline int getDimX() { return dimx; }
inline int getDimY() { return dimy; }
inline int getDimZ() { return dimz; }
bool load(QString path, QString filename);
private:
int dimx, dimy, dimz;
VOXELDATA *data;
};
#endif