Mercurial > hg > orthanc
annotate Resources/Samples/OrthancClient/Vtk/main.cpp @ 1375:3d76e26b3865
fix licensing terms of samples
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 28 May 2015 15:53:58 +0200 |
parents | 6e7e5ed91c2d |
children |
rev | line source |
---|---|
531 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
531 | 5 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
9 * License, or (at your option) any later version. |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
10 * |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, but |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
14 * General Public License for more details. |
531 | 15 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
531 | 18 **/ |
19 | |
20 | |
21 #include <iostream> | |
22 | |
23 #include <vtkRenderWindow.h> | |
24 #include <vtkImageData.h> | |
25 #include <vtkPiecewiseFunction.h> | |
26 #include <vtkFixedPointVolumeRayCastMapper.h> | |
27 #include <vtkColorTransferFunction.h> | |
28 #include <vtkVolumeProperty.h> | |
29 #include <vtkRenderWindowInteractor.h> | |
30 #include <vtkRenderer.h> | |
31 #include <vtkSmartPointer.h> | |
32 #include <vtkOpenGLRenderer.h> | |
33 #include <vtkInteractorStyleTrackballCamera.h> | |
34 | |
588
a0001c222b32
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
531
diff
changeset
|
35 #include <orthanc/OrthancCppClient.h> |
531 | 36 |
37 | |
38 void Display(OrthancClient::Series& series) | |
39 { | |
40 /** | |
41 * Load the 3D image from Orthanc into VTK. | |
42 **/ | |
43 | |
44 vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New(); | |
45 image->SetDimensions(series.GetWidth(), series.GetHeight(), series.GetInstanceCount()); | |
46 image->SetScalarType(VTK_SHORT); | |
47 image->AllocateScalars(); | |
48 | |
49 if (series.GetWidth() != 0 && | |
50 series.GetHeight() != 0 && | |
51 series.GetInstanceCount() != 0) | |
52 { | |
53 series.Load3DImage(image->GetScalarPointer(0, 0, 0), Orthanc::PixelFormat_SignedGrayscale16, | |
54 2 * series.GetWidth(), 2 * series.GetHeight() * series.GetWidth()); | |
55 } | |
56 | |
57 image->SetSpacing(series.GetVoxelSizeX(), | |
58 series.GetVoxelSizeY(), | |
59 series.GetVoxelSizeZ()); | |
60 | |
61 | |
62 /** | |
63 * The following code is based on the VTK sample for MIP | |
64 * http://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/MinIntensityRendering | |
65 **/ | |
66 | |
67 // Create a transfer function mapping scalar value to opacity | |
68 double range[2]; | |
69 image->GetScalarRange(range); | |
70 | |
71 vtkSmartPointer<vtkPiecewiseFunction> opacityTransfer = | |
72 vtkSmartPointer<vtkPiecewiseFunction>::New(); | |
73 opacityTransfer->AddSegment(range[0], 0.0, range[1], 1.0); | |
74 | |
75 vtkSmartPointer<vtkColorTransferFunction> colorTransfer = | |
76 vtkSmartPointer<vtkColorTransferFunction>::New(); | |
77 colorTransfer->AddRGBPoint(0, 1.0, 1.0, 1.0); | |
78 colorTransfer->AddRGBPoint(range[1], 1.0, 1.0, 1.0); | |
79 | |
80 vtkSmartPointer<vtkVolumeProperty> property = | |
81 vtkSmartPointer<vtkVolumeProperty>::New(); | |
82 property->SetScalarOpacity(opacityTransfer); | |
83 property->SetColor(colorTransfer); | |
84 property->SetInterpolationTypeToLinear(); | |
85 | |
86 // Create a Maximum Intensity Projection rendering | |
87 vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> mapper = | |
88 vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New(); | |
89 mapper->SetBlendModeToMaximumIntensity(); | |
90 mapper->SetInput(image); | |
91 | |
92 vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New(); | |
93 volume->SetMapper(mapper); | |
94 volume->SetProperty(property); | |
95 | |
96 vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkOpenGLRenderer>::New(); | |
97 renderer->AddViewProp(volume); | |
98 renderer->SetBackground(0.1, 0.2, 0.3); // Background color dark blue | |
99 | |
100 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = | |
101 vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New(); | |
102 | |
103 vtkSmartPointer<vtkRenderWindow> window = vtkSmartPointer<vtkRenderWindow>::New(); | |
104 window->AddRenderer(renderer); | |
105 | |
106 vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); | |
107 interactor->SetRenderWindow(window); | |
108 interactor->SetInteractorStyle(style); | |
109 interactor->Start(); | |
110 } | |
111 | |
112 | |
113 int main() | |
114 { | |
115 try | |
116 { | |
588
a0001c222b32
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
531
diff
changeset
|
117 // The following explicit initialization is not required, except |
a0001c222b32
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
531
diff
changeset
|
118 // if you wish to specify the full path to the shared library |
a0001c222b32
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
531
diff
changeset
|
119 OrthancClient::Initialize(); |
531 | 120 |
121 // Use the commented code below if you know the identifier of a | |
122 // series that corresponds to a 3D image. | |
123 | |
124 /* | |
125 { | |
126 OrthancClient::OrthancConnection orthanc("http://localhost:8042"); | |
588
a0001c222b32
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
531
diff
changeset
|
127 OrthancClient::Series series(orthanc, "dc5ec3d9-6e1a7b2c-73a829f0-64c609f6-ef976a97"); |
531 | 128 Display(series); |
129 return 0; | |
130 } | |
131 */ | |
132 | |
133 | |
134 // Try and find a 3D image inside the local store | |
135 OrthancClient::OrthancConnection orthanc("http://localhost:8042"); | |
136 | |
137 for (unsigned int i = 0; i < orthanc.GetPatientCount(); i++) | |
138 { | |
591 | 139 OrthancClient::Patient patient(orthanc.GetPatient(i)); |
531 | 140 std::cout << "Patient: " << patient.GetId() << std::endl; |
141 | |
142 for (unsigned int j = 0; j < patient.GetStudyCount(); j++) | |
143 { | |
591 | 144 OrthancClient::Study study(patient.GetStudy(j)); |
531 | 145 std::cout << " Study: " << study.GetId() << std::endl; |
146 | |
147 for (unsigned int k = 0; k < study.GetSeriesCount(); k++) | |
148 { | |
591 | 149 OrthancClient::Series series(study.GetSeries(k)); |
531 | 150 std::cout << " Series: " << series.GetId() << std::endl; |
151 | |
152 if (series.Is3DImage()) | |
153 { | |
154 Display(series); | |
155 return 0; | |
156 } | |
157 else | |
158 { | |
159 std::cout << " => Not a 3D image..." << std::endl; | |
160 } | |
161 } | |
162 } | |
163 } | |
164 | |
165 std::cout << "Unable to find a 3D image in the local Orthanc store" << std::endl; | |
166 | |
167 return 0; | |
168 } | |
656 | 169 catch (OrthancClient::OrthancClientException& e) |
531 | 170 { |
171 std::cerr << "EXCEPTION: [" << e.What() << "]" << std::endl; | |
172 return -1; | |
173 } | |
174 } |