-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleap-vtk.cpp
172 lines (138 loc) · 5.59 KB
/
leap-vtk.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkRenderer.h>
#include <vtkVolumeProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkDICOMImageReader.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#include <vtkVolume.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkCallbackCommand.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>
#include <vtkCamera.h>
#include "Leap.h"
#include <iostream>
#include <string.h>
#include <math.h>
using namespace Leap;
int xSizeWindow = 1000;
int ySizeWindow = 1000;
std::string modes[3] = { "Mode1", "Mode2", "Mode3" };
int modeNumber = 0;
bool flashTextBackGround = false;
bool freez = false;
vtkSmartPointer<vtkCamera> camera;
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor;
vtkSmartPointer <vtkTextActor> textActor;
vtkVolume * volume;
Vector originVector;
Vector rotateVec;
Vector center;
// Add class definitions here
void initializeVectors();
void initializeReader(vtkDICOMImageReader *reader);
void setupVolumeProperty(vtkVolumeProperty *volumeProperty, vtkSmartVolumeMapper *mapper, vtkColorTransferFunction *color, vtkPiecewiseFunction *compositeOpacity);
void setupRenderer(vtkRenderer *renderer);
void initializeRenderWindowInteractor();
void initializeController(SampleListener &listener, Controller &controller);
void initializeTextActor(vtkRenderer *renderer);
void startRendering(Controller &controller, SampleListener &listener);
int main(int argc, char *argv[])
{
initializeVectors();
auto *reader = vtkDICOMImageReader::New();
initializeReader(reader);
auto mapper = vtkSmartPointer<vtkSmartVolumeMapper>::New();
auto *volumeProperty = vtkVolumeProperty::New();
auto *compositeOpacity = vtkPiecewiseFunction::New();
auto *color = vtkColorTransferFunction::New();
setupVolumeProperty(volumeProperty, mapper, color, compositeOpacity);
double xyz[3];
mapper->GetCenter(xyz);
volume = vtkVolume::New();
volume->SetMapper(mapper);
volume->SetProperty(volumeProperty);
volume->SetOrigin(xyz[0], xyz[1], xyz[2]);
volume->SetPosition(xyz[0], xyz[1], xyz[2]);
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddViewProp(volume);
setupRenderer(renderer);
initializeRenderWindowInteractor();
auto callback = vtkSmartPointer<vtkTimerCallback>::New();
auto callbackKeyPress = vtkSmartPointer<vtkKeyPressCallback>::New();
renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, callbackKeyPress);
renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, callback);
renderWindowInteractor->CreateRepeatingTimer(10);
SampleListener listener;
Controller controller;
initializeController(listener, controller);
initializeTextActor(renderer);
startRendering(controller, listener);
return EXIT_SUCCESS;
}
void initializeVectors() {
originVector.x = 0.0;
originVector.y = 0.0;
originVector.z = -1.0;
rotateVec.x = 0.0;
rotateVec.y = 0.0;
rotateVec.z = -1.0;
}
void initializeReader(vtkDICOMImageReader *reader) {
reader->SetDirectoryName("C:/Users/reza/Downloads/Compressed/New folder");
reader->Update();
}
void setupVolumeProperty(vtkVolumeProperty *volumeProperty, vtkSmartVolumeMapper *mapper, vtkColorTransferFunction *color, vtkPiecewiseFunction *compositeOpacity) {
mapper->SetBlendModeToComposite();
mapper->SetInputConnection(reader->GetOutputPort());
volumeProperty->SetAmbient(0.2);
volumeProperty->SetDiffuse(0.8);
volumeProperty->SetSpecular(0.5);
volumeProperty->SetSpecularPower(5);
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationType(VTK_CUBIC_INTERPOLATION);
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetScalarOpacityUnitDistance(5.0);
compositeOpacity->AddPoint(0.0, 0.0);
compositeOpacity->AddPoint(400, 1.0);
volumeProperty->SetScalarOpacity(compositeOpacity);
color->AddRGBPoint(-10, 0.0, 0.0, 0.0);
color->AddRGBPoint(200, 0.5, 0.5, 0.5);
color->AddRGBPoint(400, 1.0, 1.0, 1.0);
volumeProperty->SetColor(color);
}
void setupRenderer(vtkRenderer *renderer) {
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(xSizeWindow, ySizeWindow);
renderWindow->AddRenderer(renderer);
camera = vtkSmartPointer<vtkCamera>::New();
renderer->SetActiveCamera(camera);
renderer->ResetCamera();
camera->SetClippingRange(1, 5000);
}
void initializeRenderWindowInteractor() {
renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->SetInteractorStyle(nullptr);
renderWindowInteractor->Initialize();
}
void initializeController(SampleListener &listener, Controller &controller) {
controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP,true);
controller.addListener(listener);
}
void initializeTextActor(vtkRenderer *renderer) {
textActor = vtkSmartPointer<vtkTextActor>::New();
textActor->SetInput(modes[0].c_str());
textActor->SetPosition(10, 100);
textActor->GetTextProperty()->SetFontSize(48);
textActor->GetTextProperty()->SetColor(1.0, 0.0, 0.0);
renderer->AddActor2D(textActor);
}
void startRendering(Controller &controller, SampleListener &listener) {
renderWindow->Render();
renderWindowInteractor->Start();
controller.removeListener(listener);
}