comparison Framework/Toolbox/SubpixelReader.h @ 183:98da3a8d4820 wasm

SubvoxelReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 15 Mar 2018 15:19:24 +0100
parents 2cbfb08f3a95
children 7a031ac16b2d
comparison
equal deleted inserted replaced
182:2cbfb08f3a95 183:98da3a8d4820
88 } 88 }
89 89
90 inline bool GetValue(PixelType& target, 90 inline bool GetValue(PixelType& target,
91 float x, 91 float x,
92 float y) const; 92 float y) const;
93
94 inline bool GetFloatValue(float& target,
95 float x,
96 float y) const;
93 }; 97 };
98
94 99
95 100
96 template <Orthanc::PixelFormat Format> 101 template <Orthanc::PixelFormat Format>
97 class SubpixelReader<Format, ImageInterpolation_Bilinear> : 102 class SubpixelReader<Format, ImageInterpolation_Bilinear> :
98 public Internals::SubpixelReaderBase 103 public Internals::SubpixelReaderBase
104 SubpixelReader(const Orthanc::ImageAccessor& source) : 109 SubpixelReader(const Orthanc::ImageAccessor& source) :
105 SubpixelReaderBase(source) 110 SubpixelReaderBase(source)
106 { 111 {
107 } 112 }
108 113
114 inline bool GetFloatValue(float& target,
115 float x,
116 float y) const;
117
109 inline bool GetValue(PixelType& target, 118 inline bool GetValue(PixelType& target,
110 float x, 119 float x,
111 float y); 120 float y) const;
112 }; 121 };
113 122
114 123
115 124
116 template <Orthanc::PixelFormat Format> 125 template <Orthanc::PixelFormat Format>
142 } 151 }
143 152
144 153
145 154
146 template <Orthanc::PixelFormat Format> 155 template <Orthanc::PixelFormat Format>
156 bool SubpixelReader<Format, ImageInterpolation_Nearest>::GetFloatValue(float& target,
157 float x,
158 float y) const
159 {
160 PixelType value;
161
162 if (GetValue(value, x, y))
163 {
164 target = Traits::PixelToFloat(value);
165 return true;
166 }
167 else
168 {
169 return false;
170 }
171 }
172
173
174
175 template <Orthanc::PixelFormat Format>
147 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetValue(PixelType& target, 176 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetValue(PixelType& target,
148 float x, 177 float x,
149 float y) 178 float y) const
179 {
180 float value;
181
182 if (GetFloatValue(value, x, y))
183 {
184 Traits::FloatToPixel(target, value);
185 return true;
186 }
187 else
188 {
189 return false;
190 }
191 }
192
193
194
195 template <Orthanc::PixelFormat Format>
196 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetFloatValue(float& target,
197 float x,
198 float y) const
150 { 199 {
151 x -= 0.5f; 200 x -= 0.5f;
152 y -= 0.5f; 201 y -= 0.5f;
153 202
154 if (x < 0 || 203 if (x < 0 ||
201 f11 = f00; 250 f11 = f00;
202 } 251 }
203 252
204 float ax = x - static_cast<float>(ux); 253 float ax = x - static_cast<float>(ux);
205 float ay = y - static_cast<float>(uy); 254 float ay = y - static_cast<float>(uy);
206 float value = GeometryToolbox::ComputeBilinearInterpolationUnitSquare(ax, ay, f00, f01, f10, f11); 255 target = GeometryToolbox::ComputeBilinearInterpolationUnitSquare(ax, ay, f00, f01, f10, f11);
207 256
208 Traits::FloatToPixel(target, value);
209 return true; 257 return true;
210 } 258 }
211 } 259 }
212 } 260 }