diff --git a/code/algorithms/rttbDoseToVolumeMeasure.cpp b/code/algorithms/rttbDoseToVolumeMeasure.cpp new file mode 100644 index 0000000..d78e495 --- /dev/null +++ b/code/algorithms/rttbDoseToVolumeMeasure.cpp @@ -0,0 +1,96 @@ +#include "rttbDoseToVolumeMeasure.h" +#include "rttbDataNotAvailableException.h" +#include "rttbInvalidParameterException.h" + +namespace rttb +{ + + namespace algorithms + { + DoseToVolumeMeasure::DoseToVolumeMeasure(complexStatistics name, DoseToVolumeFunctionType values, DoseTypeGy referenceDose) : + name(name), values(values), _referenceDose(referenceDose) {} + + void DoseToVolumeMeasure::insertValue(std::pair value) + { + this->values.insert(value); + } + + VolumeType DoseToVolumeMeasure::getValue(DoseTypeGy xVolumeAbsolute) const + { + VolumeType dummy; + return getSpecificValue(xVolumeAbsolute, false, dummy); + } + + VolumeType DoseToVolumeMeasure::getValue(DoseTypeGy xDoseAbsolute, bool findNearestValue, DoseTypeGy & nearestXDose) const + { + return getSpecificValue(xDoseAbsolute, findNearestValue, nearestXDose); + } + VolumeType DoseToVolumeMeasure::getValueRelative(DoseTypeGy xDoseRelative) const + { + if (_referenceDose != -1 && xDoseRelative >= 0 && xDoseRelative <= 1) { + DoseTypeGy xDoseAbsolute = xDoseRelative * _referenceDose; + DoseTypeGy dummy; + return getSpecificValue(xDoseAbsolute, false, dummy); + } + else { + throw rttb::core::InvalidParameterException("Reference dose must be > 0 and 0 <= relative Dose <= 1"); + } + } + VolumeType DoseToVolumeMeasure::getValueRelative(DoseTypeGy xDoseRelative, bool findNearestValue, DoseTypeGy & nearestXDose) const + { + if (_referenceDose != -1 && xDoseRelative >= 0 && xDoseRelative <= 1) { + DoseTypeGy xDoseAbsolute = xDoseRelative * _referenceDose; + return getSpecificValue(xDoseAbsolute, findNearestValue, nearestXDose); + } + else { + throw rttb::core::InvalidParameterException("Reference dose must be > 0 and 0 <= relative Dose <= 1"); + } + } + DoseToVolumeMeasure::DoseToVolumeFunctionType DoseToVolumeMeasure::getAllValues() const + { + return this->values; + } + + void DoseToVolumeMeasure::setReferenceDose(DoseTypeGy referenceDose) + { + this->_referenceDose = referenceDose; + } + + double DoseToVolumeMeasure::getSpecificValue(double key, bool findNearestValueInstead, double& storedKey) const + { + if (values.find(key) != std::end(values)) + { + return values.find(key)->second; + } + else + { + //value not in map. We have to find the nearest value + if (values.empty()) + { + throw core::DataNotAvailableException("No Vx values are defined"); + } + else + { + if (findNearestValueInstead) + { + auto iterator = findNearestKeyInMap(values, key); + storedKey = iterator->first; + return iterator->second; + } + else + { + throw core::DataNotAvailableException("No Vx value with required dose is defined"); + } + } + } + } + + bool operator==(const DoseToVolumeMeasure& volumeToDoseMesure,const DoseToVolumeMeasure& otherVolumeToDoseMesure) + { + if (volumeToDoseMesure.getName() == otherVolumeToDoseMesure.getName() && volumeToDoseMesure.getAllValues() == otherVolumeToDoseMesure.getAllValues()) { + return true; + } + return false; + } + } +} diff --git a/code/algorithms/rttbDoseToVolumeMeasure.h b/code/algorithms/rttbDoseToVolumeMeasure.h new file mode 100644 index 0000000..31a6f1b --- /dev/null +++ b/code/algorithms/rttbDoseToVolumeMeasure.h @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 1674 $ (last changed revision) +// @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) +// @author $Author: hentsch $ (last changed by) +*/ + +#ifndef __DOSE_TO_VOLUME_MEASURE_H +#define __DOSE_TO_VOLUME_MEASURE_H + +#include "rttbMeasureInterface.h" + +namespace rttb +{ + + namespace algorithms + { + class RTTBAlgorithms_EXPORT DoseToVolumeMeasure : public MeasureInterface { + + public: + typedef std::map DoseToVolumeFunctionType; + + private: + complexStatistics name; + DoseToVolumeFunctionType values; + DoseTypeGy _referenceDose; + + public: + DoseToVolumeMeasure(complexStatistics name, DoseToVolumeFunctionType values = std::map(), DoseTypeGy referenceDose = -1); + void insertValue(std::pair value); + VolumeType getValue(DoseTypeGy xVolumeAbsolute) const; + VolumeType getValue(DoseTypeGy xVolumeAbsolute, bool findNearestValue, DoseTypeGy& nearestXDose) const; + VolumeType getValueRelative(DoseTypeGy xDoseRelative) const; + VolumeType getValueRelative(DoseTypeGy xDoseRelative, bool findNearestValue, DoseTypeGy& nearestXDose) const; + DoseToVolumeFunctionType getAllValues() const; + friend bool operator==(const DoseToVolumeMeasure& volumeToDoseMesure, const DoseToVolumeMeasure& otherVolumeToDoseMesure); + void setReferenceDose(DoseTypeGy referenceDose); + private: + double getSpecificValue(double key, bool findNearestValueInstead, double& storedKey) const; + }; + } +} + + +#endif diff --git a/code/algorithms/rttbDoseToVolumeMeasureCalculator.cpp b/code/algorithms/rttbDoseToVolumeMeasureCalculator.cpp new file mode 100644 index 0000000..5e75f4a --- /dev/null +++ b/code/algorithms/rttbDoseToVolumeMeasureCalculator.cpp @@ -0,0 +1,47 @@ +#include "rttbDoseToVolumeMeasureCalculator.h" +#include +//#include + +namespace rttb +{ + + namespace algorithms + { + DoseToVolumeMeasureCalculator::DoseToVolumeMeasureCalculator(const std::vector& precomputeVolumeValues, const DoseTypeGy& referenceDose, + const core::DoseIteratorInterface::DoseIteratorPointer doseIterator, DoseToVolumeMeasure::complexStatistics name) : + measure(DoseToVolumeMeasure(name)), _precomputeVolumeValues(precomputeVolumeValues), + _referenceDose(referenceDose), _doseIterator(doseIterator) {} + + void DoseToVolumeMeasureCalculator::compute() + { + std::vector threads; + + for (size_t i = 0; i < _precomputeVolumeValues.size(); ++i) + { + if (false)//_multiThreading) + { + threads.push_back(boost::thread(&DoseToVolumeMeasureCalculator::computeSpecificValue, this, _precomputeVolumeValues.at(i) * _referenceDose)); + } + else + { + this->computeSpecificValue(_precomputeVolumeValues.at(i) * _referenceDose); + } + } + + for (unsigned int i = 0; i(xAbsolute, resultVolume)); + } + } +} diff --git a/code/algorithms/rttbVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbDoseToVolumeMeasureCalculator.h similarity index 58% copy from code/algorithms/rttbVolumeToDoseMeasureCalculator.h copy to code/algorithms/rttbDoseToVolumeMeasureCalculator.h index d17638a..8d6a950 100644 --- a/code/algorithms/rttbVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbDoseToVolumeMeasureCalculator.h @@ -1,70 +1,69 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ -#ifndef __VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#define __VOLUME_TO_DOSE_MEASURE_CALCULATOR_H +#ifndef __DOSE_TO_VOLUME_MEASURE_CALCULATOR_H +#define __DOSE_TO_VOLUME_MEASURE_CALCULATOR_H #include #include #include "rttbBaseType.h" #include "RTTBAlgorithmsExports.h" -#include "rttbVolumeToDoseMeasure.h" +#include "rttbDoseToVolumeMeasure.h" + +#include "rttbDoseIteratorInterface.h" namespace rttb { namespace algorithms { - class RTTBAlgorithms_EXPORT VolumeToDoseMeasureCalculator { + class RTTBAlgorithms_EXPORT DoseToVolumeMeasureCalculator { public: - typedef std::map VolumeToDoseFunctionType; + typedef std::map VolumeToDoseFunctionType; protected: - std::vector _doseVector; - DoseVoxelVolumeType _currentVoxelVolume; - std::vector _voxelProportionVector; + core::DoseIteratorInterface::DoseIteratorPointer _doseIterator; private: - VolumeType _volume; - VolumeToDoseMeasure measure; + DoseTypeGy _referenceDose; + DoseToVolumeMeasure measure; std::vector _precomputeVolumeValues; public: - VolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, - const std::vector& doseVector, const std::vector& voxelProportionVector, - const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); + DoseToVolumeMeasureCalculator(const std::vector& precomputeVolumeValues, + const DoseTypeGy& referenceDose, const core::DoseIteratorInterface::DoseIteratorPointer doseIterator, DoseToVolumeMeasure::complexStatistics name); void compute(); - VolumeToDoseMeasure getMeasure(); + DoseToVolumeMeasure getMeasure(); virtual void computeSpecificValue(double xAbsolute) = 0; protected: - void insertIntoMeasure(VolumeType xAbsolute, DoseTypeGy resultDose); + void insertIntoMeasure(DoseTypeGy xAbsolute, VolumeType resultVolume); }; } } #endif diff --git a/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h index 422c5db..e4c76e6 100644 --- a/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h @@ -1,57 +1,49 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __DX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __DX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" #include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT DxVolumeToDoseMeasureCalculator: public VolumeToDoseMeasureCalculator { private: DoseStatisticType _minimum; public: DxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, const DoseStatisticType& minimum, VolumeToDoseMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif diff --git a/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h index 2a4beb1..67f82a5 100644 --- a/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h @@ -1,54 +1,46 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __MOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __MOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" #include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT MOCxVolumeToDoseMeasureCalculator : public VolumeToDoseMeasureCalculator { public: MOCxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif diff --git a/code/algorithms/rttbMOHxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbMOHxVolumeToDoseMeasureCalculator.h index e5b7b57..b51df11 100644 --- a/code/algorithms/rttbMOHxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbMOHxVolumeToDoseMeasureCalculator.h @@ -1,57 +1,49 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __MOHX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __MOHX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" #include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT MOHxVolumeToDoseMeasureCalculator : public VolumeToDoseMeasureCalculator { private: DoseStatisticType _minimum; public: MOHxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif diff --git a/code/algorithms/rttbMaxOHxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbMaxOHxVolumeToDoseMeasureCalculator.h index f4c452b..7ad868f 100644 --- a/code/algorithms/rttbMaxOHxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbMaxOHxVolumeToDoseMeasureCalculator.h @@ -1,56 +1,48 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __MAXOHX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __MAXOHX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" -#include "rttbvolumetodosemeasureCalculator.h" -#include "rttbvolumetodosemeasure.h" +#include "rttbVolumeToDoseMeasureCalculator.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT MaxOHxVolumeToDoseMeasureCalculator : public VolumeToDoseMeasureCalculator { private: public: MaxOHxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif diff --git a/code/algorithms/rttbMeasureInterface.cpp b/code/algorithms/rttbMeasureInterface.cpp new file mode 100644 index 0000000..3a1ab9b --- /dev/null +++ b/code/algorithms/rttbMeasureInterface.cpp @@ -0,0 +1,49 @@ +#include "rttbMeasureInterface.h" + +namespace rttb +{ + + namespace algorithms + { + MeasureInterface::complexStatistics MeasureInterface::getName() const + { + return this->name; + } + + std::map::const_iterator MeasureInterface::findNearestKeyInMap( + const std::map& aMap, + double key) const + { + double minDistance = 1e19; + double minDistanceLast = 1e20; + + auto iterator = std::begin(aMap); + + while (iterator != std::end(aMap)) + { + minDistanceLast = minDistance; + minDistance = fabs(iterator->first - key); + + if (minDistanceLast > minDistance) + { + ++iterator; + } + else + { + if (iterator != std::begin(aMap)) + { + --iterator; + return iterator; + } + else + { + return std::begin(aMap); + } + } + } + + --iterator; + return iterator; + } + } +} \ No newline at end of file diff --git a/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbMeasureInterface.h similarity index 61% copy from code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h copy to code/algorithms/rttbMeasureInterface.h index 2a4beb1..346d53e 100644 --- a/code/algorithms/rttbMOCxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbMeasureInterface.h @@ -1,54 +1,55 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ -#ifndef __MOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#define __MOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H +#ifndef __MEASURE_INTERFACE_H +#define __MEASURE_INTERFACE_H #include #include #include "rttbBaseType.h" - #include "RTTBAlgorithmsExports.h" -#include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" namespace rttb { namespace algorithms { - class RTTBAlgorithms_EXPORT MOCxVolumeToDoseMeasureCalculator : public VolumeToDoseMeasureCalculator { + class RTTBAlgorithms_EXPORT MeasureInterface { + + public: + enum complexStatistics { Dx, Vx, MOHx, MOCx, MaxOHx, MinOCx }; + + protected: + complexStatistics name; public: - MOCxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, - const std::vector& doseVector, const std::vector& voxelProportionVector, - const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); + complexStatistics getName() const; - private: - void computeSpecificValue(double xAbsolute); + protected: + std::map::const_iterator findNearestKeyInMap(const std::map& aMap, double key) const; }; } } #endif diff --git a/code/algorithms/rttbMinOCxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbMinOCxVolumeToDoseMeasureCalculator.h index 97b21cf..d9536be 100644 --- a/code/algorithms/rttbMinOCxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbMinOCxVolumeToDoseMeasureCalculator.h @@ -1,58 +1,50 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __MINOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __MINOCX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" #include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT MinOCxVolumeToDoseMeasureCalculator : public VolumeToDoseMeasureCalculator { private: DoseStatisticType _minimum; DoseStatisticType _maximum; public: MinOCxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, const DoseStatisticType& minimum, const DoseStatisticType& maximum, VolumeToDoseMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif diff --git a/code/algorithms/rttbVolumeToDoseMeasure.cpp b/code/algorithms/rttbVolumeToDoseMeasure.cpp index e20de50..67c5a49 100644 --- a/code/algorithms/rttbVolumeToDoseMeasure.cpp +++ b/code/algorithms/rttbVolumeToDoseMeasure.cpp @@ -1,138 +1,97 @@ #include "rttbVolumeToDoseMeasure.h" #include "rttbDataNotAvailableException.h" #include "rttbInvalidParameterException.h" namespace rttb { namespace algorithms { VolumeToDoseMeasure::VolumeToDoseMeasure(complexStatistics name, VolumeToDoseFunctionType values, VolumeType volume) : name(name), values(values), _volume(volume) {} - VolumeToDoseMeasure::complexStatistics VolumeToDoseMeasure::getName() const - { - return this->name; - } - void VolumeToDoseMeasure::insertValue(std::pair value) { this->values.insert(value); } - DoseTypeGy VolumeToDoseMeasure::getValue(VolumeType xVolumeAbsolute) + DoseTypeGy VolumeToDoseMeasure::getValue(VolumeType xVolumeAbsolute) const { VolumeType dummy; return getSpecificValue(xVolumeAbsolute, false, dummy); } - DoseTypeGy VolumeToDoseMeasure::getValue(VolumeType xVolumeAbsolute, bool findNearestValue, VolumeType & nearestXVolume) + DoseTypeGy VolumeToDoseMeasure::getValue(VolumeType xVolumeAbsolute, bool findNearestValue, VolumeType & nearestXVolume) const { return getSpecificValue(xVolumeAbsolute, findNearestValue, nearestXVolume); } - DoseTypeGy VolumeToDoseMeasure::getValueRelative(VolumeType xVolumeRelative) + DoseTypeGy VolumeToDoseMeasure::getValueRelative(VolumeType xVolumeRelative) const { if (xVolumeRelative >= 0 && xVolumeRelative <= 1) { - DoseTypeGy xVolumeAbsolute = xVolumeRelative*_volume; + DoseTypeGy xVolumeAbsolute = xVolumeRelative * _volume; VolumeType dummy; return getSpecificValue(xVolumeAbsolute, false, dummy); } else { throw rttb::core::InvalidParameterException("Relative Volume must be >= 0 and <=1"); } } - DoseTypeGy VolumeToDoseMeasure::getValueRelative(VolumeType xVolumeRelative, bool findNearestValue, VolumeType & nearestXVolume) + DoseTypeGy VolumeToDoseMeasure::getValueRelative(VolumeType xVolumeRelative, bool findNearestValue, VolumeType & nearestXVolume) const { if (xVolumeRelative >= 0 && xVolumeRelative <= 1) { - DoseTypeGy xVolumeAbsolute = xVolumeRelative*_volume; + DoseTypeGy xVolumeAbsolute = xVolumeRelative * _volume; return getSpecificValue(xVolumeAbsolute, findNearestValue, nearestXVolume); } else { throw rttb::core::InvalidParameterException("Relative Volume must be >= 0 and <=1"); } } VolumeToDoseMeasure::VolumeToDoseFunctionType VolumeToDoseMeasure::getAllValues() const { return this->values; } void VolumeToDoseMeasure::setVolume(VolumeType volume) { this->_volume = volume; } double VolumeToDoseMeasure::getSpecificValue(double key, bool findNearestValueInstead, double& storedKey) const { if (values.find(key) != std::end(values)) { return values.find(key)->second; } else { //value not in map. We have to find the nearest value if (values.empty()) { throw core::DataNotAvailableException("No Vx values are defined"); } else { if (findNearestValueInstead) { auto iterator = findNearestKeyInMap(values, key); storedKey = iterator->first; return iterator->second; } else { throw core::DataNotAvailableException("No Vx value with required dose is defined"); } } } - } - - std::map::const_iterator VolumeToDoseMeasure::findNearestKeyInMap( - const std::map& aMap, - double key) const - { - double minDistance = 1e19; - double minDistanceLast = 1e20; - - auto iterator = std::begin(aMap); - - while (iterator != std::end(aMap)) - { - minDistanceLast = minDistance; - minDistance = fabs(iterator->first - key); - - if (minDistanceLast > minDistance) - { - ++iterator; - } - else - { - if (iterator != std::begin(aMap)) - { - --iterator; - return iterator; - } - else - { - return std::begin(aMap); - } - } - } - - --iterator; - return iterator; - } + } bool operator==(const VolumeToDoseMeasure& volumeToDoseMesure,const VolumeToDoseMeasure& otherVolumeToDoseMesure) { if (volumeToDoseMesure.getName() == otherVolumeToDoseMesure.getName() && volumeToDoseMesure.getAllValues() == otherVolumeToDoseMesure.getAllValues()) { return true; } return false; } } } diff --git a/code/algorithms/rttbVolumeToDoseMeasure.h b/code/algorithms/rttbVolumeToDoseMeasure.h index 4410955..4e54da7 100644 --- a/code/algorithms/rttbVolumeToDoseMeasure.h +++ b/code/algorithms/rttbVolumeToDoseMeasure.h @@ -1,68 +1,59 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __VOLUME_TO_DOSE_MEASURE_H #define __VOLUME_TO_DOSE_MEASURE_H -#include -#include - -#include "rttbBaseType.h" - -#include "RTTBAlgorithmsExports.h" +#include "rttbMeasureInterface.h" namespace rttb { namespace algorithms { - class RTTBAlgorithms_EXPORT VolumeToDoseMeasure { + class RTTBAlgorithms_EXPORT VolumeToDoseMeasure : public MeasureInterface { public: - enum complexStatistics { Dx, Vx, MOHx, MOCx, MaxOHx, MinOCx }; typedef std::map VolumeToDoseFunctionType; private: complexStatistics name; VolumeToDoseFunctionType values; VolumeType _volume; public: VolumeToDoseMeasure(complexStatistics name, VolumeToDoseFunctionType values = std::map(), VolumeType volume = -1); - complexStatistics getName() const; void insertValue(std::pair value); - DoseTypeGy getValue(VolumeType xVolumeAbsolute); - DoseTypeGy getValue(VolumeType xVolumeAbsolute, bool findNearestValue, VolumeType& nearestXDose); - DoseTypeGy getValueRelative(VolumeType xDoseRelative); - DoseTypeGy getValueRelative(VolumeType xDoseRelative, bool findNearestValue, VolumeType& nearestXDose); + DoseTypeGy getValue(VolumeType xVolumeAbsolute) const; + DoseTypeGy getValue(VolumeType xVolumeAbsolute, bool findNearestValue, VolumeType& nearestXDose) const; + DoseTypeGy getValueRelative(VolumeType xDoseRelative) const; + DoseTypeGy getValueRelative(VolumeType xDoseRelative, bool findNearestValue, VolumeType& nearestXDose) const; VolumeToDoseFunctionType getAllValues() const; friend bool operator==(const VolumeToDoseMeasure& volumeToDoseMesure, const VolumeToDoseMeasure& otherVolumeToDoseMesure); void setVolume(VolumeType volume); - private: double getSpecificValue(double key, bool findNearestValueInstead, double& storedKey) const; - std::map::const_iterator findNearestKeyInMap(const std::map& aMap, double key) const; }; } } #endif diff --git a/code/algorithms/rttbVolumeToDoseMeasureCalculator.cpp b/code/algorithms/rttbVolumeToDoseMeasureCalculator.cpp index 78d4f31..92b7e6f 100644 --- a/code/algorithms/rttbVolumeToDoseMeasureCalculator.cpp +++ b/code/algorithms/rttbVolumeToDoseMeasureCalculator.cpp @@ -1,46 +1,47 @@ #include "rttbVolumeToDoseMeasureCalculator.h" #include //#include namespace rttb { namespace algorithms { VolumeToDoseMeasureCalculator::VolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name) : measure(VolumeToDoseMeasure(name)), _precomputeVolumeValues(precomputeVolumeValues), _volume(volume), _doseVector(doseVector), _voxelProportionVector(voxelProportionVector), _currentVoxelVolume(currentVoxelVolume) {} void VolumeToDoseMeasureCalculator::compute() { std::vector threads; for (size_t i = 0; i < _precomputeVolumeValues.size(); ++i) { if (false)//_multiThreading) { threads.push_back(boost::thread(&VolumeToDoseMeasureCalculator::computeSpecificValue, this, _precomputeVolumeValues.at(i) * _volume)); } else { this->computeSpecificValue(_precomputeVolumeValues.at(i) * _volume); } } for (unsigned int i = 0; i(xAbsolute, resultDose)); } } } diff --git a/code/algorithms/rttbVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbVolumeToDoseMeasureCalculator.h index d17638a..886ffe1 100644 --- a/code/algorithms/rttbVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbVolumeToDoseMeasureCalculator.h @@ -1,70 +1,63 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __VOLUME_TO_DOSE_MEASURE_CALCULATOR_H #define __VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" #include "rttbVolumeToDoseMeasure.h" namespace rttb { namespace algorithms { class RTTBAlgorithms_EXPORT VolumeToDoseMeasureCalculator { public: typedef std::map VolumeToDoseFunctionType; protected: std::vector _doseVector; DoseVoxelVolumeType _currentVoxelVolume; std::vector _voxelProportionVector; private: VolumeType _volume; VolumeToDoseMeasure measure; std::vector _precomputeVolumeValues; public: VolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, const std::vector& doseVector, const std::vector& voxelProportionVector, const DoseVoxelVolumeType& currentVoxelVolume, VolumeToDoseMeasure::complexStatistics name); void compute(); VolumeToDoseMeasure getMeasure(); virtual void computeSpecificValue(double xAbsolute) = 0; protected: void insertIntoMeasure(VolumeType xAbsolute, DoseTypeGy resultDose); }; } } #endif diff --git a/code/algorithms/rttbVxDoseToVolumeMeasureCalculator.cpp b/code/algorithms/rttbVxDoseToVolumeMeasureCalculator.cpp new file mode 100644 index 0000000..554fe04 --- /dev/null +++ b/code/algorithms/rttbVxDoseToVolumeMeasureCalculator.cpp @@ -0,0 +1,33 @@ +#include "rttbVxDoseToVolumeMeasureCalculator.h" +namespace rttb +{ + + namespace algorithms + { + VxDoseToVolumeMeasureCalculator::VxDoseToVolumeMeasureCalculator(const std::vector& precomputeVolumeValues, + const DoseTypeGy& referenceDose, const core::DoseIteratorInterface::DoseIteratorPointer doseIterator, DoseToVolumeMeasure::complexStatistics name) : + DoseToVolumeMeasureCalculator(precomputeVolumeValues, referenceDose, doseIterator, name) {} + + void VxDoseToVolumeMeasureCalculator::computeSpecificValue(double xAbsolute) + { + + rttb::FractionType count = 0; + _doseIterator->reset(); + + DoseTypeGy currentDose = 0; + + while (_doseIterator->isPositionValid()) + { + currentDose = _doseIterator->getCurrentDoseValue(); + + if (currentDose >= xAbsolute) + { + count += _doseIterator->getCurrentRelevantVolumeFraction(); + } + + _doseIterator->next(); + } + insertIntoMeasure(xAbsolute, count * this->_doseIterator->getCurrentVoxelVolume()); + } + } +} \ No newline at end of file diff --git a/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h b/code/algorithms/rttbVxDoseToVolumeMeasureCalculator.h similarity index 59% copy from code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h copy to code/algorithms/rttbVxDoseToVolumeMeasureCalculator.h index 422c5db..f559ebe 100644 --- a/code/algorithms/rttbDxVolumeToDoseMeasureCalculator.h +++ b/code/algorithms/rttbVxDoseToVolumeMeasureCalculator.h @@ -1,57 +1,48 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1674 $ (last changed revision) // @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) // @author $Author: hentsch $ (last changed by) */ -#ifndef __DX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H -#define __DX_VOLUME_TO_DOSE_MEASURE_CALCULATOR_H +#ifndef __DV_DOSE_TO_VOLUME_MEASURE_CALCULATOR_H +#define __DV_DOSE_TO_VOLUME_MEASURE_CALCULATOR_H -#include -#include - -#include "rttbBaseType.h" - - -#include "RTTBAlgorithmsExports.h" -#include "rttbVolumeToDoseMeasureCalculator.h" -#include "rttbVolumetoDoseMeasure.h" +#include "rttbDoseToVolumeMeasureCalculator.h" namespace rttb { namespace algorithms { - class RTTBAlgorithms_EXPORT DxVolumeToDoseMeasureCalculator: public VolumeToDoseMeasureCalculator { + class RTTBAlgorithms_EXPORT VxDoseToVolumeMeasureCalculator : public DoseToVolumeMeasureCalculator { private: DoseStatisticType _minimum; public: - DxVolumeToDoseMeasureCalculator(const std::vector& precomputeVolumeValues, const VolumeType& volume, - const std::vector& doseVector, const std::vector& voxelProportionVector, - const DoseVoxelVolumeType& currentVoxelVolume, const DoseStatisticType& minimum, VolumeToDoseMeasure::complexStatistics name); + VxDoseToVolumeMeasureCalculator(const std::vector& precomputeVolumeValues, + const DoseTypeGy& referenceDose, const core::DoseIteratorInterface::DoseIteratorPointer doseIterator, DoseToVolumeMeasure::complexStatistics name); private: void computeSpecificValue(double xAbsolute); }; } } #endif