Mercurial > hg > orthanc-stone
comparison Framework/Volumes/VolumeReslicer.cpp @ 185:d61224de4883 wasm
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Mar 2018 16:10:52 +0100 |
parents | 9523ce4f44cc |
children | fac46066b933 |
comparison
equal
deleted
inserted
replaced
184:9523ce4f44cc | 185:d61224de4883 |
---|---|
7 #include <Core/Logging.h> | 7 #include <Core/Logging.h> |
8 #include <Core/OrthancException.h> | 8 #include <Core/OrthancException.h> |
9 | 9 |
10 #include <boost/math/special_functions/round.hpp> | 10 #include <boost/math/special_functions/round.hpp> |
11 | 11 |
12 #include <stdio.h> | |
12 | 13 |
13 namespace OrthancStone | 14 namespace OrthancStone |
14 { | 15 { |
15 // Anonymous namespace to avoid clashes between compilation modules | 16 // Anonymous namespace to avoid clashes between compilation modules |
16 namespace | 17 namespace |
21 TransferFunction_Float, | 22 TransferFunction_Float, |
22 TransferFunction_Linear | 23 TransferFunction_Linear |
23 }; | 24 }; |
24 | 25 |
25 | 26 |
26 template <typename VoxelReader, | 27 template <Orthanc::PixelFormat InputFormat, |
27 typename PixelWriter, | 28 Orthanc::PixelFormat OutputFormat, |
29 ImageInterpolation Interpolation, | |
28 TransferFunction Function> | 30 TransferFunction Function> |
29 class PixelShader; | 31 class PixelShader; |
30 | 32 |
31 | 33 |
32 template <typename VoxelReader, | 34 template <Orthanc::PixelFormat Format> |
33 typename PixelWriter> | 35 class PixelShader<Format, |
34 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Copy> | 36 Format, |
37 ImageInterpolation_Nearest, | |
38 TransferFunction_Copy> | |
35 { | 39 { |
36 private: | 40 private: |
41 typedef SubvoxelReader<Format, ImageInterpolation_Nearest> VoxelReader; | |
42 typedef Orthanc::PixelTraits<Format> PixelWriter; | |
43 | |
37 VoxelReader reader_; | 44 VoxelReader reader_; |
38 | 45 |
39 public: | 46 public: |
40 PixelShader(const ImageBuffer3D& image, | 47 PixelShader(const ImageBuffer3D& image, |
41 float /* scaling */, | 48 float /* scaling */, |
55 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ)) | 62 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ)) |
56 { | 63 { |
57 VoxelReader::Traits::SetMinValue(value); | 64 VoxelReader::Traits::SetMinValue(value); |
58 } | 65 } |
59 | 66 |
67 *pixel = value; | |
68 } | |
69 }; | |
70 | |
71 | |
72 template <Orthanc::PixelFormat InputFormat, | |
73 Orthanc::PixelFormat OutputFormat> | |
74 class PixelShader<InputFormat, | |
75 OutputFormat, | |
76 ImageInterpolation_Nearest, | |
77 TransferFunction_Copy> | |
78 { | |
79 private: | |
80 typedef SubvoxelReader<InputFormat, ImageInterpolation_Nearest> VoxelReader; | |
81 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter; | |
82 | |
83 VoxelReader reader_; | |
84 | |
85 public: | |
86 PixelShader(const ImageBuffer3D& image, | |
87 float /* scaling */, | |
88 float /* offset */) : | |
89 reader_(image) | |
90 { | |
91 } | |
92 | |
93 ORTHANC_FORCE_INLINE | |
94 void Apply(typename PixelWriter::PixelType* pixel, | |
95 float volumeX, | |
96 float volumeY, | |
97 float volumeZ) | |
98 { | |
99 typename VoxelReader::PixelType value; | |
100 | |
101 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ)) | |
102 { | |
103 VoxelReader::Traits::SetMinValue(value); | |
104 } | |
105 | |
60 PixelWriter::FloatToPixel(*pixel, VoxelReader::Traits::PixelToFloat(value)); | 106 PixelWriter::FloatToPixel(*pixel, VoxelReader::Traits::PixelToFloat(value)); |
61 } | 107 } |
62 }; | 108 }; |
63 | 109 |
64 | 110 |
65 template <typename VoxelReader, | 111 template <Orthanc::PixelFormat InputFormat, |
66 typename PixelWriter> | 112 Orthanc::PixelFormat OutputFormat, |
67 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Float> | 113 ImageInterpolation Interpolation> |
114 class PixelShader<InputFormat, | |
115 OutputFormat, | |
116 Interpolation, | |
117 TransferFunction_Float> | |
68 { | 118 { |
69 private: | 119 private: |
120 typedef SubvoxelReader<InputFormat, Interpolation> VoxelReader; | |
121 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter; | |
122 | |
70 VoxelReader reader_; | 123 VoxelReader reader_; |
71 float outOfVolume_; | 124 float outOfVolume_; |
72 | 125 |
73 public: | 126 public: |
74 PixelShader(const ImageBuffer3D& image, | 127 PixelShader(const ImageBuffer3D& image, |
95 PixelWriter::FloatToPixel(*pixel, value); | 148 PixelWriter::FloatToPixel(*pixel, value); |
96 } | 149 } |
97 }; | 150 }; |
98 | 151 |
99 | 152 |
100 template <typename VoxelReader, | 153 template <Orthanc::PixelFormat InputFormat, |
101 typename PixelWriter> | 154 Orthanc::PixelFormat OutputFormat, |
102 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Linear> | 155 ImageInterpolation Interpolation> |
156 class PixelShader<InputFormat, | |
157 OutputFormat, | |
158 Interpolation, | |
159 TransferFunction_Linear> | |
103 { | 160 { |
104 private: | 161 private: |
162 typedef SubvoxelReader<InputFormat, Interpolation> VoxelReader; | |
163 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter; | |
164 | |
105 VoxelReader reader_; | 165 VoxelReader reader_; |
106 float scaling_; | 166 float scaling_; |
107 float offset_; | 167 float offset_; |
108 float outOfVolume_; | 168 float outOfVolume_; |
109 | 169 |
265 const CoordinateSystem3D& plane, | 325 const CoordinateSystem3D& plane, |
266 const OrientedBoundingBox& box, | 326 const OrientedBoundingBox& box, |
267 float scaling, | 327 float scaling, |
268 float offset) | 328 float offset) |
269 { | 329 { |
270 typedef SubvoxelReader<InputFormat, Interpolation> Reader; | 330 typedef PixelShader<InputFormat, OutputFormat, Interpolation, Function> Shader; |
271 typedef Orthanc::PixelTraits<OutputFormat> Writer; | |
272 typedef PixelShader<Reader, Writer, Function> Shader; | |
273 | 331 |
274 const unsigned int outputWidth = slice.GetWidth(); | 332 const unsigned int outputWidth = slice.GetWidth(); |
275 const unsigned int outputHeight = slice.GetHeight(); | 333 const unsigned int outputHeight = slice.GetHeight(); |
276 | 334 |
277 const float sourceWidth = static_cast<float>(source.GetWidth()); | 335 const float sourceWidth = static_cast<float>(source.GetWidth()); |
280 | 338 |
281 Shader shader(source, scaling, offset); | 339 Shader shader(source, scaling, offset); |
282 | 340 |
283 for (unsigned int y = 0; y < outputHeight; y++) | 341 for (unsigned int y = 0; y < outputHeight; y++) |
284 { | 342 { |
285 typename Writer::PixelType* p = | 343 typedef typename Orthanc::ImageTraits<OutputFormat>::PixelType PixelType; |
286 reinterpret_cast<typename Writer::PixelType*>(slice.GetRow(y)); | 344 PixelType* p = reinterpret_cast<PixelType*>(slice.GetRow(y)); |
287 | 345 |
288 RowIterator it(slice, extent, plane, box, y); | 346 RowIterator it(slice, extent, plane, box, y); |
289 | 347 |
290 for (unsigned int x = 0; x < outputWidth; x++, p++) | 348 for (unsigned int x = 0; x < outputWidth; x++, p++) |
291 { | 349 { |