# HG changeset patch # User Sebastien Jodogne # Date 1605026132 -3600 # Node ID 882e2253a90e4ec7d8826642507ac429d551358a # Parent 5cc589bfb3859a611c7827bc19134d11af1d034f replacing SortedFrames::Instance by DicomInstanceParameters diff -r 5cc589bfb385 -r 882e2253a90e OrthancStone/Sources/Toolbox/SortedFrames.cpp --- a/OrthancStone/Sources/Toolbox/SortedFrames.cpp Tue Nov 10 17:21:23 2020 +0100 +++ b/OrthancStone/Sources/Toolbox/SortedFrames.cpp Tue Nov 10 17:35:32 2020 +0100 @@ -30,100 +30,7 @@ namespace OrthancStone { - SortedFrames::Instance::Instance(const Orthanc::DicomMap& tags) : - geometry_(tags) - { - tags_.Assign(tags); - - if (!tags.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - - uint32_t tmp; - if (tags.ParseUnsignedInteger32(tmp, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES) && - tmp > 0) - { - numberOfFrames_ = tmp; - } - else - { - numberOfFrames_ = 1; - } - - std::string photometric; - if (tags.LookupStringValue(photometric, Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION, false)) - { - Orthanc::Toolbox::StripSpaces(photometric); - monochrome1_ = (photometric == "MONOCHROME1"); - } - else - { - monochrome1_ = false; - } - - bool ok = false; - - if (numberOfFrames_ > 1) - { - std::string offsets, increment; - if (tags.LookupStringValue(offsets, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR, false) && - tags.LookupStringValue(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false)) - { - Orthanc::Toolbox::ToUpperCase(increment); - if (increment != "3004,000C") - { - LOG(WARNING) << "Bad value for the FrameIncrementPointer tags in a multiframe image"; - } - else if (LinearAlgebra::ParseVector(frameOffsets_, offsets)) - { - if (frameOffsets_.size() == numberOfFrames_) - { - ok = true; - } - else - { - LOG(WARNING) << "The size of the GridFrameOffsetVector does not correspond to the number of frames"; - } - } - else - { - LOG(WARNING) << "Cannot parse the GridFrameOffsetVector tag"; - } - } - else - { - LOG(INFO) << "Missing the frame offset information in a multiframe image"; - } - } - - if (!ok) - { - frameOffsets_.resize(numberOfFrames_); - for (size_t i = 0; i < numberOfFrames_; i++) - { - frameOffsets_[i] = 0; - } - } - } - - - double SortedFrames::Instance::GetFrameOffset(unsigned int frame) const - { - assert(GetNumberOfFrames() == frameOffsets_.size()); - - if (frame >= GetNumberOfFrames()) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } - else - { - return frameOffsets_[frame]; - } - } - - - SortedFrames::Frame::Frame(const Instance& instance, + SortedFrames::Frame::Frame(const DicomInstanceParameters& instance, unsigned int frameNumber) : instance_(&instance), frameNumber_(frameNumber) @@ -135,7 +42,7 @@ } - const SortedFrames::Instance& SortedFrames::GetInstance(size_t instanceIndex) const + const DicomInstanceParameters& SortedFrames::GetInstance(size_t instanceIndex) const { if (instanceIndex >= instances_.size()) { @@ -188,38 +95,30 @@ void SortedFrames::AddInstance(const Orthanc::DicomMap& tags) { - std::unique_ptr instance(new Instance(tags)); + std::unique_ptr instance(new DicomInstanceParameters(tags)); - std::string studyInstanceUid, seriesInstanceUid, sopInstanceUid; - if (!tags.LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) || - !tags.LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) || - !tags.LookupStringValue(sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - if (instances_.empty()) { - studyInstanceUid_ = studyInstanceUid; - seriesInstanceUid_ = seriesInstanceUid; + studyInstanceUid_ = instance->GetStudyInstanceUid(); + seriesInstanceUid_ = instance->GetSeriesInstanceUid(); } else { - if (studyInstanceUid_ != studyInstanceUid || - seriesInstanceUid_ != seriesInstanceUid) + if (studyInstanceUid_ != instance->GetStudyInstanceUid() || + seriesInstanceUid_ != instance->GetSeriesInstanceUid()) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "Mixing instances from different series"); } } - if (instancesIndex_.find(sopInstanceUid) != instancesIndex_.end()) + if (instancesIndex_.find(instance->GetSopInstanceUid()) != instancesIndex_.end()) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "Cannot register twice the same SOP Instance UID"); } - instancesIndex_[sopInstanceUid] = instances_.size(); + instancesIndex_[instance->GetSopInstanceUid()] = instances_.size(); instances_.push_back(instance.release()); sorted_ = false; @@ -248,7 +147,7 @@ size_t instanceIndex) { assert(instances_[instanceIndex] != NULL); - const Instance& instance = *instances_[instanceIndex]; + const DicomInstanceParameters& instance = *instances_[instanceIndex]; for (unsigned int i = 0; i < instance.GetNumberOfFrames(); i++) { @@ -306,7 +205,7 @@ it != remainingInstances.end(); ++it) { assert(instances_[*it] != NULL); - const Instance& instance = *instances_[*it]; + const DicomInstanceParameters& instance = *instances_[*it]; int32_t value; std::string sopInstanceUid; @@ -336,7 +235,7 @@ it != remainingInstances.end(); ++it) { assert(instances_[*it] != NULL); - const Instance& instance = *instances_[*it]; + const DicomInstanceParameters& instance = *instances_[*it]; std::string sopInstanceUid; if (instance.GetTags().LookupStringValue( @@ -372,7 +271,7 @@ it != remainingInstances.end(); ++it) { assert(instances_[*it] != NULL); - const Instance& instance = *instances_[*it]; + const DicomInstanceParameters& instance = *instances_[*it]; if (instance.GetGeometry().IsValid()) { @@ -388,7 +287,7 @@ it != remainingInstances.end(); ++it) { assert(instances_[*it] != NULL); - const Instance& instance = *instances_[*it]; + const DicomInstanceParameters& instance = *instances_[*it]; std::string sopInstanceUid; if (instance.GetGeometry().IsValid() && @@ -428,18 +327,7 @@ CoordinateSystem3D SortedFrames::GetFrameGeometry(size_t frameIndex) const { const Frame& frame = GetFrame(frameIndex); - CoordinateSystem3D geometry = frame.GetInstance().GetGeometry(); - - if (geometry.IsValid()) - { - geometry.SetOrigin(geometry.GetOrigin() + geometry.GetNormal() * - frame.GetInstance().GetFrameOffset(frame.GetFrameNumberInInstance())); - return geometry; - } - else - { - return geometry; - } + return frame.GetInstance().GetFrameGeometry(frame.GetFrameNumberInInstance()); } diff -r 5cc589bfb385 -r 882e2253a90e OrthancStone/Sources/Toolbox/SortedFrames.h --- a/OrthancStone/Sources/Toolbox/SortedFrames.h Tue Nov 10 17:21:23 2020 +0100 +++ b/OrthancStone/Sources/Toolbox/SortedFrames.h Tue Nov 10 17:35:32 2020 +0100 @@ -23,6 +23,7 @@ #pragma once #include "CoordinateSystem3D.h" +#include "DicomInstanceParameters.h" #include "LinearAlgebra.h" namespace OrthancStone @@ -30,58 +31,17 @@ class SortedFrames : public boost::noncopyable { private: - class Instance : public boost::noncopyable - { - private: - Orthanc::DicomMap tags_; - std::string sopInstanceUid_; - unsigned int numberOfFrames_; - CoordinateSystem3D geometry_; - bool monochrome1_; - Vector frameOffsets_; - - public: - explicit Instance(const Orthanc::DicomMap& tags); - - const Orthanc::DicomMap& GetTags() const - { - return tags_; - } - - const std::string& GetSopInstanceUid() const - { - return sopInstanceUid_; - } - - unsigned int GetNumberOfFrames() const - { - return numberOfFrames_; - } - - const CoordinateSystem3D& GetGeometry() const - { - return geometry_; - } - - bool IsMonochrome1() const - { - return monochrome1_; - } - - double GetFrameOffset(unsigned int frame) const; - }; - struct Frame { private: - const Instance* instance_; - unsigned int frameNumber_; + const DicomInstanceParameters* instance_; + unsigned int frameNumber_; public: - Frame(const Instance& instance, + Frame(const DicomInstanceParameters& instance, unsigned int frameNumber); - const Instance& GetInstance() const + const DicomInstanceParameters& GetInstance() const { return *instance_; } @@ -100,15 +60,15 @@ // "frames_" (only once "Sort()" is called) typedef std::map, size_t> FramesIndex; - std::string studyInstanceUid_; - std::string seriesInstanceUid_; - std::vector instances_; - std::vector frames_; - bool sorted_; - InstancesIndex instancesIndex_; - FramesIndex framesIndex_; + std::string studyInstanceUid_; + std::string seriesInstanceUid_; + std::vector instances_; + std::vector frames_; + bool sorted_; + InstancesIndex instancesIndex_; + FramesIndex framesIndex_; - const Instance& GetInstance(size_t instanceIndex) const; + const DicomInstanceParameters& GetInstance(size_t instanceIndex) const; const Frame& GetFrame(size_t frameIndex) const; @@ -197,9 +157,10 @@ return GetFrame(frameIndex).GetFrameNumberInInstance(); } - bool IsFrameMonochrome1(size_t frameIndex) const + bool IsFrameMonochrome1(size_t frameIndex) const // TODO - REMOVE { - return GetFrame(frameIndex).GetInstance().IsMonochrome1(); + return GetFrame(frameIndex).GetInstance().GetImageInformation().GetPhotometricInterpretation() == + Orthanc::PhotometricInterpretation_Monochrome1; } CoordinateSystem3D GetFrameGeometry(size_t frameIndex) const;