comparison Framework/Toolbox/FiniteProjectiveCamera.cpp @ 860:238693c3bc51 am-dev

merge default -> am-dev
author Alain Mazy <alain@mazy.be>
date Mon, 24 Jun 2019 14:35:00 +0200
parents ffec76a5f7eb
children 2d8ab34c8c91
comparison
equal deleted inserted replaced
856:a6e17a5a39e7 860:238693c3bc51
297 Orthanc::PixelFormat SourceFormat, 297 Orthanc::PixelFormat SourceFormat,
298 bool MIP> 298 bool MIP>
299 static void ApplyRaytracerInternal(Orthanc::ImageAccessor& target, 299 static void ApplyRaytracerInternal(Orthanc::ImageAccessor& target,
300 const FiniteProjectiveCamera& camera, 300 const FiniteProjectiveCamera& camera,
301 const ImageBuffer3D& source, 301 const ImageBuffer3D& source,
302 const VolumeImageGeometry& geometry,
302 VolumeProjection projection) 303 VolumeProjection projection)
303 { 304 {
304 if (source.GetFormat() != SourceFormat || 305 if (source.GetFormat() != SourceFormat ||
305 target.GetFormat() != TargetFormat || 306 target.GetFormat() != TargetFormat ||
306 !std::numeric_limits<float>::is_iec559 || 307 !std::numeric_limits<float>::is_iec559 ||
313 << source.GetHeight() << "x" << source.GetDepth(); 314 << source.GetHeight() << "x" << source.GetDepth();
314 LOG(WARNING) << "Input pixel format: " << Orthanc::EnumerationToString(source.GetFormat()); 315 LOG(WARNING) << "Input pixel format: " << Orthanc::EnumerationToString(source.GetFormat());
315 LOG(WARNING) << "Output image size: " << target.GetWidth() << "x" << target.GetHeight(); 316 LOG(WARNING) << "Output image size: " << target.GetWidth() << "x" << target.GetHeight();
316 LOG(WARNING) << "Output pixel format: " << Orthanc::EnumerationToString(target.GetFormat()); 317 LOG(WARNING) << "Output pixel format: " << Orthanc::EnumerationToString(target.GetFormat());
317 318
318 std::auto_ptr<OrthancStone::ParallelSlices> slices(source.GetGeometry(projection)); 319 const unsigned int slicesCount = geometry.GetProjectionDepth(projection);
319 const OrthancStone::Vector pixelSpacing = source.GetGeometry().GetVoxelDimensions(projection); 320 const OrthancStone::Vector pixelSpacing = geometry.GetVoxelDimensions(projection);
320 const unsigned int targetWidth = target.GetWidth(); 321 const unsigned int targetWidth = target.GetWidth();
321 const unsigned int targetHeight = target.GetHeight(); 322 const unsigned int targetHeight = target.GetHeight();
322 323
323 Orthanc::Image accumulator(Orthanc::PixelFormat_Float32, targetWidth, targetHeight, false); 324 Orthanc::Image accumulator(Orthanc::PixelFormat_Float32, targetWidth, targetHeight, false);
324 Orthanc::Image counter(Orthanc::PixelFormat_Grayscale16, targetWidth, targetHeight, false); 325 Orthanc::Image counter(Orthanc::PixelFormat_Grayscale16, targetWidth, targetHeight, false);
325 Orthanc::ImageProcessing::Set(accumulator, 0); 326 Orthanc::ImageProcessing::Set(accumulator, 0);
326 Orthanc::ImageProcessing::Set(counter, 0); 327 Orthanc::ImageProcessing::Set(counter, 0);
327 328
328 typedef SubpixelReader<SourceFormat, ImageInterpolation_Nearest> SourceReader; 329 typedef SubpixelReader<SourceFormat, ImageInterpolation_Nearest> SourceReader;
329 330
330 for (size_t z = 0; z < slices->GetSliceCount(); z++) 331 for (unsigned int z = 0; z < slicesCount; z++)
331 { 332 {
332 LOG(INFO) << "Applying raytracer on slice: " << z << "/" << slices->GetSliceCount(); 333 LOG(INFO) << "Applying raytracer on slice: " << z << "/" << slicesCount;
333 334
334 const OrthancStone::CoordinateSystem3D& slice = slices->GetSlice(z); 335 OrthancStone::CoordinateSystem3D slice = geometry.GetProjectionSlice(projection, z);
335 OrthancStone::ImageBuffer3D::SliceReader sliceReader(source, projection, static_cast<unsigned int>(z)); 336 OrthancStone::ImageBuffer3D::SliceReader sliceReader(source, projection, static_cast<unsigned int>(z));
336 337
337 SourceReader pixelReader(sliceReader.GetAccessor()); 338 SourceReader pixelReader(sliceReader.GetAccessor());
338 339
339 for (unsigned int y = 0; y < targetHeight; y++) 340 for (unsigned int y = 0; y < targetHeight; y++)
420 } 421 }
421 422
422 423
423 Orthanc::ImageAccessor* 424 Orthanc::ImageAccessor*
424 FiniteProjectiveCamera::ApplyRaytracer(const ImageBuffer3D& source, 425 FiniteProjectiveCamera::ApplyRaytracer(const ImageBuffer3D& source,
426 const VolumeImageGeometry& geometry,
425 Orthanc::PixelFormat targetFormat, 427 Orthanc::PixelFormat targetFormat,
426 unsigned int targetWidth, 428 unsigned int targetWidth,
427 unsigned int targetHeight, 429 unsigned int targetHeight,
428 bool mip) const 430 bool mip) const
429 { 431 {
438 if (targetFormat == Orthanc::PixelFormat_Grayscale16 && 440 if (targetFormat == Orthanc::PixelFormat_Grayscale16 &&
439 source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && mip) 441 source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && mip)
440 { 442 {
441 ApplyRaytracerInternal<Orthanc::PixelFormat_Grayscale16, 443 ApplyRaytracerInternal<Orthanc::PixelFormat_Grayscale16,
442 Orthanc::PixelFormat_Grayscale16, true> 444 Orthanc::PixelFormat_Grayscale16, true>
443 (*target, *this, source, projection); 445 (*target, *this, source, geometry, projection);
444 } 446 }
445 else if (targetFormat == Orthanc::PixelFormat_Grayscale16 && 447 else if (targetFormat == Orthanc::PixelFormat_Grayscale16 &&
446 source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && !mip) 448 source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && !mip)
447 { 449 {
448 ApplyRaytracerInternal<Orthanc::PixelFormat_Grayscale16, 450 ApplyRaytracerInternal<Orthanc::PixelFormat_Grayscale16,
449 Orthanc::PixelFormat_Grayscale16, false> 451 Orthanc::PixelFormat_Grayscale16, false>
450 (*target, *this, source, projection); 452 (*target, *this, source, geometry, projection);
451 } 453 }
452 else 454 else
453 { 455 {
454 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 456 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
455 } 457 }