Mercurial > hg > orthanc-stone
comparison UnitTestsSources/SortedFramesTests.cpp @ 1477:5732edec7cbd
sorting frames in 3D
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Jun 2020 15:48:59 +0200 |
parents | |
children | fab6c6e795a3 |
comparison
equal
deleted
inserted
replaced
1476:4db187d29731 | 1477:5732edec7cbd |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
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. | |
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 | |
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 | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include <gtest/gtest.h> | |
23 | |
24 #include <OrthancException.h> | |
25 #include <DicomFormat/DicomMap.h> | |
26 | |
27 #include "../Framework/Toolbox/GeometryToolbox.h" | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 class SortedFrames : public boost::noncopyable | |
32 { | |
33 private: | |
34 class Instance : public boost::noncopyable | |
35 { | |
36 private: | |
37 bool hasPosition_; | |
38 Orthanc::DicomMap tags_; | |
39 std::string sopInstanceUid_; | |
40 unsigned int numberOfFrames_; | |
41 Vector normal_; | |
42 Vector position_; | |
43 | |
44 public: | |
45 Instance(const Orthanc::DicomMap& tags) | |
46 { | |
47 tags_.Assign(tags); | |
48 | |
49 if (!tags.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | |
50 { | |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
52 } | |
53 | |
54 uint32_t tmp; | |
55 if (tags.ParseUnsignedInteger32(tmp, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES)) | |
56 { | |
57 numberOfFrames_ = tmp; | |
58 } | |
59 else | |
60 { | |
61 numberOfFrames_ = 1; | |
62 } | |
63 | |
64 hasPosition_ = ( | |
65 LinearAlgebra::ParseVector(position_, tags, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT) && | |
66 position_.size() == 3 && | |
67 GeometryToolbox::ComputeNormal(normal_, tags)); | |
68 } | |
69 | |
70 const Orthanc::DicomMap& GetTags() const | |
71 { | |
72 return tags_; | |
73 } | |
74 | |
75 const std::string& GetSopInstanceUid() const | |
76 { | |
77 return sopInstanceUid_; | |
78 } | |
79 | |
80 unsigned int GetNumberOfFrames() const | |
81 { | |
82 return numberOfFrames_; | |
83 } | |
84 | |
85 bool HasPosition() const | |
86 { | |
87 return hasPosition_; | |
88 } | |
89 | |
90 const Vector& GetNormal() const | |
91 { | |
92 if (hasPosition_) | |
93 { | |
94 return normal_; | |
95 } | |
96 else | |
97 { | |
98 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
99 } | |
100 } | |
101 | |
102 const Vector& GetPosition() const | |
103 { | |
104 if (hasPosition_) | |
105 { | |
106 return position_; | |
107 } | |
108 else | |
109 { | |
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
111 } | |
112 } | |
113 }; | |
114 | |
115 struct Frame | |
116 { | |
117 private: | |
118 const Instance& instance_; | |
119 unsigned int frameIndex_; | |
120 | |
121 public: | |
122 Frame(const Instance& instance, | |
123 unsigned int frameIndex) : | |
124 instance_(instance), | |
125 frameIndex_(frameIndex) | |
126 { | |
127 if (frameIndex >= instance.GetNumberOfFrames()) | |
128 { | |
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
130 } | |
131 } | |
132 | |
133 const Instance& GetInstance() const | |
134 { | |
135 return instance_; | |
136 } | |
137 | |
138 unsigned int GetFrameIndex() const | |
139 { | |
140 return frameIndex_; | |
141 } | |
142 }; | |
143 | |
144 std::string studyInstanceUid_; | |
145 std::string seriesInstanceUid_; | |
146 std::vector<Instance*> instances_; | |
147 std::vector<Frame> frames_; | |
148 bool sorted_; | |
149 | |
150 const Instance& GetInstance(size_t index) const | |
151 { | |
152 if (index >= instances_.size()) | |
153 { | |
154 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
155 } | |
156 else | |
157 { | |
158 assert(instances_[index] != NULL); | |
159 return *instances_[index]; | |
160 } | |
161 } | |
162 | |
163 const Frame& GetFrame(size_t index) const | |
164 { | |
165 if (!sorted_) | |
166 { | |
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, | |
168 "Sort() has not been called"); | |
169 } | |
170 if (index >= frames_.size()) | |
171 { | |
172 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
173 } | |
174 else | |
175 { | |
176 return frames_[index]; | |
177 } | |
178 } | |
179 | |
180 public: | |
181 SortedFrames() : | |
182 sorted_(true) | |
183 { | |
184 } | |
185 | |
186 ~SortedFrames() | |
187 { | |
188 for (size_t i = 0; i < instances_.size(); i++) | |
189 { | |
190 assert(instances_[i] != NULL); | |
191 delete instances_[i]; | |
192 } | |
193 } | |
194 | |
195 const std::string& GetStudyInstanceUid() const | |
196 { | |
197 return studyInstanceUid_; | |
198 } | |
199 | |
200 const std::string& GetSeriesInstanceUid() const | |
201 { | |
202 return seriesInstanceUid_; | |
203 } | |
204 | |
205 void AddInstance(const Orthanc::DicomMap& tags) | |
206 { | |
207 std::unique_ptr<Instance> instance(new Instance(tags)); | |
208 | |
209 std::string studyInstanceUid, seriesInstanceUid; | |
210 if (!tags.LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) || | |
211 !tags.LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false)) | |
212 { | |
213 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
214 } | |
215 | |
216 if (instances_.empty()) | |
217 { | |
218 studyInstanceUid_ = studyInstanceUid; | |
219 seriesInstanceUid_ = seriesInstanceUid; | |
220 } | |
221 else | |
222 { | |
223 if (studyInstanceUid_ != studyInstanceUid || | |
224 seriesInstanceUid_ != seriesInstanceUid) | |
225 { | |
226 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, | |
227 "Mixing instances from different series"); | |
228 } | |
229 } | |
230 | |
231 instances_.push_back(instance.release()); | |
232 sorted_ = false; | |
233 frames_.clear(); | |
234 } | |
235 | |
236 size_t GetInstancesCount() const | |
237 { | |
238 return instances_.size(); | |
239 } | |
240 | |
241 const Orthanc::DicomMap& GetInstanceTags(size_t index) const | |
242 { | |
243 return GetInstance(index).GetTags(); | |
244 } | |
245 | |
246 const std::string& GetSopInstanceUid(size_t index) const | |
247 { | |
248 return GetInstance(index).GetSopInstanceUid(); | |
249 } | |
250 | |
251 bool IsSorted() const | |
252 { | |
253 return sorted_; | |
254 } | |
255 | |
256 size_t GetFramesCount() const | |
257 { | |
258 if (sorted_) | |
259 { | |
260 return frames_.size(); | |
261 } | |
262 else | |
263 { | |
264 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, | |
265 "Sort() has not been called"); | |
266 } | |
267 } | |
268 | |
269 const Orthanc::DicomMap& GetFrameTags(size_t index) const | |
270 { | |
271 return GetFrame(index).GetInstance().GetTags(); | |
272 } | |
273 | |
274 const std::string& GetFrameSopInstanceUid(size_t index) const | |
275 { | |
276 return GetFrame(index).GetInstance().GetSopInstanceUid(); | |
277 } | |
278 | |
279 const unsigned int GetFrameSiblingsCount(size_t index) const | |
280 { | |
281 return GetFrame(index).GetInstance().GetNumberOfFrames(); | |
282 } | |
283 | |
284 const unsigned int GetFrameIndex(size_t index) const | |
285 { | |
286 return GetFrame(index).GetFrameIndex(); | |
287 } | |
288 | |
289 | |
290 void Sort() | |
291 { | |
292 if (!sorted_) | |
293 { | |
294 size_t totalFrames = 0; | |
295 std::set<size_t> remainingInstances; | |
296 | |
297 for (size_t i = 0; i < instances_.size(); i++) | |
298 { | |
299 assert(instances_[i] != NULL); | |
300 totalFrames += instances_[i]->GetNumberOfFrames(); | |
301 | |
302 remainingInstances.insert(i); | |
303 } | |
304 | |
305 frames_.clear(); | |
306 frames_.reserve(totalFrames); | |
307 | |
308 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS" | |
309 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US" | |
310 SortUsing3DLocation(remainingInstances); | |
311 SortUsingSopInstanceUid(remainingInstances); | |
312 | |
313 // The following could in theory happen if several instances | |
314 // have the same SOPInstanceUID, no ordering is available | |
315 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | |
316 it != remainingInstances.end(); it++) | |
317 { | |
318 AddFramesOfInstance(remainingInstances, *it); | |
319 } | |
320 | |
321 if (frames_.size() != totalFrames || | |
322 !remainingInstances.empty()) | |
323 { | |
324 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
325 } | |
326 | |
327 sorted_ = true; | |
328 } | |
329 } | |
330 | |
331 | |
332 private: | |
333 void AddFramesOfInstance(std::set<size_t>& remainingInstances, | |
334 size_t index) | |
335 { | |
336 assert(instances_[index] != NULL); | |
337 const Instance& instance = *instances_[index]; | |
338 | |
339 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++) | |
340 { | |
341 frames_.push_back(Frame(instance, i)); | |
342 } | |
343 | |
344 assert(remainingInstances.find(index) != remainingInstances.end()); | |
345 remainingInstances.erase(index); | |
346 } | |
347 | |
348 | |
349 template<typename T> | |
350 class SortableItem | |
351 { | |
352 private: | |
353 T value_; | |
354 size_t instance_; | |
355 std::string sopInstanceUid_; | |
356 | |
357 public: | |
358 SortableItem(const T& value, | |
359 size_t instance, | |
360 const std::string& sopInstanceUid) : | |
361 value_(value), | |
362 instance_(instance), | |
363 sopInstanceUid_(sopInstanceUid) | |
364 { | |
365 } | |
366 | |
367 size_t GetInstanceIndex() const | |
368 { | |
369 return instance_; | |
370 } | |
371 | |
372 bool operator< (const SortableItem& other) const | |
373 { | |
374 return (value_ < other.value_ || | |
375 (value_ == other.value_ && | |
376 sopInstanceUid_ < other.sopInstanceUid_)); | |
377 } | |
378 }; | |
379 | |
380 | |
381 void SortUsingIntegerTag(std::set<size_t>& remainingInstances, | |
382 const Orthanc::DicomTag& tag) | |
383 { | |
384 std::vector< SortableItem<int32_t> > items; | |
385 items.reserve(remainingInstances.size()); | |
386 | |
387 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | |
388 it != remainingInstances.end(); ++it) | |
389 { | |
390 assert(instances_[*it] != NULL); | |
391 const Instance& instance = *instances_[*it]; | |
392 | |
393 int32_t value; | |
394 std::string sopInstanceUid; | |
395 if (instance.GetTags().ParseInteger32(value, tag) && | |
396 instance.GetTags().LookupStringValue( | |
397 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | |
398 { | |
399 items.push_back(SortableItem<int32_t>(value, *it, sopInstanceUid)); | |
400 } | |
401 } | |
402 | |
403 std::sort(items.begin(), items.end()); | |
404 | |
405 for (size_t i = 0; i < items.size(); i++) | |
406 { | |
407 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); | |
408 } | |
409 } | |
410 | |
411 | |
412 void SortUsingSopInstanceUid(std::set<size_t>& remainingInstances) | |
413 { | |
414 std::vector<SortableItem<int32_t> > items; | |
415 items.reserve(remainingInstances.size()); | |
416 | |
417 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | |
418 it != remainingInstances.end(); ++it) | |
419 { | |
420 assert(instances_[*it] != NULL); | |
421 const Instance& instance = *instances_[*it]; | |
422 | |
423 std::string sopInstanceUid; | |
424 if (instance.GetTags().LookupStringValue( | |
425 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | |
426 { | |
427 items.push_back(SortableItem<int32_t>(0 /* arbitrary value */, *it, sopInstanceUid)); | |
428 } | |
429 } | |
430 | |
431 std::sort(items.begin(), items.end()); | |
432 | |
433 for (size_t i = 0; i < items.size(); i++) | |
434 { | |
435 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); | |
436 } | |
437 } | |
438 | |
439 | |
440 void SortUsing3DLocation(std::set<size_t>& remainingInstances) | |
441 { | |
442 /** | |
443 * Compute the mean of the normal vectors, using the recursive | |
444 * formula for arithmetic means for numerical stability. | |
445 * https://diego.assencio.com/?index=c34d06f4f4de2375658ed41f70177d59 | |
446 **/ | |
447 | |
448 Vector meanNormal; | |
449 LinearAlgebra::AssignVector(meanNormal, 0, 0, 0); | |
450 | |
451 unsigned int n = 0; | |
452 | |
453 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | |
454 it != remainingInstances.end(); ++it) | |
455 { | |
456 assert(instances_[*it] != NULL); | |
457 const Instance& instance = *instances_[*it]; | |
458 | |
459 if (instance.HasPosition()) | |
460 { | |
461 n += 1; | |
462 meanNormal += (instance.GetNormal() - meanNormal) / static_cast<float>(n); | |
463 } | |
464 } | |
465 | |
466 std::vector<SortableItem<float> > items; | |
467 items.reserve(n); | |
468 | |
469 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | |
470 it != remainingInstances.end(); ++it) | |
471 { | |
472 assert(instances_[*it] != NULL); | |
473 const Instance& instance = *instances_[*it]; | |
474 | |
475 std::string sopInstanceUid; | |
476 if (instance.HasPosition() && | |
477 instance.GetTags().LookupStringValue( | |
478 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | |
479 { | |
480 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetPosition()); | |
481 items.push_back(SortableItem<float>(p, *it, sopInstanceUid)); | |
482 } | |
483 } | |
484 | |
485 assert(items.size() <= n); | |
486 | |
487 std::sort(items.begin(), items.end()); | |
488 printf(">> %d\n", items.size()); | |
489 | |
490 for (size_t i = 0; i < items.size(); i++) | |
491 { | |
492 AddFramesOfInstance(remainingInstances, items[i].GetInstanceIndex()); | |
493 } | |
494 } | |
495 }; | |
496 } | |
497 | |
498 | |
499 TEST(SortedFrames, Basic) | |
500 { | |
501 OrthancStone::SortedFrames f; | |
502 ASSERT_TRUE(f.GetStudyInstanceUid().empty()); | |
503 ASSERT_TRUE(f.GetSeriesInstanceUid().empty()); | |
504 ASSERT_EQ(0u, f.GetInstancesCount()); | |
505 ASSERT_THROW(f.GetInstanceTags(0), Orthanc::OrthancException); | |
506 ASSERT_THROW(f.GetSopInstanceUid(0), Orthanc::OrthancException); | |
507 ASSERT_TRUE(f.IsSorted()); | |
508 ASSERT_EQ(0u, f.GetFramesCount()); | |
509 ASSERT_THROW(f.GetFrameTags(0), Orthanc::OrthancException); | |
510 ASSERT_THROW(f.GetFrameSopInstanceUid(0), Orthanc::OrthancException); | |
511 ASSERT_THROW(f.GetFrameSiblingsCount(0), Orthanc::OrthancException); | |
512 ASSERT_THROW(f.GetFrameIndex(0), Orthanc::OrthancException); | |
513 | |
514 Orthanc::DicomMap tags; | |
515 ASSERT_THROW(f.AddInstance(tags), Orthanc::OrthancException); | |
516 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "study", false); | |
517 ASSERT_THROW(f.AddInstance(tags), Orthanc::OrthancException); | |
518 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "series", false); | |
519 ASSERT_THROW(f.AddInstance(tags), Orthanc::OrthancException); | |
520 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop", false); | |
521 f.AddInstance(tags); | |
522 | |
523 ASSERT_EQ("study", f.GetStudyInstanceUid()); | |
524 ASSERT_EQ("series", f.GetSeriesInstanceUid()); | |
525 ASSERT_EQ(1u, f.GetInstancesCount()); | |
526 std::string s; | |
527 ASSERT_TRUE(f.GetInstanceTags(0).LookupStringValue(s, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)); | |
528 ASSERT_EQ("sop", s); | |
529 ASSERT_EQ("sop", f.GetSopInstanceUid(0)); | |
530 ASSERT_FALSE(f.IsSorted()); | |
531 ASSERT_THROW(f.GetFramesCount(), Orthanc::OrthancException); | |
532 ASSERT_THROW(f.GetFrameTags(0), Orthanc::OrthancException); | |
533 ASSERT_THROW(f.GetFrameSopInstanceUid(0), Orthanc::OrthancException); | |
534 ASSERT_THROW(f.GetFrameSiblingsCount(0), Orthanc::OrthancException); | |
535 ASSERT_THROW(f.GetFrameIndex(0), Orthanc::OrthancException); | |
536 | |
537 f.Sort(); | |
538 ASSERT_TRUE(f.IsSorted()); | |
539 ASSERT_EQ(1u, f.GetFramesCount()); | |
540 ASSERT_TRUE(f.GetFrameTags(0).LookupStringValue(s, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)); | |
541 ASSERT_EQ("sop", s); | |
542 ASSERT_EQ("sop", f.GetFrameSopInstanceUid(0)); | |
543 ASSERT_EQ(1u, f.GetFrameSiblingsCount(0)); | |
544 ASSERT_EQ(0u, f.GetFrameIndex(0)); | |
545 ASSERT_THROW(f.GetFrameTags(1), Orthanc::OrthancException); | |
546 } | |
547 | |
548 | |
549 TEST(SortedFrames, SortSopInstanceUid) | |
550 { | |
551 Orthanc::DicomMap tags; | |
552 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "study", false); | |
553 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "series", false); | |
554 | |
555 OrthancStone::SortedFrames f; | |
556 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop3", false); | |
557 tags.SetValue(Orthanc::DICOM_TAG_NUMBER_OF_FRAMES, "1", false); | |
558 f.AddInstance(tags); | |
559 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop1", false); | |
560 tags.SetValue(Orthanc::DICOM_TAG_NUMBER_OF_FRAMES, "3", false); | |
561 f.AddInstance(tags); | |
562 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop2", false); | |
563 tags.SetValue(Orthanc::DICOM_TAG_NUMBER_OF_FRAMES, "2", false); | |
564 f.AddInstance(tags); | |
565 | |
566 f.Sort(); | |
567 ASSERT_EQ(3u, f.GetInstancesCount()); | |
568 ASSERT_EQ("sop3", f.GetSopInstanceUid(0)); | |
569 ASSERT_EQ("sop1", f.GetSopInstanceUid(1)); | |
570 ASSERT_EQ("sop2", f.GetSopInstanceUid(2)); | |
571 ASSERT_EQ(6u, f.GetFramesCount()); | |
572 ASSERT_EQ("sop1", f.GetFrameSopInstanceUid(0)); ASSERT_EQ(0u, f.GetFrameIndex(0)); | |
573 ASSERT_EQ("sop1", f.GetFrameSopInstanceUid(1)); ASSERT_EQ(1u, f.GetFrameIndex(1)); | |
574 ASSERT_EQ("sop1", f.GetFrameSopInstanceUid(2)); ASSERT_EQ(2u, f.GetFrameIndex(2)); | |
575 ASSERT_EQ("sop2", f.GetFrameSopInstanceUid(3)); ASSERT_EQ(0u, f.GetFrameIndex(3)); | |
576 ASSERT_EQ("sop2", f.GetFrameSopInstanceUid(4)); ASSERT_EQ(1u, f.GetFrameIndex(4)); | |
577 ASSERT_EQ("sop3", f.GetFrameSopInstanceUid(5)); ASSERT_EQ(0u, f.GetFrameIndex(5)); | |
578 } | |
579 | |
580 | |
581 TEST(SortedFrames, SortInstanceNumber) | |
582 { | |
583 Orthanc::DicomMap tags; | |
584 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "study", false); | |
585 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "series", false); | |
586 | |
587 OrthancStone::SortedFrames f; | |
588 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop1", false); | |
589 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "20", false); | |
590 f.AddInstance(tags); | |
591 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop2", false); | |
592 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "-20", false); | |
593 f.AddInstance(tags); | |
594 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop2a", false); | |
595 tags.Remove(Orthanc::DICOM_TAG_INSTANCE_NUMBER); | |
596 f.AddInstance(tags); | |
597 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop4", false); | |
598 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "10", false); | |
599 f.AddInstance(tags); | |
600 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop3", false); | |
601 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "10", false); | |
602 f.AddInstance(tags); | |
603 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop5", false); | |
604 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "10", false); | |
605 f.AddInstance(tags); | |
606 | |
607 f.Sort(); | |
608 ASSERT_EQ(6u, f.GetInstancesCount()); | |
609 ASSERT_EQ("sop1", f.GetSopInstanceUid(0)); | |
610 ASSERT_EQ("sop2", f.GetSopInstanceUid(1)); | |
611 ASSERT_EQ("sop2a", f.GetSopInstanceUid(2)); | |
612 ASSERT_EQ("sop4", f.GetSopInstanceUid(3)); | |
613 ASSERT_EQ("sop3", f.GetSopInstanceUid(4)); | |
614 ASSERT_EQ("sop5", f.GetSopInstanceUid(5)); | |
615 ASSERT_EQ(6u, f.GetFramesCount()); | |
616 ASSERT_EQ("sop2", f.GetFrameSopInstanceUid(0)); ASSERT_EQ(0u, f.GetFrameIndex(0)); | |
617 ASSERT_EQ("sop3", f.GetFrameSopInstanceUid(1)); ASSERT_EQ(0u, f.GetFrameIndex(1)); | |
618 ASSERT_EQ("sop4", f.GetFrameSopInstanceUid(2)); ASSERT_EQ(0u, f.GetFrameIndex(2)); | |
619 ASSERT_EQ("sop5", f.GetFrameSopInstanceUid(3)); ASSERT_EQ(0u, f.GetFrameIndex(3)); | |
620 ASSERT_EQ("sop1", f.GetFrameSopInstanceUid(4)); ASSERT_EQ(0u, f.GetFrameIndex(4)); | |
621 ASSERT_EQ("sop2a", f.GetFrameSopInstanceUid(5)); ASSERT_EQ(0u, f.GetFrameIndex(5)); | |
622 } | |
623 | |
624 | |
625 TEST(SortedFrames, SortInstanceNumberAndImageIndex) | |
626 { | |
627 Orthanc::DicomMap tags; | |
628 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "study", false); | |
629 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "series", false); | |
630 | |
631 OrthancStone::SortedFrames f; | |
632 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop1", false); | |
633 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "20", false); | |
634 f.AddInstance(tags); | |
635 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop2", false); | |
636 tags.Remove(Orthanc::DICOM_TAG_INSTANCE_NUMBER); | |
637 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_INDEX, "20", false); | |
638 f.AddInstance(tags); | |
639 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop3", false); | |
640 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_INDEX, "30", false); | |
641 f.AddInstance(tags); | |
642 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "sop4", false); | |
643 tags.Remove(Orthanc::DICOM_TAG_IMAGE_INDEX); | |
644 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "30", false); | |
645 f.AddInstance(tags); | |
646 | |
647 f.Sort(); | |
648 ASSERT_EQ(4u, f.GetInstancesCount()); | |
649 ASSERT_EQ("sop1", f.GetSopInstanceUid(0)); | |
650 ASSERT_EQ("sop2", f.GetSopInstanceUid(1)); | |
651 ASSERT_EQ("sop3", f.GetSopInstanceUid(2)); | |
652 ASSERT_EQ("sop4", f.GetSopInstanceUid(3)); | |
653 ASSERT_EQ(4u, f.GetFramesCount()); | |
654 // First instance number, then image index | |
655 ASSERT_EQ("sop1", f.GetFrameSopInstanceUid(0)); ASSERT_EQ(0u, f.GetFrameIndex(0)); | |
656 ASSERT_EQ("sop4", f.GetFrameSopInstanceUid(1)); ASSERT_EQ(0u, f.GetFrameIndex(1)); | |
657 ASSERT_EQ("sop2", f.GetFrameSopInstanceUid(2)); ASSERT_EQ(0u, f.GetFrameIndex(2)); | |
658 ASSERT_EQ("sop3", f.GetFrameSopInstanceUid(3)); ASSERT_EQ(0u, f.GetFrameIndex(3)); | |
659 } | |
660 | |
661 | |
662 TEST(SortedFrames, Knix) // Created using "SortedFramesCreateTest.py" | |
663 { | |
664 Orthanc::DicomMap tags; | |
665 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "1.2.840.113619.2.176.2025.1499492.7391.1171285944.390", false); | |
666 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "1.2.840.113619.2.176.2025.1499492.7391.1171285944.392", false); | |
667 OrthancStone::SortedFrames f; | |
668 | |
669 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "67b44a5e-8997f88d-6e527bd6-df342483-dab1674c", false); | |
670 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-60.7285\\-105.586\\73.7768", false); | |
671 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
672 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "10", false); | |
673 f.AddInstance(tags); | |
674 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "a8ee83f9-1cc26ad9-ebba3043-8afc47c2-bd784610", false); | |
675 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-42.7285\\-105.586\\73.7768", false); | |
676 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
677 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "6", false); | |
678 f.AddInstance(tags); | |
679 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "5a2acb03-063f5063-cac452d1-a55992f9-769900fb", false); | |
680 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-114.729\\-105.586\\73.7768", false); | |
681 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
682 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "22", false); | |
683 f.AddInstance(tags); | |
684 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "23d12f39-e9a4fc21-8da338c4-97feff30-48e95534", false); | |
685 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-83.2285\\-105.586\\73.7768", false); | |
686 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
687 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "15", false); | |
688 f.AddInstance(tags); | |
689 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "16606f69-83b48518-ab34304a-c8871b7f-a9298d74", false); | |
690 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-78.7285\\-105.586\\73.7768", false); | |
691 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
692 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "14", false); | |
693 f.AddInstance(tags); | |
694 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "63d595f3-327a306d-1709bb8b-2a72e11c-4f7221fe", false); | |
695 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-96.7285\\-105.586\\73.7768", false); | |
696 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
697 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "18", false); | |
698 f.AddInstance(tags); | |
699 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "8bdecadd-e3477e28-bbbf0297-22b0b680-37b13a7c", false); | |
700 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-65.2285\\-105.586\\73.7768", false); | |
701 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
702 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "11", false); | |
703 f.AddInstance(tags); | |
704 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "b590cc95-55789755-ebd10b76-911e855e-f24e4fe7", false); | |
705 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-74.2285\\-105.586\\73.7768", false); | |
706 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
707 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "13", false); | |
708 f.AddInstance(tags); | |
709 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "eaa49a94-b9042041-7f45150b-e414f800-d7232874", false); | |
710 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-38.2285\\-105.586\\73.7768", false); | |
711 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
712 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "5", false); | |
713 f.AddInstance(tags); | |
714 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "6824db93-ed4e2740-07be953f-6d0a8fb3-af0a3a0b", false); | |
715 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-105.729\\-105.586\\73.7768", false); | |
716 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
717 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "20", false); | |
718 f.AddInstance(tags); | |
719 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "e0d82343-9cef01e9-e21df50a-11886a94-1d0216ea", false); | |
720 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-51.7285\\-105.586\\73.7768", false); | |
721 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
722 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "8", false); | |
723 f.AddInstance(tags); | |
724 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "dc1576ee-25b0b1ef-e038df76-d296fcad-a1456169", false); | |
725 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-110.229\\-105.586\\73.7768", false); | |
726 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
727 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "21", false); | |
728 f.AddInstance(tags); | |
729 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "b9cf5158-06f8e713-7d5111aa-411fd75b-7be2c51e", false); | |
730 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-20.2285\\-105.586\\73.7768", false); | |
731 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
732 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "1", false); | |
733 f.AddInstance(tags); | |
734 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "5faf886f-bd5517cf-1a6ba06e-ac0e6ddb-47bdd8b2", false); | |
735 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-101.229\\-105.586\\73.7768", false); | |
736 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
737 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "19", false); | |
738 f.AddInstance(tags); | |
739 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "3e8f8ec1-b603f874-825552f1-6fcac7fa-72ca1aa5", false); | |
740 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-24.7285\\-105.586\\73.7768", false); | |
741 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
742 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "2", false); | |
743 f.AddInstance(tags); | |
744 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "7a7c0120-37f6dd58-c46312e6-2559975d-5af4616f", false); | |
745 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-87.7285\\-105.586\\73.7768", false); | |
746 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
747 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "16", false); | |
748 f.AddInstance(tags); | |
749 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "a0ca6802-56c697c3-0205bab8-42217cfc-84ff0de6", false); | |
750 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-33.7285\\-105.586\\73.7768", false); | |
751 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
752 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "4", false); | |
753 f.AddInstance(tags); | |
754 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "efce9ff4-3fe07d83-745846f8-fefe5d64-bfea65e6", false); | |
755 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-56.2285\\-105.586\\73.7768", false); | |
756 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
757 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "9", false); | |
758 f.AddInstance(tags); | |
759 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "fa56f961-d1ae8f6a-989c04f4-7a588e9e-b41b1a13", false); | |
760 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-92.2285\\-105.586\\73.7768", false); | |
761 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
762 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "17", false); | |
763 f.AddInstance(tags); | |
764 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "f5e889ac-c5afdc37-c5b62074-a8bdeef3-c58d9889", false); | |
765 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-69.7285\\-105.586\\73.7768", false); | |
766 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
767 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "12", false); | |
768 f.AddInstance(tags); | |
769 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "c19fb4b6-ad1224f2-2c3a2b28-0ea233be-38eea0de", false); | |
770 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-47.2285\\-105.586\\73.7768", false); | |
771 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
772 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "7", false); | |
773 f.AddInstance(tags); | |
774 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "348efc0a-71ee4758-56bd51fa-9703cbff-9b51d4c9", false); | |
775 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-29.2285\\-105.586\\73.7768", false); | |
776 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "-0\\1\\0\\-0\\-0\\-1", false); | |
777 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "3", false); | |
778 f.AddInstance(tags); | |
779 f.Sort(); | |
780 ASSERT_EQ(22u, f.GetFramesCount()); | |
781 ASSERT_EQ(f.GetFrameSopInstanceUid(0), "b9cf5158-06f8e713-7d5111aa-411fd75b-7be2c51e"); | |
782 ASSERT_EQ(f.GetFrameSopInstanceUid(1), "3e8f8ec1-b603f874-825552f1-6fcac7fa-72ca1aa5"); | |
783 ASSERT_EQ(f.GetFrameSopInstanceUid(2), "348efc0a-71ee4758-56bd51fa-9703cbff-9b51d4c9"); | |
784 ASSERT_EQ(f.GetFrameSopInstanceUid(3), "a0ca6802-56c697c3-0205bab8-42217cfc-84ff0de6"); | |
785 ASSERT_EQ(f.GetFrameSopInstanceUid(4), "eaa49a94-b9042041-7f45150b-e414f800-d7232874"); | |
786 ASSERT_EQ(f.GetFrameSopInstanceUid(5), "a8ee83f9-1cc26ad9-ebba3043-8afc47c2-bd784610"); | |
787 ASSERT_EQ(f.GetFrameSopInstanceUid(6), "c19fb4b6-ad1224f2-2c3a2b28-0ea233be-38eea0de"); | |
788 ASSERT_EQ(f.GetFrameSopInstanceUid(7), "e0d82343-9cef01e9-e21df50a-11886a94-1d0216ea"); | |
789 ASSERT_EQ(f.GetFrameSopInstanceUid(8), "efce9ff4-3fe07d83-745846f8-fefe5d64-bfea65e6"); | |
790 ASSERT_EQ(f.GetFrameSopInstanceUid(9), "67b44a5e-8997f88d-6e527bd6-df342483-dab1674c"); | |
791 ASSERT_EQ(f.GetFrameSopInstanceUid(10), "8bdecadd-e3477e28-bbbf0297-22b0b680-37b13a7c"); | |
792 ASSERT_EQ(f.GetFrameSopInstanceUid(11), "f5e889ac-c5afdc37-c5b62074-a8bdeef3-c58d9889"); | |
793 ASSERT_EQ(f.GetFrameSopInstanceUid(12), "b590cc95-55789755-ebd10b76-911e855e-f24e4fe7"); | |
794 ASSERT_EQ(f.GetFrameSopInstanceUid(13), "16606f69-83b48518-ab34304a-c8871b7f-a9298d74"); | |
795 ASSERT_EQ(f.GetFrameSopInstanceUid(14), "23d12f39-e9a4fc21-8da338c4-97feff30-48e95534"); | |
796 ASSERT_EQ(f.GetFrameSopInstanceUid(15), "7a7c0120-37f6dd58-c46312e6-2559975d-5af4616f"); | |
797 ASSERT_EQ(f.GetFrameSopInstanceUid(16), "fa56f961-d1ae8f6a-989c04f4-7a588e9e-b41b1a13"); | |
798 ASSERT_EQ(f.GetFrameSopInstanceUid(17), "63d595f3-327a306d-1709bb8b-2a72e11c-4f7221fe"); | |
799 ASSERT_EQ(f.GetFrameSopInstanceUid(18), "5faf886f-bd5517cf-1a6ba06e-ac0e6ddb-47bdd8b2"); | |
800 ASSERT_EQ(f.GetFrameSopInstanceUid(19), "6824db93-ed4e2740-07be953f-6d0a8fb3-af0a3a0b"); | |
801 ASSERT_EQ(f.GetFrameSopInstanceUid(20), "dc1576ee-25b0b1ef-e038df76-d296fcad-a1456169"); | |
802 ASSERT_EQ(f.GetFrameSopInstanceUid(21), "5a2acb03-063f5063-cac452d1-a55992f9-769900fb"); | |
803 } | |
804 | |
805 | |
806 TEST(SortedFrames, Cardiac) // Created using "SortedFramesCreateTest.py" | |
807 { | |
808 Orthanc::DicomMap tags; | |
809 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "1.3.51.0.1.1.192.168.29.133.1681753.1681732", false); | |
810 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "1.3.12.2.1107.5.2.33.37097.2012041612474981424569674.0.0.0", false); | |
811 OrthancStone::SortedFrames f; | |
812 | |
813 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "a468da62-a8a6e0b9-f66b86b0-b15fa30b-93077161", false); | |
814 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
815 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
816 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "14", false); | |
817 f.AddInstance(tags); | |
818 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "1cf40ac9-e823e677-cbd5db4b-9e48b451-cccbf950", false); | |
819 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
820 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
821 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "21", false); | |
822 f.AddInstance(tags); | |
823 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "d52d5f21-54f1ad99-4015a995-108f7210-ee157944", false); | |
824 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
825 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
826 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "15", false); | |
827 f.AddInstance(tags); | |
828 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "b348f629-11d59f98-fb22710b-4964b90a-f44436ff", false); | |
829 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
830 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
831 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "12", false); | |
832 f.AddInstance(tags); | |
833 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "aac4f2ba-e863f124-6af96709-053258a7-3d39db26", false); | |
834 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
835 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
836 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "13", false); | |
837 f.AddInstance(tags); | |
838 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "8fefe14c-c4c34152-2c3d3514-04e75747-eb7f01f0", false); | |
839 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
840 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
841 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "20", false); | |
842 f.AddInstance(tags); | |
843 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "20b42f52-6d5f784b-cdbc0fbe-4bfc6b0c-5a199c75", false); | |
844 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
845 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
846 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "17", false); | |
847 f.AddInstance(tags); | |
848 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "931d0c36-8fbb4101-70e6d756-edb15431-aaa9a31b", false); | |
849 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
850 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
851 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "19", false); | |
852 f.AddInstance(tags); | |
853 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "9e3b97ec-25b86a67-2cbb8f77-94e73268-4509d383", false); | |
854 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
855 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
856 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "10", false); | |
857 f.AddInstance(tags); | |
858 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "caa62568-fdf894fe-08f830a2-5a468967-681d954b", false); | |
859 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
860 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
861 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "18", false); | |
862 f.AddInstance(tags); | |
863 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "e734c170-96b0a397-95e3b43e-d7a5ed74-025843c8", false); | |
864 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
865 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
866 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "22", false); | |
867 f.AddInstance(tags); | |
868 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "efc9f411-9f4294e0-66d292a1-b8b6b421-897f1d80", false); | |
869 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
870 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
871 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "11", false); | |
872 f.AddInstance(tags); | |
873 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "8346a1db-0b08a22b-9045aaad-57098aac-5b2e9159", false); | |
874 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
875 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
876 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "16", false); | |
877 f.AddInstance(tags); | |
878 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "8c7d1e4d-7936f799-c4b8b56b-32d0d9a6-2b492e98", false); | |
879 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
880 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
881 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "3", false); | |
882 f.AddInstance(tags); | |
883 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "faec09f9-ca7fe0f0-2b25c370-bb1bfaef-8ccfa560", false); | |
884 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
885 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
886 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "4", false); | |
887 f.AddInstance(tags); | |
888 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "99c20bcc-115ae447-84d616f2-cb6c5576-9f67aa7a", false); | |
889 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
890 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
891 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "23", false); | |
892 f.AddInstance(tags); | |
893 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "7906b806-47190031-72c5043c-d42704c1-688a3b23", false); | |
894 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
895 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
896 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "9", false); | |
897 f.AddInstance(tags); | |
898 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "c9dfc022-7b377063-08bdc5e8-fedcc463-8de22ee6", false); | |
899 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
900 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
901 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "6", false); | |
902 f.AddInstance(tags); | |
903 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "6570b6c0-7d2f324d-db7cad50-843f62df-d0446352", false); | |
904 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
905 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
906 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "5", false); | |
907 f.AddInstance(tags); | |
908 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "0be36fe7-6c7a762b-281cf109-fff9d8ea-42e16b7a", false); | |
909 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
910 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
911 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "7", false); | |
912 f.AddInstance(tags); | |
913 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "ec282396-a8209d00-1c5091f3-f632bf3d-a1bcebba", false); | |
914 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
915 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
916 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "8", false); | |
917 f.AddInstance(tags); | |
918 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "fda415d4-f1429b07-5d1cd9f0-675059ff-c0ce9e67", false); | |
919 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
920 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
921 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "1", false); | |
922 f.AddInstance(tags); | |
923 tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "f555ef96-6b01a90c-bdc2585a-dd17bb3a-75e89920", false); | |
924 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "-37.318577811371\\-157.20910163001\\232.94204104611", false); | |
925 tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "0.73931693068262\\0.61320183243991\\-0.2781977510663\\-0.3521819177853\\-3.9073598e-009\\-0.9359315662938", false); | |
926 tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "2", false); | |
927 f.AddInstance(tags); | |
928 f.Sort(); | |
929 ASSERT_EQ(23u, f.GetFramesCount()); | |
930 ASSERT_EQ(f.GetFrameSopInstanceUid(0), "fda415d4-f1429b07-5d1cd9f0-675059ff-c0ce9e67"); | |
931 ASSERT_EQ(f.GetFrameSopInstanceUid(1), "f555ef96-6b01a90c-bdc2585a-dd17bb3a-75e89920"); | |
932 ASSERT_EQ(f.GetFrameSopInstanceUid(2), "8c7d1e4d-7936f799-c4b8b56b-32d0d9a6-2b492e98"); | |
933 ASSERT_EQ(f.GetFrameSopInstanceUid(3), "faec09f9-ca7fe0f0-2b25c370-bb1bfaef-8ccfa560"); | |
934 ASSERT_EQ(f.GetFrameSopInstanceUid(4), "6570b6c0-7d2f324d-db7cad50-843f62df-d0446352"); | |
935 ASSERT_EQ(f.GetFrameSopInstanceUid(5), "c9dfc022-7b377063-08bdc5e8-fedcc463-8de22ee6"); | |
936 ASSERT_EQ(f.GetFrameSopInstanceUid(6), "0be36fe7-6c7a762b-281cf109-fff9d8ea-42e16b7a"); | |
937 ASSERT_EQ(f.GetFrameSopInstanceUid(7), "ec282396-a8209d00-1c5091f3-f632bf3d-a1bcebba"); | |
938 ASSERT_EQ(f.GetFrameSopInstanceUid(8), "7906b806-47190031-72c5043c-d42704c1-688a3b23"); | |
939 ASSERT_EQ(f.GetFrameSopInstanceUid(9), "9e3b97ec-25b86a67-2cbb8f77-94e73268-4509d383"); | |
940 ASSERT_EQ(f.GetFrameSopInstanceUid(10), "efc9f411-9f4294e0-66d292a1-b8b6b421-897f1d80"); | |
941 ASSERT_EQ(f.GetFrameSopInstanceUid(11), "b348f629-11d59f98-fb22710b-4964b90a-f44436ff"); | |
942 ASSERT_EQ(f.GetFrameSopInstanceUid(12), "aac4f2ba-e863f124-6af96709-053258a7-3d39db26"); | |
943 ASSERT_EQ(f.GetFrameSopInstanceUid(13), "a468da62-a8a6e0b9-f66b86b0-b15fa30b-93077161"); | |
944 ASSERT_EQ(f.GetFrameSopInstanceUid(14), "d52d5f21-54f1ad99-4015a995-108f7210-ee157944"); | |
945 ASSERT_EQ(f.GetFrameSopInstanceUid(15), "8346a1db-0b08a22b-9045aaad-57098aac-5b2e9159"); | |
946 ASSERT_EQ(f.GetFrameSopInstanceUid(16), "20b42f52-6d5f784b-cdbc0fbe-4bfc6b0c-5a199c75"); | |
947 ASSERT_EQ(f.GetFrameSopInstanceUid(17), "caa62568-fdf894fe-08f830a2-5a468967-681d954b"); | |
948 ASSERT_EQ(f.GetFrameSopInstanceUid(18), "931d0c36-8fbb4101-70e6d756-edb15431-aaa9a31b"); | |
949 ASSERT_EQ(f.GetFrameSopInstanceUid(19), "8fefe14c-c4c34152-2c3d3514-04e75747-eb7f01f0"); | |
950 ASSERT_EQ(f.GetFrameSopInstanceUid(20), "1cf40ac9-e823e677-cbd5db4b-9e48b451-cccbf950"); | |
951 ASSERT_EQ(f.GetFrameSopInstanceUid(21), "e734c170-96b0a397-95e3b43e-d7a5ed74-025843c8"); | |
952 ASSERT_EQ(f.GetFrameSopInstanceUid(22), "99c20bcc-115ae447-84d616f2-cb6c5576-9f67aa7a"); | |
953 } |