Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/ImageGeometry.cpp @ 340:f5d5814a41a0 am-2
rendering BitmapStack
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 20 Oct 2018 18:26:05 +0200 |
parents | b3b3fa0e3689 |
children | c2e040ea8fbe |
comparison
equal
deleted
inserted
replaced
339:5a7915b23138 | 340:f5d5814a41a0 |
---|---|
172 | 172 |
173 template <Orthanc::PixelFormat Format, | 173 template <Orthanc::PixelFormat Format, |
174 ImageInterpolation Interpolation> | 174 ImageInterpolation Interpolation> |
175 static void ApplyAffineInternal(Orthanc::ImageAccessor& target, | 175 static void ApplyAffineInternal(Orthanc::ImageAccessor& target, |
176 const Orthanc::ImageAccessor& source, | 176 const Orthanc::ImageAccessor& source, |
177 const Matrix& a) | 177 const Matrix& a, |
178 bool clear) | |
178 { | 179 { |
179 assert(target.GetFormat() == Format && | 180 assert(target.GetFormat() == Format && |
180 source.GetFormat() == Format); | 181 source.GetFormat() == Format); |
181 | 182 |
182 typedef SubpixelReader<Format, Interpolation> Reader; | 183 typedef SubpixelReader<Format, Interpolation> Reader; |
183 typedef typename Reader::PixelType PixelType; | 184 typedef typename Reader::PixelType PixelType; |
184 | 185 |
185 if (Format == Orthanc::PixelFormat_RGB24) | 186 if (clear) |
186 { | 187 { |
187 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); | 188 if (Format == Orthanc::PixelFormat_RGB24) |
188 } | 189 { |
189 else | 190 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); |
190 { | 191 } |
191 Orthanc::ImageProcessing::Set(target, 0); | 192 else |
193 { | |
194 Orthanc::ImageProcessing::Set(target, 0); | |
195 } | |
192 } | 196 } |
193 | 197 |
194 Matrix inva; | 198 Matrix inva; |
195 if (!LinearAlgebra::InvertMatrixUnsafe(inva, a)) | 199 if (!LinearAlgebra::InvertMatrixUnsafe(inva, a)) |
196 { | 200 { |
258 double a12, | 262 double a12, |
259 double b1, | 263 double b1, |
260 double a21, | 264 double a21, |
261 double a22, | 265 double a22, |
262 double b2, | 266 double b2, |
263 ImageInterpolation interpolation) | 267 ImageInterpolation interpolation, |
268 bool clear) | |
264 { | 269 { |
265 if (source.GetFormat() != target.GetFormat()) | 270 if (source.GetFormat() != target.GetFormat()) |
266 { | 271 { |
267 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 272 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
268 } | 273 } |
290 case Orthanc::PixelFormat_Grayscale8: | 295 case Orthanc::PixelFormat_Grayscale8: |
291 switch (interpolation) | 296 switch (interpolation) |
292 { | 297 { |
293 case ImageInterpolation_Nearest: | 298 case ImageInterpolation_Nearest: |
294 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale8, | 299 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale8, |
295 ImageInterpolation_Nearest>(target, source, a); | 300 ImageInterpolation_Nearest>(target, source, a, clear); |
296 break; | 301 break; |
297 | 302 |
298 case ImageInterpolation_Bilinear: | 303 case ImageInterpolation_Bilinear: |
299 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale8, | 304 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale8, |
300 ImageInterpolation_Bilinear>(target, source, a); | 305 ImageInterpolation_Bilinear>(target, source, a, clear); |
301 break; | 306 break; |
302 | 307 |
303 default: | 308 default: |
304 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 309 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
305 } | 310 } |
308 case Orthanc::PixelFormat_Grayscale16: | 313 case Orthanc::PixelFormat_Grayscale16: |
309 switch (interpolation) | 314 switch (interpolation) |
310 { | 315 { |
311 case ImageInterpolation_Nearest: | 316 case ImageInterpolation_Nearest: |
312 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale16, | 317 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale16, |
313 ImageInterpolation_Nearest>(target, source, a); | 318 ImageInterpolation_Nearest>(target, source, a, clear); |
314 break; | 319 break; |
315 | 320 |
316 case ImageInterpolation_Bilinear: | 321 case ImageInterpolation_Bilinear: |
317 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale16, | 322 ApplyAffineInternal<Orthanc::PixelFormat_Grayscale16, |
318 ImageInterpolation_Bilinear>(target, source, a); | 323 ImageInterpolation_Bilinear>(target, source, a, clear); |
319 break; | 324 break; |
320 | 325 |
321 default: | 326 default: |
322 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 327 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
323 } | 328 } |
326 case Orthanc::PixelFormat_SignedGrayscale16: | 331 case Orthanc::PixelFormat_SignedGrayscale16: |
327 switch (interpolation) | 332 switch (interpolation) |
328 { | 333 { |
329 case ImageInterpolation_Nearest: | 334 case ImageInterpolation_Nearest: |
330 ApplyAffineInternal<Orthanc::PixelFormat_SignedGrayscale16, | 335 ApplyAffineInternal<Orthanc::PixelFormat_SignedGrayscale16, |
331 ImageInterpolation_Nearest>(target, source, a); | 336 ImageInterpolation_Nearest>(target, source, a, clear); |
332 break; | 337 break; |
333 | 338 |
334 case ImageInterpolation_Bilinear: | 339 case ImageInterpolation_Bilinear: |
335 ApplyAffineInternal<Orthanc::PixelFormat_SignedGrayscale16, | 340 ApplyAffineInternal<Orthanc::PixelFormat_SignedGrayscale16, |
336 ImageInterpolation_Bilinear>(target, source, a); | 341 ImageInterpolation_Bilinear>(target, source, a, clear); |
337 break; | 342 break; |
338 | 343 |
339 default: | 344 default: |
340 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 345 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
341 } | 346 } |
344 case Orthanc::PixelFormat_Float32: | 349 case Orthanc::PixelFormat_Float32: |
345 switch (interpolation) | 350 switch (interpolation) |
346 { | 351 { |
347 case ImageInterpolation_Nearest: | 352 case ImageInterpolation_Nearest: |
348 ApplyAffineInternal<Orthanc::PixelFormat_Float32, | 353 ApplyAffineInternal<Orthanc::PixelFormat_Float32, |
349 ImageInterpolation_Nearest>(target, source, a); | 354 ImageInterpolation_Nearest>(target, source, a, clear); |
350 break; | 355 break; |
351 | 356 |
352 case ImageInterpolation_Bilinear: | 357 case ImageInterpolation_Bilinear: |
353 ApplyAffineInternal<Orthanc::PixelFormat_Float32, | 358 ApplyAffineInternal<Orthanc::PixelFormat_Float32, |
354 ImageInterpolation_Bilinear>(target, source, a); | 359 ImageInterpolation_Bilinear>(target, source, a, clear); |
355 break; | 360 break; |
356 | 361 |
357 default: | 362 default: |
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 363 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
359 } | 364 } |
362 case Orthanc::PixelFormat_RGB24: | 367 case Orthanc::PixelFormat_RGB24: |
363 switch (interpolation) | 368 switch (interpolation) |
364 { | 369 { |
365 case ImageInterpolation_Nearest: | 370 case ImageInterpolation_Nearest: |
366 ApplyAffineInternal<Orthanc::PixelFormat_RGB24, | 371 ApplyAffineInternal<Orthanc::PixelFormat_RGB24, |
367 ImageInterpolation_Nearest>(target, source, a); | 372 ImageInterpolation_Nearest>(target, source, a, clear); |
368 break; | 373 break; |
369 | 374 |
370 default: | 375 default: |
371 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 376 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
372 } | 377 } |
445 | 450 |
446 | 451 |
447 void ApplyProjectiveTransform(Orthanc::ImageAccessor& target, | 452 void ApplyProjectiveTransform(Orthanc::ImageAccessor& target, |
448 const Orthanc::ImageAccessor& source, | 453 const Orthanc::ImageAccessor& source, |
449 const Matrix& a, | 454 const Matrix& a, |
450 ImageInterpolation interpolation) | 455 ImageInterpolation interpolation, |
456 bool clear) | |
451 { | 457 { |
452 if (source.GetFormat() != target.GetFormat()) | 458 if (source.GetFormat() != target.GetFormat()) |
453 { | 459 { |
454 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 460 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
455 } | 461 } |
479 else | 485 else |
480 { | 486 { |
481 ApplyAffineTransform(target, source, | 487 ApplyAffineTransform(target, source, |
482 a(0, 0) / w, a(0, 1) / w, a(0, 2) / w, | 488 a(0, 0) / w, a(0, 1) / w, a(0, 2) / w, |
483 a(1, 0) / w, a(1, 1) / w, a(1, 2) / w, | 489 a(1, 0) / w, a(1, 1) / w, a(1, 2) / w, |
484 interpolation); | 490 interpolation, clear); |
485 return; | 491 return; |
486 } | 492 } |
487 } | 493 } |
488 | 494 |
489 if (target.GetFormat() == Orthanc::PixelFormat_RGB24) | 495 if (clear) |
490 { | 496 { |
491 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); | 497 if (target.GetFormat() == Orthanc::PixelFormat_RGB24) |
492 } | 498 { |
493 else | 499 Orthanc::ImageProcessing::Set(target, 0, 0, 0, 255); |
494 { | 500 } |
495 Orthanc::ImageProcessing::Set(target, 0); | 501 else |
502 { | |
503 Orthanc::ImageProcessing::Set(target, 0); | |
504 } | |
496 } | 505 } |
497 | 506 |
498 Matrix inva; | 507 Matrix inva; |
499 if (!LinearAlgebra::InvertMatrixUnsafe(inva, a)) | 508 if (!LinearAlgebra::InvertMatrixUnsafe(inva, a)) |
500 { | 509 { |