Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/ImageBuffer3D.cpp @ 1851:739a69562826
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Jun 2021 14:25:58 +0200 |
parents | f053c80ea411 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
47 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
15 * Lesser General Public License for more details. |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
212
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1564
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
0 | 20 **/ |
21 | |
22 | |
23 #include "ImageBuffer3D.h" | |
24 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
25 #include <Images/ImageProcessing.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
26 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
27 #include <OrthancException.h> |
0 | 28 |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
29 #include <string.h> |
0 | 30 |
31 namespace OrthancStone | |
32 { | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
33 void ImageBuffer3D::GetAxialSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
34 unsigned int slice, |
1564
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
35 bool readOnly) |
0 | 36 { |
37 if (slice >= depth_) | |
38 { | |
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
40 } | |
41 | |
42 if (readOnly) | |
43 { | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
44 target.AssignReadOnly(format_, width_, height_, image_.GetPitch(), |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
45 image_.GetConstRow(height_ * (depth_ - 1 - slice))); |
0 | 46 } |
47 else | |
48 { | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
49 target.AssignWritable(format_, width_, height_, image_.GetPitch(), |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
50 image_.GetRow(height_ * (depth_ - 1 - slice))); |
0 | 51 } |
52 } | |
53 | |
54 | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
55 void ImageBuffer3D::GetCoronalSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
56 unsigned int slice, |
1564
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
57 bool readOnly) |
0 | 58 { |
59 if (slice >= height_) | |
60 { | |
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
62 } | |
63 | |
64 if (readOnly) | |
65 { | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
66 target.AssignReadOnly(format_, width_, depth_, image_.GetPitch() * height_, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
67 image_.GetConstRow(slice)); |
0 | 68 } |
69 else | |
70 { | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
71 target.AssignWritable(format_, width_, depth_, image_.GetPitch() * height_, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
72 image_.GetRow(slice)); |
0 | 73 } |
74 } | |
75 | |
76 | |
77 Orthanc::Image* ImageBuffer3D::ExtractSagittalSlice(unsigned int slice) const | |
78 { | |
79 if (slice >= width_) | |
80 { | |
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
82 } | |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
83 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
84 std::unique_ptr<Orthanc::Image> result(new Orthanc::Image(format_, height_, depth_, false)); |
0 | 85 |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
86 const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); |
0 | 87 |
88 for (unsigned int z = 0; z < depth_; z++) | |
89 { | |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
90 uint8_t* q = reinterpret_cast<uint8_t*>(result->GetRow(z)); |
0 | 91 |
92 for (unsigned int y = 0; y < height_; y++) | |
93 { | |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
94 const uint8_t* p = reinterpret_cast<const uint8_t*>(image_.GetConstRow(y + z * height_)) + bytesPerPixel * slice; |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
95 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
96 for (size_t x = 0; x < bytesPerPixel; ++x) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
97 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
98 q[x] = p[x]; |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
99 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
100 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
101 q += bytesPerPixel; |
0 | 102 } |
103 } | |
104 | |
105 return result.release(); | |
106 } | |
107 | |
108 | |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
109 void ImageBuffer3D::CommitSagittalSlice(unsigned int slice, |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
110 const Orthanc::ImageAccessor& source) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
111 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
112 if (slice >= width_) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
113 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
115 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
116 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
117 const unsigned int bytesPerPixel = Orthanc::GetBytesPerPixel(format_); |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
118 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
119 for (unsigned int z = 0; z < depth_; z++) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
120 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
121 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(z)); |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
122 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
123 for (unsigned int y = 0; y < height_; y++) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
124 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
125 uint8_t* q = reinterpret_cast<uint8_t*>(image_.GetRow(y + z * height_)) + bytesPerPixel * slice; |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
126 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
127 for (size_t x = 0; x < bytesPerPixel; ++x) |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
128 { |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
129 q[x] = p[x]; |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
130 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
131 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
132 p += bytesPerPixel; |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
133 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
134 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
135 } |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
136 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
137 |
0 | 138 ImageBuffer3D::ImageBuffer3D(Orthanc::PixelFormat format, |
139 unsigned int width, | |
140 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
141 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
142 bool computeRange) : |
11 | 143 image_(format, width, height * depth, false), |
0 | 144 format_(format), |
145 width_(width), | |
146 height_(height), | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
147 depth_(depth), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
148 computeRange_(computeRange), |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
149 hasRange_(false) |
0 | 150 { |
1105
640feb146fa8
Code formatting (dummyc) + log level (dummyc)
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
151 LOG(TRACE) << "Created a 3D image of size " << width << "x" << height |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
152 << "x" << depth << " in " << Orthanc::EnumerationToString(format) |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
153 << " (" << (GetEstimatedMemorySize() / (1024ll * 1024ll)) << "MB)"; |
0 | 154 } |
155 | |
156 | |
157 void ImageBuffer3D::Clear() | |
158 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
159 memset(image_.GetBuffer(), 0, image_.GetHeight() * image_.GetPitch()); |
0 | 160 } |
161 | |
162 | |
105 | 163 uint64_t ImageBuffer3D::GetEstimatedMemorySize() const |
164 { | |
165 return image_.GetPitch() * image_.GetHeight() * Orthanc::GetBytesPerPixel(format_); | |
166 } | |
167 | |
168 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
169 void ImageBuffer3D::ExtendImageRange(const Orthanc::ImageAccessor& slice) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
170 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
171 if (!computeRange_ || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
172 slice.GetWidth() == 0 || |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
173 slice.GetHeight() == 0) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
174 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
175 return; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
176 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
177 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
178 float sliceMin, sliceMax; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
212
diff
changeset
|
179 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
180 switch (slice.GetFormat()) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
181 { |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
182 case Orthanc::PixelFormat_Grayscale8: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
183 case Orthanc::PixelFormat_Grayscale16: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
184 case Orthanc::PixelFormat_Grayscale32: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
185 case Orthanc::PixelFormat_SignedGrayscale16: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
186 { |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
187 int64_t a, b; |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
188 Orthanc::ImageProcessing::GetMinMaxIntegerValue(a, b, slice); |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
189 sliceMin = static_cast<float>(a); |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
190 sliceMax = static_cast<float>(b); |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
191 break; |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
192 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
193 |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
194 case Orthanc::PixelFormat_Float32: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
195 Orthanc::ImageProcessing::GetMinMaxFloatValue(sliceMin, sliceMax, slice); |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
196 break; |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
197 |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
198 default: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
199 return; |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
200 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
201 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
202 if (hasRange_) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
203 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
204 minValue_ = std::min(minValue_, sliceMin); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
205 maxValue_ = std::max(maxValue_, sliceMax); |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
206 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
207 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
208 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
209 hasRange_ = true; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
210 minValue_ = sliceMin; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
211 maxValue_ = sliceMax; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
212 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
213 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
214 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
215 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
216 bool ImageBuffer3D::GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
217 float& maxValue) const |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
218 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
219 if (hasRange_) |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
220 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
221 minValue = minValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
222 maxValue = maxValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
223 return true; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
224 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
225 else |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
226 { |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
227 return false; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
228 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
229 } |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
230 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
231 |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
232 ImageBuffer3D::SliceReader::SliceReader(const ImageBuffer3D& that, |
0 | 233 VolumeProjection projection, |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
234 unsigned int slice) |
0 | 235 { |
1564
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
236 /** |
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
237 * NB: The "const_cast" below are OK, as the "readonly" argument |
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
238 * to "GetAxialSliceAccessor()" and "GetCoronalSliceAccessor()" |
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
239 * are set to "true", which implies read-only access. |
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
240 **/ |
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
241 |
0 | 242 switch (projection) |
243 { | |
244 case VolumeProjection_Axial: | |
1564
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
245 const_cast<ImageBuffer3D&>(that).GetAxialSliceAccessor(accessor_, slice, true); |
0 | 246 break; |
247 | |
248 case VolumeProjection_Coronal: | |
1564
e731e62692a9
upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
249 const_cast<ImageBuffer3D&>(that).GetCoronalSliceAccessor(accessor_, slice, true); |
0 | 250 break; |
251 | |
252 case VolumeProjection_Sagittal: | |
253 sagittal_.reset(that.ExtractSagittalSlice(slice)); | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
254 sagittal_->GetReadOnlyAccessor(accessor_); |
0 | 255 break; |
256 | |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
257 default: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
258 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
0 | 259 } |
260 } | |
261 | |
262 | |
263 void ImageBuffer3D::SliceWriter::Flush() | |
264 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
265 if (modified_) |
0 | 266 { |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
267 if (sagittal_.get() != NULL) |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
268 { |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
269 assert(sagittal_->GetWidth() == that_.height_ && |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
270 sagittal_->GetHeight() == that_.depth_ && |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
271 sagittal_->GetFormat() == that_.format_); |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
272 |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
273 that_.CommitSagittalSlice(slice_, *sagittal_); |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
274 } |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
275 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
276 // Update the dynamic range of the underlying image, if |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
277 // "computeRange_" is set to true |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
278 that_.ExtendImageRange(accessor_); |
0 | 279 } |
280 } | |
281 | |
282 | |
283 ImageBuffer3D::SliceWriter::SliceWriter(ImageBuffer3D& that, | |
284 VolumeProjection projection, | |
285 unsigned int slice) : | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
286 that_(that), |
1782
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
287 modified_(false), |
f053c80ea411
ImageBuffer3D::CommitSagittalSlice()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
288 slice_(slice) |
0 | 289 { |
290 switch (projection) | |
291 { | |
292 case VolumeProjection_Axial: | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
293 that.GetAxialSliceAccessor(accessor_, slice, false); |
0 | 294 break; |
295 | |
296 case VolumeProjection_Coronal: | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
297 that.GetCoronalSliceAccessor(accessor_, slice, false); |
0 | 298 break; |
299 | |
300 case VolumeProjection_Sagittal: | |
301 sagittal_.reset(that.ExtractSagittalSlice(slice)); | |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
302 sagittal_->GetWriteableAccessor(accessor_); |
0 | 303 break; |
304 | |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
305 default: |
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
306 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
0 | 307 } |
308 } | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
309 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
310 |
143 | 311 uint8_t ImageBuffer3D::GetVoxelGrayscale8(unsigned int x, |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
312 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
313 unsigned int z) const |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
314 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
315 if (format_ != Orthanc::PixelFormat_Grayscale8) |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
316 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
317 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
318 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
319 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
320 if (x >= width_ || |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
321 y >= height_ || |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
322 z >= depth_) |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
323 { |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
324 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
325 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
326 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
327 const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z)); |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
328 return reinterpret_cast<const uint8_t*>(p) [x]; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
329 } |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
330 |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
331 |
143 | 332 uint16_t ImageBuffer3D::GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
333 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
334 unsigned int z) const |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
335 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
336 if (format_ != Orthanc::PixelFormat_Grayscale16) |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
337 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
338 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
339 } |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
340 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
341 if (x >= width_ || |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
342 y >= height_ || |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
343 z >= depth_) |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
344 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
345 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
346 } |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
347 |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
348 const void* p = image_.GetConstRow(y + height_ * (depth_ - 1 - z)); |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
349 return reinterpret_cast<const uint16_t*>(p) [x]; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
350 } |
0 | 351 } |