Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
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. | |
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 | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "../StoneEnumerations.h" | |
25 #include "../Toolbox/LinearAlgebra.h" | |
26 | |
27 #include <Compatibility.h> | |
28 #include <Images/Image.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 /* | |
33 | |
34 This classes stores volume images sliced across the Z axis, vertically, in the decreasing Z order : | |
35 | |
36 +---------------+ | |
37 | | | |
38 | SLICE N-1 | | |
39 | | | |
40 +---------------+ | |
41 | | | |
42 | SLICE N-2 | | |
43 | | | |
44 +---------------+ | |
45 | | | |
46 | SLICE N-3 | | |
47 | | | |
48 . . | |
49 ...... ...... | |
50 . . | |
51 | | | |
52 | SLICE 2 | | |
53 | | | |
54 +---------------+ | |
55 | | | |
56 | SLICE 1 | | |
57 | | | |
58 +---------------+ | |
59 | | | |
60 | SLICE 0 | | |
61 | | | |
62 +---------------+ | |
63 | |
64 As you can see, if the 3d image has size width, height, depth, the 2d image has : | |
65 - 2d width = 3d width | |
66 - 2d height = 3d height * 3d depth | |
67 | |
68 */ | |
69 | |
70 class ImageBuffer3D : public boost::noncopyable | |
71 { | |
72 private: | |
73 Orthanc::Image image_; | |
74 Orthanc::PixelFormat format_; | |
75 unsigned int width_; | |
76 unsigned int height_; | |
77 unsigned int depth_; | |
78 bool computeRange_; | |
79 bool hasRange_; | |
80 float minValue_; | |
81 float maxValue_; | |
82 Matrix transform_; | |
83 Matrix transformInverse_; | |
84 | |
85 void ExtendImageRange(const Orthanc::ImageAccessor& slice); | |
86 | |
87 void GetAxialSliceAccessor(Orthanc::ImageAccessor& target, | |
88 unsigned int slice, | |
89 bool readOnly) const; | |
90 | |
91 void GetCoronalSliceAccessor(Orthanc::ImageAccessor& target, | |
92 unsigned int slice, | |
93 bool readOnly) const; | |
94 | |
95 Orthanc::Image* ExtractSagittalSlice(unsigned int slice) const; | |
96 | |
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 | |
107 public: | |
108 ImageBuffer3D(Orthanc::PixelFormat format, | |
109 unsigned int width, | |
110 unsigned int height, | |
111 unsigned int depth, | |
112 bool computeRange); | |
113 | |
114 void Clear(); | |
115 | |
116 const Orthanc::ImageAccessor& GetInternalImage() const | |
117 { | |
118 return image_; | |
119 } | |
120 | |
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 | |
141 unsigned int GetBytesPerPixel() const | |
142 { | |
143 return Orthanc::GetBytesPerPixel(format_); | |
144 } | |
145 | |
146 uint64_t GetEstimatedMemorySize() const; | |
147 | |
148 bool GetRange(float& minValue, | |
149 float& maxValue) const; | |
150 | |
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 | |
165 int16_t GetVoxelSignedGrayscale16Unchecked(unsigned int x, | |
166 unsigned int y, | |
167 unsigned int z) const | |
168 { | |
169 return GetPixelUnchecked<int16_t>(x, y, z); | |
170 } | |
171 | |
172 uint8_t GetVoxelGrayscale8(unsigned int x, | |
173 unsigned int y, | |
174 unsigned int z) const; | |
175 | |
176 uint16_t GetVoxelGrayscale16(unsigned int x, | |
177 unsigned int y, | |
178 unsigned int z) const; | |
179 | |
180 | |
181 class SliceReader : public boost::noncopyable | |
182 { | |
183 private: | |
184 Orthanc::ImageAccessor accessor_; | |
185 std::unique_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
186 | |
187 public: | |
188 SliceReader(const ImageBuffer3D& that, | |
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: | |
202 ImageBuffer3D& that_; | |
203 bool modified_; | |
204 Orthanc::ImageAccessor accessor_; | |
205 std::unique_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
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 | |
219 const Orthanc::ImageAccessor& GetAccessor() const | |
220 { | |
221 return accessor_; | |
222 } | |
223 | |
224 Orthanc::ImageAccessor& GetAccessor() | |
225 { | |
226 modified_ = true; | |
227 return accessor_; | |
228 } | |
229 }; | |
230 }; | |
231 } |