Mercurial > hg > orthanc-stone
annotate Framework/Volumes/ImageBuffer3D.h @ 1039:3a35d8397559
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 07 Oct 2019 22:37:24 +0200 |
parents | f6438fdc447e |
children | 2d8ab34c8c91 |
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" |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
734
diff
changeset
|
25 #include "../Toolbox/LinearAlgebra.h" |
0 | 26 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/Images/Image.h> |
0 | 28 |
29 namespace OrthancStone | |
30 { | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
31 class ImageBuffer3D : public boost::noncopyable |
0 | 32 { |
33 private: | |
34 Orthanc::Image image_; | |
35 Orthanc::PixelFormat format_; | |
36 unsigned int width_; | |
37 unsigned int height_; | |
38 unsigned int depth_; | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
39 bool computeRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
40 bool hasRange_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
41 float minValue_; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
42 float maxValue_; |
683
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
43 Matrix transform_; |
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
44 Matrix transformInverse_; |
dbc1d8bfc68a
reorganizing ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
45 |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
46 void ExtendImageRange(const Orthanc::ImageAccessor& slice); |
0 | 47 |
316
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
48 void GetAxialSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
49 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
50 bool readOnly) const; |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
51 |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
52 void GetCoronalSliceAccessor(Orthanc::ImageAccessor& target, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
53 unsigned int slice, |
ce48c3b3b0e9
fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
54 bool readOnly) const; |
0 | 55 |
56 Orthanc::Image* ExtractSagittalSlice(unsigned int slice) const; | |
57 | |
143 | 58 template <typename T> |
59 T GetPixelUnchecked(unsigned int x, | |
60 unsigned int y, | |
61 unsigned int z) const | |
62 { | |
63 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(image_.GetConstBuffer()); | |
64 const uint8_t* row = buffer + (y + height_ * (depth_ - 1 - z)) * image_.GetPitch(); | |
65 return reinterpret_cast<const T*>(row) [x]; | |
66 } | |
67 | |
0 | 68 public: |
69 ImageBuffer3D(Orthanc::PixelFormat format, | |
70 unsigned int width, | |
71 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
72 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
73 bool computeRange); |
0 | 74 |
75 void Clear(); | |
76 | |
179
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
77 const Orthanc::ImageAccessor& GetInternalImage() const |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
78 { |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
79 return image_; |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
80 } |
db21c1810c89
moving PixelTraits to the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
149
diff
changeset
|
81 |
0 | 82 unsigned int GetWidth() const |
83 { | |
84 return width_; | |
85 } | |
86 | |
87 unsigned int GetHeight() const | |
88 { | |
89 return height_; | |
90 } | |
91 | |
92 unsigned int GetDepth() const | |
93 { | |
94 return depth_; | |
95 } | |
96 | |
97 Orthanc::PixelFormat GetFormat() const | |
98 { | |
99 return format_; | |
100 } | |
101 | |
765 | 102 unsigned int GetBytesPerPixel() const |
103 { | |
104 return Orthanc::GetBytesPerPixel(format_); | |
105 } | |
106 | |
105 | 107 uint64_t GetEstimatedMemorySize() const; |
108 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
109 bool GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
110 float& maxValue) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
111 |
143 | 112 uint8_t GetVoxelGrayscale8Unchecked(unsigned int x, |
113 unsigned int y, | |
114 unsigned int z) const | |
115 { | |
116 return GetPixelUnchecked<uint8_t>(x, y, z); | |
117 } | |
118 | |
119 uint16_t GetVoxelGrayscale16Unchecked(unsigned int x, | |
120 unsigned int y, | |
121 unsigned int z) const | |
122 { | |
123 return GetPixelUnchecked<uint16_t>(x, y, z); | |
124 } | |
125 | |
149
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
126 int16_t GetVoxelSignedGrayscale16Unchecked(unsigned int x, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
127 unsigned int y, |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
128 unsigned int z) const |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
129 { |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
130 return GetPixelUnchecked<int16_t>(x, y, z); |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
131 } |
f7be90de6d1b
ImageBuffer3D::GetVoxelSignedGrayscale16Unchecked()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
132 |
143 | 133 uint8_t GetVoxelGrayscale8(unsigned int x, |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
134 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
135 unsigned int z) const; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
136 |
143 | 137 uint16_t GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
138 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
139 unsigned int z) const; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
140 |
684
7719eb852dd5
new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
683
diff
changeset
|
141 |
0 | 142 class SliceReader : public boost::noncopyable |
143 { | |
144 private: | |
145 Orthanc::ImageAccessor accessor_; | |
146 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
147 | |
148 public: | |
192
371da7fe2c0e
FiniteProjectiveCamera::ApplyRaytracer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
149 SliceReader(const ImageBuffer3D& that, |
0 | 150 VolumeProjection projection, |
151 unsigned int slice); | |
152 | |
153 const Orthanc::ImageAccessor& GetAccessor() const | |
154 { | |
155 return accessor_; | |
156 } | |
157 }; | |
158 | |
159 | |
160 class SliceWriter : public boost::noncopyable | |
161 { | |
162 private: | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 ImageBuffer3D& that_; |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
164 bool modified_; |
0 | 165 Orthanc::ImageAccessor accessor_; |
166 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
167 | |
168 void Flush(); | |
169 | |
170 public: | |
171 SliceWriter(ImageBuffer3D& that, | |
172 VolumeProjection projection, | |
173 unsigned int slice); | |
174 | |
175 ~SliceWriter() | |
176 { | |
177 Flush(); | |
178 } | |
179 | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
180 const Orthanc::ImageAccessor& GetAccessor() const |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
181 { |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
182 return accessor_; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
183 } |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
184 |
0 | 185 Orthanc::ImageAccessor& GetAccessor() |
186 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
187 modified_ = true; |
0 | 188 return accessor_; |
189 } | |
190 }; | |
191 }; | |
192 } |