Mercurial > hg > orthanc-wsi
changeset 89:61e629ce7c94
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Dec 2016 21:13:29 +0100 |
parents | 7dffa59c498d |
children | bdc5cb0db9bf |
files | Framework/Inputs/DicomPyramidInstance.cpp Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h |
diffstat | 3 files changed, 68 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Inputs/DicomPyramidInstance.cpp Fri Dec 16 17:02:32 2016 +0100 +++ b/Framework/Inputs/DicomPyramidInstance.cpp Fri Dec 16 21:13:29 2016 +0100 @@ -81,9 +81,16 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); } - unsigned int bitsStored = reader.GetUnsignedIntegerValue(DICOM_TAG_BITS_STORED); - unsigned int samplesPerPixel = reader.GetUnsignedIntegerValue(DICOM_TAG_SAMPLES_PER_PIXEL); - bool isSigned = (reader.GetUnsignedIntegerValue(DICOM_TAG_PIXEL_REPRESENTATION) != 0); + unsigned int bitsStored, samplesPerPixel, tmp; + + if (!reader.GetUnsignedIntegerValue(bitsStored, DICOM_TAG_BITS_STORED) || + !reader.GetUnsignedIntegerValue(samplesPerPixel, DICOM_TAG_SAMPLES_PER_PIXEL) || + !reader.GetUnsignedIntegerValue(tmp, DICOM_TAG_PIXEL_REPRESENTATION)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); + } + + bool isSigned = (tmp != 0); if (bitsStored == 8 && samplesPerPixel == 1 && @@ -142,10 +149,16 @@ hasCompression_ = false; format_ = DetectPixelFormat(reader); - tileWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_COLUMNS); - tileHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_ROWS); - totalWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS); - totalHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS); + + unsigned int tmp; + if (!reader.GetUnsignedIntegerValue(tileWidth_, DICOM_TAG_COLUMNS) || + !reader.GetUnsignedIntegerValue(tileHeight_, DICOM_TAG_ROWS) || + !reader.GetUnsignedIntegerValue(totalWidth_, DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS) || + !reader.GetUnsignedIntegerValue(totalHeight_, DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS) || + !reader.GetUnsignedIntegerValue(tmp, DICOM_TAG_NUMBER_OF_FRAMES)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); + } size_t countFrames; if (!reader.GetDataset().GetSequenceSize(countFrames, DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE)) @@ -153,7 +166,7 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); } - if (countFrames != reader.GetUnsignedIntegerValue(DICOM_TAG_NUMBER_OF_FRAMES)) + if (countFrames != tmp) { LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId; throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); @@ -163,13 +176,20 @@ for (size_t i = 0; i < countFrames; i++) { - int xx = reader.GetIntegerValue(DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, - DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, - DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX)); + DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, + DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, + DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); - int yy = reader.GetIntegerValue(DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, - DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, - DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX)); + DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i, + DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0, + DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX); + + int xx, yy; + if (!reader.GetIntegerValue(xx, pathX) || + !reader.GetIntegerValue(yy, pathY)) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); + } // "-1", because coordinates are shifted by 1 in DICOM xx -= 1;
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 17:02:32 2016 +0100 +++ b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 21:13:29 2016 +0100 @@ -104,8 +104,9 @@ template <typename T> - static T GetValueInternal(const IDicomDataset& dataset, - const DicomPath& path) + static bool GetValueInternal(T& target, + const IDicomDataset& dataset, + const DicomPath& path) { try { @@ -113,11 +114,12 @@ if (dataset.GetStringValue(s, path)) { - return boost::lexical_cast<T>(StripSpaces(s)); + target = boost::lexical_cast<T>(StripSpaces(s)); + return true; } else { - ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag); + return false; } } catch (boost::bad_lexical_cast&) @@ -127,19 +129,26 @@ } - int DicomDatasetReader::GetIntegerValue(const DicomPath& path) const + bool DicomDatasetReader::GetIntegerValue(int& target, + const DicomPath& path) const { - return GetValueInternal<int>(dataset_, path); + return GetValueInternal<int>(target, dataset_, path); } - unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) const + bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target, + const DicomPath& path) const { - int value = GetIntegerValue(path); - - if (value >= 0) + int value; + + if (!GetIntegerValue(value, path)) { - return static_cast<unsigned int>(value); + return false; + } + else if (value >= 0) + { + target = static_cast<unsigned int>(value); + return true; } else { @@ -148,14 +157,16 @@ } - float DicomDatasetReader::GetFloatValue(const DicomPath& path) const + bool DicomDatasetReader::GetFloatValue(float& target, + const DicomPath& path) const { - return GetValueInternal<float>(dataset_, path); + return GetValueInternal<float>(target, dataset_, path); } - double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const + bool DicomDatasetReader::GetDoubleValue(double& target, + const DicomPath& path) const { - return GetValueInternal<double>(dataset_, path); + return GetValueInternal<double>(target, dataset_, path); } }
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h Fri Dec 16 17:02:32 2016 +0100 +++ b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h Fri Dec 16 21:13:29 2016 +0100 @@ -57,12 +57,16 @@ std::string GetMandatoryStringValue(const DicomPath& path) const; - int GetIntegerValue(const DicomPath& path) const; + bool GetIntegerValue(int& target, + const DicomPath& path) const; - unsigned int GetUnsignedIntegerValue(const DicomPath& path) const; + bool GetUnsignedIntegerValue(unsigned int& target, + const DicomPath& path) const; - float GetFloatValue(const DicomPath& path) const; + bool GetFloatValue(float& target, + const DicomPath& path) const; - double GetDoubleValue(const DicomPath& path) const; + bool GetDoubleValue(double& target, + const DicomPath& path) const; }; }