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