Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/ParallelSlices.cpp @ 1213:86a8266b8888 broker
moving the scene from IViewport to ViewportController
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Dec 2019 17:54:10 +0100 |
parents | ffec76a5f7eb |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "ParallelSlices.h" | |
23 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
24 #include "../../Toolbox/GeometryToolbox.h" |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
25 #include "../../Volumes/ImageBuffer3D.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/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
28 #include <Core/OrthancException.h> |
0 | 29 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
30 namespace Deprecated |
0 | 31 { |
32 ParallelSlices::ParallelSlices() | |
33 { | |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
34 Clear(); |
0 | 35 } |
36 | |
37 | |
38 ParallelSlices::ParallelSlices(const ParallelSlices& other) | |
39 { | |
40 normal_ = other.normal_; | |
41 | |
42 slices_.resize(other.slices_.size()); | |
43 | |
44 for (size_t i = 0; i < slices_.size(); i++) | |
45 { | |
46 assert(other.slices_[i] != NULL); | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
47 slices_[i] = new OrthancStone::CoordinateSystem3D(*other.slices_[i]); |
0 | 48 } |
49 } | |
50 | |
51 | |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
52 void ParallelSlices::Clear() |
0 | 53 { |
54 for (size_t i = 0; i < slices_.size(); i++) | |
55 { | |
56 if (slices_[i] != NULL) | |
57 { | |
58 delete slices_[i]; | |
59 slices_[i] = NULL; | |
60 } | |
61 } | |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
62 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
63 slices_.clear(); |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
64 OrthancStone::LinearAlgebra::AssignVector(normal_, 0, 0, 1); |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
65 } |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
66 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
67 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
68 ParallelSlices::~ParallelSlices() |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
69 { |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
70 Clear(); |
0 | 71 } |
72 | |
73 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
74 void ParallelSlices::AddSlice(const OrthancStone::CoordinateSystem3D& slice) |
0 | 75 { |
76 if (slices_.empty()) | |
77 { | |
78 normal_ = slice.GetNormal(); | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
79 slices_.push_back(new OrthancStone::CoordinateSystem3D(slice)); |
0 | 80 } |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
81 else if (OrthancStone::GeometryToolbox::IsParallel(slice.GetNormal(), normal_)) |
0 | 82 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
83 slices_.push_back(new OrthancStone::CoordinateSystem3D(slice)); |
0 | 84 } |
85 else | |
86 { | |
87 LOG(ERROR) << "Trying to add a slice that is not parallel to the previous ones"; | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
89 } | |
90 } | |
91 | |
92 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
93 void ParallelSlices::AddSlice(const OrthancStone::Vector& origin, |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
94 const OrthancStone::Vector& axisX, |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
95 const OrthancStone::Vector& axisY) |
0 | 96 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
97 OrthancStone::CoordinateSystem3D slice(origin, axisX, axisY); |
0 | 98 AddSlice(slice); |
99 } | |
100 | |
101 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
102 const OrthancStone::CoordinateSystem3D& ParallelSlices::GetSlice(size_t index) const |
0 | 103 { |
104 if (index >= slices_.size()) | |
105 { | |
106 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
107 } | |
108 else | |
109 { | |
110 return *slices_[index]; | |
111 } | |
112 } | |
113 | |
114 | |
115 bool ParallelSlices::ComputeClosestSlice(size_t& closestSlice, | |
116 double& closestDistance, | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
117 const OrthancStone::Vector& origin) const |
0 | 118 { |
119 if (slices_.empty()) | |
120 { | |
121 return false; | |
122 } | |
123 | |
124 double reference = boost::numeric::ublas::inner_prod(origin, normal_); | |
125 | |
126 closestSlice = 0; | |
127 closestDistance = std::numeric_limits<double>::infinity(); | |
128 | |
129 for (size_t i = 0; i < slices_.size(); i++) | |
130 { | |
131 double distance = fabs(boost::numeric::ublas::inner_prod(slices_[i]->GetOrigin(), normal_) - reference); | |
132 | |
133 if (distance < closestDistance) | |
134 { | |
135 closestSlice = i; | |
136 closestDistance = distance; | |
137 } | |
138 } | |
139 | |
140 return true; | |
141 } | |
142 | |
143 | |
144 ParallelSlices* ParallelSlices::Reverse() const | |
145 { | |
146 std::auto_ptr<ParallelSlices> reversed(new ParallelSlices); | |
147 | |
148 for (size_t i = slices_.size(); i > 0; i--) | |
149 { | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
150 const OrthancStone::CoordinateSystem3D& slice = *slices_[i - 1]; |
0 | 151 |
152 reversed->AddSlice(slice.GetOrigin(), | |
153 -slice.GetAxisX(), | |
154 slice.GetAxisY()); | |
155 } | |
156 | |
157 return reversed.release(); | |
158 } | |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
159 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
160 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
161 ParallelSlices* ParallelSlices::FromVolumeImage(const OrthancStone::VolumeImageGeometry& geometry, |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
162 OrthancStone::VolumeProjection projection) |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
163 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
164 const OrthancStone::Vector dimensions = geometry.GetVoxelDimensions(OrthancStone::VolumeProjection_Axial); |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
165 const OrthancStone::CoordinateSystem3D& axial = geometry.GetAxialGeometry(); |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
166 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
167 std::auto_ptr<ParallelSlices> result(new ParallelSlices); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
168 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
169 switch (projection) |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
170 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
171 case OrthancStone::VolumeProjection_Axial: |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
172 for (unsigned int z = 0; z < geometry.GetDepth(); z++) |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
173 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
174 OrthancStone::Vector origin = axial.GetOrigin(); |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
175 origin += static_cast<double>(z) * dimensions[2] * axial.GetNormal(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
176 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
177 result->AddSlice(origin, |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
178 axial.GetAxisX(), |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
179 axial.GetAxisY()); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
180 } |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
181 break; |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
182 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
183 case OrthancStone::VolumeProjection_Coronal: |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
184 for (unsigned int y = 0; y < geometry.GetHeight(); y++) |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
185 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
186 OrthancStone::Vector origin = axial.GetOrigin(); |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
187 origin += static_cast<double>(y) * dimensions[1] * axial.GetAxisY(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
188 origin += static_cast<double>(geometry.GetDepth() - 1) * dimensions[2] * axial.GetNormal(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
189 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
190 result->AddSlice(origin, |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
191 axial.GetAxisX(), |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
192 -axial.GetNormal()); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
193 } |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
194 break; |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
195 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
196 case OrthancStone::VolumeProjection_Sagittal: |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
197 for (unsigned int x = 0; x < geometry.GetWidth(); x++) |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
198 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
199 OrthancStone::Vector origin = axial.GetOrigin(); |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
200 origin += static_cast<double>(x) * dimensions[0] * axial.GetAxisX(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
201 origin += static_cast<double>(geometry.GetDepth() - 1) * dimensions[2] * axial.GetNormal(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
202 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
203 result->AddSlice(origin, |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
204 axial.GetAxisY(), |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
205 -axial.GetNormal()); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
206 } |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
207 break; |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
208 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
209 default: |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
210 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
211 } |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
212 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
213 return result.release(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
214 } |
0 | 215 } |