Mercurial > hg > orthanc-stone
changeset 1635:1a714e21ea7c
start refactoring DicomInstanceParameters
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:08:44 +0100 |
parents | a4418a489e86 |
children | d1e0b08b809d |
files | OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp OrthancStone/Sources/Toolbox/DicomInstanceParameters.h OrthancStone/Sources/Toolbox/LinearAlgebra.cpp |
diffstat | 3 files changed, 62 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp Tue Nov 10 11:11:28 2020 +0100 +++ b/OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp Tue Nov 10 16:08:44 2020 +0100 @@ -45,18 +45,23 @@ if (dicom.LookupStringValue(increment, Orthanc::DICOM_TAG_FRAME_INCREMENT_POINTER, false)) { Orthanc::Toolbox::ToUpperCase(increment); - if (increment != "3004,000C") // This is the "Grid Frame Offset Vector" tag (DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) + + // This is the "Grid Frame Offset Vector" tag (DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) + if (increment != "3004,000C") { LOG(WARNING) << "Bad value for the FrameIncrementPointer tags in a multiframe image"; + frameOffsets_.resize(0); return; } } if (!LinearAlgebra::ParseVector(frameOffsets_, dicom, Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR) || - frameOffsets_.size() != imageInformation_.GetNumberOfFrames()) + frameOffsets_.size() != numberOfFrames_) { LOG(INFO) << "The frame offset information is missing in a multiframe image"; - frameOffsets_.clear(); + + // DO NOT use ".clear()" here, as the "Vector" class doesn't behave like std::vector! + frameOffsets_.resize(0); } } @@ -64,11 +69,6 @@ DicomInstanceParameters::Data::Data(const Orthanc::DicomMap& dicom) : imageInformation_(dicom) { - if (imageInformation_.GetNumberOfFrames() == 0) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); - } - if (!dicom.LookupStringValue(studyInstanceUid_, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) || !dicom.LookupStringValue(seriesInstanceUid_, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) || !dicom.LookupStringValue(sopInstanceUid_, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false)) @@ -77,15 +77,37 @@ } std::string s; - if (!dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false)) + if (dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false)) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + sopClassUid_ = StringToSopClassUid(s); } else { - sopClassUid_ = StringToSopClassUid(s); + sopClassUid_ = SopClassUid_Other; + } + + uint32_t n; + if (dicom.ParseUnsignedInteger32(n, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES)) + { + numberOfFrames_ = n; + } + else + { + numberOfFrames_ = 1; } + if (!dicom.HasTag(Orthanc::DICOM_TAG_COLUMNS) || + !dicom.GetValue(Orthanc::DICOM_TAG_COLUMNS).ParseFirstUnsignedInteger(width_)) + { + width_ = 0; + } + + if (!dicom.HasTag(Orthanc::DICOM_TAG_ROWS) || + !dicom.GetValue(Orthanc::DICOM_TAG_ROWS).ParseFirstUnsignedInteger(height_)) + { + height_ = 0; + } + if (!dicom.ParseDouble(sliceThickness_, Orthanc::DICOM_TAG_SLICE_THICKNESS)) { sliceThickness_ = 100.0 * std::numeric_limits<double>::epsilon(); @@ -100,6 +122,7 @@ geometry_ = CoordinateSystem3D(position, orientation); } + // Must be AFTER setting "numberOfFrames_" ExtractFrameOffsets(dicom); if (sopClassUid_ == SopClassUid_RTDose) @@ -206,11 +229,7 @@ CoordinateSystem3D DicomInstanceParameters::Data::GetFrameGeometry(unsigned int frame) const { - if (frame == 0) - { - return geometry_; - } - else if (frame >= imageInformation_.GetNumberOfFrames()) + if (frame >= numberOfFrames_) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } @@ -220,7 +239,7 @@ } else { - assert(frameOffsets_.size() == imageInformation_.GetNumberOfFrames()); + assert(frameOffsets_.size() == numberOfFrames_); return CoordinateSystem3D( geometry_.GetOrigin() + frameOffsets_[frame] * geometry_.GetNormal(), @@ -233,7 +252,7 @@ bool DicomInstanceParameters::Data::IsPlaneWithinSlice(unsigned int frame, const CoordinateSystem3D& plane) const { - if (frame >= imageInformation_.GetNumberOfFrames()) + if (frame >= numberOfFrames_) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); }
--- a/OrthancStone/Sources/Toolbox/DicomInstanceParameters.h Tue Nov 10 11:11:28 2020 +0100 +++ b/OrthancStone/Sources/Toolbox/DicomInstanceParameters.h Tue Nov 10 16:08:44 2020 +0100 @@ -43,21 +43,24 @@ std::string studyInstanceUid_; std::string seriesInstanceUid_; std::string sopInstanceUid_; - Orthanc::DicomImageInformation imageInformation_; + Orthanc::DicomImageInformation imageInformation_; // TODO REMOVE SopClassUid sopClassUid_; + unsigned int numberOfFrames_; + unsigned int width_; + unsigned int height_; double sliceThickness_; double pixelSpacingX_; double pixelSpacingY_; CoordinateSystem3D geometry_; Vector frameOffsets_; - bool isColor_; + bool isColor_; // TODO REMOVE bool hasRescale_; double rescaleIntercept_; double rescaleSlope_; bool hasDefaultWindowing_; float defaultWindowingCenter_; float defaultWindowingWidth_; - Orthanc::PixelFormat expectedPixelFormat_; + Orthanc::PixelFormat expectedPixelFormat_; // TODO REMOVE bool hasIndexInSeries_; unsigned int indexInSeries_; std::string doseUnits_; @@ -135,6 +138,21 @@ return data_.sopClassUid_; } + unsigned int GetNumberOfFrames() const + { + return data_.numberOfFrames_; + } + + unsigned int GetWidth() const + { + return data_.width_; + } + + unsigned int GetHeight() const + { + return data_.height_; + } + double GetSliceThickness() const { return data_.sliceThickness_;
--- a/OrthancStone/Sources/Toolbox/LinearAlgebra.cpp Tue Nov 10 11:11:28 2020 +0100 +++ b/OrthancStone/Sources/Toolbox/LinearAlgebra.cpp Tue Nov 10 16:08:44 2020 +0100 @@ -107,7 +107,8 @@ } catch (std::exception&) { - target.clear(); + // DO NOT use ".clear()" here, as the "Vector" class doesn't behave like std::vector! + target.resize(0); return false; } @@ -147,7 +148,8 @@ } catch (boost::bad_lexical_cast&) { - target.clear(); + // DO NOT use ".clear()" here, as the "Vector" class doesn't behave like std::vector! + target.resize(0); return false; } #endif