Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1630:78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Nov 2020 18:01:32 +0100 |
parents | b3c439d96d3e |
children | 960bb5fcc440 |
comparison
equal
deleted
inserted
replaced
1629:7fc8a3ff09ee | 1630:78509230f0d7 |
---|---|
27 #include <OrthancException.h> | 27 #include <OrthancException.h> |
28 #include <Toolbox.h> | 28 #include <Toolbox.h> |
29 | 29 |
30 namespace OrthancStone | 30 namespace OrthancStone |
31 { | 31 { |
32 SortedFrames::Instance::Instance(const Orthanc::DicomMap& tags) | 32 SortedFrames::Instance::Instance(const Orthanc::DicomMap& tags) : |
33 geometry_(tags) | |
33 { | 34 { |
34 tags_.Assign(tags); | 35 tags_.Assign(tags); |
35 | 36 |
36 if (!tags.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | 37 if (!tags.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) |
37 { | 38 { |
56 } | 57 } |
57 else | 58 else |
58 { | 59 { |
59 monochrome1_ = false; | 60 monochrome1_ = false; |
60 } | 61 } |
61 | 62 } |
62 hasPosition_ = ( | 63 |
63 LinearAlgebra::ParseVector(position_, tags, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT) && | 64 |
64 position_.size() == 3 && | |
65 GeometryToolbox::ComputeNormal(normal_, tags)); | |
66 } | |
67 | |
68 | |
69 const Vector& SortedFrames::Instance::GetNormal() const | |
70 { | |
71 if (hasPosition_) | |
72 { | |
73 return normal_; | |
74 } | |
75 else | |
76 { | |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
78 } | |
79 } | |
80 | |
81 | |
82 const Vector& SortedFrames::Instance::GetPosition() const | |
83 { | |
84 if (hasPosition_) | |
85 { | |
86 return position_; | |
87 } | |
88 else | |
89 { | |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
91 } | |
92 } | |
93 | |
94 | |
95 SortedFrames::Frame::Frame(const Instance& instance, | 65 SortedFrames::Frame::Frame(const Instance& instance, |
96 unsigned int frameNumber) : | 66 unsigned int frameNumber) : |
97 instance_(&instance), | 67 instance_(&instance), |
98 frameNumber_(frameNumber) | 68 frameNumber_(frameNumber) |
99 { | 69 { |
341 it != remainingInstances.end(); ++it) | 311 it != remainingInstances.end(); ++it) |
342 { | 312 { |
343 assert(instances_[*it] != NULL); | 313 assert(instances_[*it] != NULL); |
344 const Instance& instance = *instances_[*it]; | 314 const Instance& instance = *instances_[*it]; |
345 | 315 |
346 if (instance.HasPosition()) | 316 if (instance.GetGeometry().IsValid()) |
347 { | 317 { |
348 n += 1; | 318 n += 1; |
349 meanNormal += (instance.GetNormal() - meanNormal) / static_cast<float>(n); | 319 meanNormal += (instance.GetGeometry().GetNormal() - meanNormal) / static_cast<float>(n); |
350 } | 320 } |
351 } | 321 } |
352 | 322 |
353 std::vector<SortableItem<float> > items; | 323 std::vector<SortableItem<float> > items; |
354 items.reserve(n); | 324 items.reserve(n); |
356 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); | 326 for (std::set<size_t>::const_iterator it = remainingInstances.begin(); |
357 it != remainingInstances.end(); ++it) | 327 it != remainingInstances.end(); ++it) |
358 { | 328 { |
359 assert(instances_[*it] != NULL); | 329 assert(instances_[*it] != NULL); |
360 const Instance& instance = *instances_[*it]; | 330 const Instance& instance = *instances_[*it]; |
361 | 331 |
362 std::string sopInstanceUid; | 332 std::string sopInstanceUid; |
363 if (instance.HasPosition() && | 333 if (instance.GetGeometry().IsValid() && |
364 instance.GetTags().LookupStringValue( | 334 instance.GetTags().LookupStringValue( |
365 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) | 335 sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) |
366 { | 336 { |
367 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetPosition()); | 337 double p = LinearAlgebra::DotProduct(meanNormal, instance.GetGeometry().GetOrigin()); |
368 items.push_back(SortableItem<float>(static_cast<float>(p), *it, sopInstanceUid)); | 338 items.push_back(SortableItem<float>(static_cast<float>(p), *it, sopInstanceUid)); |
369 } | 339 } |
370 } | 340 } |
371 | 341 |
372 assert(items.size() <= n); | 342 assert(items.size() <= n); |