Mercurial > hg > orthanc-stone
annotate Framework/Volumes/ImageBuffer3D.cpp @ 281:300d8b8c48b3 am-2
mouse tracker tuning
author | am@osimis.io |
---|---|
date | Tue, 28 Aug 2018 10:01:31 +0200 |
parents | 5412adf19980 |
children | ce48c3b3b0e9 3a4ca166fafa |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "ImageBuffer3D.h" | |
23 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
24 #include <Core/Images/ImageProcessing.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
25 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/OrthancException.h> |
0 | 27 |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
28 #include <string.h> |
0 | 29 |
30 namespace OrthancStone | |
31 { | |
32 Orthanc::ImageAccessor ImageBuffer3D::GetAxialSliceAccessor(unsigned int slice, | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
33 bool readOnly) const |
0 | 34 { |
35 if (slice >= depth_) | |
36 { | |
37 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
38 } | |
39 | |
40 Orthanc::ImageAccessor accessor; | |
41 | |
42 if (readOnly) | |
43 { | |
44 accessor.AssignReadOnly(format_, width_, height_, image_.GetPitch(), | |
45 image_.GetConstRow(height_ * (depth_ - 1 - slice))); | |
46 } | |
47 else | |
48 { | |
49 accessor.AssignWritable(format_, width_, height_, image_.GetPitch(), | |
50 image_.GetRow(height_ * (depth_ - 1 - slice))); | |
51 } | |
52 | |
53 return accessor; | |
54 } | |
55 | |
56 | |
57 Orthanc::ImageAccessor ImageBuffer3D::GetCoronalSliceAccessor(unsigned int slice, | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
58 bool readOnly) const |
0 | 59 { |
60 if (slice >= height_) | |
61 { | |
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
63 } | |
64 | |
65 Orthanc::ImageAccessor accessor; | |
66 | |
67 if (readOnly) | |
68 { | |
69 accessor.AssignReadOnly(format_, width_, depth_, image_.GetPitch() * height_, | |
70 image_.GetConstRow(slice)); | |
71 } | |
72 else | |
73 { | |
74 accessor.AssignWritable(format_, width_, depth_, image_.GetPitch() * height_, | |
75 image_.GetRow(slice)); | |
76 } | |
77 | |
78 return accessor; | |
79 } | |
80 | |
81 | |
82 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const | |
83 { | |
84 if (slice >= width_) | |
85 { | |
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
87 } | |
88 | |
11 | 89 std::auto_ptr<Orthanc::Image> result(new Orthanc::Image(format_, height_, depth_, false)); |
0 | 90 |
91 unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); | |
92 | |
93 for (unsigned int z = 0; z < depth_; z++) | |
94 { | |
95 //uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(depth_ - 1 - z)); | |
96 uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(z)); | |
97 | |
98 for (unsigned int y = 0; y < height_; y++) | |
99 { | |
100 const void* source = (reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + | |
101 bytesPerPixel * slice); | |
102 | |
103 memcpy(target, source, bytesPerPixel); | |
104 target += bytesPerPixel; | |
105 } | |
106 } | |
107 | |
108 return result.release(); | |
109 } | |
110 | |
111 | |
112 ImageBuffer3D::ImageBuffer3D(Orthanc::PixelFormat format, | |
113 unsigned int width, | |
114 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
115 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
116 bool computeRange) : |
11 | 117 image_(format, width, height * depth, false), |
0 | 118 format_(format), |
119 width_(width), | |
120 height_(height), | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
121 depth_(depth), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
122 computeRange_(computeRange), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
123 hasRange_(false) |
0 | 124 { |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
125 LinearAlgebra::AssignVector(voxelDimensions_, 1, 1, 1); |
105 | 126 |
127 LOG(INFO) << "Created an image of " | |
128 << (GetEstimatedMemorySize() / (1024ll * 1024ll)) << "MB"; | |
0 | 129 } |
130 | |
131 | |
132 void ImageBuffer3D::Clear() | |
133 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
134 memset(image_.GetBuffer(), 0, image_.GetHeight() * image_.GetPitch()); |
0 | 135 } |
136 | |
137 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
105
diff
changeset
|
138 void ImageBuffer3D::SetAxialGeometry(const CoordinateSystem3D& geometry) |
0 | 139 { |
140 axialGeometry_ = geometry; | |
141 } | |
142 | |
143 | |
144 void ImageBuffer3D::SetVoxelDimensions(double x, | |
145 double y, | |
146 double z) | |
147 { | |
148 if (x <= 0 || | |
149 y <= 0 || | |
150 z <= 0) | |
151 { | |
152 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
153 } | |
154 | |
155 { | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
156 LinearAlgebra::AssignVector(voxelDimensions_, x, y, z); |
0 | 157 } |
158 } | |
159 | |
160 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
161 Vector ImageBuffer3D::GetVoxelDimensions(VolumeProjection projection) const |
0 | 162 { |
163 Vector result; | |
164 switch (projection) | |
165 { | |
166 case VolumeProjection_Axial: | |
167 result = voxelDimensions_; | |
168 break; | |
169 | |
170 case VolumeProjection_Coronal: | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
171 LinearAlgebra::AssignVector(result, voxelDimensions_[0], voxelDimensions_[2], voxelDimensions_[1]); |
0 | 172 break; |
173 | |
174 case VolumeProjection_Sagittal: | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
175 LinearAlgebra::AssignVector(result, voxelDimensions_[1], voxelDimensions_[2], voxelDimensions_[0]); |
0 | 176 break; |
177 | |
178 default: | |
179 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
180 } | |
181 | |
182 return result; | |
183 } | |
184 | |
185 | |
186 void ImageBuffer3D::GetSliceSize(unsigned int& width, | |
187 unsigned int& height, | |
188 VolumeProjection projection) | |
189 { | |
190 switch (projection) | |
191 { | |
192 case VolumeProjection_Axial: | |
193 width = width_; | |
194 height = height_; | |
195 break; | |
196 | |
197 case VolumeProjection_Coronal: | |
198 width = width_; | |
199 height = depth_; | |
200 break; | |
201 | |
202 case VolumeProjection_Sagittal: | |
203 width = height_; | |
204 height = depth_; | |
205 break; | |
206 | |
207 default: | |
208 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
209 } | |
210 } | |
211 | |
212 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
213 ParallelSlices* ImageBuffer3D::GetGeometry(VolumeProjection projection) const |
0 | 214 { |
215 std::auto_ptr<ParallelSlices> result(new ParallelSlices); | |
216 | |
217 switch (projection) | |
218 { | |
219 case VolumeProjection_Axial: | |
220 for (unsigned int z = 0; z < depth_; z++) | |
221 { | |
222 Vector origin = axialGeometry_.GetOrigin(); | |
223 origin += static_cast<double>(z) * voxelDimensions_[2] * axialGeometry_.GetNormal(); | |
224 | |
225 result->AddSlice(origin, | |
226 axialGeometry_.GetAxisX(), | |
227 axialGeometry_.GetAxisY()); | |
228 } | |
229 break; | |
230 | |
231 case VolumeProjection_Coronal: | |
232 for (unsigned int y = 0; y < height_; y++) | |
233 { | |
234 Vector origin = axialGeometry_.GetOrigin(); | |
235 origin += static_cast<double>(y) * voxelDimensions_[1] * axialGeometry_.GetAxisY(); | |
236 origin += static_cast<double>(depth_ - 1) * voxelDimensions_[2] * axialGeometry_.GetNormal(); | |
237 | |
238 result->AddSlice(origin, | |
239 axialGeometry_.GetAxisX(), | |
240 -axialGeometry_.GetNormal()); | |
241 } | |
242 break; | |
243 | |
244 case VolumeProjection_Sagittal: | |
245 for (unsigned int x = 0; x < width_; x++) | |
246 { | |
247 Vector origin = axialGeometry_.GetOrigin(); | |
248 origin += static_cast<double>(x) * voxelDimensions_[0] * axialGeometry_.GetAxisX(); | |
249 origin += static_cast<double>(depth_ - 1) * voxelDimensions_[2] * axialGeometry_.GetNormal(); | |
250 | |
251 result->AddSlice(origin, | |
252 axialGeometry_.GetAxisY(), | |
253 -axialGeometry_.GetNormal()); | |
254 } | |
255 break; | |
256 | |
257 default: | |
258 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
259 } | |
260 | |
261 return result.release(); | |
262 } | |
263 | |
264 | |
105 | 265 uint64_t ImageBuffer3D::GetEstimatedMemorySize() const |
266 { | |
267 return image_.GetPitch() * image_.GetHeight() * Orthanc::GetBytesPerPixel(format_); | |
268 } | |
269 | |
270 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
271 void ImageBuffer3D::ExtendImageRange(const Orthanc::ImageAccessor& slice) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
272 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
273 if (!computeRange_ || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
274 slice.GetWidth() == 0 || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
275 slice.GetHeight() == 0) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
276 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
277 return; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
278 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
279 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
280 float sliceMin, sliceMax; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
281 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
282 switch (slice.GetFormat()) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
283 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
284 case Orthanc::PixelFormat_Grayscale8: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
285 case Orthanc::PixelFormat_Grayscale16: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
286 case Orthanc::PixelFormat_Grayscale32: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
287 case Orthanc::PixelFormat_SignedGrayscale16: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
288 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
289 int64_t a, b; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
290 Orthanc::ImageProcessing::GetMinMaxIntegerValue(a, b, slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
291 sliceMin = static_cast<float>(a); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
292 sliceMax = static_cast<float>(b); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
293 break; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
294 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
295 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
296 case Orthanc::PixelFormat_Float32: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
297 Orthanc::ImageProcessing::GetMinMaxFloatValue(sliceMin, sliceMax, slice); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
298 break; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
299 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
300 default: |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
301 return; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
302 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
303 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
304 if (hasRange_) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
305 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
306 minValue_ = std::min(minValue_, sliceMin); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
307 maxValue_ = std::max(maxValue_, sliceMax); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
308 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
309 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
310 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
311 hasRange_ = true; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
312 minValue_ = sliceMin; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
313 maxValue_ = sliceMax; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
314 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
315 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
316 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
317 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
318 bool ImageBuffer3D::GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
319 float& maxValue) const |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
320 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
321 if (hasRange_) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
322 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
323 minValue = minValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
324 maxValue = maxValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
325 return true; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
326 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
327 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
328 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
329 return false; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
330 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
331 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
332 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
333 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
334 bool ImageBuffer3D::FitWindowingToRange(RenderStyle& style, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
335 const DicomFrameConverter& converter) const |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
336 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
337 if (hasRange_) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
338 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
339 style.windowing_ = ImageWindowing_Custom; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
340 style.customWindowCenter_ = converter.Apply((minValue_ + maxValue_) / 2.0); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
341 style.customWindowWidth_ = converter.Apply(maxValue_ - minValue_); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
342 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
343 if (style.customWindowWidth_ > 1) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
344 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
345 return true; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
346 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
347 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
348 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
349 style.windowing_ = ImageWindowing_Custom; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
350 style.customWindowCenter_ = 128.0; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
351 style.customWindowWidth_ = 256.0; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
352 return false; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
353 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
354 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
355 |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
356 ImageBuffer3D::SliceReader::SliceReader(const ImageBuffer3D& that, |
0 | 357 VolumeProjection projection, |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
358 unsigned int slice) |
0 | 359 { |
360 switch (projection) | |
361 { | |
362 case VolumeProjection_Axial: | |
363 accessor_ = that.GetAxialSliceAccessor(slice, true); | |
364 break; | |
365 | |
366 case VolumeProjection_Coronal: | |
367 accessor_ = that.GetCoronalSliceAccessor(slice, true); | |
368 break; | |
369 | |
370 case VolumeProjection_Sagittal: | |
371 sagittal_.reset(that.ExtractSagittalSlice(slice)); | |
372 accessor_ = *sagittal_; | |
373 break; | |
374 | |
375 default: | |
376 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
377 } | |
378 } | |
379 | |
380 | |
381 void ImageBuffer3D::SliceWriter::Flush() | |
382 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
383 if (modified_) |
0 | 384 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
385 if (sagittal_.get() != NULL) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
386 { |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
387 // TODO |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
388 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
389 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
390 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
391 // Update the dynamic range of the underlying image, if |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
392 // "computeRange_" is set to true |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
393 that_.ExtendImageRange(accessor_); |
0 | 394 } |
395 } | |
396 | |
397 | |
398 ImageBuffer3D::SliceWriter::SliceWriter(ImageBuffer3D& that, | |
399 VolumeProjection projection, | |
400 unsigned int slice) : | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
401 that_(that), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
402 modified_(false) |
0 | 403 { |
404 switch (projection) | |
405 { | |
406 case VolumeProjection_Axial: | |
407 accessor_ = that.GetAxialSliceAccessor(slice, false); | |
408 break; | |
409 | |
410 case VolumeProjection_Coronal: | |
411 accessor_ = that.GetCoronalSliceAccessor(slice, false); | |
412 break; | |
413 | |
414 case VolumeProjection_Sagittal: | |
415 sagittal_.reset(that.ExtractSagittalSlice(slice)); | |
416 accessor_ = *sagittal_; | |
417 break; | |
418 | |
419 default: | |
420 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
421 } | |
422 } | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
423 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
424 |
143 | 425 uint8_t ImageBuffer3D::GetVoxelGrayscale8(unsigned int x, |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
426 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
427 unsigned int z) const |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
428 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
429 if (format_ != Orthanc::PixelFormat_Grayscale8) |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
430 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
431 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
432 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
433 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
434 if (x >= width_ || |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
435 y >= height_ || |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
436 z >= depth_) |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
437 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
438 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
439 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
440 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
441 const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z)); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
442 return reinterpret_cast<const uint8_t*>(p) [x]; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
443 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
444 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
445 |
143 | 446 uint16_t ImageBuffer3D::GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
447 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
448 unsigned int z) const |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
449 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
450 if (format_ != Orthanc::PixelFormat_Grayscale16) |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
451 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
452 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
453 } |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
454 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
455 if (x >= width_ || |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
456 y >= height_ || |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
457 z >= depth_) |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
458 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
460 } |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
461 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
462 const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z)); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
463 return reinterpret_cast<const uint16_t*>(p) [x]; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
464 } |
187
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
465 |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
466 |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
467 Vector ImageBuffer3D::GetCoordinates(float x, |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
468 float y, |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
469 float z) const |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
470 { |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
471 Vector ps = GetVoxelDimensions(OrthancStone::VolumeProjection_Axial); |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
472 |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
473 const CoordinateSystem3D& axial = GetAxialGeometry(); |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
474 |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
475 Vector origin = (axial.MapSliceToWorldCoordinates(-0.5 * ps[0], -0.5 * ps[1]) - |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
476 0.5 * ps[2] * axial.GetNormal()); |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
477 |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
478 return (origin + |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
479 axial.GetAxisX() * ps[0] * x * static_cast<double>(GetWidth()) + |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
480 axial.GetAxisY() * ps[1] * y * static_cast<double>(GetHeight()) + |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
481 axial.GetNormal() * ps[2] * z * static_cast<double>(GetDepth())); |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
482 } |
0 | 483 } |