comparison Framework/Volumes/ImageBuffer3D.cpp @ 316:ce48c3b3b0e9

fix for new ImageAccessor API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Oct 2018 12:45:27 +0200
parents 5412adf19980
children 557c8ff1db5c 88c79f1537de
comparison
equal deleted inserted replaced
310:348e00b837b9 316:ce48c3b3b0e9
27 27
28 #include <string.h> 28 #include <string.h>
29 29
30 namespace OrthancStone 30 namespace OrthancStone
31 { 31 {
32 Orthanc::ImageAccessor ImageBuffer3D::GetAxialSliceAccessor(unsigned int slice, 32 void ImageBuffer3D::GetAxialSliceAccessor(Orthanc::ImageAccessor& target,
33 bool readOnly) const 33 unsigned int slice,
34 bool readOnly) const
34 { 35 {
35 if (slice >= depth_) 36 if (slice >= depth_)
36 { 37 {
37 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 38 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
38 } 39 }
39 40
40 Orthanc::ImageAccessor accessor;
41
42 if (readOnly) 41 if (readOnly)
43 { 42 {
44 accessor.AssignReadOnly(format_, width_, height_, image_.GetPitch(), 43 target.AssignReadOnly(format_, width_, height_, image_.GetPitch(),
45 image_.GetConstRow(height_ * (depth_ - 1 - slice))); 44 image_.GetConstRow(height_ * (depth_ - 1 - slice)));
46 } 45 }
47 else 46 else
48 { 47 {
49 accessor.AssignWritable(format_, width_, height_, image_.GetPitch(), 48 target.AssignWritable(format_, width_, height_, image_.GetPitch(),
50 image_.GetRow(height_ * (depth_ - 1 - slice))); 49 image_.GetRow(height_ * (depth_ - 1 - slice)));
51 } 50 }
52 51 }
53 return accessor; 52
54 } 53
55 54 void ImageBuffer3D::GetCoronalSliceAccessor(Orthanc::ImageAccessor& target,
56 55 unsigned int slice,
57 Orthanc::ImageAccessor ImageBuffer3D::GetCoronalSliceAccessor(unsigned int slice, 56 bool readOnly) const
58 bool readOnly) const
59 { 57 {
60 if (slice >= height_) 58 if (slice >= height_)
61 { 59 {
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 60 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
63 } 61 }
64 62
65 Orthanc::ImageAccessor accessor;
66
67 if (readOnly) 63 if (readOnly)
68 { 64 {
69 accessor.AssignReadOnly(format_, width_, depth_, image_.GetPitch() * height_, 65 target.AssignReadOnly(format_, width_, depth_, image_.GetPitch() * height_,
70 image_.GetConstRow(slice)); 66 image_.GetConstRow(slice));
71 } 67 }
72 else 68 else
73 { 69 {
74 accessor.AssignWritable(format_, width_, depth_, image_.GetPitch() * height_, 70 target.AssignWritable(format_, width_, depth_, image_.GetPitch() * height_,
75 image_.GetRow(slice)); 71 image_.GetRow(slice));
76 } 72 }
77
78 return accessor;
79 } 73 }
80 74
81 75
82 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const 76 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const
83 { 77 {
358 unsigned int slice) 352 unsigned int slice)
359 { 353 {
360 switch (projection) 354 switch (projection)
361 { 355 {
362 case VolumeProjection_Axial: 356 case VolumeProjection_Axial:
363 accessor_ = that.GetAxialSliceAccessor(slice, true); 357 that.GetAxialSliceAccessor(accessor_, slice, true);
364 break; 358 break;
365 359
366 case VolumeProjection_Coronal: 360 case VolumeProjection_Coronal:
367 accessor_ = that.GetCoronalSliceAccessor(slice, true); 361 that.GetCoronalSliceAccessor(accessor_, slice, true);
368 break; 362 break;
369 363
370 case VolumeProjection_Sagittal: 364 case VolumeProjection_Sagittal:
371 sagittal_.reset(that.ExtractSagittalSlice(slice)); 365 sagittal_.reset(that.ExtractSagittalSlice(slice));
372 accessor_ = *sagittal_; 366 sagittal_->GetReadOnlyAccessor(accessor_);
373 break; 367 break;
374 368
375 default: 369 default:
376 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 370 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
377 } 371 }
402 modified_(false) 396 modified_(false)
403 { 397 {
404 switch (projection) 398 switch (projection)
405 { 399 {
406 case VolumeProjection_Axial: 400 case VolumeProjection_Axial:
407 accessor_ = that.GetAxialSliceAccessor(slice, false); 401 that.GetAxialSliceAccessor(accessor_, slice, false);
408 break; 402 break;
409 403
410 case VolumeProjection_Coronal: 404 case VolumeProjection_Coronal:
411 accessor_ = that.GetCoronalSliceAccessor(slice, false); 405 that.GetCoronalSliceAccessor(accessor_, slice, false);
412 break; 406 break;
413 407
414 case VolumeProjection_Sagittal: 408 case VolumeProjection_Sagittal:
415 sagittal_.reset(that.ExtractSagittalSlice(slice)); 409 sagittal_.reset(that.ExtractSagittalSlice(slice));
416 accessor_ = *sagittal_; 410 sagittal_->GetWriteableAccessor(accessor_);
417 break; 411 break;
418 412
419 default: 413 default:
420 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 414 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
421 } 415 }