Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/SlicesSorter.cpp @ 1770:073484e33bee
fix offset of textures
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 May 2021 10:53:37 +0200 |
parents | ae18b5cfbd3e |
children | 3889ae96d2e9 |
rev | line source |
---|---|
73 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
73 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
73 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
73 | 20 **/ |
21 | |
22 | |
23 #include "SlicesSorter.h" | |
24 | |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
25 #include "GeometryToolbox.h" |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
26 |
1624 | 27 #include <Logging.h> |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
28 #include <OrthancException.h> |
73 | 29 |
30 namespace OrthancStone | |
31 { | |
32 class SlicesSorter::SliceWithDepth : public boost::noncopyable | |
33 { | |
34 private: | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
35 CoordinateSystem3D geometry_; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
36 double depth_; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
37 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
38 std::unique_ptr<Orthanc::IDynamicObject> payload_; |
73 | 39 |
40 public: | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
41 SliceWithDepth(const CoordinateSystem3D& geometry, |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
42 Orthanc::IDynamicObject* payload) : |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
43 geometry_(geometry), |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
44 depth_(0), |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
45 payload_(payload) |
73 | 46 { |
47 } | |
48 | |
49 void SetNormal(const Vector& normal) | |
50 { | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
51 depth_ = boost::numeric::ublas::inner_prod(geometry_.GetOrigin(), normal); |
73 | 52 } |
53 | |
54 double GetDepth() const | |
55 { | |
56 return depth_; | |
57 } | |
58 | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
59 const CoordinateSystem3D& GetGeometry() const |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
60 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
61 return geometry_; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
62 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
63 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
64 bool HasPayload() const |
73 | 65 { |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
66 return (payload_.get() != NULL); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
67 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
68 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
69 const Orthanc::IDynamicObject& GetPayload() const |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
70 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
71 if (HasPayload()) |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
72 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
73 return *payload_; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
74 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
75 else |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
76 { |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
757
diff
changeset
|
77 LOG(ERROR) << "SlicesSorter::SliceWithDepth::GetPayload(): (!HasPayload())"; |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
79 } |
73 | 80 } |
81 }; | |
82 | |
83 | |
84 struct SlicesSorter::Comparator | |
85 { | |
86 bool operator() (const SliceWithDepth* const& a, | |
87 const SliceWithDepth* const& b) const | |
88 { | |
89 return a->GetDepth() < b->GetDepth(); | |
90 } | |
91 }; | |
92 | |
93 | |
94 SlicesSorter::~SlicesSorter() | |
95 { | |
96 for (size_t i = 0; i < slices_.size(); i++) | |
97 { | |
98 assert(slices_[i] != NULL); | |
99 delete slices_[i]; | |
100 } | |
101 } | |
102 | |
103 | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
104 void SlicesSorter::AddSlice(const CoordinateSystem3D& slice, |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
105 Orthanc::IDynamicObject* payload) |
73 | 106 { |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
107 slices_.push_back(new SliceWithDepth(slice, payload)); |
73 | 108 } |
109 | |
110 | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
111 const SlicesSorter::SliceWithDepth& SlicesSorter::GetSlice(size_t i) const |
73 | 112 { |
113 if (i >= slices_.size()) | |
114 { | |
115 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
116 } | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
117 else |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
118 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
119 assert(slices_[i] != NULL); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
120 return *slices_[i]; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
121 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
122 } |
73 | 123 |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
124 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
125 const CoordinateSystem3D& SlicesSorter::GetSliceGeometry(size_t i) const |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
126 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
127 return GetSlice(i).GetGeometry(); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
128 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
129 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
130 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
131 bool SlicesSorter::HasSlicePayload(size_t i) const |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
132 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
133 return GetSlice(i).HasPayload(); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
134 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
135 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
136 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
137 const Orthanc::IDynamicObject& SlicesSorter::GetSlicePayload(size_t i) const |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
138 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
139 return GetSlice(i).GetPayload(); |
73 | 140 } |
141 | |
142 | |
143 void SlicesSorter::SetNormal(const Vector& normal) | |
144 { | |
145 for (size_t i = 0; i < slices_.size(); i++) | |
146 { | |
147 slices_[i]->SetNormal(normal); | |
148 } | |
149 | |
150 hasNormal_ = true; | |
151 } | |
152 | |
153 | |
648 | 154 void SlicesSorter::SortInternal() |
73 | 155 { |
156 if (!hasNormal_) | |
157 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
757
diff
changeset
|
158 LOG(ERROR) << "SlicesSorter::SortInternal(): (!hasNormal_)"; |
73 | 159 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
160 } | |
161 | |
162 Comparator comparator; | |
163 std::sort(slices_.begin(), slices_.end(), comparator); | |
164 } | |
165 | |
166 | |
167 void SlicesSorter::FilterNormal(const Vector& normal) | |
168 { | |
169 size_t pos = 0; | |
170 | |
171 for (size_t i = 0; i < slices_.size(); i++) | |
172 { | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
173 if (GeometryToolbox::IsParallel(normal, slices_[i]->GetGeometry().GetNormal())) |
73 | 174 { |
175 // This slice is compatible with the selected normal | |
176 slices_[pos] = slices_[i]; | |
177 pos += 1; | |
178 } | |
179 else | |
180 { | |
181 delete slices_[i]; | |
182 slices_[i] = NULL; | |
183 } | |
184 } | |
185 | |
186 slices_.resize(pos); | |
187 } | |
188 | |
189 | |
190 bool SlicesSorter::SelectNormal(Vector& normal) const | |
191 { | |
192 std::vector<Vector> normalCandidates; | |
193 std::vector<unsigned int> normalCount; | |
194 | |
195 bool found = false; | |
196 | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
197 for (size_t i = 0; !found && i < GetSlicesCount(); i++) |
73 | 198 { |
199 const Vector& normal = GetSlice(i).GetGeometry().GetNormal(); | |
200 | |
201 bool add = true; | |
202 for (size_t j = 0; add && j < normalCandidates.size(); j++) // (*) | |
203 { | |
204 if (GeometryToolbox::IsParallel(normal, normalCandidates[j])) | |
205 { | |
206 normalCount[j] += 1; | |
207 add = false; | |
208 } | |
209 } | |
210 | |
211 if (add) | |
212 { | |
213 if (normalCount.size() > 2) | |
214 { | |
215 // To get linear-time complexity in (*). This heuristics | |
216 // allows the series to have one single frame that is | |
217 // not parallel to the others (such a frame could be a | |
218 // generated preview) | |
219 found = false; | |
220 } | |
221 else | |
222 { | |
223 normalCandidates.push_back(normal); | |
224 normalCount.push_back(1); | |
225 } | |
226 } | |
227 } | |
228 | |
229 for (size_t i = 0; !found && i < normalCandidates.size(); i++) | |
230 { | |
231 unsigned int count = normalCount[i]; | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
232 if (count == GetSlicesCount() || |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
233 count + 1 == GetSlicesCount()) |
73 | 234 { |
235 normal = normalCandidates[i]; | |
236 found = true; | |
237 } | |
238 } | |
239 | |
240 return found; | |
241 } | |
77 | 242 |
243 | |
648 | 244 bool SlicesSorter::Sort() |
245 { | |
246 if (GetSlicesCount() > 0) | |
247 { | |
248 Vector normal; | |
249 if (SelectNormal(normal)) | |
250 { | |
251 FilterNormal(normal); | |
252 SetNormal(normal); | |
253 SortInternal(); | |
254 return true; | |
255 } | |
256 } | |
257 | |
258 return false; | |
259 } | |
260 | |
261 | |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
262 bool SlicesSorter::ComputeSpacingBetweenSlices(double& spacing /* out */) const |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
263 { |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
264 if (GetSlicesCount() <= 1) |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
265 { |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
266 // This is a volume that is empty or that contains one single |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
267 // slice: Choose a dummy z-dimension for voxels |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
268 spacing = 1.0; |
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
269 return true; |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
270 } |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
271 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
272 const CoordinateSystem3D& reference = GetSliceGeometry(0); |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
273 |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
274 double referencePosition = reference.ProjectAlongNormal(reference.GetOrigin()); |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
275 |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
276 double p = reference.ProjectAlongNormal(GetSliceGeometry(1).GetOrigin()); |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
277 spacing = p - referencePosition; |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
278 |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
279 if (spacing <= 0) |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
280 { |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
281 LOG(ERROR) << "SlicesSorter::ComputeSpacingBetweenSlices(): (spacing <= 0)"; |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
282 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
283 "Please call the Sort() method before"); |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
284 } |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
285 |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
286 for (size_t i = 1; i < GetSlicesCount(); i++) |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
287 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
288 Vector q = reference.GetOrigin() + spacing * static_cast<double>(i) * reference.GetNormal(); |
1571 | 289 double d = boost::numeric::ublas::norm_2(q - GetSliceGeometry(i).GetOrigin()); |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
290 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
291 if (!LinearAlgebra::IsNear(d, 0, 0.001 /* tolerance expressed in mm */)) |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
292 { |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
293 return false; |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
294 } |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
295 } |
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
296 |
1156
34ee7204fde3
removing IGeometryProvider
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1015
diff
changeset
|
297 return true; |
667
e9339f2b5de7
refactoring of VolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
648
diff
changeset
|
298 } |
1015
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
299 |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
300 |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
301 bool SlicesSorter::AreAllSlicesDistinct() const |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
302 { |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
303 if (GetSlicesCount() <= 1) |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
304 { |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
305 return true; |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
306 } |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
307 else |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
308 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
309 const CoordinateSystem3D& reference = GetSliceGeometry(0); |
1015
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
310 double previousPosition = reference.ProjectAlongNormal(GetSliceGeometry(0).GetOrigin()); |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
311 |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
312 for (size_t i = 1; i < GetSlicesCount(); i++) |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
313 { |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
314 double position = reference.ProjectAlongNormal(GetSliceGeometry(i).GetOrigin()); |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
315 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
316 if (LinearAlgebra::IsNear(position, previousPosition, 0.001 /* tolerance expressed in mm */)) |
1015
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
317 { |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
318 return false; |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
319 } |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
320 |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
321 previousPosition = position; |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
322 } |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
323 |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
324 return true; |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
325 } |
24fecc02bfb1
SlicesSorter::AreAllSlicesDistinct()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
326 } |
73 | 327 } |