Mercurial > hg > orthanc-stone
annotate Framework/Volumes/ImageBuffer3D.h @ 627:b7fd0471281c am-dev
fix CodeGeneration unit tests
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 08 May 2019 10:51:41 +0200 |
parents | b70e9be013e4 |
children | dbc1d8bfc68a |
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 | |
439 | 5 * Copyright (C) 2017-2019 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" |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
25 #include "../Layers/RenderStyle.h" |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
105
diff
changeset
|
26 #include "../Toolbox/CoordinateSystem3D.h" |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
27 #include "../Toolbox/DicomFrameConverter.h" |
0 | 28 #include "../Toolbox/ParallelSlices.h" |
29 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
30 #include <Core/Images/Image.h> |
0 | 31 |
32 namespace OrthancStone | |
33 { | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
34 class ImageBuffer3D : public boost::noncopyable |
0 | 35 { |
36 private: | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
105
diff
changeset
|
37 CoordinateSystem3D axialGeometry_; |
0 | 38 Vector voxelDimensions_; |
39 Orthanc::Image image_; | |
40 Orthanc::PixelFormat format_; | |
41 unsigned int width_; | |
42 unsigned int height_; | |
43 unsigned int depth_; | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
44 bool computeRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
45 bool hasRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
46 float minValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
47 float maxValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
48 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
49 void ExtendImageRange(const Orthanc::ImageAccessor& slice); |
0 | 50 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
51 void GetAxialSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
52 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
53 bool readOnly) const; |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
54 |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
55 void GetCoronalSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
56 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
57 bool readOnly) const; |
0 | 58 |
59 Orthanc::Image* ExtractSagittalSlice(unsigned int slice) const; | |
60 | |
143 | 61 template <typename T> |
62 T GetPixelUnchecked(unsigned int x, | |
63 unsigned int y, | |
64 unsigned int z) const | |
65 { | |
66 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(image_.GetConstBuffer()); | |
67 const uint8_t* row = buffer + (y + height_ * (depth_ - 1 - z)) * image_.GetPitch(); | |
68 return reinterpret_cast<const T*>(row) [x]; | |
69 } | |
70 | |
0 | 71 public: |
72 ImageBuffer3D(Orthanc::PixelFormat format, | |
73 unsigned int width, | |
74 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
75 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
76 bool computeRange); |
0 | 77 |
78 void Clear(); | |
79 | |
80 // Set the geometry of the first axial slice (i.e. the one whose | |
81 // depth == 0) | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
105
diff
changeset
|
82 void SetAxialGeometry(const CoordinateSystem3D& geometry); |
0 | 83 |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
84 const CoordinateSystem3D& GetAxialGeometry() const |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
85 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
86 return axialGeometry_; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
87 } |
0 | 88 |
89 void SetVoxelDimensions(double x, | |
90 double y, | |
91 double z); | |
92 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
93 Vector GetVoxelDimensions(VolumeProjection projection) const; |
0 | 94 |
95 void GetSliceSize(unsigned int& width, | |
96 unsigned int& height, | |
97 VolumeProjection projection); | |
98 | |
179
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
99 const Orthanc::ImageAccessor& GetInternalImage() const |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
100 { |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
101 return image_; |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
102 } |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
103 |
0 | 104 unsigned int GetWidth() const |
105 { | |
106 return width_; | |
107 } | |
108 | |
109 unsigned int GetHeight() const | |
110 { | |
111 return height_; | |
112 } | |
113 | |
114 unsigned int GetDepth() const | |
115 { | |
116 return depth_; | |
117 } | |
118 | |
119 Orthanc::PixelFormat GetFormat() const | |
120 { | |
121 return format_; | |
122 } | |
123 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
124 ParallelSlices* GetGeometry(VolumeProjection projection) const; |
0 | 125 |
105 | 126 uint64_t GetEstimatedMemorySize() const; |
127 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
128 bool GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
129 float& maxValue) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
130 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
131 bool FitWindowingToRange(RenderStyle& style, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
132 const DicomFrameConverter& converter) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
133 |
143 | 134 uint8_t GetVoxelGrayscale8Unchecked(unsigned int x, |
135 unsigned int y, | |
136 unsigned int z) const | |
137 { | |
138 return GetPixelUnchecked<uint8_t>(x, y, z); | |
139 } | |
140 | |
141 uint16_t GetVoxelGrayscale16Unchecked(unsigned int x, | |
142 unsigned int y, | |
143 unsigned int z) const | |
144 { | |
145 return GetPixelUnchecked<uint16_t>(x, y, z); | |
146 } | |
147 | |
149
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
148 int16_t GetVoxelSignedGrayscale16Unchecked(unsigned int x, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
149 unsigned int y, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
150 unsigned int z) const |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
151 { |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
152 return GetPixelUnchecked<int16_t>(x, y, z); |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
153 } |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
154 |
143 | 155 uint8_t GetVoxelGrayscale8(unsigned int x, |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
156 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
157 unsigned int z) const; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
158 |
143 | 159 uint16_t GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
160 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
161 unsigned int z) const; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
162 |
187
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
163 // Get the 3D position of a point in the volume, where x, y and z |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
164 // lie in the [0;1] range |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
165 Vector GetCoordinates(float x, |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
166 float y, |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
167 float z) const; |
a12ca0f4aaaa
ImageBuffer3D::GetCoordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
168 |
0 | 169 |
170 class SliceReader : public boost::noncopyable | |
171 { | |
172 private: | |
173 Orthanc::ImageAccessor accessor_; | |
174 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
175 | |
176 public: | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
177 SliceReader(const ImageBuffer3D& that, |
0 | 178 VolumeProjection projection, |
179 unsigned int slice); | |
180 | |
181 const Orthanc::ImageAccessor& GetAccessor() const | |
182 { | |
183 return accessor_; | |
184 } | |
185 }; | |
186 | |
187 | |
188 class SliceWriter : public boost::noncopyable | |
189 { | |
190 private: | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
191 ImageBuffer3D& that_; |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
192 bool modified_; |
0 | 193 Orthanc::ImageAccessor accessor_; |
194 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
195 | |
196 void Flush(); | |
197 | |
198 public: | |
199 SliceWriter(ImageBuffer3D& that, | |
200 VolumeProjection projection, | |
201 unsigned int slice); | |
202 | |
203 ~SliceWriter() | |
204 { | |
205 Flush(); | |
206 } | |
207 | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
208 const Orthanc::ImageAccessor& GetAccessor() const |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
209 { |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
210 return accessor_; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
211 } |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
212 |
0 | 213 Orthanc::ImageAccessor& GetAccessor() |
214 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
215 modified_ = true; |
0 | 216 return accessor_; |
217 } | |
218 }; | |
219 }; | |
220 } |