Mercurial > hg > orthanc
changeset 2238:4f0a9a61d905
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Dec 2016 16:22:38 +0100 |
parents | 403d92d8df83 |
children | 15637de71fee |
files | Plugins/Samples/Common/DicomDatasetReader.cpp Plugins/Samples/Common/DicomDatasetReader.h Plugins/Samples/Common/DicomTag.h |
diffstat | 3 files changed, 74 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 14:45:40 2016 +0100 +++ b/Plugins/Samples/Common/DicomDatasetReader.cpp Fri Dec 16 16:22:38 2016 +0100 @@ -68,20 +68,31 @@ } - DicomDatasetReader::DicomDatasetReader(IDicomDataset* dataset) : // takes ownership + DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) : dataset_(dataset) { - if (dataset == NULL) + } + + + std::string DicomDatasetReader::GetStringValue(const DicomPath& path, + const std::string& defaultValue) const + { + std::string s; + if (dataset_.GetStringValue(s, path)) { - ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + return s; + } + else + { + return defaultValue; } } - + std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const { std::string s; - if (dataset_->GetStringValue(s, path)) + if (dataset_.GetStringValue(s, path)) { return s; } @@ -92,12 +103,22 @@ } - int DicomDatasetReader::GetIntegerValue(const DicomPath& path) + template <typename T> + static T GetValueInternal(const IDicomDataset& dataset, + const DicomPath& path) { try { - std::string s = StripSpaces(GetMandatoryStringValue(path)); - return boost::lexical_cast<int>(s); + std::string s; + + if (dataset.GetStringValue(s, path)) + { + return boost::lexical_cast<T>(StripSpaces(s)); + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag); + } } catch (boost::bad_lexical_cast&) { @@ -106,10 +127,16 @@ } - unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) + int DicomDatasetReader::GetIntegerValue(const DicomPath& path) const + { + return GetValueInternal<int>(dataset_, path); + } + + + unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path) const { int value = GetIntegerValue(path); - + if (value >= 0) { return static_cast<unsigned int>(value); @@ -119,4 +146,16 @@ ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); } } + + + float DicomDatasetReader::GetFloatValue(const DicomPath& path) const + { + return GetValueInternal<float>(dataset_, path); + } + + + double DicomDatasetReader::GetDoubleValue(const DicomPath& path) const + { + return GetValueInternal<double>(dataset_, path); + } }
--- a/Plugins/Samples/Common/DicomDatasetReader.h Fri Dec 16 14:45:40 2016 +0100 +++ b/Plugins/Samples/Common/DicomDatasetReader.h Fri Dec 16 16:22:38 2016 +0100 @@ -35,26 +35,34 @@ #include "IDicomDataset.h" #include <memory> +#include <vector> namespace OrthancPlugins { class DicomDatasetReader : public boost::noncopyable { private: - std::auto_ptr<IDicomDataset> dataset_; + const IDicomDataset& dataset_; public: - DicomDatasetReader(IDicomDataset* dataset); // takes ownership + DicomDatasetReader(const IDicomDataset& dataset); - IDicomDataset& GetDataset() const + const IDicomDataset& GetDataset() const { - return *dataset_; + return dataset_; } + std::string GetStringValue(const DicomPath& path, + const std::string& defaultValue) const; + std::string GetMandatoryStringValue(const DicomPath& path) const; - int GetIntegerValue(const DicomPath& path); + int GetIntegerValue(const DicomPath& path) const; + + unsigned int GetUnsignedIntegerValue(const DicomPath& path) const; - unsigned int GetUnsignedIntegerValue(const DicomPath& path); + float GetFloatValue(const DicomPath& path) const; + + double GetDoubleValue(const DicomPath& path) const; }; }
--- a/Plugins/Samples/Common/DicomTag.h Fri Dec 16 14:45:40 2016 +0100 +++ b/Plugins/Samples/Common/DicomTag.h Fri Dec 16 16:22:38 2016 +0100 @@ -77,19 +77,27 @@ static const DicomTag DICOM_TAG_BITS_STORED(0x0028, 0x0101); + static const DicomTag DICOM_TAG_COLUMNS(0x0028, 0x0011); static const DicomTag DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021e); - static const DicomTag DICOM_TAG_COLUMNS(0x0028, 0x0011); + static const DicomTag DICOM_TAG_IMAGE_ORIENTATION_PATIENT(0x0020, 0x0037); + static const DicomTag DICOM_TAG_IMAGE_POSITION_PATIENT(0x0020, 0x0032); static const DicomTag DICOM_TAG_MODALITY(0x0008, 0x0060); static const DicomTag DICOM_TAG_NUMBER_OF_FRAMES(0x0028, 0x0008); static const DicomTag DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE(0x5200, 0x9230); static const DicomTag DICOM_TAG_PHOTOMETRIC_INTERPRETATION(0x0028, 0x0004); static const DicomTag DICOM_TAG_PIXEL_REPRESENTATION(0x0028, 0x0103); + static const DicomTag DICOM_TAG_PIXEL_SPACING(0x0028, 0x0030); static const DicomTag DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE(0x0048, 0x021a); - static const DicomTag DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021f); + static const DicomTag DICOM_TAG_RESCALE_INTERCEPT(0x0028, 0x1052); + static const DicomTag DICOM_TAG_RESCALE_SLOPE(0x0028, 0x1053); static const DicomTag DICOM_TAG_ROWS(0x0028, 0x0010); + static const DicomTag DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021f); + static const DicomTag DICOM_TAG_SAMPLES_PER_PIXEL(0x0028, 0x0002); + static const DicomTag DICOM_TAG_SLICE_THICKNESS(0x0018, 0x0050); static const DicomTag DICOM_TAG_SOP_CLASS_UID(0x0008, 0x0016); - static const DicomTag DICOM_TAG_SAMPLES_PER_PIXEL(0x0028, 0x0002); static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS(0x0048, 0x0006); static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS(0x0048, 0x0007); static const DicomTag DICOM_TAG_TRANSFER_SYNTAX_UID(0x0002, 0x0010); + static const DicomTag DICOM_TAG_WINDOW_CENTER(0x0028, 0x1050); + static const DicomTag DICOM_TAG_WINDOW_WIDTH(0x0028, 0x1051); }