diff --git a/code/io/models/rttbModelXMLWriter.cpp b/code/io/models/rttbModelXMLWriter.cpp index 71594d3..9d3218f 100644 --- a/code/io/models/rttbModelXMLWriter.cpp +++ b/code/io/models/rttbModelXMLWriter.cpp @@ -1,105 +1,101 @@ // ----------------------------------------------------------------------- // 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" #include "rttbInvalidParameterException.h" #include namespace rttb { namespace io { namespace models { ModelXMLWriter::ModelXMLWriter(std::string fileName, rttb::models::BioModel* model){ this->setFileName(fileName); this->setModel(model); } void ModelXMLWriter::setFileName(FileNameString fileName){ _fileName = fileName; } FileNameString ModelXMLWriter::getFileName() const{ return _fileName; } void ModelXMLWriter::setModel(rttb::models::BioModel* model){ _model = model; } rttb::models::BioModel* ModelXMLWriter::getModel() const { return _model; } void ModelXMLWriter::writeModel(){ using boost::property_tree::ptree; ptree pt; static const std::string xmlattrNameTag = ".name"; - static const std::string statisticsTag = "statistics"; + static const std::string modelTag = "BioModel"; static const std::string propertyTag = "property"; + static const std::string configTag = "config"; + static const std::string resultsTag = "results"; ptree propertynode; + ptree confignode; - propertynode.put("", getModel()->getModelType()); - propertynode.put(xmlattrNameTag, "BioModelType"); - pt.add_child(statisticsTag + "." + propertyTag, propertynode); + confignode.put("BioModelType", getModel()->getModelType()); + confignode.put("StructureID", getModel()->getDVH()->getStructureID()); + confignode.put("DoseID", getModel()->getDVH()->getDoseID()); + pt.add_child(modelTag + "." + configTag, confignode); propertynode.put("", getModel()->getValue()); propertynode.put(xmlattrNameTag, "Value"); - pt.add_child(statisticsTag + "." + propertyTag, propertynode); - - propertynode.put("", getModel()->getDVH()->getStructureID()); - propertynode.put(xmlattrNameTag, "StructureID"); - pt.add_child(statisticsTag + "." + propertyTag, propertynode); - - propertynode.put("", getModel()->getDVH()->getDoseID()); - propertynode.put(xmlattrNameTag, "DoseID"); - pt.add_child(statisticsTag + "." + propertyTag, propertynode); + pt.add_child(modelTag + "."+ resultsTag + "." + propertyTag, propertynode); std::map parameterMap = _model->getParameterMap(); for (std::map::iterator it = parameterMap.begin(); it != parameterMap.end(); ++it){ propertynode.put("", it->second); propertynode.put(xmlattrNameTag, it->first); - pt.add_child(statisticsTag + "." + propertyTag, propertynode); + 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 (boost::property_tree::xml_parser_error& e) { std::cout << e.what(); throw core::InvalidParameterException("Write xml failed: xml_parser_error!"); } } } } } diff --git a/testing/models/DummyModel.cpp b/testing/models/DummyModel.cpp index 8be1167..f7ea302 100644 --- a/testing/models/DummyModel.cpp +++ b/testing/models/DummyModel.cpp @@ -1,117 +1,120 @@ // ----------------------------------------------------------------------- // 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; } 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(){ return parameterMap; } + std::string DummyModel::getModelType(){ + return "DummyModel"; + } } } \ No newline at end of file diff --git a/testing/models/DummyModel.h b/testing/models/DummyModel.h index b30cfa1..c9bc8fe 100644 --- a/testing/models/DummyModel.h +++ b/testing/models/DummyModel.h @@ -1,95 +1,96 @@ // ----------------------------------------------------------------------- // 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 DummyModel::getParameterMap(); + std::string getModelType(); 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