Go to the documentation of this file.00001 #include "slicingview.h"
00002 #include "Volume.h"
00003
00004 SlicingView::SlicingView(void)
00005 :QWidget(), volume(NULL), image(NULL)
00006 {
00007 }
00008
00009 SlicingView::SlicingView(QGroupBox*& gb)
00010 :QWidget(gb), volume(NULL), image(NULL)
00011 {
00012 }
00013
00014 SlicingView::~SlicingView()
00015 {
00016 }
00017
00018 void SlicingView::paintEvent(QPaintEvent* event)
00019 {
00020 QPainter painter(this);
00021 if (volume == NULL) {
00022 painter.fillRect(0, 0, this->width(), this->height(), QColor(0, 0, 0));
00023 return;
00024 }
00025 if (image != NULL) {
00026 delete image;
00027 image = NULL;
00028 }
00029 int x,y,z;
00030 int value;
00031 switch (this->direction) {
00032 case DIRECTION_X:
00033 x = this->position;
00034 if (x < 0 || x >= volume->GetWidth()) break;
00035 image = new QImage(volume->GetDepth(), volume->GetHeight(), QImage::Format_RGB32);
00036 for (y=0; y<volume->GetHeight(); y++) {
00037 for (z=0; z<volume->GetDepth(); z++) {
00038 value = (int)(volume->Get(x, y, z).GetValue() * 255.f);
00039 image->setPixel(z, y, qRgb(value, value, value));
00040 }
00041 }
00042 break;
00043 case DIRECTION_Y:
00044 y = this->position;
00045 if (y < 0 || y >= volume->GetHeight()) break;
00046 image = new QImage(volume->GetWidth(), volume->GetDepth(), QImage::Format_RGB32);
00047 for (x=0; x<volume->GetWidth(); x++) {
00048 for (z=0; z<volume->GetDepth(); z++) {
00049 value = (int)(volume->Get(x, y, z).GetValue() * 255.f);
00050 image->setPixel(x, z, qRgb(value, value, value));
00051 }
00052 }
00053 break;
00054 case DIRECTION_Z:
00055 z = this->position;
00056 if (z < 0 || z >= volume->GetDepth()) break;
00057 image = new QImage(volume->GetWidth(), volume->GetHeight(), QImage::Format_RGB32);
00058 for (x=0; x<volume->GetWidth(); x++) {
00059 for (y=0; y<volume->GetHeight(); y++) {
00060 value = (int)(volume->Get(x, y, z).GetValue() * 255.f);
00061 image->setPixel(x, y, qRgb(value, value, value));
00062 }
00063 }
00064 break;
00065 default: break;
00066 }
00067 if (image != NULL) {
00068 painter.drawImage(QRect(0, 0, this->width(), this->height()), *image);
00069 }
00070 }