Mercurial > hg > orthanc-stone
diff OrthancStone/Sources/Volumes/ImageBuffer3D.cpp @ 1782:f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 May 2021 16:30:54 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
line wrap: on
line diff
--- a/OrthancStone/Sources/Volumes/ImageBuffer3D.cpp Fri May 14 15:35:24 2021 +0200 +++ b/OrthancStone/Sources/Volumes/ImageBuffer3D.cpp Fri May 14 16:30:54 2021 +0200 @@ -76,29 +76,29 @@ Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const { - //LOG(TRACE) << "ImageBuffer3D::ExtractSagittalSlice this= " << std::hex << this << std::dec << " width_ = " << width_ << " height_ = " << height_ << " depth_ = " << depth_ << " slice = " << slice; if (slice >= width_) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } - + std::unique_ptr<Orthanc::Image> result(new Orthanc::Image(format_, height_, depth_, false)); - //LOG(TRACE) << "ImageBuffer3D::ExtractSagittalSlice result will be an image of WIDTH = " << height_ << " and HEIGHT = " << depth_; - unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); + const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); for (unsigned int z = 0; z < depth_; z++) { - //uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(depth_ - 1 - z)); - uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(z)); + uint8_t* q = reinterpret_cast<uint8_t*>(result->GetRow(z)); for (unsigned int y = 0; y < height_; y++) { - const void* source = (reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + bytesPerPixel * slice); - const uint8_t* byteSrc = reinterpret_cast<const uint8_t*>(source); - for (size_t byte = 0; byte < bytesPerPixel; ++byte) - target[byte] = byteSrc[byte]; - target += bytesPerPixel; + const uint8_t* p = reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + bytesPerPixel * slice; + + for (size_t x = 0; x < bytesPerPixel; ++x) + { + q[x] = p[x]; + } + + q += bytesPerPixel; } } @@ -106,6 +106,35 @@ } + void ImageBuffer3D::CommitSagittalSlice(unsigned int slice, + const Orthanc::ImageAccessor& source) + { + if (slice >= width_) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + + const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); + + for (unsigned int z = 0; z < depth_; z++) + { + const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(z)); + + for (unsigned int y = 0; y < height_; y++) + { + uint8_t* q = reinterpret_cast<uint8_t*>(image_.GetRow(y + z * height_)) + bytesPerPixel * slice; + + for (size_t x = 0; x < bytesPerPixel; ++x) + { + q[x] = p[x]; + } + + p += bytesPerPixel; + } + } + } + + ImageBuffer3D::ImageBuffer3D(Orthanc::PixelFormat format, unsigned int width, unsigned int height, @@ -237,8 +266,11 @@ { if (sagittal_.get() != NULL) { - // TODO - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + assert(sagittal_->GetWidth() == that_.height_ && + sagittal_->GetHeight() == that_.depth_ && + sagittal_->GetFormat() == that_.format_); + + that_.CommitSagittalSlice(slice_, *sagittal_); } // Update the dynamic range of the underlying image, if @@ -252,7 +284,8 @@ VolumeProjection projection, unsigned int slice) : that_(that), - modified_(false) + modified_(false), + slice_(slice) { switch (projection) {