Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/ImageBuffer3D.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Volumes/ImageBuffer3D.h@7f16987131e1 |
children | e731e62692a9 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
765
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
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 | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
212
diff
changeset
|
16 * |
47 | 17 * You should have received a copy of the GNU Affero General Public License |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
194
7a031ac16b2d
rename Enumerations.h to StoneEnumerations.h to avoid clashes with Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
24 #include "../StoneEnumerations.h" |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
734
diff
changeset
|
25 #include "../Toolbox/LinearAlgebra.h" |
0 | 26 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
27 #include <Compatibility.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1298
diff
changeset
|
28 #include <Images/Image.h> |
0 | 29 |
30 namespace OrthancStone | |
31 { | |
1488
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
32 /* |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
33 |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
34 This classes stores volume images sliced across the Z axis, vertically, in the decreasing Z order : |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
35 |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
36 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
37 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
38 | SLICE N-1 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
39 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
40 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
41 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
42 | SLICE N-2 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
43 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
44 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
45 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
46 | SLICE N-3 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
47 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
48 . . |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
49 ...... ...... |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
50 . . |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
51 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
52 | SLICE 2 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
53 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
54 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
55 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
56 | SLICE 1 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
57 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
58 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
59 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
60 | SLICE 0 | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
61 | | |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
62 +---------------+ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
63 |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
64 As you can see, if the 3d image has size width, height, depth, the 2d image has : |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
65 - 2d width = 3d width |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
66 - 2d height = 3d height * 3d depth |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
67 |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
68 */ |
7f16987131e1
Missing include + docs + public getter for volume geometry in multiframe loader
Benjamin Golinvaux <bgo@osimis.io>
parents:
1455
diff
changeset
|
69 |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
70 class ImageBuffer3D : public boost::noncopyable |
0 | 71 { |
72 private: | |
73 Orthanc::Image image_; | |
74 Orthanc::PixelFormat format_; | |
75 unsigned int width_; | |
76 unsigned int height_; | |
77 unsigned int depth_; | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
78 bool computeRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
79 bool hasRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
80 float minValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
81 float maxValue_; |
683
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
82 Matrix transform_; |
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
83 Matrix transformInverse_; |
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
84 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
85 void ExtendImageRange(const Orthanc::ImageAccessor& slice); |
0 | 86 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
87 void GetAxialSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
88 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
89 bool readOnly) const; |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
90 |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
91 void GetCoronalSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
92 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
93 bool readOnly) const; |
0 | 94 |
95 Orthanc::Image* ExtractSagittalSlice(unsigned int slice) const; | |
96 | |
143 | 97 template <typename T> |
98 T GetPixelUnchecked(unsigned int x, | |
99 unsigned int y, | |
100 unsigned int z) const | |
101 { | |
102 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(image_.GetConstBuffer()); | |
103 const uint8_t* row = buffer + (y + height_ * (depth_ - 1 - z)) * image_.GetPitch(); | |
104 return reinterpret_cast<const T*>(row) [x]; | |
105 } | |
106 | |
0 | 107 public: |
108 ImageBuffer3D(Orthanc::PixelFormat format, | |
109 unsigned int width, | |
110 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
111 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
112 bool computeRange); |
0 | 113 |
114 void Clear(); | |
115 | |
179
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
116 const Orthanc::ImageAccessor& GetInternalImage() const |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
117 { |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
118 return image_; |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
119 } |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
120 |
0 | 121 unsigned int GetWidth() const |
122 { | |
123 return width_; | |
124 } | |
125 | |
126 unsigned int GetHeight() const | |
127 { | |
128 return height_; | |
129 } | |
130 | |
131 unsigned int GetDepth() const | |
132 { | |
133 return depth_; | |
134 } | |
135 | |
136 Orthanc::PixelFormat GetFormat() const | |
137 { | |
138 return format_; | |
139 } | |
140 | |
765 | 141 unsigned int GetBytesPerPixel() const |
142 { | |
143 return Orthanc::GetBytesPerPixel(format_); | |
144 } | |
145 | |
105 | 146 uint64_t GetEstimatedMemorySize() const; |
147 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
148 bool GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
149 float& maxValue) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
150 |
143 | 151 uint8_t GetVoxelGrayscale8Unchecked(unsigned int x, |
152 unsigned int y, | |
153 unsigned int z) const | |
154 { | |
155 return GetPixelUnchecked<uint8_t>(x, y, z); | |
156 } | |
157 | |
158 uint16_t GetVoxelGrayscale16Unchecked(unsigned int x, | |
159 unsigned int y, | |
160 unsigned int z) const | |
161 { | |
162 return GetPixelUnchecked<uint16_t>(x, y, z); | |
163 } | |
164 | |
149
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
165 int16_t GetVoxelSignedGrayscale16Unchecked(unsigned int x, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
166 unsigned int y, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
167 unsigned int z) const |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
168 { |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
169 return GetPixelUnchecked<int16_t>(x, y, z); |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
170 } |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
171 |
143 | 172 uint8_t GetVoxelGrayscale8(unsigned int x, |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
173 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
174 unsigned int z) const; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
175 |
143 | 176 uint16_t GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
177 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
178 unsigned int z) const; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
179 |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
180 |
0 | 181 class SliceReader : public boost::noncopyable |
182 { | |
183 private: | |
184 Orthanc::ImageAccessor accessor_; | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
185 std::unique_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal |
0 | 186 |
187 public: | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
188 SliceReader(const ImageBuffer3D& that, |
0 | 189 VolumeProjection projection, |
190 unsigned int slice); | |
191 | |
192 const Orthanc::ImageAccessor& GetAccessor() const | |
193 { | |
194 return accessor_; | |
195 } | |
196 }; | |
197 | |
198 | |
199 class SliceWriter : public boost::noncopyable | |
200 { | |
201 private: | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
202 ImageBuffer3D& that_; |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
203 bool modified_; |
0 | 204 Orthanc::ImageAccessor accessor_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
205 std::unique_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal |
0 | 206 |
207 void Flush(); | |
208 | |
209 public: | |
210 SliceWriter(ImageBuffer3D& that, | |
211 VolumeProjection projection, | |
212 unsigned int slice); | |
213 | |
214 ~SliceWriter() | |
215 { | |
216 Flush(); | |
217 } | |
218 | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
219 const Orthanc::ImageAccessor& GetAccessor() const |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
220 { |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
221 return accessor_; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
222 } |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
223 |
0 | 224 Orthanc::ImageAccessor& GetAccessor() |
225 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
226 modified_ = true; |
0 | 227 return accessor_; |
228 } | |
229 }; | |
230 }; | |
231 } |