|
11 | 11 | #include <vtkSmartVolumeMapper.h> |
12 | 12 | #include <vtkVolumeProperty.h> |
13 | 13 |
|
14 | | -int main(int, char* []) |
| 14 | +int main(int argc, char* argv[]) |
15 | 15 | { |
16 | | - int dim[3] = { 10, 10, 10 }; |
17 | | - double spc[3] = { 0.05, 0.05, 0.05 }; |
18 | | - vtkNew<vtkImageData> img; |
19 | | - img->SetDimensions(dim); |
20 | | - img->AllocateScalars(VTK_INT, 1); |
21 | | - img->SetSpacing(spc); |
22 | | - for (int x=0; x<dim[0]; ++x) |
23 | | - for (int y=0; y<dim[1]; ++y) |
24 | | - for (int z=0; z<dim[2]; ++z) |
25 | | - { |
26 | | - img->SetScalarComponentFromDouble(x, y, z, 0, x); |
27 | | - } |
28 | | - vtkNew<vtkColorSeries> colors; |
29 | | - colors->SetColorScheme(vtkColorSeries::BREWER_QUALITATIVE_SET3); |
30 | | - vtkNew<vtkColorTransferFunction> ctf; |
31 | | - for (int x = 0; x < dim[0]; ++x) |
32 | | - { |
33 | | - auto c = colors->GetColor(x); |
34 | | - ctf->AddRGBPoint(x, c.GetRed() / 255.0, c.GetGreen() / 255.0, c.GetBlue() / 255.0); |
35 | | - } |
36 | | - ctf->AddRGBPoint(dim[0], 1.0, 1.0, 1.0); |
37 | | - ctf->Build(); |
38 | | - vtkNew<vtkSmartVolumeMapper> volMapper; |
39 | | - vtkNew<vtkVolume> volume; |
40 | | - vtkNew<vtkVolumeProperty> volProp; |
41 | | - volMapper->SetBlendModeToComposite(); |
42 | | - volume->SetMapper(volMapper); |
43 | | - volume->SetProperty(volProp); |
44 | | - volume->SetVisibility(true); |
45 | | - volMapper->SetInputData(img); |
46 | | - volProp->SetColor(0, ctf); |
47 | | - vtkNew<vtkPiecewiseFunction> otf; |
48 | | - otf->AddPoint(0.0, 1.0); |
49 | | - otf->AddPoint(dim[0], 1.0); |
50 | | - volProp->SetScalarOpacity(0, otf); |
51 | | - volProp->Modified(); |
52 | | - volProp->SetScalarOpacityUnitDistance(1); |
| 16 | + int dim[3] = {10, 10, 10}; |
| 17 | + double spc[3] = {0.05, 0.05, 0.05}; |
| 18 | + vtkNew<vtkImageData> img; |
| 19 | + img->SetDimensions(dim); |
| 20 | + img->AllocateScalars(VTK_INT, 1); |
| 21 | + img->SetSpacing(spc); |
| 22 | + for (int x = 0; x < dim[0]; ++x) |
| 23 | + for (int y = 0; y < dim[1]; ++y) |
| 24 | + for (int z = 0; z < dim[2]; ++z) |
| 25 | + { |
| 26 | + img->SetScalarComponentFromDouble(x, y, z, 0, x); |
| 27 | + } |
| 28 | + vtkNew<vtkColorSeries> colors; |
| 29 | + colors->SetColorScheme(vtkColorSeries::BREWER_QUALITATIVE_SET3); |
| 30 | + vtkNew<vtkColorTransferFunction> ctf; |
| 31 | + for (int x = 0; x < dim[0]; ++x) |
| 32 | + { |
| 33 | + auto c = colors->GetColor(x); |
| 34 | + ctf->AddRGBPoint(x, c.GetRed() / 255.0, c.GetGreen() / 255.0, |
| 35 | + c.GetBlue() / 255.0); |
| 36 | + } |
| 37 | + ctf->AddRGBPoint(dim[0], 1.0, 1.0, 1.0); |
| 38 | + ctf->Build(); |
| 39 | + vtkNew<vtkSmartVolumeMapper> volMapper; |
| 40 | + vtkNew<vtkVolume> volume; |
| 41 | + vtkNew<vtkVolumeProperty> volProp; |
| 42 | + volMapper->SetBlendModeToComposite(); |
| 43 | + volume->SetMapper(volMapper); |
| 44 | + volume->SetProperty(volProp); |
| 45 | + volume->SetVisibility(true); |
| 46 | + volMapper->SetInputData(img); |
| 47 | + volProp->SetColor(0, ctf); |
| 48 | + vtkNew<vtkPiecewiseFunction> otf; |
| 49 | + otf->AddPoint(0.0, 1.0); |
| 50 | + otf->AddPoint(dim[0], 1.0); |
| 51 | + volProp->SetScalarOpacity(0, otf); |
| 52 | + volProp->Modified(); |
| 53 | + volProp->SetScalarOpacityUnitDistance(1); |
53 | 54 |
|
54 | | - vtkNew<vtkOpenVRRenderWindow> renderWindow; |
55 | | - renderWindow->Initialize(); |
56 | | - vtkNew<vtkOpenVRRenderWindowInteractor> renderWindowInteractor; |
57 | | - renderWindowInteractor->SetRenderWindow(renderWindow); |
| 55 | + vtkNew<vtkOpenVRRenderWindow> renderWindow; |
| 56 | + renderWindow->Initialize(); |
| 57 | + vtkNew<vtkOpenVRRenderWindowInteractor> renderWindowInteractor; |
| 58 | + renderWindowInteractor->SetRenderWindow(renderWindow); |
58 | 59 |
|
59 | | - vtkNew<vtkOpenVRRenderer> renderer; |
60 | | - renderWindow->AddRenderer(renderer); |
61 | | - vtkNew<vtkNamedColors> namedColors; |
62 | | - renderer->SetBackground(namedColors->GetColor3d("ForestGreen").GetData()); |
63 | | - renderer->AddVolume(volume); |
64 | | - volume->SetPosition(0, 0.5, 0); |
| 60 | + vtkNew<vtkOpenVRRenderer> renderer; |
| 61 | + renderWindow->AddRenderer(renderer); |
| 62 | + vtkNew<vtkNamedColors> namedColors; |
| 63 | + renderer->SetBackground(namedColors->GetColor3d("ForestGreen").GetData()); |
| 64 | + renderer->AddVolume(volume); |
| 65 | + volume->SetPosition(0, 0.5, 0); |
65 | 66 |
|
| 67 | + renderWindow->Render(); |
| 68 | + renderWindowInteractor->Start(); |
66 | 69 |
|
67 | | - renderWindow->Render(); |
68 | | - renderWindowInteractor->Start(); |
69 | | - |
70 | | - return EXIT_SUCCESS; |
| 70 | + return EXIT_SUCCESS; |
71 | 71 | } |
0 commit comments