comparison OrthancStone/Sources/Toolbox/SortedFrames.cpp @ 1602:b2941196cabf

SortedFrames::LookupFrame()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2020 16:35:45 +0100
parents b253b79906fa
children b3c439d96d3e
comparison
equal deleted inserted replaced
1601:1704341bb96e 1602:b2941196cabf
142 { 142 {
143 assert(instances_[i] != NULL); 143 assert(instances_[i] != NULL);
144 delete instances_[i]; 144 delete instances_[i];
145 } 145 }
146 146
147 instancesIndex_.clear();
148 studyInstanceUid_.clear(); 147 studyInstanceUid_.clear();
149 seriesInstanceUid_.clear(); 148 seriesInstanceUid_.clear();
150 frames_.clear(); 149 frames_.clear();
150
151 instancesIndex_.clear();
152 framesIndex_.clear();
153
151 sorted_ = true; 154 sorted_ = true;
152 } 155 }
153 156
154 157
155 void SortedFrames::AddInstance(const Orthanc::DicomMap& tags) 158 void SortedFrames::AddInstance(const Orthanc::DicomMap& tags)
216 assert(instances_[instanceIndex] != NULL); 219 assert(instances_[instanceIndex] != NULL);
217 const Instance& instance = *instances_[instanceIndex]; 220 const Instance& instance = *instances_[instanceIndex];
218 221
219 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++) 222 for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++)
220 { 223 {
224 framesIndex_[std::make_pair(instance.GetSopInstanceUid(), i)] = frames_.size();
221 frames_.push_back(Frame(instance, i)); 225 frames_.push_back(Frame(instance, i));
222 } 226 }
223 227
224 assert(remainingInstances.find(instanceIndex) != remainingInstances.end()); 228 assert(remainingInstances.find(instanceIndex) != remainingInstances.end());
225 remainingInstances.erase(instanceIndex); 229 remainingInstances.erase(instanceIndex);
388 "Sort() has not been called"); 392 "Sort() has not been called");
389 } 393 }
390 } 394 }
391 395
392 396
397 bool SortedFrames::LookupFrame(size_t& frameIndex,
398 const std::string& sopInstanceUid,
399 unsigned int frameNumber) const
400 {
401 if (sorted_)
402 {
403 FramesIndex::const_iterator found = framesIndex_.find(
404 std::make_pair(sopInstanceUid, frameNumber));
405
406 if (found == framesIndex_.end())
407 {
408 return false;
409 }
410 else
411 {
412 frameIndex = found->second;
413 return true;
414 }
415 }
416 else
417 {
418 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
419 "Sort() has not been called");
420 }
421 }
422
423
393 void SortedFrames::Sort() 424 void SortedFrames::Sort()
394 { 425 {
395 if (!sorted_) 426 if (!sorted_)
396 { 427 {
397 size_t totalFrames = 0; 428 size_t totalFrames = 0;
405 remainingInstances.insert(i); 436 remainingInstances.insert(i);
406 } 437 }
407 438
408 frames_.clear(); 439 frames_.clear();
409 frames_.reserve(totalFrames); 440 frames_.reserve(totalFrames);
441 framesIndex_.clear();
410 442
411 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS" 443 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_INSTANCE_NUMBER); // VR is "IS"
412 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US" 444 SortUsingIntegerTag(remainingInstances, Orthanc::DICOM_TAG_IMAGE_INDEX); // VR is "US"
413 SortUsing3DLocation(remainingInstances); 445 SortUsing3DLocation(remainingInstances);
414 SortUsingSopInstanceUid(remainingInstances); 446 SortUsingSopInstanceUid(remainingInstances);