diff --git a/code/io/CMakeLists.txt b/code/io/CMakeLists.txt index 95ce070..dddff81 100644 --- a/code/io/CMakeLists.txt +++ b/code/io/CMakeLists.txt @@ -1,24 +1,29 @@ MESSAGE (STATUS "processing RTToolbox io") ADD_SUBDIRECTORY (other) OPTION(BUILD_IO_Dicom "Determine if the IO class wrappers for DICOM format will be generated." ON) IF(BUILD_IO_Dicom) ADD_SUBDIRECTORY(dicom) OPTION(BUILD_IO_HELAX "Determine if the IO class wrappers for HELAX format will be generated." OFF) IF(BUILD_IO_HELAX) ADD_SUBDIRECTORY(helax) ENDIF(BUILD_IO_HELAX) ENDIF(BUILD_IO_Dicom) OPTION(BUILD_IO_ITK "Determine if the IO class wrappers for ITK image formats will be generated." OFF) IF(BUILD_IO_ITK) ADD_SUBDIRECTORY(itk) ENDIF(BUILD_IO_ITK) + +IF(BUILD_Models) + ADD_SUBDIRECTORY(models) +ENDIF() + IF (RTTB_VIRTUOS_SUPPORT) OPTION(BUILD_IO_Virtuos "Determine if the IO class wrappers for Virtuos format will be generated." OFF) IF(BUILD_IO_Virtuos) ADD_SUBDIRECTORY(virtuos) ENDIF(BUILD_IO_Virtuos) ENDIF() diff --git a/code/io/other/CMakeLists.txt b/code/io/models/CMakeLists.txt similarity index 68% copy from code/io/other/CMakeLists.txt copy to code/io/models/CMakeLists.txt index f4d76bc..c1a2627 100644 --- a/code/io/other/CMakeLists.txt +++ b/code/io/models/CMakeLists.txt @@ -1,5 +1,5 @@ -RTTB_CREATE_MODULE(RTTBOtherIO DEPENDS RTTBCore RTTBAlgorithms PACKAGE_DEPENDS Boost) +RTTB_CREATE_MODULE(RTTBModelsIO DEPENDS RTTBCore RTTBModels RTTBAlgorithms PACKAGE_DEPENDS Boost) IF (NOT WIN32) #CMake 3.1 provides target_compile_features(RTTB_Interpolation cxx_auto_type cxx_nullptr cxx_override) to automatically add required compiler flags set(CMAKE_CXX_FLAGS "-std=c++11") ENDIF() diff --git a/code/io/models/files.cmake b/code/io/models/files.cmake new file mode 100644 index 0000000..1920a9b --- /dev/null +++ b/code/io/models/files.cmake @@ -0,0 +1,7 @@ +SET(CPP_FILES + rttbModelXMLWriter.cpp + ) + +SET(H_FILES + rttbModelXMLWriter.h +) diff --git a/code/io/models/rttbModelXMLWriter.cpp b/code/io/models/rttbModelXMLWriter.cpp new file mode 100644 index 0000000..cfe9c18 --- /dev/null +++ b/code/io/models/rttbModelXMLWriter.cpp @@ -0,0 +1,106 @@ +// ----------------------------------------------------------------------- +// 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: 1328 $ (last changed revision) +// @date $Date: 2016-04-22 09:50:01 +0200 (Fr, 22 Apr 2016) $ (last change date) +// @author $Author: hentsch $ (last changed by) +*/ + +#include "rttbModelXMLWriter.h" + +/*boost includes*/ +#include +#include +#include +#include + +#include "rttbInvalidParameterException.h" + + + +namespace rttb +{ + namespace io + { + namespace models + { + ModelXMLWriter::ModelXMLWriter(const std::string& filename, boost::shared_ptr model) : _filename(filename), _model(model){ + } + + void ModelXMLWriter::setFilename(FileNameString filename){ + _filename = filename; + } + + FileNameString ModelXMLWriter::getFilename() const{ + return _filename; + } + + void ModelXMLWriter::setModel(boost::shared_ptr model){ + _model = model; + } + + boost::shared_ptr ModelXMLWriter::getModel() const { + return _model; + } + + void ModelXMLWriter::writeModel(){ + + boost::property_tree::ptree pt; + + std::string xmlattrNameTag = ".name"; + std::string modelTag = "BioModel"; + std::string propertyTag = "property"; + std::string configTag = "config"; + std::string resultsTag = "results"; + std::string valueTag = "value"; + + boost::property_tree::ptree propertynode; + boost::property_tree::ptree confignode; + + confignode.put("BioModelType", _model->getModelType()); + confignode.put("StructureID", _model->getDVH()->getStructureID()); + confignode.put("DoseID", _model->getDVH()->getDoseID()); + pt.add_child(modelTag + "." + configTag, confignode); + + propertynode.put("", _model->getValue()); + propertynode.put(xmlattrNameTag, valueTag); + pt.add_child(modelTag + "."+ resultsTag + "." + propertyTag, propertynode); + + std::map parameterMap = _model->getParameterMap(); + + for (std::map::const_iterator it = parameterMap.begin(); it != parameterMap.end(); ++it){ + propertynode.put("", it->second); + propertynode.put(xmlattrNameTag, it->first); + pt.add_child(modelTag + "." + resultsTag + "." + propertyTag, propertynode); + } + try + { + boost::property_tree::xml_parser::xml_writer_settings settings = + boost::property_tree::xml_writer_make_settings('\t', 1); + boost::property_tree::xml_parser::write_xml(_filename, pt, std::locale(), settings); + } + catch (const boost::property_tree::xml_parser_error& e) + { + std::cout << e.what(); + throw core::InvalidParameterException("Write xml failed: xml_parser_error!"); + } + + + } + + } + } +} diff --git a/code/io/models/rttbModelXMLWriter.h b/code/io/models/rttbModelXMLWriter.h new file mode 100644 index 0000000..4f8bc7a --- /dev/null +++ b/code/io/models/rttbModelXMLWriter.h @@ -0,0 +1,56 @@ +// ----------------------------------------------------------------------- +// 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: 1250 $ (last changed revision) +// @date $Date: 2016-02-18 15:25:55 +0100 (Do, 18 Feb 2016) $ (last change date) +// @author $Author: zhangl $ (last changed by) +*/ +#ifndef __MODELS_XML_WRITER_H +#define __MODELS_XML_WRITER_H + + + +#include "rttbBioModel.h" + + + +namespace rttb +{ + namespace io + { + namespace models + { + class ModelXMLWriter{ + private: + std::string _filename; + boost::shared_ptr _model; + public: + ModelXMLWriter(const std::string& filename, boost::shared_ptr model); + + void setFilename(std::string filename); + std::string getFilename() const; + + void setModel(boost::shared_ptr model); + boost::shared_ptr getModel() const; + + void writeModel(); + + }; + + } + } +} +#endif diff --git a/code/io/other/CMakeLists.txt b/code/io/other/CMakeLists.txt index f4d76bc..12c1dd7 100644 --- a/code/io/other/CMakeLists.txt +++ b/code/io/other/CMakeLists.txt @@ -1,5 +1,5 @@ -RTTB_CREATE_MODULE(RTTBOtherIO DEPENDS RTTBCore RTTBAlgorithms PACKAGE_DEPENDS Boost) +RTTB_CREATE_MODULE(RTTBOtherIO DEPENDS RTTBCore RTTBAlgorithms PACKAGE_DEPENDS Boost) IF (NOT WIN32) #CMake 3.1 provides target_compile_features(RTTB_Interpolation cxx_auto_type cxx_nullptr cxx_override) to automatically add required compiler flags set(CMAKE_CXX_FLAGS "-std=c++11") ENDIF() diff --git a/code/models/rttbBioModel.cpp b/code/models/rttbBioModel.cpp index 4fa1c3f..f030869 100644 --- a/code/models/rttbBioModel.cpp +++ b/code/models/rttbBioModel.cpp @@ -1,60 +1,62 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #define _USE_MATH_DEFINES #include #include #include "rttbBioModel.h" + namespace rttb { namespace models { bool BioModel::init(const double doseFactor) { if (_dvh != NULL) { _value = this->calcModel(doseFactor); return true; } return false; } void BioModel::setDVH(const DVHPointer aDVH) { _dvh = aDVH; } const BioModel::DVHPointer BioModel::getDVH() const { return _dvh; } const BioModelValueType BioModel::getValue() const { return _value; } + }//end namespace models }//end namespace rttb diff --git a/code/models/rttbBioModel.h b/code/models/rttbBioModel.h index d7fee79..9b53b6d 100644 --- a/code/models/rttbBioModel.h +++ b/code/models/rttbBioModel.h @@ -1,94 +1,108 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #ifndef __BIO_MODEL_H #define __BIO_MODEL_H #include "rttbBaseType.h" #include "rttbDVH.h" #include "rttbBaseTypeModels.h" #include "RTTBModelsExports.h" +#include + namespace rttb { namespace models { /*! @class BioModel @brief This is the interface class for biological models */ class RTTBModels_EXPORT BioModel { public: typedef std::vector ParamVectorType; typedef core::DVH::DVHPointer DVHPointer; protected: DVHPointer _dvh; BioModelValueType _value; /*! @brief Calculate the model value @param doseFactor scaling factor for the dose. The model calculation will use the dvh with each di=old di*doseFactor. */ virtual BioModelValueType calcModel(const double doseFactor = 1) = 0; + /* Map of all parameters + */ + std::map parameterMap; + + std::string _name; + public: BioModel(): _value(0) {}; BioModel(DVHPointer aDvh): _dvh(aDvh), _value(0) {}; /*! @brief Start the calculation. If any parameter changed, init() should be called again and return =true before getValue() is called! @return Return true if successful */ bool init(const double doseFactor = 1); /*! @param aDVH must be a DVH calculated by a cumulative dose distribution, not a fraction DVH! */ void setDVH(const DVHPointer aDVH); const DVHPointer getDVH() const; /*! @brief Set parameter vector, where index of vector is the parameter ID. */ virtual void setParameterVector(const ParamVectorType& aParameterVector) = 0; virtual void setParameterByID(const int aParamId, const BioModelParamType aValue) = 0; + /*! @brief Get parameter by ID. @return Return -1 if ID is not found. */ virtual const int getParameterID(const std::string& aParamName) const = 0; + virtual std::map getParameterMap() const = 0; + virtual void fillParameterMap() = 0 ; + + virtual std::string getModelType() const = 0; + /*! @brief Get the value of biological model @pre init() must be called and =true! */ const BioModelValueType getValue() const; }; }//end namespace models }//end namespace rttb #endif diff --git a/code/models/rttbNTCPLKBModel.cpp b/code/models/rttbNTCPLKBModel.cpp index 412100a..36df48f 100644 --- a/code/models/rttbNTCPLKBModel.cpp +++ b/code/models/rttbNTCPLKBModel.cpp @@ -1,163 +1,183 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #include #include #include #include #define _USE_MATH_DEFINES #include #include "rttbIntegration.h" #include "rttbNTCPLKBModel.h" #include "rttbDvhBasedModels.h" #include "rttbInvalidParameterException.h" #include "rttbExceptionMacros.h" namespace rttb { namespace models { - NTCPLKBModel::NTCPLKBModel(): NTCPModel(), _m(0), _a(0) {} + NTCPLKBModel::NTCPLKBModel() : NTCPModel(), _m(0), _a(0){ + _name = "NTCPLKBModel"; + fillParameterMap(); + } NTCPLKBModel::NTCPLKBModel(DVHPointer aDvh, BioModelParamType aD50, BioModelParamType aM, BioModelParamType aA): - NTCPModel(aDvh, aD50), _m(aM), _a(aA) {} + NTCPModel(aDvh, aD50), _m(aM), _a(aA) { + _name = "NTCPLKBModel"; + fillParameterMap(); + } void NTCPLKBModel::setA(const BioModelParamType aA) { _a = aA; } const BioModelParamType NTCPLKBModel::getA() { return _a; } void NTCPLKBModel::setM(const BioModelParamType aM) { _m = aM; } const BioModelParamType NTCPLKBModel::getM() { return _m; } void NTCPLKBModel::setParameterVector(const ParamVectorType& aParameterVector) { if (aParameterVector.size() != 3) { throw core::InvalidParameterException("Parameter invalid: aParameterVector.size must be 3! "); } else { _d50 = aParameterVector.at(0); _m = aParameterVector.at(1); _a = aParameterVector.at(2); } } void NTCPLKBModel::setParameterByID(const int aParamId, const BioModelParamType aValue) { if (aParamId == 0) { _d50 = aValue; } else if (aParamId == 1) { _m = aValue; } else if (aParamId == 2) { _a = aValue; } else { throw core::InvalidParameterException("Parameter invalid: aParamID must be 0(for d50) or 1(for m) or 2(for a)! "); } } const int NTCPLKBModel::getParameterID(const std::string& aParamName) const { if (aParamName == "d50") { return 0; } else if (aParamName == "m") { return 1; } else if (aParamName == "a") { return 2; } else { rttbExceptionMacro(core::InvalidParameterException, << "Parameter name " << aParamName << " invalid: it should be d50 or m or a!"); } } + std::map NTCPLKBModel::getParameterMap() const{ + return parameterMap; + } + + void NTCPLKBModel::fillParameterMap(){ + parameterMap["d50"] = getD50(); + parameterMap["m"] = getM(); + parameterMap["a"] = getA(); + } + + std::string NTCPLKBModel::getModelType() const{ + return _name; + } + BioModelValueType NTCPLKBModel::calcModel(const double doseFactor) { if (_a == 0) { throw core::InvalidParameterException("_a must not be zero"); } if (_m == 0) { throw core::InvalidParameterException("_m must not be zero"); } core::DVH variantDVH = core::DVH(_dvh->getDataDifferential(), (DoseTypeGy)(_dvh->getDeltaD() * doseFactor), _dvh->getDeltaV(), "temporary", "temporary"); boost::shared_ptr spDVH = boost::make_shared(variantDVH); double eud = getEUD(spDVH, this->_a); //_m must not be zero double t = (eud - this->_d50) / (this->_m * this->_d50); double value = 1 / pow(2 * M_PI, 0.5); double result = integrateLKB(t); if (result != -100) { value *= result; return value; } else { return false; } } }//end namespace models }//end namespace rttb diff --git a/code/models/rttbNTCPLKBModel.h b/code/models/rttbNTCPLKBModel.h index c6382e8..b08ff30 100644 --- a/code/models/rttbNTCPLKBModel.h +++ b/code/models/rttbNTCPLKBModel.h @@ -1,101 +1,107 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #ifndef __NTCP_LKB_MODEL_H #define __NTCP_LKB_MODEL_H #include #include #include "rttbBaseType.h" #include "rttbNTCPModel.h" #include "rttbBaseTypeModels.h" namespace rttb { namespace models { /*! @class NTCPLKBModel @brief This class represents a NTCP(Normal Tissue Complication Probability) LKB model (Lyman 1985, Kutcher and Burman 1989) @see NTCPModel */ class NTCPLKBModel: public NTCPModel { public: typedef NTCPModel::ParamVectorType ParamVectorType; typedef NTCPModel::DVHPointer DVHPointer; private: /*! The steepness of the dose-response curve. Must not be zero on model evaluation. */ BioModelParamType _m; /*! Tumor or normal tissue-specific parameter that describes the dose–volume effect, e.g. -10 for prostate (Wu 2002). Must not be zero on model evaluation, because EUD calculation will fail. */ BioModelParamType _a; protected: /*! @brief Calculate the model value * @param doseFactor: scaling factor for the dose. The model calculation will use the dvh with each di=old di*doseFactor. * @throw if either _a or _m is zero for the model calculation */ - BioModelValueType calcModel(const double doseFactor = 1); + BioModelValueType calcModel(const double doseFactor = 1) override; public: NTCPLKBModel(); NTCPLKBModel(DVHPointer aDvh, BioModelParamType aD50, BioModelParamType aM, BioModelParamType aA); void setM(const BioModelParamType aM); const BioModelParamType getM(); void setA(const BioModelParamType aA); const BioModelParamType getA(); /*! @brief Set parameter with ID. "d50":0,"m":1,"a":2 @exception InvalidParameterException Thrown if aParamId is not 0 or 1 or 2. */ - virtual void setParameterByID(const int aParamId, const BioModelParamType aValue); + virtual void setParameterByID(const int aParamId, const BioModelParamType aValue) override; /*! @brief Set parameter vector, where index of vector is the parameter ID. "d50":0,"m":1,"a":2 @exception InvalidParameterException Thrown if aParamterVector.size()!=3. */ - virtual void setParameterVector(const ParamVectorType& aParameterVector); + virtual void setParameterVector(const ParamVectorType& aParameterVector) override; /*! @brief Get parameter ID. "d50":0,"m":1,"a":2 @return 0 for "d50", 1 for "m", 2 for "a" @exception InvalidParameterException Thrown if aParamName is not d50 or m or a. */ - virtual const int getParameterID(const std::string& aParamName) const; + virtual const int getParameterID(const std::string& aParamName) const override; + + virtual std::map getParameterMap() const override; + + void fillParameterMap() override; + + virtual std::string getModelType() const override; }; } } #endif diff --git a/code/models/rttbNTCPRSModel.cpp b/code/models/rttbNTCPRSModel.cpp index 95c1c87..9da34d8 100644 --- a/code/models/rttbNTCPRSModel.cpp +++ b/code/models/rttbNTCPRSModel.cpp @@ -1,153 +1,174 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #define _USE_MATH_DEFINES #include #include "rttbNTCPRSModel.h" #include "rttbInvalidParameterException.h" #include "rttbExceptionMacros.h" namespace rttb { namespace models { - NTCPRSModel::NTCPRSModel(): NTCPModel(), _gamma(0), _s(0) {} + NTCPRSModel::NTCPRSModel() : NTCPModel(), _gamma(0), _s(0){ + _name = "NTCPRSModel"; + fillParameterMap(); + } NTCPRSModel::NTCPRSModel(DVHPointer aDvh, BioModelParamType aD50, BioModelParamType aGamma, BioModelParamType aS): - NTCPModel(aDvh, aD50), _gamma(aGamma), _s(aS) {} + NTCPModel(aDvh, aD50), _gamma(aGamma), _s(aS) { + _name = "NTCPRSModel"; + fillParameterMap(); + } void NTCPRSModel::setGamma(const BioModelParamType aGamma) { _gamma = aGamma; } const BioModelParamType NTCPRSModel::getGamma() { return _gamma; } void NTCPRSModel::setS(const BioModelParamType aS) { _s = aS; } const BioModelParamType NTCPRSModel::getS() { return _s; } void NTCPRSModel::setParameterVector(const ParamVectorType& aParameterVector) { if (aParameterVector.size() != 3) { throw core::InvalidParameterException("Parameter invalid: aParameterVector.size must be 3! "); } else { _d50 = aParameterVector.at(0); _gamma = aParameterVector.at(1); _s = aParameterVector.at(2); } } void NTCPRSModel::setParameterByID(const int aParamId, const BioModelParamType aValue) { if (aParamId == 0) { _d50 = aValue; } else if (aParamId == 1) { _gamma = aValue; } else if (aParamId == 2) { _s = aValue; } else { throw core::InvalidParameterException("Parameter invalid: aParamID must be 0(for d50) or 1(for gamma) or 2(for s)! "); } } const int NTCPRSModel::getParameterID(const std::string& aParamName) const { if (aParamName == "d50") { return 0; } else if (aParamName == "gamma") { return 1; } else if (aParamName == "s") { return 2; } else { rttbExceptionMacro(core::InvalidParameterException, << "Parameter name " << aParamName << " invalid: it should be d50 or gamma or s!"); } } + std::map NTCPRSModel::getParameterMap() const{ + return parameterMap; + } + + void NTCPRSModel::fillParameterMap() + { + parameterMap["d50"] = getD50(); + parameterMap["gamma"] = getGamma(); + parameterMap["s"] = getS(); + } + + std::string NTCPRSModel::getModelType() const{ + return _name; + } + const double NTCPRSModel::poissonModel(const double dose) { //_d50 must not be zero return pow(2, -exp(M_E * this->_gamma * (1 - dose / this->_d50))); } BioModelValueType NTCPRSModel::calcModel(double doseFactor) { if (_d50 == 0) { throw core::InvalidParameterException("d50 must not be zero"); } if (_s == 0) { throw core::InvalidParameterException("s must not be zero"); } std::deque dataDifferential = this->_dvh->getDataDifferential(); double ntcp = 1; for (GridIndexType i = 0; i < dataDifferential.size(); i++) { double pd = pow(this->poissonModel(i * this->_dvh->getDeltaD() * doseFactor), this->_s); double vi = dataDifferential[i] / this->_dvh->getNumberOfVoxels(); ntcp *= pow((1 - pd), vi); } //_s must not be zero return (BioModelValueType)(pow((1 - ntcp), 1 / this->_s)); } }//end namespace models }//end namespace rttb diff --git a/code/models/rttbNTCPRSModel.h b/code/models/rttbNTCPRSModel.h index 74f2f1a..c86f02b 100644 --- a/code/models/rttbNTCPRSModel.h +++ b/code/models/rttbNTCPRSModel.h @@ -1,107 +1,113 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #ifndef __NTCP_RS_MODEL_H #define __NTCP_RS_MODEL_H #include #include #include "rttbBaseType.h" #include "rttbNTCPModel.h" #include "rttbBaseTypeModels.h" namespace rttb { namespace models { /*! @class NTCPRSModel @brief This class represents a NTCP(Normal Tissue Complication Probability) relative seriality model (Källman 1992) @see NTCPModel */ class NTCPRSModel: public NTCPModel { public: typedef NTCPModel::ParamVectorType ParamVectorType; typedef NTCPModel::DVHPointer DVHPointer; private: /*! _gamma The normalised dose-response gradient, values between 1.7 and 2.0 are typical for human tumours. (Källman 1992) */ BioModelParamType _gamma; /*! _s The relative seriality factor, e.g. s=3.4 for the esophagus (highly serial structure) and s=0.0061 for the lung(highly parallel structure). Must not be zero on model evaluation. */ BioModelParamType _s; const double poissonModel(const double dose); protected: /*! @brief Calculate the model value @param doseFactor scaling factor for the dose. The model calculation will use the dvh with each di=old di*doseFactor. @throw if either _s or _d50 is zero for the model calculation. */ - BioModelValueType calcModel(const double doseFactor = 1); + BioModelValueType calcModel(const double doseFactor = 1) override; public: NTCPRSModel(); /*!@brief Constructor initializing all member variables with given parameters. */ NTCPRSModel(DVHPointer aDvh, BioModelParamType aD50, BioModelParamType aGamma, BioModelParamType aS); void setGamma(const BioModelParamType aGamma); const BioModelParamType getGamma(); void setS(const BioModelParamType aS); const BioModelParamType getS(); /*! @brief Set parameter with ID. "d50":0,"gamma":1,"s":2 @exception InvalidParameterException Thrown if aParamId is not 0 or 1 or 2. */ - virtual void setParameterByID(const int aParamId, const BioModelParamType aValue); + virtual void setParameterByID(const int aParamId, const BioModelParamType aValue) override; /*! @brief Set parameter vector, where index of vector is the parameter Id. "d50":0,"gamma":1,"s":2 @exception InvalidParameterException Thrown if aParamterVector.size()!=3. */ - virtual void setParameterVector(const ParamVectorType& aParameterVector); + virtual void setParameterVector(const ParamVectorType& aParameterVector) override; /*! @brief Get parameter ID. "d50":0,"gamma":1,"s":2 @return 0 for "d50", 1 for "gamma", 2 for "s" @exception InvalidParameterException Thrown if aParamName is not d50 or gamma or s. */ - virtual const int getParameterID(const std::string& aParamName) const; + virtual const int getParameterID(const std::string& aParamName) const override; + + virtual std::map getParameterMap() const override; + + void fillParameterMap() override; + + virtual std::string getModelType() const override; }; } } #endif diff --git a/code/models/rttbTCPLQModel.cpp b/code/models/rttbTCPLQModel.cpp index 3df5ac9..38d3b4f 100644 --- a/code/models/rttbTCPLQModel.cpp +++ b/code/models/rttbTCPLQModel.cpp @@ -1,286 +1,308 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #define _USE_MATH_DEFINES #include #include #include #include #include "rttbTCPLQModel.h" #include "rttbDvhBasedModels.h" #include "rttbBaseTypeModels.h" #include "rttbIntegration.h" #include "rttbInvalidParameterException.h" #include "rttbExceptionMacros.h" namespace rttb { namespace models { - TCPLQModel::TCPLQModel(): TCPModel(), _alphaMean(0), _alphaVariance(0), _alpha_beta(0), _rho(0) {} + TCPLQModel::TCPLQModel(): TCPModel(), _alphaMean(0), _alphaVariance(0), _alpha_beta(0), _rho(0) { + _name = "TCPLQModel"; + fillParameterMap(); + } TCPLQModel::TCPLQModel(DVHPointer aDVH, BioModelParamType aAlphaMean, BioModelParamType aBeta, BioModelParamType aRho, int aNumberOfFractions): TCPModel(aDVH, aNumberOfFractions), _alphaMean(aAlphaMean), _alphaVariance(0), - _alpha_beta(aAlphaMean / aBeta), _rho(aRho) {} + _alpha_beta(aAlphaMean / aBeta), _rho(aRho) { + _name = "TCPLQModel"; + fillParameterMap(); + } TCPLQModel::TCPLQModel(DVHPointer aDVH, BioModelParamType aRho, int aNumberOfFractions, BioModelParamType aAlpha_Beta, BioModelParamType aAlphaMean, BioModelParamType aAlphaVariance): TCPModel(aDVH, aNumberOfFractions), _alphaMean(aAlphaMean), _alphaVariance(aAlphaVariance), _alpha_beta(aAlpha_Beta), _rho(aRho) {} void TCPLQModel::setParameters(const BioModelParamType aAlphaMean, const BioModelParamType aAlpha_Beta, const BioModelParamType aRho, const BioModelParamType aAlphaVariance) { _alphaMean = aAlphaMean; _alphaVariance = aAlphaVariance; _alpha_beta = aAlpha_Beta; _rho = aRho; //reset _value, because parameters have changed. _value = 0; } void TCPLQModel::setAlpha(const BioModelParamType aAlphaMean, const BioModelParamType aAlphaVariance) { _alphaVariance = aAlphaVariance; _alphaMean = aAlphaMean; } void TCPLQModel::setAlphaBeta(const BioModelParamType aAlpha_Beta) { _alpha_beta = aAlpha_Beta; } void TCPLQModel::setRho(const BioModelParamType aRho) { _rho = aRho; } const BioModelParamType TCPLQModel::getAlphaBeta() { return _alpha_beta; } const BioModelParamType TCPLQModel::getAlphaMean() { return _alphaMean; } const BioModelParamType TCPLQModel::getAlphaVariance() { return _alphaVariance; } const BioModelParamType TCPLQModel::getRho() { return _rho; } long double TCPLQModel::calcTCPi(BioModelParamType aRho, BioModelParamType aAlphaMean, double vj, double bedj) { return exp(-aRho * vj * exp(-aAlphaMean * bedj)); } long double TCPLQModel::calcTCP(std::map aBEDDVH, BioModelParamType aRho, BioModelParamType aAlphaMean, double aDeltaV) { std::map::iterator it; long double tcp = 1; for (it = aBEDDVH.begin(); it != aBEDDVH.end(); ++it) { long double tcpi = this->calcTCPi(aRho, aAlphaMean, (*it).second * aDeltaV, (*it).first); tcp = tcp * tcpi; } return tcp; } long double TCPLQModel::calcTCPAlphaNormalDistribution( std::map aBEDDVH, BioModelParamType aRho, BioModelParamType aAlphaMean, BioModelParamType aAlphaVariance, double aDeltaV) { std::map::iterator it; std::vector volumeV2; std::vector bedV2; int i = 0; for (it = aBEDDVH.begin(); it != aBEDDVH.end(); ++it) { volumeV2.push_back((*it).second * aDeltaV); bedV2.push_back((*it).first); i++; } struct TcpParams params = {aAlphaMean, aAlphaVariance, aRho, volumeV2, bedV2}; double result = integrateTCP(0, params); if (result == -100) { std::cerr << "Integration error!\n"; return -1; } else { long double tcp = 1 / (pow(2 * M_PI, 0.5) * _alphaVariance) * result; return tcp; } } BioModelValueType TCPLQModel::calcModel(const double doseFactor) { core::DVH variantDVH = core::DVH(_dvh->getDataDifferential(), (DoseTypeGy)(_dvh->getDeltaD() * doseFactor), _dvh->getDeltaV(), "temporary", "temporary"); boost::shared_ptr spDVH = boost::make_shared(variantDVH); BioModelValueType value = 0; if (_alphaVariance == 0) { if (_alphaMean <= 0 || _alpha_beta <= 0 || _rho <= 0) { throw core::InvalidParameterException("Parameter invalid: alpha, alpha/beta, rho and number of fractions must >0!"); } if (_numberOfFractions <= 1) { throw core::InvalidParameterException("Parameter invalid: numberOfFractions must be >1! The dvh should be an accumulated-dvh of all fractions, not a single fraction-dvh!"); } std::map dataBED = calcBEDDVH(spDVH, _numberOfFractions, _alpha_beta); value = (BioModelValueType)this->calcTCP(dataBED, _rho, _alphaMean, variantDVH.getDeltaV()); return value; } //if alpha normal distribution else { if (this->_alpha_beta <= 0 || this->_alphaMean <= 0 || this->_alphaVariance < 0 || _rho <= 0) { throw core::InvalidParameterException("Parameter invalid: alpha/beta, alphaMean, rho and number of fractions must >0!"); } if (_numberOfFractions <= 1) { throw core::InvalidParameterException("Parameter invalid: numberOfFractions must be >1! The dvh should be an accumulated-dvh of all fractions, not a single fraction-dvh!"); } std::map dataBED = calcBEDDVH(spDVH, _numberOfFractions, _alpha_beta); value = (BioModelValueType)(this->calcTCPAlphaNormalDistribution(dataBED, _rho, _alphaMean, _alphaVariance, variantDVH.getDeltaV())); return value; } } void TCPLQModel::setParameterVector(const ParamVectorType& aParameterVector) { if (aParameterVector.size() != 4) { throw core::InvalidParameterException("Parameter invalid: aParameterVector.size must be 4! "); } else { _alphaMean = aParameterVector.at(0); _alphaVariance = aParameterVector.at(1); _alpha_beta = aParameterVector.at(2); _rho = aParameterVector.at(3); } } void TCPLQModel::setParameterByID(const int aParamId, const BioModelParamType aValue) { if (aParamId == 0) { _alphaMean = aValue; } else if (aParamId == 1) { _alphaVariance = aValue; } else if (aParamId == 2) { _alpha_beta = aValue; } else if (aParamId == 3) { _rho = aValue; } else { throw core::InvalidParameterException("Parameter invalid: aParamID must be 0(alphaMean) or 1(alphaVariance) or 2(alpha_beta) or 3(rho)! "); } } const int TCPLQModel::getParameterID(const std::string& aParamName) const { if (aParamName == "alphaMean") { return 0; } else if (aParamName == "alphaVariance") { return 1; } else if (aParamName == "alpha_beta") { return 2; } else if (aParamName == "rho") { return 3; } else { rttbExceptionMacro(core::InvalidParameterException, << "Parameter name " << aParamName << " invalid: it should be alphaMean or alphaVariance or alpha_beta or rho!"); } } + std::map TCPLQModel::getParameterMap() const{ + return parameterMap; + } + + void TCPLQModel::fillParameterMap(){ + parameterMap["numberOfFraction"] = getNumberOfFractions(); + parameterMap["alphaMean"] = getAlphaMean(); + parameterMap["alphaVariance"] = getAlphaVariance(); + parameterMap["alpha_beta"] = getAlphaBeta(); + parameterMap["rho"] = getRho(); + } + + std::string TCPLQModel::getModelType() const{ + return _name; + } + }//end namespace models }//end namespace rttb diff --git a/code/models/rttbTCPLQModel.h b/code/models/rttbTCPLQModel.h index fbf95c5..10c7200 100644 --- a/code/models/rttbTCPLQModel.h +++ b/code/models/rttbTCPLQModel.h @@ -1,165 +1,171 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #ifndef __TCP_LQ_MODEL_H #define __TCP_LQ_MODEL_H #include #include #include #include "rttbBaseType.h" #include "rttbTCPModel.h" #include "rttbBaseTypeModels.h" namespace rttb { namespace models { /*! @class TCPLQModel @brief This class represents a TCP(Tumor Control Probability) LQ model (Nahum and Sanchez-Nieto 2001, Hall and Giaccia 2006) @see TCPModel */ class TCPLQModel: public TCPModel { public: typedef TCPModel::ParamVectorType ParamVectorType; typedef TCPModel::DVHPointer DVHPointer; private: /*! @brief Calculate intermediate tcp using alpha constant. This is a helper function for calcTCP() @see calcTCP */ long double calcTCPi(BioModelParamType aRho, BioModelParamType aAlphaMean, double vj, double bedj); /*! @brief Calculate tcp using alpha constant. */ long double calcTCP(std::map aBEDDVH, BioModelParamType aRho, BioModelParamType aAlphaMean, double aDeltaV); /*! @brief Calculate tcp using a normal distribution for alpha. */ long double calcTCPAlphaNormalDistribution(std::map aBEDDVH, BioModelParamType aRho, BioModelParamType aAlphaMean, BioModelParamType aAlphaVariance, double aDeltaV); protected: BioModelParamType _alphaMean; BioModelParamType _alphaVariance; BioModelParamType _alpha_beta; /*! Roh is the initial clonogenic cell density */ BioModelParamType _rho; /*! @brief Calculate the model value @param doseFactor scaling factor for prescribed dose. The model calculation will use the dvh with each di=old di*doseFactor. @pre _alphaMean >0 @pre _alphaVariance >= 0 @pre _alpha_beta > 0 @pre _rho > 0 @pre _numberOfFractions > 1 @exception InvalidParameterException Thrown if parameters were not set correctly. */ - BioModelValueType calcModel(const double doseFactor = 1); + BioModelValueType calcModel(const double doseFactor = 1) override; public: TCPLQModel(); /*! @brief Constructor initializes member variables with given parameters. @pre aAlphaMean >0 @pre aBeta > 0 @pre aRho > 0 @pre aNumberOfFractions > 1 */ TCPLQModel(DVHPointer aDVH, BioModelParamType aAlphaMean, BioModelParamType aBeta, BioModelParamType aRho, int aNumberOfFractions); /*! @brief Constructor for alpha distribution initializes member variables with given parameters. @pre aAlphaMean >0 @pre aAlphaVariance >0 @pre aAlpha_Beta > 0 @pre aRho > 0 @pre aNumberOfFractions > 1 */ TCPLQModel(DVHPointer aDVH, BioModelParamType aRho, int aNumberOfFractions, BioModelParamType aAlpha_Beta, BioModelParamType aAlphaMean, BioModelParamType aAlphaVariance); const BioModelParamType getRho(); void setRho(const BioModelParamType aRho); const BioModelParamType getAlphaMean(); const BioModelParamType getAlphaVariance(); /*! @brief The distribution of the parameter alpha, which is characteristic for a population of cells, is described by the its mean and variance. If alpha is constant the variance is 0. @param aAlphaVariance The variance of alpha can be given, the default value is 0 resulting in constant alpha. */ void setAlpha(const BioModelParamType aAlphaMean, const BioModelParamType aAlphaVariance = 0); const BioModelParamType getAlphaBeta(); void setAlphaBeta(const BioModelParamType aAlpha_Beta); /*! @brief Set parameters for the TCP model. _value will be reset to 0. @param aAlpha_Beta alpha/beta constant . @param aAlphaMean mean of alpha distribution. @param aAlphaVariance variance of alpha distribution. */ void setParameters(const BioModelParamType aAlphaMean, const BioModelParamType aAlpha_Beta, const BioModelParamType aRho, const BioModelParamType aAlphaVariance = 0); /*! @brief Set parameter with ID. "alphaMean":0,"alphaVariance":1,"alpha_beta":2, "rho":3 @exception InvalidParameterException Thrown if aParamId is not 0 or 1 or 2 or 3. */ - virtual void setParameterByID(const int aParamId, const BioModelParamType aValue); + virtual void setParameterByID(const int aParamId, const BioModelParamType aValue) override; /*! @brief Set parameter vector, where index of vector is the parameter id. "alphaMean":0,"alphaVariance":1,"alpha_beta":2, "rho":3 @exception InvalidParameterException Thrown if aParamterVector.size()!=4. */ - virtual void setParameterVector(const ParamVectorType& aParameterVector); + virtual void setParameterVector(const ParamVectorType& aParameterVector) override; /*! @brief Get parameter id. "alphaMean":0,"alphaVariance":1,"alpha_beta":2, "rho":3 @return 0 for "alphaMean", 1 for "alphaVariance", 2 for "alpha_beta", 3 for "rho" @exception InvalidParameterException Thrown if aParamName is not alphaMean or alphaVariance or alpha_beta or rho. */ - virtual const int getParameterID(const std::string& aParamName) const; + virtual const int getParameterID(const std::string& aParamName) const override; + + virtual std::map getParameterMap() const override; + + void fillParameterMap() override; + + virtual std::string getModelType() const override; }; }//end algorithms }//end rttb #endif diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 05399d5..d9b8b6e 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -1,86 +1,92 @@ MESSAGE(STATUS "processing RTToolbox testing code") # Testing branch PROJECT(RTTBTesting) #----------------------------------------------------------------------------- # extract and build Litmus #----------------------------------------------------------------------------- include(ExternalProject) message(STATUS "Litmus will be automatically downloaded and built.") set(LITMUS_SOURCE_DIR "${CMAKE_BINARY_DIR}/external/Litmus-src") set(LITMUS_BUILD_DIR "${CMAKE_BINARY_DIR}/external/Litmus-build") set(LITMUS_CMAKE_DIR "${CMAKE_BINARY_DIR}/external/Litmus-cmake") IF ((BUILD_RTToolbox_interpolation_Tester AND BUILD_InterpolationMatchPointTransformation) OR (BUILD_RTToolbox_io_Tester AND BUILD_IO_ITK)) set(ENABLE_ITK "-DLIT_ENABLE_ITK_SUPPORT:BOOL=ON") set(ITK_DIRECTORY "-DITK_DIR:STRING=${ITK_DIR}") ENDIF() #extract and build Litmus ExternalProject_Add( Litmus URL ${RTToolbox_SOURCE_DIR}/utilities/Litmus/Litmus.tar.gz SOURCE_DIR ${LITMUS_SOURCE_DIR} BINARY_DIR ${LITMUS_BUILD_DIR} PREFIX ${LITMUS_CMAKE_DIR} INSTALL_COMMAND "" UPDATE_COMMAND "" # Don't update SVN on every build CMAKE_ARGS -DBUILD_TESTING:BOOL=OFF ${ENABLE_ITK} ${ITK_DIRECTORY} ) #----------------------------------------------------------------------------- # Configure Testing branch #----------------------------------------------------------------------------- MAKE_DIRECTORY(${RTTBTesting_BINARY_DIR}/Temporary) MESSAGE(STATUS "Process All Tests...") #----------------------------------------------------------------------------- # Include sub directories #----------------------------------------------------------------------------- OPTION(BUILD_RTToolbox_core_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_Test_examples "build project on/off" OFF) OPTION(BUILD_RTToolbox_algorithms_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_models_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_io_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_masks_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_interpolation_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_apps_Tester "build project on/off" OFF) IF(${BUILD_RTToolbox_core_Tester} STREQUAL ON) ADD_SUBDIRECTORY(core) ENDIF(${BUILD_RTToolbox_core_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_Test_examples} STREQUAL ON) ADD_SUBDIRECTORY(examples) ENDIF(${BUILD_RTToolbox_Test_examples} STREQUAL ON) IF(${BUILD_RTToolbox_algorithms_Tester} STREQUAL ON) ADD_SUBDIRECTORY(algorithms) ENDIF(${BUILD_RTToolbox_algorithms_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_models_Tester} STREQUAL ON) ADD_SUBDIRECTORY(models) ENDIF(${BUILD_RTToolbox_models_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_io_Tester} STREQUAL ON) ADD_SUBDIRECTORY(io) ENDIF(${BUILD_RTToolbox_io_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_masks_Tester} STREQUAL ON) ADD_SUBDIRECTORY(masks) ENDIF(${BUILD_RTToolbox_masks_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_interpolation_Tester} STREQUAL ON) ADD_SUBDIRECTORY(interpolation) ENDIF(${BUILD_RTToolbox_interpolation_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_apps_Tester} STREQUAL ON) ADD_SUBDIRECTORY(apps) ENDIF(${BUILD_RTToolbox_apps_Tester} STREQUAL ON) + + + + + + diff --git a/testing/io/CMakeLists.txt b/testing/io/CMakeLists.txt index 6b0166b..8fb1403 100644 --- a/testing/io/CMakeLists.txt +++ b/testing/io/CMakeLists.txt @@ -1,23 +1,27 @@ MESSAGE (STATUS "Process All IO Tests...") #----------------------------------------------------------------------------- # Include sub directories #----------------------------------------------------------------------------- ADD_SUBDIRECTORY (other) IF(BUILD_IO_Dicom) ADD_SUBDIRECTORY(dicom) IF(BUILD_IO_HELAX) ADD_SUBDIRECTORY(helax) ENDIF(BUILD_IO_HELAX) ENDIF(BUILD_IO_Dicom) IF(BUILD_IO_ITK) ADD_SUBDIRECTORY(itk) ENDIF(BUILD_IO_ITK) + + IF(BUILD_IO_MODELS) + ADD_SUBDIRECTORY(models) + ENDIF(BUILD_IO_MODELS) IF(BUILD_IO_Virtuos) ADD_SUBDIRECTORY(virtuos) ENDIF(BUILD_IO_Virtuos) \ No newline at end of file diff --git a/testing/io/other/CMakeLists.txt b/testing/io/models/CMakeLists.txt similarity index 61% copy from testing/io/other/CMakeLists.txt copy to testing/io/models/CMakeLists.txt index 1241b7b..cb0c42e 100644 --- a/testing/io/other/CMakeLists.txt +++ b/testing/io/models/CMakeLists.txt @@ -1,26 +1,23 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- -SET(OTHERIO_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbOtherIOTests) +SET(MODELSIO_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbModelsIOTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- -ADD_TEST(DoseStatisticsIOTest ${OTHERIO_TEST} DoseStatisticsIOTest) +ADD_TEST(ModelsIOTest ${MODELSIO_TEST} ModelsIOTest) -ADD_TEST(DVHXMLIOTest ${OTHERIO_TEST} DVHXMLIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") -ADD_TEST(DVHTXTIOTest ${OTHERIO_TEST} DVHTXTIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") - -RTTB_CREATE_TEST_MODULE(rttbOtherIO DEPENDS RTTBOtherIO PACKAGE_DEPENDS Boost Litmus) +RTTB_CREATE_TEST_MODULE(rttbModelsIO DEPENDS RTTBModelsIO RTTBModels PACKAGE_DEPENDS Boost Litmus) IF (NOT WIN32) #CMake 3.1 provides target_compile_features(RTTB_Interpolation cxx_auto_type cxx_nullptr cxx_override) to automatically add required compiler flags set(CMAKE_CXX_FLAGS "-std=c++11") ENDIF() diff --git a/testing/io/models/ModelsIOTest.cpp b/testing/io/models/ModelsIOTest.cpp new file mode 100644 index 0000000..42a3640 --- /dev/null +++ b/testing/io/models/ModelsIOTest.cpp @@ -0,0 +1,128 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// (c) Copyright 2007, DKFZ, Heidelberg, Germany +// ALL RIGHTS RESERVED +// +// THIS FILE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF DKFZ. +// ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR +// DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY PROHIBITED +// WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF DKFZ. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 1221 $ (last changed revision) +// @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) +// @author zhangl (last changed by) +// @author *none* (Reviewer) +// @author zhangl (Programmer) +// +// Subversion HeadURL: $HeadURL: http://sidt-hpc1/dkfz_repository/NotMeVisLab/SIDT/RTToolbox/trunk/testing/core/DVHCalculatorTest.cpp $ +*/ + +// this file defines the rttbCoreTests for the test driver +// and all it expects is that you have a function called RegisterTests + + + + + +#include "litCheckMacros.h" +#include "rttbBioModel.h" +#include "rttbTCPLQModel.h" +#include "rttbNTCPLKBModel.h" + +#include +#include +#include "boost/filesystem.hpp" + +#include "rttbModelXMLWriter.h" + +namespace rttb +{ + + namespace testing + { + static std::string readFile(const std::string& filename); + int ModelsIOTest(int argc, char* argv[]) + { + + + typedef core::DVH::DataDifferentialType DataDifferentialType; + + PREPARE_DEFAULT_TEST_REPORTING; + + //generate artificial DVH and corresponding statistical values + DoseTypeGy binSize = DoseTypeGy(0.1); + DoseVoxelVolumeType voxelVolume = 8; + + DataDifferentialType aDataDifferential; + + DoseCalcType value = 0; + DVHVoxelNumber numberOfVoxels = 0; + + // creat default values + for (int i = 0; i < 98; i++) + { + value = 0; + numberOfVoxels += value; + aDataDifferential.push_back(value); + } + + aDataDifferential.push_back(10); + aDataDifferential.push_back(20); + + const IDType structureID = "myStructure"; + const IDType doseID = "myDose"; + const IDType voxelizationID = "myVoxelization"; + + core::DVH::DVHPointer dvhPtr = boost::make_shared(aDataDifferential, binSize, + voxelVolume, structureID, + doseID, voxelizationID); + + //test TCP LQ Model + models::BioModelParamType alpha = 0.35; + models::BioModelParamType beta = 0.023333333333333; + models::BioModelParamType roh = 10000000; + int numFractions = 8; + + + boost::shared_ptr tcplq = boost::make_shared(dvhPtr, roh, numFractions, alpha / beta, alpha, 0.08); + + std::string filename = "BioModeltcpleqIOTest.xml"; + rttb::io::models::ModelXMLWriter writer = rttb::io::models::ModelXMLWriter(filename, tcplq); + CHECK_NO_THROW(writer.writeModel()); + CHECK_EQUAL(boost::filesystem::exists(filename), true); + CHECK_EQUAL(std::remove(filename.c_str()), 0); + + //test NTCPLKBModel + models::BioModelParamType aVal = 10; + models::BioModelParamType mVal = 0.16; + models::BioModelParamType d50Val = 35; + + boost::shared_ptr ntcplk= boost::make_shared(dvhPtr, d50Val, mVal, aVal); + filename = "BioModelntcplkIOTest.xml"; + rttb::io::models::ModelXMLWriter writer2 = rttb::io::models::ModelXMLWriter(filename, ntcplk); + CHECK_NO_THROW(writer2.writeModel()); + CHECK_EQUAL(boost::filesystem::exists(filename), true); + + + std::string defaultAsIs = readFile(filename); + std::string defaultExpected = readFile("referenceBioModelntcplkIOTest.xml"); + + CHECK_EQUAL(defaultAsIs, defaultExpected); + CHECK_EQUAL(std::remove(filename.c_str()), 0); + + RETURN_AND_REPORT_TEST_SUCCESS; + } + + std::string readFile(const std::string& filename) + { + std::ifstream fileStream(filename.c_str()); + std::string content((std::istreambuf_iterator(fileStream)), + (std::istreambuf_iterator())); + return content; + } + } +} \ No newline at end of file diff --git a/testing/io/models/files.cmake b/testing/io/models/files.cmake new file mode 100644 index 0000000..76c3d02 --- /dev/null +++ b/testing/io/models/files.cmake @@ -0,0 +1,8 @@ +SET(CPP_FILES + ModelsIOTest.cpp + rttbModelsIOTests.cpp + ) + +SET(H_FILES + +) diff --git a/testing/io/models/rttbModelsIOTests.cpp b/testing/io/models/rttbModelsIOTests.cpp new file mode 100644 index 0000000..6ce7276 --- /dev/null +++ b/testing/io/models/rttbModelsIOTests.cpp @@ -0,0 +1,60 @@ +// ----------------------------------------------------------------------- +// 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: 1221 $ (last changed revision) +// @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) +// @author $Author: hentsch $ (last changed by) +*/ + +// this file defines the rttbCoreTests for the test driver +// and all it expects is that you have a function called RegisterTests + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "litMultiTestsMain.h" + +namespace rttb +{ + namespace testing + { + + void registerTests() + { + LIT_REGISTER_TEST(ModelsIOTest); + } + } +} + +int main(int argc, char* argv[]) +{ + int result = 0; + + rttb::testing::registerTests(); + + try + { + result = lit::multiTestsMain(argc, argv); + } + + catch (...) + { + result = -1; + } + + return result; +} diff --git a/testing/io/other/CMakeLists.txt b/testing/io/other/CMakeLists.txt index 1241b7b..78693ad 100644 --- a/testing/io/other/CMakeLists.txt +++ b/testing/io/other/CMakeLists.txt @@ -1,26 +1,27 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(OTHERIO_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbOtherIOTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- ADD_TEST(DoseStatisticsIOTest ${OTHERIO_TEST} DoseStatisticsIOTest) ADD_TEST(DVHXMLIOTest ${OTHERIO_TEST} DVHXMLIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") ADD_TEST(DVHTXTIOTest ${OTHERIO_TEST} DVHTXTIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") + RTTB_CREATE_TEST_MODULE(rttbOtherIO DEPENDS RTTBOtherIO PACKAGE_DEPENDS Boost Litmus) IF (NOT WIN32) #CMake 3.1 provides target_compile_features(RTTB_Interpolation cxx_auto_type cxx_nullptr cxx_override) to automatically add required compiler flags set(CMAKE_CXX_FLAGS "-std=c++11") ENDIF() diff --git a/testing/models/BioModelTest.cpp b/testing/models/BioModelTest.cpp index 40db317..d6d6416 100644 --- a/testing/models/BioModelTest.cpp +++ b/testing/models/BioModelTest.cpp @@ -1,301 +1,306 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbBaseTypeModels.h" #include "rttbBioModel.h" #include "rttbDVH.h" #include "rttbTCPLQModel.h" #include "rttbNTCPLKBModel.h" #include "rttbNTCPRSModel.h" #include "rttbBaseTypeModels.h" #include "rttbBioModelCurve.h" #include "rttbInvalidParameterException.h" #include "rttbBioModelScatterPlots.h" + + + namespace rttb { namespace testing { typedef core::DVH::DataDifferentialType DataDifferentialType; /*! @brief RTBioModelTest. TCP calculated using a DVH PTV and LQ Model. NTCP tested using 3 Normal Tissue DVHs and LKB/RS Model. TCPLQ: 1) test constructors (values as expected?) 2) test init (calcTCPxxx) 3) test set/get NTCP (LKB): 1) test constructors (values as expected?) 2) test init (calcxxx) 3) test set/get NTCP (RS): 1) test constructors (values as expected?) 2) test init (calcxxx) 3) test set/get */ int BioModelTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; //generate artificial DVH and corresponding statistical values DoseTypeGy binSize = DoseTypeGy(0.1); DoseVoxelVolumeType voxelVolume = 8; DataDifferentialType aDataDifferential; DoseCalcType value = 0; DVHVoxelNumber numberOfVoxels = 0; // creat default values for (int i = 0; i < 98; i++) { value = 0; numberOfVoxels += value; aDataDifferential.push_back(value); } aDataDifferential.push_back(10); aDataDifferential.push_back(20); const IDType structureID = "myStructure"; const IDType doseID = "myDose"; const IDType voxelizationID = "myVoxelization"; core::DVH::DVHPointer dvhPtr = boost::make_shared(aDataDifferential, binSize, voxelVolume, structureID, doseID, voxelizationID); //test TCP LQ Model models::BioModelParamType alpha = 0.35; models::BioModelParamType beta = 0.023333333333333; models::BioModelParamType roh = 10000000; int numFractions = 8; DoseTypeGy normalizationDose = 50; //1) test constructors (values as expected?) rttb::models::TCPLQModel tcplq = rttb::models::TCPLQModel(); CHECK_EQUAL(0, tcplq.getAlphaMean()); CHECK_EQUAL(0, tcplq.getAlphaBeta()); CHECK_EQUAL(0, tcplq.getRho()); CHECK_EQUAL(0, tcplq.getValue()); + tcplq = rttb::models::TCPLQModel(dvhPtr, roh, numFractions, alpha / beta, alpha, 0.08); CHECK_EQUAL(alpha, tcplq.getAlphaMean()); CHECK_EQUAL(alpha / beta, tcplq.getAlphaBeta()); CHECK_EQUAL(roh, tcplq.getRho()); CHECK_EQUAL(0, tcplq.getValue()); + tcplq = rttb::models::TCPLQModel(); CHECK_EQUAL(0, tcplq.getAlphaMean()); CHECK_EQUAL(0, tcplq.getAlphaBeta()); CHECK_EQUAL(0, tcplq.getRho()); CHECK_EQUAL(0, tcplq.getValue()); tcplq = rttb::models::TCPLQModel(dvhPtr, alpha, beta, roh, numFractions); CHECK_EQUAL(alpha, tcplq.getAlphaMean()); CHECK_EQUAL(alpha / beta, tcplq.getAlphaBeta()); CHECK_EQUAL(roh, tcplq.getRho()); CHECK_EQUAL(0, tcplq.getValue()); //2) test init (calcTCPxxx) CHECK_NO_THROW(tcplq.init(1)); //3) test set/get CHECK_EQUAL(0, tcplq.getValue()); CHECK_NO_THROW(tcplq.setParameters(alpha, 10, roh, 0.08)); CHECK_EQUAL(10, tcplq.getAlphaBeta()); CHECK_EQUAL(0.08, tcplq.getAlphaVariance()); CHECK_EQUAL(alpha, tcplq.getAlphaMean()); CHECK_EQUAL(roh, tcplq.getRho()); CHECK_NO_THROW(models::getCurveDoseVSBioModel(tcplq, normalizationDose)); std::vector aParameterVector; aParameterVector.push_back(alpha + 0.02); CHECK_THROW_EXPLICIT(tcplq.setParameterVector(aParameterVector), core::InvalidParameterException); aParameterVector.push_back(0.06); aParameterVector.push_back(8); aParameterVector.push_back(roh / 10); CHECK_NO_THROW(tcplq.setParameterVector(aParameterVector)); CHECK_EQUAL(8, tcplq.getAlphaBeta()); CHECK_EQUAL(0.06, tcplq.getAlphaVariance()); CHECK_EQUAL(alpha + 0.02, tcplq.getAlphaMean()); CHECK_EQUAL(roh / 10, tcplq.getRho()); for (int i = 0; i < 4; i++) { CHECK_NO_THROW(tcplq.setParameterByID(i, models::BioModelParamType(i))); } CHECK_THROW_EXPLICIT(tcplq.setParameterByID(4, 4.0), core::InvalidParameterException); CHECK_EQUAL(0, tcplq.getParameterID("alphaMean")); CHECK_EQUAL(0, tcplq.getAlphaMean()); CHECK_EQUAL(1, tcplq.getParameterID("alphaVariance")); CHECK_EQUAL(1, tcplq.getAlphaVariance()); CHECK_EQUAL(2, tcplq.getParameterID("alpha_beta")); CHECK_EQUAL(2, tcplq.getAlphaBeta()); CHECK_EQUAL(3, tcplq.getParameterID("rho")); CHECK_EQUAL(3, tcplq.getRho()); //test NTCPLKBModel //1) test constructors (values as expected?) models::BioModelParamType aVal = 10; models::BioModelParamType mVal = 0.16; models::BioModelParamType d50Val = 35; CHECK_NO_THROW(rttb::models::NTCPLKBModel()); rttb::models::NTCPLKBModel lkb = rttb::models::NTCPLKBModel(); CHECK_EQUAL(0, lkb.getA()); CHECK_EQUAL(0, lkb.getM()); CHECK_EQUAL(0, lkb.getD50()); CHECK_EQUAL(0, lkb.getValue()); CHECK_NO_THROW(rttb::models::NTCPLKBModel(dvhPtr, d50Val, mVal, aVal)); lkb = rttb::models::NTCPLKBModel(dvhPtr, d50Val, mVal, aVal); CHECK_EQUAL(0, lkb.getValue()); CHECK_EQUAL(dvhPtr, lkb.getDVH()); CHECK_EQUAL(aVal, lkb.getA()); CHECK_EQUAL(mVal, lkb.getM()); CHECK_EQUAL(d50Val, lkb.getD50()); //2) test init (calcxxx) CHECK_NO_THROW(lkb.init(1)); lkb.getValue(); //3) test set/get lkb = rttb::models::NTCPLKBModel(); CHECK_EQUAL(0, lkb.getA()); CHECK_EQUAL(0, lkb.getM()); CHECK_EQUAL(0, lkb.getD50()); lkb.setDVH(dvhPtr); CHECK_EQUAL(dvhPtr, lkb.getDVH()); lkb.setA(aVal); CHECK_EQUAL(aVal, lkb.getA()); lkb.setM(mVal); CHECK_EQUAL(mVal, lkb.getM()); lkb.setD50(d50Val); CHECK_EQUAL(d50Val, lkb.getD50()); CHECK_NO_THROW(models::getCurveEUDVSBioModel(lkb)); aParameterVector.clear(); aParameterVector.push_back(d50Val + 5); CHECK_THROW_EXPLICIT(lkb.setParameterVector(aParameterVector), core::InvalidParameterException); aParameterVector.push_back(mVal + 0.2); aParameterVector.push_back(aVal + 0.5); CHECK_NO_THROW(lkb.setParameterVector(aParameterVector)); CHECK_EQUAL(aVal + 0.5, lkb.getA()); CHECK_EQUAL(mVal + 0.2, lkb.getM()); CHECK_EQUAL(d50Val + 5, lkb.getD50()); for (int i = 0; i < 3; i++) { CHECK_NO_THROW(lkb.setParameterByID(i, models::BioModelParamType(i))); } CHECK_THROW_EXPLICIT(lkb.setParameterByID(3, 4.0), core::InvalidParameterException); CHECK_EQUAL(0, lkb.getParameterID("d50")); CHECK_EQUAL(0, lkb.getD50()); CHECK_EQUAL(1, lkb.getParameterID("m")); CHECK_EQUAL(1, lkb.getM()); CHECK_EQUAL(2, lkb.getParameterID("a")); CHECK_EQUAL(2, lkb.getA()); //test NTCPRSModel //1) test constructors (values as expected?) CHECK_NO_THROW(rttb::models::NTCPRSModel()); models::BioModelParamType gammaVal = 1.7; models::BioModelParamType sVal = 1; CHECK_NO_THROW(rttb::models::NTCPRSModel(dvhPtr, d50Val, gammaVal, sVal)); rttb::models::NTCPRSModel rs = rttb::models::NTCPRSModel(dvhPtr, d50Val, gammaVal, sVal); CHECK_EQUAL(dvhPtr, rs.getDVH()); CHECK_EQUAL(d50Val, rs.getD50()); CHECK_EQUAL(gammaVal, rs.getGamma()); CHECK_EQUAL(sVal, rs.getS()); rs = rttb::models::NTCPRSModel(); CHECK_EQUAL(0, rs.getGamma()); CHECK_EQUAL(0, rs.getS()); CHECK_EQUAL(0, rs.getD50()); //3) test set/get rs.setDVH(dvhPtr); CHECK_EQUAL(dvhPtr, rs.getDVH()); rs.setD50(d50Val); CHECK_EQUAL(d50Val, rs.getD50()); rs.setGamma(gammaVal); CHECK_EQUAL(gammaVal, rs.getGamma()); rs.setS(sVal); CHECK_EQUAL(sVal, rs.getS()); //2) test init (calcxxx) CHECK_NO_THROW(rs.init(1)); //3) test set/get continued aParameterVector.clear(); aParameterVector.push_back(d50Val + 5); CHECK_THROW_EXPLICIT(rs.setParameterVector(aParameterVector), core::InvalidParameterException); aParameterVector.push_back(gammaVal + 0.2); aParameterVector.push_back(sVal + 0.5); CHECK_NO_THROW(rs.setParameterVector(aParameterVector)); CHECK_EQUAL(gammaVal + 0.2, rs.getGamma()); CHECK_EQUAL(sVal + 0.5, rs.getS()); CHECK_EQUAL(d50Val + 5, rs.getD50()); for (int i = 0; i < 3; i++) { CHECK_NO_THROW(rs.setParameterByID(i, models::BioModelParamType(i))); } CHECK_THROW_EXPLICIT(rs.setParameterByID(3, 4.0), core::InvalidParameterException); CHECK_EQUAL(0, rs.getParameterID("d50")); CHECK_EQUAL(0, rs.getD50()); CHECK_EQUAL(1, rs.getParameterID("gamma")); CHECK_EQUAL(1, rs.getGamma()); CHECK_EQUAL(2, rs.getParameterID("s")); CHECK_EQUAL(2, rs.getS()); //Scatter plot tests CHECK_NO_THROW(models::getScatterPlotVary1Parameter(tcplq, 0, alpha, 0, normalizationDose)); //variance=0, will be set to 1e-30 CHECK_THROW_EXPLICIT(models::getScatterPlotVary1Parameter(tcplq, 0, alpha, alpha * 0.1, 0), core::InvalidParameterException);//normalisationdose=0 CHECK_THROW_EXPLICIT(models::getScatterPlotVary1Parameter(tcplq, 0, alpha, alpha * 0.1, normalizationDose, 10000, 0, 0), core::InvalidParameterException);//maxDose-minDose=0 RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb \ No newline at end of file diff --git a/testing/models/CMakeLists.txt b/testing/models/CMakeLists.txt index c81cb75..bf380db 100644 --- a/testing/models/CMakeLists.txt +++ b/testing/models/CMakeLists.txt @@ -1,22 +1,22 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(MODELS_TESTS ${EXECUTABLE_OUTPUT_PATH}/rttbModelTests) SET(MODELS_HEADER_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbModelsHeaderTest) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- ADD_TEST(BioModelTest ${MODELS_TESTS} BioModelTest) ADD_TEST(BioModelScatterPlotTest ${MODELS_TESTS} BioModelScatterPlotTest) ADD_TEST(DvhBasedModelsTest ${MODELS_TESTS} DvhBasedModelsTest) ADD_TEST(LQModelAccessorTest ${MODELS_TESTS} LQModelAccessorTest "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/LinearIncreaseX.dcm") -RTTB_CREATE_TEST_MODULE(rttbModel DEPENDS RTTBModels RTTBOtherIO RTTBDicomIO PACKAGE_DEPENDS Boost Litmus DCMTK) +RTTB_CREATE_TEST_MODULE(rttbModel DEPENDS RTTBModels RTTBDicomIO PACKAGE_DEPENDS Boost Litmus DCMTK) diff --git a/testing/models/DummyModel.cpp b/testing/models/DummyModel.cpp index ceed7b4..d3848f3 100644 --- a/testing/models/DummyModel.cpp +++ b/testing/models/DummyModel.cpp @@ -1,114 +1,126 @@ // ----------------------------------------------------------------------- // 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 $ (last changed revision) // @date $Date $ (last change date) // @author $Author $ (last changed by) */ #include "DummyModel.h" namespace rttb { namespace models { DummyModel::DummyModel(DVHPointer aDvh): BioModel(aDvh) { _calcCount = 0; _setParam1Count = 0; _setParam2Count = 0; _setParam3Count = 0; + _name = "DummyModel"; } BioModelValueType DummyModel::calcModel(const double doseFactor) { _calcCount++; _value = doseFactor; return _value; } void DummyModel::setParameterVector(const ParamVectorType& aParameterVector) { if (aParameterVector.size() != 3) { std::cerr << "aParameterVector.size must be 3! Nothing will be done." << std::endl; } else { _param1 = aParameterVector.at(0); _setParam1Count++; _param2 = aParameterVector.at(1); _setParam2Count++; _param3 = aParameterVector.at(2); _setParam3Count++; } } void DummyModel::setParameterByID(const int aParamId, const BioModelParamType aValue) { if (aParamId == 0) { _param1 = aValue; _setParam1Count++; } else if (aParamId == 1) { _param2 = aValue; _setParam2Count++; } else if (aParamId == 2) { _param3 = aValue; _setParam3Count++; } else { std::cerr << "aParamID must be 0(DummyParam1) or 1(DummyParam2) or 2(DummyParam3)! Nothing will be done." << std::endl; } } const int DummyModel::getParameterID(const std::string& aParamName) const { if (aParamName == "DummyParam1") { return 0; } else if (aParamName == "DummyParam2") { return 1; } else if (aParamName == "DummyParam3") { return 2; } else { std::cerr << "There is no parameter with the name " << aParamName << "!" << std::endl; return -1; } } void DummyModel::resetCounters() { _calcCount = 0; _setParam1Count = 0; _setParam2Count = 0; _setParam3Count = 0; } + std::map DummyModel::getParameterMap() const { + return parameterMap; + } + + void DummyModel::fillParameterMap(){ + parameterMap["Dummy"] = 2; + } + + std::string DummyModel::getModelType() const{ + return _name; + } } } \ No newline at end of file diff --git a/testing/models/DummyModel.h b/testing/models/DummyModel.h index 115fbb2..742ba1c 100644 --- a/testing/models/DummyModel.h +++ b/testing/models/DummyModel.h @@ -1,94 +1,97 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) */ #ifndef __DUMMY_MODEL_H #define __DUMMY_MODEL_H #include "rttbBaseType.h" #include "rttbBaseTypeModels.h" #include "rttbBioModel.h" namespace rttb { namespace models { /*! @class DummyModel @brief generates a dummy model object used for unit tests */ class DummyModel: public BioModel { private: BioModelParamType _param1; BioModelParamType _param2; BioModelParamType _param3; int _calcCount; int _setParam1Count; int _setParam2Count; int _setParam3Count; protected: /*! @brief Calculate the model value @param doseFactor scaling factor for the dose. The model calculation will use the dvh with each di=old di*doseFactor. */ BioModelValueType calcModel(const double doseFactor = 1); + std::map getParameterMap() const; + void fillParameterMap() override; + std::string getModelType() const; public: /*!@constructor initializes DVH pointer */ DummyModel(DVHPointer aDvh); /*! @brief Set parameter vector, where index of vector is the parameter ID. The length of the vector has to be 3. */ void setParameterVector(const ParamVectorType& aParameterVector); void setParameterByID(const int aParamId, const BioModelParamType aValue); /*! @brief Get parameter by ID. @return Return -1 if ID is not found. */ const int getParameterID(const std::string& aParamName) const; /*! return counting values */ const int getSetParam1Count() const { return _setParam1Count; }; const int getSetParam2Count() const { return _setParam2Count; }; const int getSetParam3Count() const { return _setParam3Count; }; const int getCalcCount() const { return _calcCount; }; void resetCounters(); }; } } #endif \ No newline at end of file