This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
136 lines (90 loc) · 3.69 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkImageData.h>
#include <vtkImagePlaneWidget.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkSLCReader.h>
#include <vtkImageThreshold.h>
#include <vtkContourFilter.h>
#include <vtkVolumeTextureMapper2D.h>
#include <vtkVolume.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkVolumeProperty.h>
#include "vtkSmartPointer.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
vtkSLCReader *slcreader = vtkSLCReader::New();
slcreader->SetFileName("vm_foot.slc");
vtkVolumeTextureMapper2D *negMapper = vtkVolumeTextureMapper2D::New();
negMapper->SetInput(slcreader->GetOutput());
m_opacityFunction = vtkPiecewiseFunction::New();
m_colorTransferFunction = vtkColorTransferFunction::New();
vtkVolumeProperty *vol = vtkVolumeProperty::New();
vol->SetColor(m_colorTransferFunction);
vol->SetScalarOpacity(m_opacityFunction);
Update();
vtkVolume *volume = vtkVolume::New();
volume->SetMapper(negMapper);
volume->SetProperty(vol);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddVolume(volume);
renderer->ResetCamera();
this->ui->qVtkWidget->GetRenderWindow()->AddRenderer(renderer);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::Update()
{
// Zone 1
float intensity1 = this->ui->IntensitySpinBox->value();
float redInit = this->ui->RedInitSpinBox->value();
float redFinal = this->ui->RedFinalSpinBox->value();
float greenInit = this->ui->GreenInitSpinBox->value();
float greenFinal = this->ui->GreenFinalSpinBox->value();
float blueInit = this->ui->BlueInitSpinBox->value();
float blueFinal = this->ui->BlueFinalSpinBox->value();
float alphaInit = this->ui->AlphaInitSpinBox->value();
float alphaFinal = this->ui->AlphaFinalSpinBox->value();
// Zone 2
float intensity2 = this->ui->Intensity2SpinBox->value();
float red2Init = this->ui->Red2InitSpinBox->value();
float red2Final = this->ui->Red2FinalSpinBox->value();
float green2Init = this->ui->Green2InitSpinBox->value();
float green2Final = this->ui->Green2FinalSpinBox->value();
float blue2Init = this->ui->Blue2InitSpinBox->value();
float blue2Final = this->ui->Blue2FinalSpinBox->value();
float alpha2Init = this->ui->Alpha2InitSpinBox->value();
float alpha2Final = this->ui->Alpha2FinalSpinBox->value();
// Color Transfer funcions
m_colorTransferFunction->RemoveAllPoints();
m_colorTransferFunction->AddRGBPoint(0,0,0,0);
m_colorTransferFunction->AddRGBPoint(intensity1,0,0,0);
m_colorTransferFunction->AddRGBPoint(intensity1+1,redInit,greenInit,blueInit);
m_colorTransferFunction->AddRGBPoint(intensity2,redFinal,greenFinal,blueFinal);
m_colorTransferFunction->AddRGBPoint(intensity2+1,red2Init,green2Init,blue2Init);
m_colorTransferFunction->AddRGBPoint(255,red2Final,green2Final,blue2Final);
// Opacity Transfer funcion
m_opacityFunction->RemoveAllPoints();
m_opacityFunction->AddPoint(0,0);
m_opacityFunction->AddPoint(intensity1,0);
m_opacityFunction->AddPoint(intensity1+1,alphaInit);
m_opacityFunction->AddPoint(intensity2,alphaFinal);
m_opacityFunction->AddPoint(intensity2+1,alpha2Init);
m_opacityFunction->AddPoint(255,alpha2Final);
// Refresh the widget to reflect changes.
ui->qVtkWidget->repaint();
}