annotate Framework/Volumes/VolumeReslicer.cpp @ 884:aad5ccf1be10 am-dev

cleanup
author Alain Mazy <alain@mazy.be>
date Tue, 09 Jul 2019 14:43:00 +0200
parents cd13a062c9bd
children a7351ad54960
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
186
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
1 /**
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
2 * Stone of Orthanc
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
186
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
6 *
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
7 * This program is free software: you can redistribute it and/or
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
10 * the License, or (at your option) any later version.
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
11 *
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
12 * This program is distributed in the hope that it will be useful, but
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
15 * Affero General Public License for more details.
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
16 *
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
19 **/
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
20
fac46066b933 missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 185
diff changeset
21
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "VolumeReslicer.h"
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
24 #include "../Toolbox/GeometryToolbox.h"
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
25 #include "../Toolbox/SubvoxelReader.h"
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
26
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
27 #include <Core/Images/ImageTraits.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
28 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
29 #include <Core/OrthancException.h>
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/math/special_functions/round.hpp>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 // Anonymous namespace to avoid clashes between compilation modules
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 enum TransferFunction
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 TransferFunction_Copy,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 TransferFunction_Float,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 TransferFunction_Linear
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
46 template <Orthanc::PixelFormat InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
47 Orthanc::PixelFormat OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
48 ImageInterpolation Interpolation,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 TransferFunction Function>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 class PixelShader;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
53 template <Orthanc::PixelFormat Format>
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
54 class PixelShader<Format,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
55 Format,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
56 ImageInterpolation_Nearest,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
57 TransferFunction_Copy>
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 private:
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
60 typedef SubvoxelReader<Format, ImageInterpolation_Nearest> VoxelReader;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
61 typedef Orthanc::PixelTraits<Format> PixelWriter;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
62
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
63 VoxelReader reader_;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
64
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
65 public:
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
66 PixelShader(const ImageBuffer3D& image,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
67 float /* scaling */,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
68 float /* offset */) :
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
69 reader_(image)
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
70 {
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
71 }
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
72
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
73 ORTHANC_FORCE_INLINE
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
74 void Apply(typename PixelWriter::PixelType* pixel,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
75 float volumeX,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
76 float volumeY,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
77 float volumeZ)
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
78 {
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
79 typename VoxelReader::PixelType value;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
80
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
81 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ))
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
82 {
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
83 VoxelReader::Traits::SetMinValue(value);
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
84 }
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
85
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
86 *pixel = value;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
87 }
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
88 };
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
89
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
90
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
91 template <Orthanc::PixelFormat InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
92 Orthanc::PixelFormat OutputFormat>
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
93 class PixelShader<InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
94 OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
95 ImageInterpolation_Nearest,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
96 TransferFunction_Copy>
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
97 {
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
98 private:
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
99 typedef SubvoxelReader<InputFormat, ImageInterpolation_Nearest> VoxelReader;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
100 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
101
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 VoxelReader reader_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 public:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 PixelShader(const ImageBuffer3D& image,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 float /* scaling */,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 float /* offset */) :
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 reader_(image)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
180
4da803580da9 remove macro ORTHANC_STONE_FORCE_INLINE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
112 ORTHANC_FORCE_INLINE
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
113 void Apply(typename PixelWriter::PixelType* pixel,
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
114 float volumeX,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
115 float volumeY,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
116 float volumeZ)
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
118 typename VoxelReader::PixelType value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
119
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
120 if (!reader_.GetValue(value, volumeX, volumeY, volumeZ))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
121 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
122 VoxelReader::Traits::SetMinValue(value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
123 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
124
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
125 PixelWriter::FloatToPixel(*pixel, VoxelReader::Traits::PixelToFloat(value));
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
130 template <Orthanc::PixelFormat InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
131 Orthanc::PixelFormat OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
132 ImageInterpolation Interpolation>
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
133 class PixelShader<InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
134 OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
135 Interpolation,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
136 TransferFunction_Float>
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 private:
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
139 typedef SubvoxelReader<InputFormat, Interpolation> VoxelReader;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
140 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
141
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 VoxelReader reader_;
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
143 float outOfVolume_;
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 public:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 PixelShader(const ImageBuffer3D& image,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 float /* scaling */,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 float /* offset */) :
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
149 reader_(image),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
150 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min()))
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
180
4da803580da9 remove macro ORTHANC_STONE_FORCE_INLINE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
154 ORTHANC_FORCE_INLINE
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
155 void Apply(typename PixelWriter::PixelType* pixel,
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
156 float volumeX,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
157 float volumeY,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
158 float volumeZ)
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
160 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
161
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
162 if (!reader_.GetFloatValue(value, volumeX, volumeY, volumeZ))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
163 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
164 value = outOfVolume_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
165 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
166
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
167 PixelWriter::FloatToPixel(*pixel, value);
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
168 }
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
172 template <Orthanc::PixelFormat InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
173 Orthanc::PixelFormat OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
174 ImageInterpolation Interpolation>
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
175 class PixelShader<InputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
176 OutputFormat,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
177 Interpolation,
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
178 TransferFunction_Linear>
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 private:
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
181 typedef SubvoxelReader<InputFormat, Interpolation> VoxelReader;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
182 typedef Orthanc::PixelTraits<OutputFormat> PixelWriter;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
183
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 VoxelReader reader_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 float scaling_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 float offset_;
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
187 float outOfVolume_;
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 public:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 PixelShader(const ImageBuffer3D& image,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 float scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 float offset) :
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 reader_(image),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 scaling_(scaling),
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
195 offset_(offset),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
196 outOfVolume_(static_cast<float>(std::numeric_limits<typename VoxelReader::PixelType>::min()))
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
180
4da803580da9 remove macro ORTHANC_STONE_FORCE_INLINE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
200 ORTHANC_FORCE_INLINE
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
201 void Apply(typename PixelWriter::PixelType* pixel,
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
202 float volumeX,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
203 float volumeY,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
204 float volumeZ)
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
206 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
207
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
208 if (reader_.GetFloatValue(value, volumeX, volumeY, volumeZ))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
209 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
210 value = scaling_ * value + offset_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
211 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
212 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
213 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
214 value = outOfVolume_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
215 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
216
184
9523ce4f44cc removing PixelWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
217 PixelWriter::FloatToPixel(*pixel, value);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 class FastRowIterator : public boost::noncopyable
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 private:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 float position_[3];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 float offset_[3];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 public:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 FastRowIterator(const Orthanc::ImageAccessor& slice,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 const Extent2D& extent,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
233 const OrientedVolumeBoundingBox& box,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 unsigned int y)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 const double width = static_cast<double>(slice.GetWidth());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 const double height = static_cast<double>(slice.GetHeight());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 assert(y < height);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 Vector q1 = plane.MapSliceToWorldCoordinates
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 (extent.GetX1() + extent.GetWidth() * static_cast<double>(0) / static_cast<double>(width + 1),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 extent.GetY1() + extent.GetHeight() * static_cast<double>(y) / static_cast<double>(height + 1));
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 Vector q2 = plane.MapSliceToWorldCoordinates
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 (extent.GetX1() + extent.GetWidth() * static_cast<double>(width - 1) / static_cast<double>(width + 1),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 extent.GetY1() + extent.GetHeight() * static_cast<double>(y) / static_cast<double>(height + 1));
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 Vector r1, r2;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 box.ToInternalCoordinates(r1, q1);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 box.ToInternalCoordinates(r2, q2);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 position_[0] = static_cast<float>(r1[0]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 position_[1] = static_cast<float>(r1[1]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 position_[2] = static_cast<float>(r1[2]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 Vector tmp = (r2 - r1) / static_cast<double>(width - 1);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 offset_[0] = static_cast<float>(tmp[0]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 offset_[1] = static_cast<float>(tmp[1]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 offset_[2] = static_cast<float>(tmp[2]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
180
4da803580da9 remove macro ORTHANC_STONE_FORCE_INLINE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
262 ORTHANC_FORCE_INLINE
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 void Next()
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 position_[0] += offset_[0];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 position_[1] += offset_[1];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 position_[2] += offset_[2];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
180
4da803580da9 remove macro ORTHANC_STONE_FORCE_INLINE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
270 ORTHANC_FORCE_INLINE
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
271 void GetVolumeCoordinates(float& x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
272 float& y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
273 float& z) const
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 x = position_[0];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 y = position_[1];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 z = position_[2];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 class SlowRowIterator : public boost::noncopyable
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 private:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 const Orthanc::ImageAccessor& slice_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 const Extent2D& extent_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 const CoordinateSystem3D& plane_;
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
288 const OrientedVolumeBoundingBox& box_;
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 unsigned int x_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 unsigned int y_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 public:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 SlowRowIterator(const Orthanc::ImageAccessor& slice,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 const Extent2D& extent,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
296 const OrientedVolumeBoundingBox& box,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 unsigned int y) :
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 slice_(slice),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 extent_(extent),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 plane_(plane),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 box_(box),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 x_(0),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 y_(y)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 assert(y_ < slice_.GetHeight());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 void Next()
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 x_++;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
313 void GetVolumeCoordinates(float& x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
314 float& y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
315 float& z) const
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 assert(x_ < slice_.GetWidth());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 const double width = static_cast<double>(slice_.GetWidth());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 const double height = static_cast<double>(slice_.GetHeight());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 Vector q = plane_.MapSliceToWorldCoordinates
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 (extent_.GetX1() + extent_.GetWidth() * static_cast<double>(x_) / (width + 1.0),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 extent_.GetY1() + extent_.GetHeight() * static_cast<double>(y_) / (height + 1.0));
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 Vector r;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 box_.ToInternalCoordinates(r, q);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 x = static_cast<float>(r[0]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 y = static_cast<float>(r[1]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 z = static_cast<float>(r[2]);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 };
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 template <typename RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 Orthanc::PixelFormat InputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 Orthanc::PixelFormat OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ImageInterpolation Interpolation,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 TransferFunction Function>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 static void ProcessImage(Orthanc::ImageAccessor& slice,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 const Extent2D& extent,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 const ImageBuffer3D& source,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
345 const OrientedVolumeBoundingBox& box,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 float scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 float offset)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
349 typedef PixelShader<InputFormat, OutputFormat, Interpolation, Function> Shader;
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 const unsigned int outputWidth = slice.GetWidth();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 const unsigned int outputHeight = slice.GetHeight();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
354 const float sourceWidth = static_cast<float>(source.GetWidth());
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
355 const float sourceHeight = static_cast<float>(source.GetHeight());
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
356 const float sourceDepth = static_cast<float>(source.GetDepth());
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
357
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 Shader shader(source, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 for (unsigned int y = 0; y < outputHeight; y++)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
185
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
362 typedef typename Orthanc::ImageTraits<OutputFormat>::PixelType PixelType;
d61224de4883 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 184
diff changeset
363 PixelType* p = reinterpret_cast<PixelType*>(slice.GetRow(y));
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 RowIterator it(slice, extent, plane, box, y);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 for (unsigned int x = 0; x < outputWidth; x++, p++)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
369 float volumeX, volumeY, volumeZ;
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
370 it.GetVolumeCoordinates(volumeX, volumeY, volumeZ);
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
371
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
372 shader.Apply(p,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
373 volumeX * sourceWidth,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
374 volumeY * sourceHeight,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
375 volumeZ * sourceDepth);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 it.Next();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 template <typename RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Orthanc::PixelFormat InputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 Orthanc::PixelFormat OutputFormat>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 static void ProcessImage(Orthanc::ImageAccessor& slice,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 const Extent2D& extent,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 const ImageBuffer3D& source,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
389 const OrientedVolumeBoundingBox& box,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 ImageInterpolation interpolation,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 bool hasLinearFunction,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 float scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 float offset)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 if (hasLinearFunction)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 switch (interpolation)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 case ImageInterpolation_Nearest:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 ImageInterpolation_Nearest, TransferFunction_Linear>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 (slice, extent, source, plane, box, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 case ImageInterpolation_Bilinear:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ImageInterpolation_Bilinear, TransferFunction_Linear>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 (slice, extent, source, plane, box, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 case ImageInterpolation_Trilinear:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 ImageInterpolation_Trilinear, TransferFunction_Linear>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 (slice, extent, source, plane, box, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 default:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 switch (interpolation)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 case ImageInterpolation_Nearest:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 ImageInterpolation_Nearest, TransferFunction_Copy>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 (slice, extent, source, plane, box, 0, 0);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 case ImageInterpolation_Bilinear:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 ImageInterpolation_Bilinear, TransferFunction_Float>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 (slice, extent, source, plane, box, 0, 0);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 case ImageInterpolation_Trilinear:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 ProcessImage<RowIterator, InputFormat, OutputFormat,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 ImageInterpolation_Trilinear, TransferFunction_Float>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 (slice, extent, source, plane, box, 0, 0);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 default:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 template <typename RowIterator>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 static void ProcessImage(Orthanc::ImageAccessor& slice,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 const Extent2D& extent,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 const ImageBuffer3D& source,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
455 const OrientedVolumeBoundingBox& box,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 ImageInterpolation interpolation,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 bool hasLinearFunction,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 float scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 float offset)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 slice.GetFormat() == Orthanc::PixelFormat_Grayscale8)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 ProcessImage<RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 Orthanc::PixelFormat_Grayscale16,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 Orthanc::PixelFormat_Grayscale8>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 else if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 slice.GetFormat() == Orthanc::PixelFormat_Grayscale16)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 ProcessImage<RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 Orthanc::PixelFormat_Grayscale16,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 Orthanc::PixelFormat_Grayscale16>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 else if (source.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 slice.GetFormat() == Orthanc::PixelFormat_BGRA32)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 ProcessImage<RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 Orthanc::PixelFormat_SignedGrayscale16,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 Orthanc::PixelFormat_BGRA32>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 else if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 slice.GetFormat() == Orthanc::PixelFormat_BGRA32)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 ProcessImage<RowIterator,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 Orthanc::PixelFormat_Grayscale16,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 Orthanc::PixelFormat_BGRA32>
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 void VolumeReslicer::CheckIterators(const ImageBuffer3D& source,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 const CoordinateSystem3D& plane,
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
504 const OrientedVolumeBoundingBox& box) const
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 for (unsigned int y = 0; y < slice_->GetHeight(); y++)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 FastRowIterator fast(*slice_, extent_, plane, box, y);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 SlowRowIterator slow(*slice_, extent_, plane, box, y);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 for (unsigned int x = 0; x < slice_->GetWidth(); x++)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 float px, py, pz;
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
514 fast.GetVolumeCoordinates(px, py, pz);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 float qx, qy, qz;
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
517 slow.GetVolumeCoordinates(qx, qy, qz);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 Vector d;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 154
diff changeset
520 LinearAlgebra::AssignVector(d, px - qx, py - qy, pz - qz);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 double norm = boost::numeric::ublas::norm_2(d);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 if (norm > 0.0001)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 fast.Next();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 slow.Next();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 void VolumeReslicer::Reset()
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 success_ = false;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 extent_.Reset();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 slice_.reset(NULL);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 float VolumeReslicer::GetMinOutputValue() const
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 switch (outputFormat_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 case Orthanc::PixelFormat_Grayscale8:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 case Orthanc::PixelFormat_Grayscale16:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 case Orthanc::PixelFormat_BGRA32:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 return 0.0f;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 default:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 float VolumeReslicer::GetMaxOutputValue() const
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 switch (outputFormat_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 case Orthanc::PixelFormat_Grayscale8:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 case Orthanc::PixelFormat_BGRA32:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 return static_cast<float>(std::numeric_limits<uint8_t>::max());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 case Orthanc::PixelFormat_Grayscale16:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 return static_cast<float>(std::numeric_limits<uint16_t>::max());
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 break;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 default:
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 VolumeReslicer::VolumeReslicer() :
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 outputFormat_(Orthanc::PixelFormat_Grayscale8),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 interpolation_(ImageInterpolation_Nearest),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 fastMode_(true),
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 success_(false)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 ResetLinearFunction();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 void VolumeReslicer::GetLinearFunction(float& scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 float& offset) const
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 if (hasLinearFunction_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 scaling = scaling_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 offset = offset_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 scaling = 1.0f;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 offset = 0.0f;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 void VolumeReslicer::ResetLinearFunction()
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 Reset();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 hasLinearFunction_ = false;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 scaling_ = 1.0f;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 offset_ = 0.0f;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 void VolumeReslicer::SetLinearFunction(float scaling,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 float offset)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 Reset();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 hasLinearFunction_ = true;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 scaling_ = scaling;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 offset_ = offset;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 void VolumeReslicer::SetWindow(float low,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 float high)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 //printf("Range in pixel values: %f->%f\n", low, high);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 float scaling = (GetMaxOutputValue() - GetMinOutputValue()) / (high - low);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 float offset = GetMinOutputValue() - scaling * low;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 SetLinearFunction(scaling, offset);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 /*float x = scaling_ * low + offset_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 float y = scaling_ * high + offset_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 printf("%f %f (should be %f->%f)\n", x, y, GetMinOutputValue(), GetMaxOutputValue());*/
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 void VolumeReslicer::FitRange(const ImageBuffer3D& image)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 float minInputValue, maxInputValue;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 if (!image.GetRange(minInputValue, maxInputValue) ||
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 maxInputValue < 1)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 ResetLinearFunction();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 SetWindow(minInputValue, maxInputValue);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 void VolumeReslicer::SetWindowing(ImageWindowing windowing,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 const ImageBuffer3D& image,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 float rescaleSlope,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 float rescaleIntercept)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 {
589
3080ec4ec6b9 removed enum value: ImageWindowing_Default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
658 if (windowing == ImageWindowing_Custom)
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 float center, width;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 ComputeWindowing(center, width, windowing, 0, 0);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 float a = (center - width / 2.0f - rescaleIntercept) / rescaleSlope;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 float b = (center + width / 2.0f - rescaleIntercept) / rescaleSlope;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 SetWindow(a, b);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 void VolumeReslicer::SetOutputFormat(Orthanc::PixelFormat format)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 if (format != Orthanc::PixelFormat_Grayscale8 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 format != Orthanc::PixelFormat_Grayscale16 &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 format != Orthanc::PixelFormat_BGRA32)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 if (hasLinearFunction_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 LOG(WARNING) << "Calls to VolumeReslicer::SetOutputFormat() should be done before VolumeReslicer::FitRange()";
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 outputFormat_ = format;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 Reset();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 void VolumeReslicer::SetInterpolation(ImageInterpolation interpolation)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 if (interpolation != ImageInterpolation_Nearest &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 interpolation != ImageInterpolation_Bilinear &&
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 interpolation != ImageInterpolation_Trilinear)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 interpolation_ = interpolation;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 Reset();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 const Extent2D& VolumeReslicer::GetOutputExtent() const
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 if (success_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 return extent_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 const Orthanc::ImageAccessor& VolumeReslicer::GetOutputSlice() const
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 if (success_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 assert(slice_.get() != NULL);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 return *slice_;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 Orthanc::ImageAccessor* VolumeReslicer::ReleaseOutputSlice()
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 if (success_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 assert(slice_.get() != NULL);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 success_ = false;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 return slice_.release();
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 void VolumeReslicer::Apply(const ImageBuffer3D& source,
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 684
diff changeset
748 const VolumeImageGeometry& geometry,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 const CoordinateSystem3D& plane)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 // Choose the default voxel size as the finest voxel dimension
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 // of the source volumetric image
684
7719eb852dd5 new class: VolumeImageGeometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 589
diff changeset
753 const OrthancStone::Vector dim =
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 684
diff changeset
754 geometry.GetVoxelDimensions(OrthancStone::VolumeProjection_Axial);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 double voxelSize = dim[0];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 if (dim[1] < voxelSize)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 voxelSize = dim[1];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 if (dim[2] < voxelSize)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 voxelSize = dim[2];
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 if (voxelSize <= 0)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 684
diff changeset
772 Apply(source, geometry, plane, voxelSize);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 void VolumeReslicer::Apply(const ImageBuffer3D& source,
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 684
diff changeset
777 const VolumeImageGeometry& geometry,
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 const CoordinateSystem3D& plane,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 double voxelSize)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 Reset();
783
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
782 pixelSpacing_ = voxelSize;
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 // Firstly, compute the intersection of the source volumetric
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 // image with the reslicing plane. This leads to a polygon with 3
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 // to 6 vertices. We compute the extent of the intersection
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 // polygon, with respect to the coordinate system of the reslicing
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 // plane.
742
fa5febe0f0c2 moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 735
diff changeset
789 OrientedVolumeBoundingBox box(geometry);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 if (!box.ComputeExtent(extent_, plane))
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 // The plane does not intersect with the bounding box of the volume
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 slice_.reset(new Orthanc::Image(outputFormat_, 0, 0, false));
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 success_ = true;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 return;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 // Secondly, the extent together with the voxel size gives the
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 // size of the output image
172
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
801 unsigned int width = boost::math::iround(extent_.GetWidth() / voxelSize);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
802 unsigned int height = boost::math::iround(extent_.GetHeight() / voxelSize);
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 slice_.reset(new Orthanc::Image(outputFormat_, width, height, false));
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 //CheckIterators(source, plane, box);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 if (fastMode_)
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 ProcessImage<FastRowIterator>(*slice_, extent_, source, plane, box,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 interpolation_, hasLinearFunction_, scaling_, offset_);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 else
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 {
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 ProcessImage<SlowRowIterator>(*slice_, extent_, source, plane, box,
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 interpolation_, hasLinearFunction_, scaling_, offset_);
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 }
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 success_ = true;
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 }
783
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
821
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
822
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
823 double VolumeReslicer::GetPixelSpacing() const
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
824 {
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
825 if (success_)
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
826 {
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
827 return pixelSpacing_;
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
828 }
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
829 else
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
830 {
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
831 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
832 }
cd13a062c9bd DicomVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
833 }
153
ae531ab5dcd9 new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 }