# HG changeset patch # User Sebastien Jodogne # Date 1520959369 -3600 # Node ID db21c1810c89471ee625a1ed55ffd5f894f21af0 # Parent 6dafcdec4b87e6afc7ddeb29e090d62ff384b9d5 moving PixelTraits to the Orthanc core diff -r 6dafcdec4b87 -r db21c1810c89 Framework/Volumes/ImageBuffer3D.h --- a/Framework/Volumes/ImageBuffer3D.h Tue Mar 13 17:03:51 2018 +0100 +++ b/Framework/Volumes/ImageBuffer3D.h Tue Mar 13 17:42:49 2018 +0100 @@ -94,6 +94,11 @@ unsigned int& height, VolumeProjection projection); + const Orthanc::ImageAccessor& GetInternalImage() const + { + return image_; + } + unsigned int GetWidth() const { return width_; diff -r 6dafcdec4b87 -r db21c1810c89 Framework/Volumes/VolumeReslicer.cpp --- a/Framework/Volumes/VolumeReslicer.cpp Tue Mar 13 17:03:51 2018 +0100 +++ b/Framework/Volumes/VolumeReslicer.cpp Tue Mar 13 17:42:49 2018 +0100 @@ -2,6 +2,7 @@ #include "../Toolbox/GeometryToolbox.h" +#include #include #include @@ -28,124 +29,14 @@ TransferFunction_Linear }; - - template - struct PixelTraits; - - template <> - struct PixelTraits - { - typedef uint8_t PixelType; - - static void SetOutOfVolume(PixelType& target) - { - target = 0; - } - - static void GetVoxel(PixelType& target, - const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - target = image.GetVoxelGrayscale8Unchecked(x, y, z); - } - - static float GetFloatVoxel(const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - return static_cast(image.GetVoxelGrayscale8Unchecked(x, y, z)); - } - }; - - template <> - struct PixelTraits - { - typedef uint16_t PixelType; - - static void SetOutOfVolume(PixelType& target) - { - target = 0; - } - - static void GetVoxel(PixelType& target, - const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - target = image.GetVoxelGrayscale16Unchecked(x, y, z); - } - - static float GetFloatVoxel(const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - return static_cast(image.GetVoxelGrayscale16Unchecked(x, y, z)); - } - }; - - - template <> - struct PixelTraits - { - typedef int16_t PixelType; - - static void SetOutOfVolume(PixelType& target) - { - target = std::numeric_limits::min(); - } - - static void GetVoxel(PixelType& target, - const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - target = image.GetVoxelSignedGrayscale16Unchecked(x, y, z); - } - - static float GetFloatVoxel(const ImageBuffer3D& image, - unsigned int x, - unsigned int y, - unsigned int z) - { - assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); - return static_cast(image.GetVoxelSignedGrayscale16Unchecked(x, y, z)); - } - }; - - - template <> - struct PixelTraits - { - struct PixelType - { - uint8_t blue_; - uint8_t green_; - uint8_t red_; - uint8_t alpha_; - }; - }; - - - template class PixelWriter { public: - typedef typename PixelTraits::PixelType InputPixelType; - typedef PixelTraits OutputPixelTraits; - typedef typename PixelTraits::PixelType OutputPixelType; + typedef typename Orthanc::PixelTraits::PixelType InputPixelType; + typedef Orthanc::PixelTraits OutputPixelTraits; + typedef typename Orthanc::PixelTraits::PixelType OutputPixelType; private: template @@ -187,9 +78,9 @@ class PixelWriter { public: - typedef typename PixelTraits::PixelType InputPixelType; - typedef PixelTraits OutputPixelTraits; - typedef PixelTraits::PixelType OutputPixelType; + typedef typename Orthanc::PixelTraits::PixelType InputPixelType; + typedef Orthanc::PixelTraits OutputPixelTraits; + typedef Orthanc::PixelTraits::PixelType OutputPixelType; private: template @@ -237,17 +128,17 @@ class VoxelReaderBase : public boost::noncopyable { private: - const ImageBuffer3D& image_; - unsigned int width_; - unsigned int height_; - unsigned int depth_; - float widthFloat_; - float heightFloat_; - float depthFloat_; + const Orthanc::ImageAccessor& image_; + unsigned int width_; + unsigned int height_; + unsigned int depth_; + float widthFloat_; + float heightFloat_; + float depthFloat_; public: VoxelReaderBase(const ImageBuffer3D& image) : - image_(image), + image_(image.GetInternalImage()), width_(image.GetWidth()), height_(image.GetHeight()), depth_(image.GetDepth()), @@ -257,7 +148,7 @@ { } - const ImageBuffer3D& GetImage() const + const Orthanc::ImageAccessor& GetImage() const { return image_; } @@ -331,7 +222,7 @@ public VoxelReaderBase { public: - typedef typename PixelTraits::PixelType InputPixelType; + typedef typename Orthanc::PixelTraits::PixelType InputPixelType; VoxelReader(const ImageBuffer3D& image) : VoxelReaderBase(image) @@ -361,11 +252,12 @@ fractionalX, fractionalY, fractionalZ, volumeX, volumeY, volumeZ)) { - PixelTraits::GetVoxel(target, GetImage(), imageX, imageY, imageZ); + Orthanc::ImageTraits::GetPixel(target, GetImage(), imageX, + imageY + imageZ * GetImageHeight()); } else { - PixelTraits::SetOutOfVolume(target); + target = std::numeric_limits::min(); } } }; @@ -382,9 +274,8 @@ VoxelReader(const ImageBuffer3D& image) : VoxelReaderBase(image) { - typename PixelTraits::PixelType value; - PixelTraits::SetOutOfVolume(value); - outOfVolume_ = static_cast(value); + typedef typename Orthanc::PixelTraits::PixelType Pixel; + outOfVolume_ = static_cast(std::numeric_limits::min()); } void SampleVoxels(float& f00, @@ -395,11 +286,13 @@ unsigned int imageY, unsigned int imageZ) const { - f00 = PixelTraits::GetFloatVoxel(GetImage(), imageX, imageY, imageZ); + f00 = Orthanc::ImageTraits::GetFloatPixel + (GetImage(), imageX, imageY + imageZ * GetImageHeight()); if (imageX + 1 < GetImageWidth()) { - f01 = PixelTraits::GetFloatVoxel(GetImage(), imageX + 1, imageY, imageZ); + f01 = Orthanc::ImageTraits::GetFloatPixel + (GetImage(), imageX + 1, imageY + imageZ * GetImageHeight()); } else { @@ -408,7 +301,8 @@ if (imageY + 1 < GetImageWidth()) { - f10 = PixelTraits::GetFloatVoxel(GetImage(), imageX, imageY + 1, imageZ); + f10 = Orthanc::ImageTraits::GetFloatPixel + (GetImage(), imageX, imageY + 1 + imageZ * GetImageHeight()); } else { @@ -418,7 +312,8 @@ if (imageX + 1 < GetImageWidth() && imageY + 1 < GetImageHeight()) { - f11 = PixelTraits::GetFloatVoxel(GetImage(), imageX + 1, imageY + 1, imageZ); + f11 = Orthanc::ImageTraits::GetFloatPixel + (GetImage(), imageX + 1, imageY + 1 + imageZ * GetImageHeight()); } else { @@ -740,7 +635,8 @@ for (unsigned int y = 0; y < outputHeight; y++) { - typename Writer::OutputPixelType* p = reinterpret_cast(slice.GetRow(y)); + typename Writer::OutputPixelType* p = + reinterpret_cast(slice.GetRow(y)); RowIterator it(slice, extent, plane, box, y);