comparison 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
comparison
equal deleted inserted replaced
1781:bf4b15b059ea 1782:f053c80ea411
74 } 74 }
75 75
76 76
77 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const 77 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const
78 { 78 {
79 //LOG(TRACE) << "ImageBuffer3D::ExtractSagittalSlice this= " << std::hex << this << std::dec << " width_ = " << width_ << " height_ = " << height_ << " depth_ = " << depth_ << " slice = " << slice;
80 if (slice >= width_) 79 if (slice >= width_)
81 { 80 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 81 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
83 } 82 }
84 83
85 std::unique_ptr<Orthanc::Image> result(new Orthanc::Image(format_, height_, depth_, false)); 84 std::unique_ptr<Orthanc::Image> result(new Orthanc::Image(format_, height_, depth_, false));
86 //LOG(TRACE) << "ImageBuffer3D::ExtractSagittalSlice result will be an image of WIDTH = " << height_ << " and HEIGHT = " << depth_; 85
87 86 const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_);
88 unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_);
89 87
90 for (unsigned int z = 0; z < depth_; z++) 88 for (unsigned int z = 0; z < depth_; z++)
91 { 89 {
92 //uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(depth_ - 1 - z)); 90 uint8_t* q = reinterpret_cast<uint8_t*>(result->GetRow(z));
93 uint8_t* target = reinterpret_cast<uint8_t*>(result->GetRow(z));
94 91
95 for (unsigned int y = 0; y < height_; y++) 92 for (unsigned int y = 0; y < height_; y++)
96 { 93 {
97 const void* source = (reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + bytesPerPixel * slice); 94 const uint8_t* p = reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + bytesPerPixel * slice;
98 const uint8_t* byteSrc = reinterpret_cast<const uint8_t*>(source); 95
99 for (size_t byte = 0; byte < bytesPerPixel; ++byte) 96 for (size_t x = 0; x < bytesPerPixel; ++x)
100 target[byte] = byteSrc[byte]; 97 {
101 target += bytesPerPixel; 98 q[x] = p[x];
99 }
100
101 q += bytesPerPixel;
102 } 102 }
103 } 103 }
104 104
105 return result.release(); 105 return result.release();
106 } 106 }
107
108
109 void ImageBuffer3D::CommitSagittalSlice(unsigned int slice,
110 const Orthanc::ImageAccessor& source)
111 {
112 if (slice >= width_)
113 {
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
115 }
116
117 const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_);
118
119 for (unsigned int z = 0; z < depth_; z++)
120 {
121 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(z));
122
123 for (unsigned int y = 0; y < height_; y++)
124 {
125 uint8_t* q = reinterpret_cast<uint8_t*>(image_.GetRow(y + z * height_)) + bytesPerPixel * slice;
126
127 for (size_t x = 0; x < bytesPerPixel; ++x)
128 {
129 q[x] = p[x];
130 }
131
132 p += bytesPerPixel;
133 }
134 }
135 }
107 136
108 137
109 ImageBuffer3D::ImageBuffer3D(Orthanc::PixelFormat format, 138 ImageBuffer3D::ImageBuffer3D(Orthanc::PixelFormat format,
110 unsigned int width, 139 unsigned int width,
111 unsigned int height, 140 unsigned int height,
235 { 264 {
236 if (modified_) 265 if (modified_)
237 { 266 {
238 if (sagittal_.get() != NULL) 267 if (sagittal_.get() != NULL)
239 { 268 {
240 // TODO 269 assert(sagittal_->GetWidth() == that_.height_ &&
241 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 270 sagittal_->GetHeight() == that_.depth_ &&
271 sagittal_->GetFormat() == that_.format_);
272
273 that_.CommitSagittalSlice(slice_, *sagittal_);
242 } 274 }
243 275
244 // Update the dynamic range of the underlying image, if 276 // Update the dynamic range of the underlying image, if
245 // "computeRange_" is set to true 277 // "computeRange_" is set to true
246 that_.ExtendImageRange(accessor_); 278 that_.ExtendImageRange(accessor_);
250 282
251 ImageBuffer3D::SliceWriter::SliceWriter(ImageBuffer3D& that, 283 ImageBuffer3D::SliceWriter::SliceWriter(ImageBuffer3D& that,
252 VolumeProjection projection, 284 VolumeProjection projection,
253 unsigned int slice) : 285 unsigned int slice) :
254 that_(that), 286 that_(that),
255 modified_(false) 287 modified_(false),
288 slice_(slice)
256 { 289 {
257 switch (projection) 290 switch (projection)
258 { 291 {
259 case VolumeProjection_Axial: 292 case VolumeProjection_Axial:
260 that.GetAxialSliceAccessor(accessor_, slice, false); 293 that.GetAxialSliceAccessor(accessor_, slice, false);