comparison Framework/Volumes/VolumeReslicer.cpp @ 184:9523ce4f44cc wasm

removing PixelWriter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 15 Mar 2018 15:44:41 +0100
parents 98da3a8d4820
children d61224de4883
comparison
equal deleted inserted replaced
183:98da3a8d4820 184:9523ce4f44cc
20 TransferFunction_Copy, 20 TransferFunction_Copy,
21 TransferFunction_Float, 21 TransferFunction_Float,
22 TransferFunction_Linear 22 TransferFunction_Linear
23 }; 23 };
24 24
25 template <Orthanc::PixelFormat InputFormat,
26 Orthanc::PixelFormat OutputFormat>
27 class PixelWriter
28 {
29 public:
30 typedef typename Orthanc::PixelTraits<InputFormat>::PixelType InputPixelType;
31 typedef Orthanc::PixelTraits<OutputFormat> OutputPixelTraits;
32 typedef typename Orthanc::PixelTraits<OutputFormat>::PixelType OutputPixelType;
33
34 private:
35 template <typename T>
36 static void SetValueInternal(OutputPixelType* pixel,
37 const T& value)
38 {
39 if (value < std::numeric_limits<OutputPixelType>::min())
40 {
41 *pixel = std::numeric_limits<OutputPixelType>::min();
42 }
43 else if (value > std::numeric_limits<OutputPixelType>::max())
44 {
45 *pixel = std::numeric_limits<OutputPixelType>::max();
46 }
47 else
48 {
49 *pixel = static_cast<OutputPixelType>(value);
50 }
51 }
52
53 public:
54 ORTHANC_FORCE_INLINE
55 void SetFloatValue(OutputPixelType* pixel,
56 float value) const
57 {
58 SetValueInternal<float>(pixel, value);
59 }
60
61 ORTHANC_FORCE_INLINE
62 void SetValue(OutputPixelType* pixel,
63 const InputPixelType& value) const
64 {
65 SetValueInternal<InputPixelType>(pixel, value);
66 }
67 };
68
69
70 template <Orthanc::PixelFormat InputFormat>
71 class PixelWriter<InputFormat, Orthanc::PixelFormat_BGRA32>
72 {
73 public:
74 typedef typename Orthanc::PixelTraits<InputFormat>::PixelType InputPixelType;
75 typedef Orthanc::PixelTraits<Orthanc::PixelFormat_BGRA32> OutputPixelTraits;
76 typedef Orthanc::PixelTraits<Orthanc::PixelFormat_BGRA32>::PixelType OutputPixelType;
77
78 private:
79 template <typename T>
80 static void SetValueInternal(OutputPixelType* pixel,
81 const T& value)
82 {
83 uint8_t v;
84 if (value < 0)
85 {
86 v = 0;
87 }
88 else if (value >= 255.0f)
89 {
90 v = 255;
91 }
92 else
93 {
94 v = static_cast<uint8_t>(value);
95 }
96
97 pixel->blue_ = v;
98 pixel->green_ = v;
99 pixel->red_ = v;
100 pixel->alpha_ = 255;
101 }
102
103 public:
104 ORTHANC_FORCE_INLINE
105 void SetFloatValue(OutputPixelType* pixel,
106 float value) const
107 {
108 SetValueInternal<float>(pixel, value);
109 }
110
111 ORTHANC_FORCE_INLINE
112 void SetValue(OutputPixelType* pixel,
113 const InputPixelType& value) const
114 {
115 SetValueInternal<InputPixelType>(pixel, value);
116 }
117 };
118
119 25
120 template <typename VoxelReader, 26 template <typename VoxelReader,
121 typename PixelWriter, 27 typename PixelWriter,
122 TransferFunction Function> 28 TransferFunction Function>
123 class PixelShader; 29 class PixelShader;
127 typename PixelWriter> 33 typename PixelWriter>
128 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Copy> 34 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Copy>
129 { 35 {
130 private: 36 private:
131 VoxelReader reader_; 37 VoxelReader reader_;
132 PixelWriter writer_;
133 38
134 public: 39 public:
135 PixelShader(const ImageBuffer3D& image, 40 PixelShader(const ImageBuffer3D& image,
136 float /* scaling */, 41 float /* scaling */,
137 float /* offset */) : 42 float /* offset */) :
138 reader_(image) 43 reader_(image)
139 { 44 {
140 } 45 }
141 46
142 ORTHANC_FORCE_INLINE 47 ORTHANC_FORCE_INLINE
143 void Apply(typename PixelWriter::OutputPixelType* pixel, 48 void Apply(typename PixelWriter::PixelType* pixel,
144 float volumeX, 49 float volumeX,
145 float volumeY, 50 float volumeY,
146 float volumeZ) 51 float volumeZ)
147 { 52 {
148 typename VoxelReader::PixelType value; 53 typename VoxelReader::PixelType value;
150 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ)) 55 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ))
151 { 56 {
152 VoxelReader::Traits::SetMinValue(value); 57 VoxelReader::Traits::SetMinValue(value);
153 } 58 }
154 59
155 writer_.SetValue(pixel, value); 60 PixelWriter::FloatToPixel(*pixel, VoxelReader::Traits::PixelToFloat(value));
156 } 61 }
157 }; 62 };
158 63
159 64
160 template <typename VoxelReader, 65 template <typename VoxelReader,
161 typename PixelWriter> 66 typename PixelWriter>
162 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Float> 67 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Float>
163 { 68 {
164 private: 69 private:
165 VoxelReader reader_; 70 VoxelReader reader_;
166 PixelWriter writer_;
167 float outOfVolume_; 71 float outOfVolume_;
168 72
169 public: 73 public:
170 PixelShader(const ImageBuffer3D& image, 74 PixelShader(const ImageBuffer3D& image,
171 float /* scaling */, 75 float /* scaling */,
174 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min())) 78 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min()))
175 { 79 {
176 } 80 }
177 81
178 ORTHANC_FORCE_INLINE 82 ORTHANC_FORCE_INLINE
179 void Apply(typename PixelWriter::OutputPixelType* pixel, 83 void Apply(typename PixelWriter::PixelType* pixel,
180 float volumeX, 84 float volumeX,
181 float volumeY, 85 float volumeY,
182 float volumeZ) 86 float volumeZ)
183 { 87 {
184 float value; 88 float value;
186 if (!reader_.GetFloatValue(value, volumeX, volumeY, volumeZ)) 90 if (!reader_.GetFloatValue(value, volumeX, volumeY, volumeZ))
187 { 91 {
188 value = outOfVolume_; 92 value = outOfVolume_;
189 } 93 }
190 94
191 writer_.SetFloatValue(pixel, value); 95 PixelWriter::FloatToPixel(*pixel, value);
192 } 96 }
193 }; 97 };
194 98
195 99
196 template <typename VoxelReader, 100 template <typename VoxelReader,
197 typename PixelWriter> 101 typename PixelWriter>
198 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Linear> 102 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Linear>
199 { 103 {
200 private: 104 private:
201 VoxelReader reader_; 105 VoxelReader reader_;
202 PixelWriter writer_;
203 float scaling_; 106 float scaling_;
204 float offset_; 107 float offset_;
205 float outOfVolume_; 108 float outOfVolume_;
206 109
207 public: 110 public:
214 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min())) 117 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min()))
215 { 118 {
216 } 119 }
217 120
218 ORTHANC_FORCE_INLINE 121 ORTHANC_FORCE_INLINE
219 void Apply(typename PixelWriter::OutputPixelType* pixel, 122 void Apply(typename PixelWriter::PixelType* pixel,
220 float volumeX, 123 float volumeX,
221 float volumeY, 124 float volumeY,
222 float volumeZ) 125 float volumeZ)
223 { 126 {
224 float value; 127 float value;
230 else 133 else
231 { 134 {
232 value = outOfVolume_; 135 value = outOfVolume_;
233 } 136 }
234 137
235 writer_.SetFloatValue(pixel, value); 138 PixelWriter::FloatToPixel(*pixel, value);
236 } 139 }
237 }; 140 };
238 141
239 142
240 143
363 const OrientedBoundingBox& box, 266 const OrientedBoundingBox& box,
364 float scaling, 267 float scaling,
365 float offset) 268 float offset)
366 { 269 {
367 typedef SubvoxelReader<InputFormat, Interpolation> Reader; 270 typedef SubvoxelReader<InputFormat, Interpolation> Reader;
368 typedef PixelWriter<InputFormat, OutputFormat> Writer; 271 typedef Orthanc::PixelTraits<OutputFormat> Writer;
369 typedef PixelShader<Reader, Writer, Function> Shader; 272 typedef PixelShader<Reader, Writer, Function> Shader;
370 273
371 const unsigned int outputWidth = slice.GetWidth(); 274 const unsigned int outputWidth = slice.GetWidth();
372 const unsigned int outputHeight = slice.GetHeight(); 275 const unsigned int outputHeight = slice.GetHeight();
373 276
377 280
378 Shader shader(source, scaling, offset); 281 Shader shader(source, scaling, offset);
379 282
380 for (unsigned int y = 0; y < outputHeight; y++) 283 for (unsigned int y = 0; y < outputHeight; y++)
381 { 284 {
382 typename Writer::OutputPixelType* p = 285 typename Writer::PixelType* p =
383 reinterpret_cast<typename Writer::OutputPixelType*>(slice.GetRow(y)); 286 reinterpret_cast<typename Writer::PixelType*>(slice.GetRow(y));
384 287
385 RowIterator it(slice, extent, plane, box, y); 288 RowIterator it(slice, extent, plane, box, y);
386 289
387 for (unsigned int x = 0; x < outputWidth; x++, p++) 290 for (unsigned int x = 0; x < outputWidth; x++, p++)
388 { 291 {