Mercurial > hg > orthanc-stone
annotate Framework/Volumes/ImageBuffer3D.h @ 148:c6a464c266dd wasm
accessors
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Jan 2018 15:30:51 +0100 |
parents | 58c545177c1c |
children | f7be90de6d1b |
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 | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
5 * Copyright (C) 2017-2018 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. | |
16 * | |
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 | |
24 #include "../Enumerations.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 | |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
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 |
51 Orthanc::ImageAccessor GetAxialSliceAccessor(unsigned int slice, | |
52 bool readOnly); | |
53 | |
54 Orthanc::ImageAccessor GetCoronalSliceAccessor(unsigned int slice, | |
55 bool readOnly); | |
56 | |
57 Orthanc::Image* ExtractSagittalSlice(unsigned int slice) const; | |
58 | |
143 | 59 template <typename T> |
60 T GetPixelUnchecked(unsigned int x, | |
61 unsigned int y, | |
62 unsigned int z) const | |
63 { | |
64 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(image_.GetConstBuffer()); | |
65 const uint8_t* row = buffer + (y + height_ * (depth_ - 1 - z)) * image_.GetPitch(); | |
66 return reinterpret_cast<const T*>(row) [x]; | |
67 } | |
68 | |
0 | 69 public: |
70 ImageBuffer3D(Orthanc::PixelFormat format, | |
71 unsigned int width, | |
72 unsigned int height, | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
73 unsigned int depth, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
74 bool computeRange); |
0 | 75 |
76 void Clear(); | |
77 | |
78 // Set the geometry of the first axial slice (i.e. the one whose | |
79 // depth == 0) | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
105
diff
changeset
|
80 void SetAxialGeometry(const CoordinateSystem3D& geometry); |
0 | 81 |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
82 const CoordinateSystem3D& GetAxialGeometry() const |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
83 { |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
84 return axialGeometry_; |
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 |
0 | 87 void SetVoxelDimensions(double x, |
88 double y, | |
89 double z); | |
90 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
91 Vector GetVoxelDimensions(VolumeProjection projection) const; |
0 | 92 |
93 void GetSliceSize(unsigned int& width, | |
94 unsigned int& height, | |
95 VolumeProjection projection); | |
96 | |
97 unsigned int GetWidth() const | |
98 { | |
99 return width_; | |
100 } | |
101 | |
102 unsigned int GetHeight() const | |
103 { | |
104 return height_; | |
105 } | |
106 | |
107 unsigned int GetDepth() const | |
108 { | |
109 return depth_; | |
110 } | |
111 | |
112 Orthanc::PixelFormat GetFormat() const | |
113 { | |
114 return format_; | |
115 } | |
116 | |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
117 ParallelSlices* GetGeometry(VolumeProjection projection) const; |
0 | 118 |
105 | 119 uint64_t GetEstimatedMemorySize() const; |
120 | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
121 bool GetRange(float& minValue, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
122 float& maxValue) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
123 |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
124 bool FitWindowingToRange(RenderStyle& style, |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
125 const DicomFrameConverter& converter) const; |
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
126 |
143 | 127 uint8_t GetVoxelGrayscale8Unchecked(unsigned int x, |
128 unsigned int y, | |
129 unsigned int z) const | |
130 { | |
131 return GetPixelUnchecked<uint8_t>(x, y, z); | |
132 } | |
133 | |
134 uint16_t GetVoxelGrayscale16Unchecked(unsigned int x, | |
135 unsigned int y, | |
136 unsigned int z) const | |
137 { | |
138 return GetPixelUnchecked<uint16_t>(x, y, z); | |
139 } | |
140 | |
141 uint8_t GetVoxelGrayscale8(unsigned int x, | |
141
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
142 unsigned int y, |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
143 unsigned int z) const; |
88bca952cb17
ImageBuffer3D::GetPixelGrayscale8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
139
diff
changeset
|
144 |
143 | 145 uint16_t GetVoxelGrayscale16(unsigned int x, |
139
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
146 unsigned int y, |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
147 unsigned int z) const; |
22628d37ef5c
ImageBuffer3D::GetPixelGrayscale16
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
148 |
0 | 149 |
150 class SliceReader : public boost::noncopyable | |
151 { | |
152 private: | |
153 Orthanc::ImageAccessor accessor_; | |
154 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
155 | |
156 public: | |
157 SliceReader(ImageBuffer3D& that, | |
158 VolumeProjection projection, | |
159 unsigned int slice); | |
160 | |
161 const Orthanc::ImageAccessor& GetAccessor() const | |
162 { | |
163 return accessor_; | |
164 } | |
165 }; | |
166 | |
167 | |
168 class SliceWriter : public boost::noncopyable | |
169 { | |
170 private: | |
119
ba83e38cf3ff
rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
171 ImageBuffer3D& that_; |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
172 bool modified_; |
0 | 173 Orthanc::ImageAccessor accessor_; |
174 std::auto_ptr<Orthanc::Image> sagittal_; // Unused for axial and coronal | |
175 | |
176 void Flush(); | |
177 | |
178 public: | |
179 SliceWriter(ImageBuffer3D& that, | |
180 VolumeProjection projection, | |
181 unsigned int slice); | |
182 | |
183 ~SliceWriter() | |
184 { | |
185 Flush(); | |
186 } | |
187 | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
188 const Orthanc::ImageAccessor& GetAccessor() const |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
189 { |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
190 return accessor_; |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
191 } |
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
192 |
0 | 193 Orthanc::ImageAccessor& GetAccessor() |
194 { | |
87
4a541cd4fa83
OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
195 modified_ = true; |
0 | 196 return accessor_; |
197 } | |
198 }; | |
199 }; | |
200 } |