-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray_cast_mip.cpp
More file actions
115 lines (96 loc) · 3.43 KB
/
Copy pathray_cast_mip.cpp
File metadata and controls
115 lines (96 loc) · 3.43 KB
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
#include <vtkCamera.h>
#include <vtkColorTransferFunction.h>
#include <vtkContourValues.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkMetaImageReader.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOpenGLGPUVolumeRayCastMapper.h>
#include <vtkPiecewiseFunction.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>
#include <iostream>
#include "load_dicom.h"
#include "load_3d.h"
#include "ray_cast_actor.h"
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " filepath [is_poly=false]" << std::endl;
std::cout << "e.g. dicom" << std::endl;
return EXIT_FAILURE;
}
bool is_poly = false;
vtkSmartPointer<vtkImageData> imgdata = nullptr;
if (argc > 2 && std::string(argv[2]) == "true")
{
auto polydata = ReadPolyData(argv[1]);
double spacing[]{1, 1, 1};
imgdata = ConvertMeshPolyDataToImageData(polydata, spacing);
is_poly = true;
}
else
imgdata = ReadDicomFolder(argv[1]);
assert(imgdata);
vtkNew<vtkNamedColors> colors;
vtkNew<vtkOpenGLGPUVolumeRayCastMapper> mapper;
mapper->SetInputData(imgdata);
mapper->Update();
// mapper->AutoAdjustSampleDistancesOff();
// mapper->SetSampleDistance(0.5);
mapper->AutoAdjustSampleDistancesOn();
mapper->SetBlendModeToMaximumIntensity();
vtkNew<vtkColorTransferFunction> colorTransferFunction;
colorTransferFunction->RemoveAllPoints();
if (is_poly)
{
colorTransferFunction->AddRGBPoint(0, 1.0, 1.0, 1.0);
colorTransferFunction->AddRGBPoint(255, 1.0, 1.0, 1.0);
}
else
{
// bone: https://examples.vtk.org/site/Cxx/VolumeRendering/FixedPointVolumeRayCastMapperCT/
colorTransferFunction->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
colorTransferFunction->AddRGBPoint(-16, 0.73, 0.25, 0.30, 0.49, .61);
colorTransferFunction->AddRGBPoint(641, .90, .82, .56, .5, 0.0);
colorTransferFunction->AddRGBPoint(3071, 1, 1, 1, .5, 0.0);
}
vtkNew<vtkPiecewiseFunction> scalarOpacity;
if (is_poly)
scalarOpacity->AddSegment(0, 1.0, 256, 0.1);
else
{
scalarOpacity->AddPoint(-3024, 0, 0.5, 0.0);
scalarOpacity->AddPoint(-16, 0, .49, .61);
scalarOpacity->AddPoint(641, .72, .5, 0.0);
scalarOpacity->AddPoint(3071, .71, 0.5, 0.0);
}
vtkNew<vtkVolumeProperty> volumeProperty;
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(scalarOpacity);
vtkNew<vtkVolume> volume;
volume->SetMapper(mapper);
volume->SetProperty(volumeProperty);
vtkNew<vtkRenderer> renderer;
renderer->AddVolume(volume);
renderer->SetBackground(colors->GetColor3d("cornflower").GetData());
renderer->ResetCamera();
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(800, 600);
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("RayCastIsosurface");
vtkNew<vtkInteractorStyleTrackballCamera> style;
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
interactor->SetInteractorStyle(style);
renderer->ResetCamera();
renderer->ResetCameraClippingRange();
renderWindow->Render();
interactor->Start();
return EXIT_SUCCESS;
}