diff --git a/apps/BioModelCalc/BioModelCalcApplicationData.cpp b/apps/BioModelCalc/BioModelCalcApplicationData.cpp index 5474684..cc9a343 100644 --- a/apps/BioModelCalc/BioModelCalcApplicationData.cpp +++ b/apps/BioModelCalc/BioModelCalcApplicationData.cpp @@ -1,72 +1,66 @@ // ----------------------------------------------------------------------- // 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: 1233 $ (last changed revision) -// @date $Date: 2016-01-20 15:47:47 +0100 (Mi, 20 Jan 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "BioModelCalcApplicationData.h" #include "BioModelCmdLineParser.h" namespace rttb { namespace apps { namespace bioModelCalc { ApplicationData:: ApplicationData() { this->reset(); } void ApplicationData:: reset() { _doseFileName = ""; _outputFileName = ""; _doseScaling = 1.0; _nFractions = 1; _modelParameters.clear(); _modelParameterMapsFilename.clear(); _modelParameterMaps.clear(); } void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData._doseFileName = argParser->get(argParser->OPTION_DOSE_FILE); - appData._doseLoadStyle = argParser->get >(argParser->OPTION_LOAD_STYLE); + appData._doseLoadStyle = argParser->get(argParser->OPTION_LOAD_STYLE); appData._doseScaling = argParser->get(argParser->OPTION_DOSE_SCALING); appData._outputFileName = argParser->get(argParser->OPTION_OUTPUT_FILE); appData._model = argParser->get(argParser->OPTION_MODEL); if (argParser->isSet(argParser->OPTION_MODEL_PARAMETERS)){ appData._modelParameters = argParser->get >(argParser->OPTION_MODEL_PARAMETERS); } else { appData._modelParameterMapsFilename = argParser->get >(argParser->OPTION_MODEL_PARAMETER_MAPS); - appData._parameterMapsLoadStyle = argParser->get >(argParser->OPTION_LOAD_STYLE_PARAMETER_MAPS); + appData._parameterMapsLoadStyle = argParser->get(argParser->OPTION_LOAD_STYLE_PARAMETER_MAPS); } if (argParser->isSet(argParser->OPTION_N_FRACTIONS)){ appData._nFractions = argParser->get(argParser->OPTION_N_FRACTIONS); } } } } } diff --git a/apps/BioModelCalc/BioModelCalcApplicationData.h b/apps/BioModelCalc/BioModelCalcApplicationData.h index 165e3e9..9a27136 100644 --- a/apps/BioModelCalc/BioModelCalcApplicationData.h +++ b/apps/BioModelCalc/BioModelCalcApplicationData.h @@ -1,74 +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: 1210 $ (last changed revision) -// @date $Date: 2015-11-24 15:52:45 +0100 (Di, 24 Nov 2015) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ - #ifndef __BIO_MODEL_CALC_APPLICATION_DATA_H #define __BIO_MODEL_CALC_APPLICATION_DATA_H #include #include #include "rttbDoseAccessorInterface.h" namespace rttb { namespace apps { namespace bioModelCalc { class BioModelCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in BioModelCalc */ class ApplicationData { public: - /**Vector of arguments used to specify the loading style (always the first argument) - * and, if needed, additional arguments for the specified loading style. - */ - typedef std::vector LoadingStyleArgType; - core::DoseAccessorInterface::DoseAccessorPointer _dose; std::deque _modelParameterMaps; std::string _doseFileName; - LoadingStyleArgType _doseLoadStyle; - LoadingStyleArgType _parameterMapsLoadStyle; + std::string _doseLoadStyle; + std::string _parameterMapsLoadStyle; double _doseScaling; unsigned int _nFractions; std::string _outputFileName; std::string _model; std::vector _modelParameters; std::vector _modelParameterMapsFilename; void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the BioModelCmdLineParser and writes them in the respective variables of ApplicationData */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/BioModelCalc/BioModelCmdLineParser.cpp b/apps/BioModelCalc/BioModelCmdLineParser.cpp index 6738c9a..35d4fb8 100644 --- a/apps/BioModelCalc/BioModelCmdLineParser.cpp +++ b/apps/BioModelCalc/BioModelCmdLineParser.cpp @@ -1,125 +1,141 @@ +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ + #include "BioModelCmdLineParser.h" namespace rttb { namespace apps { namespace bioModelCalc { BioModelCmdLineParser::BioModelCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category) : CmdLineParserBase(name, version, description, contributor, category) { //REQUIRED addOption(OPTION_DOSE_FILE, OPTION_GROUP_REQUIRED, "The name of the dose file. Can be omitted if used as " "positional argument (see above).", 'd', true); addInformationForXML(OPTION_DOSE_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOption(OPTION_OUTPUT_FILE, OPTION_GROUP_REQUIRED, "The name of the output file. Can be omitted if used as " "positional argument (see above).", 'o', true); addInformationForXML(OPTION_OUTPUT_FILE, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "*" }); addPositionalOption(OPTION_DOSE_FILE, 1); addPositionalOption(OPTION_OUTPUT_FILE, 1); addOptionWithDefaultValue(OPTION_MODEL, OPTION_GROUP_REQUIRED, "The used radiobiological model the dose should be analyzed with. Available models are:\n \"LQ\", Formula: exp(-(alpha * D + beta * D^2/n))", "LQ", "LQ", 'm'); addInformationForXML(OPTION_MODEL, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "LQ" }); addOptionWithDefaultValue(OPTION_DOSE_SCALING, OPTION_GROUP_REQUIRED, "Dose scaling that should be applied.", 1.0, "1.0", 'e'); addInformationForXML(OPTION_DOSE_SCALING, cmdlineparsing::XMLGenerator::paramType::DOUBLE); - std::vector defaultLoadingStyle; - defaultLoadingStyle.push_back("itk"); + std::string defaultLoadingStyle; + defaultLoadingStyle = "itk"; - std::string doseLoadStyleDescription = "The loading style for the dose. Available styles are:\n" - "\"dicom\": normal dicom dose\n" - "\"itk\": use itk image loading\n" - "\"helax\": load a helax dose (choosing this style, the dose path should only be a directory)."; + std::string doseLoadStyleDescription = "The loading style for the dose. Available styles are:" + "\ndicom: normal dicom dose" + "\nitk: use itk image loading" + "\nitkDicom: use itk dicom image loading" + "\nhelax: load a helax dose (choosing this style, the dose path should only be a directory)."; - addOptionWithDefaultValue >(OPTION_LOAD_STYLE, OPTION_GROUP_REQUIRED, doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), + addOptionWithDefaultValue(OPTION_LOAD_STYLE, OPTION_GROUP_REQUIRED, doseLoadStyleDescription, + defaultLoadingStyle, defaultLoadingStyle, 't', true, true); - addInformationForXML(OPTION_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "itk", "dicom", "helax" }); + addInformationForXML(OPTION_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRING); //OPTIONAL addOption >(OPTION_MODEL_PARAMETERS, OPTION_GROUP_OPTIONAL, "The parameters for the radiobiological model.", 'p', false, true); addInformationForXML(OPTION_MODEL_PARAMETERS, cmdlineparsing::XMLGenerator::paramType::STRING); addOption >(OPTION_MODEL_PARAMETER_MAPS, OPTION_GROUP_OPTIONAL, "The parameters maps as itk readable image files for the radiobiological model.", 'a', false, true); addInformationForXML(OPTION_MODEL_PARAMETER_MAPS, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOption(OPTION_N_FRACTIONS, OPTION_GROUP_OPTIONAL, "The number of fractions (n in the formula).", 'f'); addInformationForXML(OPTION_N_FRACTIONS, cmdlineparsing::XMLGenerator::paramType::INTEGER); - addOptionWithDefaultValue >(OPTION_LOAD_STYLE_PARAMETER_MAPS, OPTION_GROUP_OPTIONAL, doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), + addOptionWithDefaultValue(OPTION_LOAD_STYLE_PARAMETER_MAPS, OPTION_GROUP_OPTIONAL, doseLoadStyleDescription, + defaultLoadingStyle, defaultLoadingStyle, 'u', true, true); - addInformationForXML(OPTION_LOAD_STYLE_PARAMETER_MAPS, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "itk", "dicom", "helax" }); + addInformationForXML(OPTION_LOAD_STYLE_PARAMETER_MAPS, cmdlineparsing::XMLGenerator::paramType::STRING); parse(argc, argv); } void BioModelCmdLineParser::validateInput() const { std::string model = get(OPTION_MODEL); if (model != "LQ") { throw cmdlineparsing::InvalidConstraintException("Unknown model: " + model + ".\nPlease refer to the help for valid models."); } else { if (!isSet(OPTION_MODEL_PARAMETERS) && !isSet(OPTION_MODEL_PARAMETER_MAPS)){ throw cmdlineparsing::InvalidConstraintException("Either the model parameters or model parameter maps must be specified!"); } if ((isSet(OPTION_MODEL_PARAMETERS) && get >(OPTION_MODEL_PARAMETERS).size() != 2) || (isSet(OPTION_MODEL_PARAMETER_MAPS) && get >(OPTION_MODEL_PARAMETER_MAPS).size() != 2)) { throw cmdlineparsing::InvalidConstraintException("The LQ Model requires two parameters or parameter maps!"); } } - std::vector loadStyle = get >(OPTION_LOAD_STYLE); - std::string loadStyleAbbreviation = loadStyle.at(0); + std::string loadStyle = get(OPTION_LOAD_STYLE); - if (loadStyleAbbreviation != "dicom" - && loadStyleAbbreviation != "itk" - && loadStyleAbbreviation != "helax") + if (loadStyle != "dicom" + && loadStyle != "itk" + && loadStyle != "itkDicom" + && loadStyle != "helax") { - throw cmdlineparsing::InvalidConstraintException("Unknown load style: " + loadStyleAbbreviation + + throw cmdlineparsing::InvalidConstraintException("Unknown load style: " + loadStyle + ".\nPlease refer to the help for valid loading style settings."); } double doseScaling = get(OPTION_DOSE_SCALING); if (doseScaling <= 0) { throw cmdlineparsing::InvalidConstraintException("Negative dose scaling is not allowed. Dose scaling has to be >0."); } } void BioModelCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << "Example:" << std::endl << std::endl; std::cout << m_programName << " dose.mhd result.mhd -m LQ -p 0.2 0.02" << std::endl << std::endl; std::cout << "This will calculate the Linear quadratic (LQ) BioModel from \"dose.mhd\" and will write the result to \"result.mhd\". " "The alpha and beta parameters for the LQ model are 0.2 and 0.02, respectively." << std::endl; } } } } diff --git a/apps/DoseAcc/DoseAccApplicationData.cpp b/apps/DoseAcc/DoseAccApplicationData.cpp index 0ce1965..9d74070 100644 --- a/apps/DoseAcc/DoseAccApplicationData.cpp +++ b/apps/DoseAcc/DoseAccApplicationData.cpp @@ -1,76 +1,70 @@ // ----------------------------------------------------------------------- // 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: 1145 $ (last changed revision) -// @date $Date: 2015-10-12 17:06:10 +0200 (Mo, 12 Okt 2015) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "DoseAccApplicationData.h" #include "DoseAccCmdLineParser.h" namespace rttb { namespace apps { namespace doseAcc { ApplicationData:: ApplicationData() { this->Reset(); } void ApplicationData:: Reset() { _dose1FileName = ""; _dose2FileName = ""; _outputFileName = ""; _regFileName = ""; _interpolatorName = "linear"; _weightDose1 = 1.0; _weightDose2 = 1.0; _operator = "+"; } void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData._dose1FileName = argParser->get(argParser->OPTION_DOSE1_FILENAME); - appData._dose1LoadStyle = argParser->get > + appData._dose1LoadStyle = argParser->get (argParser->OPTION_LOAD_STYLE_DOSE1); appData._dose2FileName = argParser->get(argParser->OPTION_DOSE2_FILENAME); - appData._dose2LoadStyle = argParser->get > + appData._dose2LoadStyle = argParser->get (argParser->OPTION_LOAD_STYLE_DOSE2); appData._outputFileName = argParser->get(argParser->OPTION_OUTPUT_FILENAME); appData._interpolatorName = argParser->get(argParser->OPTION_INTERPOLATOR); appData._weightDose1 = argParser->get(argParser->OPTION_WEIGHT1); appData._weightDose2 = argParser->get(argParser->OPTION_WEIGHT2); appData._regFileName = argParser->get(argParser->OPTION_REGISTRATION_FILENAME); appData._operator = argParser->get(argParser->OPTION_OPERATOR); } } } } diff --git a/apps/DoseAcc/DoseAccApplicationData.h b/apps/DoseAcc/DoseAccApplicationData.h index 2fbed4a..85de2f8 100644 --- a/apps/DoseAcc/DoseAccApplicationData.h +++ b/apps/DoseAcc/DoseAccApplicationData.h @@ -1,78 +1,68 @@ // ----------------------------------------------------------------------- // 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: 1107 $ (last changed revision) -// @date $Date: 2015-09-17 12:47:41 +0200 (Do, 17 Sep 2015) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ - #ifndef __DOSE_ACC_APPLICATION_DATA_H #define __DOSE_ACC_APPLICATION_DATA_H #include "mapRegistration.h" #include "rttbDoseAccessorInterface.h" namespace rttb { namespace apps { namespace doseAcc { class DoseAccCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in DoseAcc */ class ApplicationData { public: typedef map::core::Registration<3, 3> RegistrationType; - /**Vector of arguments used to specify the loading style (always the first argument) - * and, if needed, additional arguments for the specified loading style. - */ - typedef std::vector LoadingStyleArgType; + /** Loaded Dose.*/ core::DoseAccessorInterface::DoseAccessorPointer _dose1; std::string _dose1FileName; - LoadingStyleArgType _dose1LoadStyle; + std::string _dose1LoadStyle; core::DoseAccessorInterface::DoseAccessorPointer _dose2; std::string _dose2FileName; - LoadingStyleArgType _dose2LoadStyle; + std::string _dose2LoadStyle; RegistrationType::Pointer _spReg; std::string _regFileName; std::string _operator; std::string _outputFileName; double _weightDose1; double _weightDose2; std::string _interpolatorName; void Reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the DoseToolCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/DoseAcc/DoseAccCmdLineParser.cpp b/apps/DoseAcc/DoseAccCmdLineParser.cpp index 93e6bcb..659c979 100644 --- a/apps/DoseAcc/DoseAccCmdLineParser.cpp +++ b/apps/DoseAcc/DoseAccCmdLineParser.cpp @@ -1,162 +1,159 @@ // ----------------------------------------------------------------------- // 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: 1374 $ (last changed revision) -// @date $Date: 2016-05-30 14:15:42 +0200 (Mo, 30 Mai 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "DoseAccCmdLineParser.h" namespace rttb { namespace apps { namespace doseAcc { DoseAccCmdLineParser::DoseAccCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category) : CmdLineParserBase(name, version, description, contributor, category) { //REQUIRED addOption(OPTION_DOSE1_FILENAME, OPTION_GROUP_REQUIRED, "File path to the first dose.", 'd', true); addInformationForXML(OPTION_DOSE1_FILENAME, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOption(OPTION_DOSE2_FILENAME, OPTION_GROUP_REQUIRED, "File path to the second dose.", 'e', true); addInformationForXML(OPTION_DOSE2_FILENAME, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOption(OPTION_OUTPUT_FILENAME, OPTION_GROUP_REQUIRED, "File path where the output should be stored.", 'o', true); addInformationForXML(OPTION_OUTPUT_FILENAME, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "*" }); addOptionWithDefaultValue(OPTION_INTERPOLATOR, OPTION_GROUP_REQUIRED, "Specifies the interpolator that should be used for mapping. Available options are: " "\"nn\": nearest neighbour, \"linear\": linear interpolation, \"rosu\" interpolation based on the concept of Rosu et al..", "linear", "linear", 'i', true); addInformationForXML(OPTION_INTERPOLATOR, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "linear", "nn", "rosu" }); addOptionWithDefaultValue(OPTION_WEIGHT1, OPTION_GROUP_REQUIRED, "Specifies the weight for dose 1.", 1.0, "1.0", 'w', true); addInformationForXML(OPTION_WEIGHT1, cmdlineparsing::XMLGenerator::paramType::DOUBLE); addOptionWithDefaultValue(OPTION_WEIGHT2, OPTION_GROUP_REQUIRED, "Specifies the weight for dose 2.", 1.0, "1.0", 'z', true); addInformationForXML(OPTION_WEIGHT2, cmdlineparsing::XMLGenerator::paramType::DOUBLE); addOptionWithDefaultValue(OPTION_REGISTRATION_FILENAME, OPTION_GROUP_REQUIRED, "Specifies name and location of the registration file that should be used to map dose 2 before accumulating it with dose 1." "The registration should be stored as MatchPoint registration.", "", "no mapping", 'r', true); addInformationForXML(OPTION_REGISTRATION_FILENAME, cmdlineparsing::XMLGenerator::paramType::INPUT, { "mapr" }); - std::vector defaultLoadingStyle; - defaultLoadingStyle.push_back("dicom"); - std::string doseLoadStyleDescription = "Options are:\n \"dicom\": normal dicom dose\n" - "\"itk\": use itk image loading\n\"helax\": load a helax dose (choosing this style, the dose path should only be a directory)."; + std::string defaultLoadingStyle; + defaultLoadingStyle = "dicom"; + std::string doseLoadStyleDescription = "Options are:" + "\ndicom: normal dicom dose" + "\nitk: use itk image loading" + "\nitkDicom: use itk dicom image loading" + "\nhelax: load a helax dose (choosing this style, the dose path should only be a directory)."; - addOptionWithDefaultValue >(OPTION_LOAD_STYLE_DOSE1, OPTION_GROUP_REQUIRED, + addOptionWithDefaultValue(OPTION_LOAD_STYLE_DOSE1, OPTION_GROUP_REQUIRED, "Load style for dose 1. " + doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), + defaultLoadingStyle, defaultLoadingStyle, 't', true, true); - addInformationForXML(OPTION_LOAD_STYLE_DOSE1, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom","itk","helax" }); + addInformationForXML(OPTION_LOAD_STYLE_DOSE1, cmdlineparsing::XMLGenerator::paramType::STRING); - addOptionWithDefaultValue >(OPTION_LOAD_STYLE_DOSE2, OPTION_GROUP_REQUIRED, + addOptionWithDefaultValue(OPTION_LOAD_STYLE_DOSE2, OPTION_GROUP_REQUIRED, "Load style for dose 2. See " + OPTION_LOAD_STYLE_DOSE1, - defaultLoadingStyle, defaultLoadingStyle.at(0), + defaultLoadingStyle, defaultLoadingStyle, 'u', true, true); - addInformationForXML(OPTION_LOAD_STYLE_DOSE2, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom","itk","helax" }); + addInformationForXML(OPTION_LOAD_STYLE_DOSE2, cmdlineparsing::XMLGenerator::paramType::STRING); addOptionWithDefaultValue(OPTION_OPERATOR, OPTION_GROUP_REQUIRED, "Specifies the operator used. Available operators are '+' and '*'. Operator '*' has implemented no weight option.", "+", "+", 'p', true); addInformationForXML(OPTION_OPERATOR, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "+","*"}); addPositionalOption(OPTION_DOSE1_FILENAME, 1); addPositionalOption(OPTION_DOSE2_FILENAME, 1); addPositionalOption(OPTION_OUTPUT_FILENAME, 1); parse(argc, argv); } void DoseAccCmdLineParser::validateInput() const { - std::vector doseLoadStyle1 = get >(OPTION_LOAD_STYLE_DOSE1); - std::string doseLoadStyleAbbreviation1 = doseLoadStyle1.at(0); + std::string doseLoadStyle1 = get(OPTION_LOAD_STYLE_DOSE1); - if (doseLoadStyleAbbreviation1 != "dicom" - && doseLoadStyleAbbreviation1 != "itk" - && doseLoadStyleAbbreviation1 != "helax") + if (doseLoadStyle1 != "dicom" + && doseLoadStyle1 != "itk" + && doseLoadStyle1 != "itkDicom" + && doseLoadStyle1 != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for dose1 file: " + - doseLoadStyleAbbreviation1 + + doseLoadStyle1 + ".\nPlease refer to the help for valid loading style settings."); } - std::vector doseLoadStyle2 = get >(OPTION_LOAD_STYLE_DOSE2); - std::string doseLoadStyleAbbreviation2 = doseLoadStyle2.at(0); + std::string doseLoadStyle2 = get(OPTION_LOAD_STYLE_DOSE2); - if (doseLoadStyleAbbreviation2 != "dicom" - && doseLoadStyleAbbreviation2 != "itk" - && doseLoadStyleAbbreviation2 != "helax") + if (doseLoadStyle2 != "dicom" + && doseLoadStyle2 != "itk" + && doseLoadStyle2 != "itkDicom" + && doseLoadStyle2 != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for dose2 file: " + - doseLoadStyleAbbreviation2 + + doseLoadStyle2 + ".\nPlease refer to the help for valid loading style settings."); } std::string interpolator = get(OPTION_INTERPOLATOR); if (interpolator != "nn" && interpolator != "linear" && interpolator != "rosu") { throw cmdlineparsing::InvalidConstraintException("Unknown interpolator: " + interpolator + ".\nPlease refer to the help for valid interpolator settings."); } std::string operatorString = get(OPTION_OPERATOR); if (operatorString != "+" && operatorString != "*") { throw cmdlineparsing::InvalidConstraintException("Unknown operator: " + operatorString + ".\nPlease refer to the help for valid operator settings."); } if (operatorString == "*"){ double weight1 = get(OPTION_WEIGHT1); double weight2 = get(OPTION_WEIGHT2); if (weight1 != 1.0 || weight2 != 1.0){ throw cmdlineparsing::InvalidConstraintException("Operator \"*\" has no weight option implemented. Options --" + OPTION_WEIGHT1 + " and --" + OPTION_WEIGHT2 + " are invalid."); } } } void DoseAccCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << " Example:" << std::endl << std::endl; std::cout << " DoseAcc dose1.mhd dose2.mhd result.mhd --" + OPTION_LOAD_STYLE_DOSE1 + " itk --" + OPTION_LOAD_STYLE_DOSE2 + " itk --" + OPTION_WEIGHT1 + " 2 -r reg.mapr" << std::endl << std::endl; std::cout << " This will accumulate \"dose1.mhd\" and \"dose2.mhd\" by using \"reg.mapr\" to map dose 2."; std::cout << " For the accumulation, dose 1 will be multiplied by 2. The resulting dose will be stored in \"result.mhd\"." << std::endl << std::endl; } } } } diff --git a/apps/DoseMap/DoseMapApplicationData.cpp b/apps/DoseMap/DoseMapApplicationData.cpp index edae0f0..3af2ef6 100644 --- a/apps/DoseMap/DoseMapApplicationData.cpp +++ b/apps/DoseMap/DoseMapApplicationData.cpp @@ -1,73 +1,66 @@ // ----------------------------------------------------------------------- // 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: 1145 $ (last changed revision) -// @date $Date: 2015-10-12 17:06:10 +0200 (Mo, 12 Okt 2015) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "DoseMapApplicationData.h" #include "DoseMapCmdLineParser.h" namespace rttb { namespace apps { namespace doseMap { ApplicationData:: ApplicationData() { this->reset(); } void ApplicationData:: reset() { _inputDoseFileName = ""; _refDoseFileName = ""; _outputFileName = ""; _regFileName = ""; _interpolatorName = "linear"; } void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData.reset(); appData._inputDoseFileName = argParser->get(argParser->OPTION_INPUT_DOSE_FILE_NAME); appData._outputFileName = argParser->get(argParser->OPTION_OUTPUT_FILE_NAME); appData._interpolatorName = argParser->get(argParser->OPTION_INTERPOLATOR); appData._regFileName = argParser->get(argParser->OPTION_REG_FILE_NAME); - appData._inputDoseLoadStyle = argParser->get > (argParser->OPTION_INPUT_DOSE_LOAD_STYLE); + appData._inputDoseLoadStyle = argParser->get(argParser->OPTION_INPUT_DOSE_LOAD_STYLE); if (!argParser->isSet(argParser->OPTION_REF_DOSE_FILE)){ appData._refDoseFileName = argParser->get(argParser->OPTION_INPUT_DOSE_FILE_NAME); - appData._refDoseLoadStyle = argParser->get >(argParser->OPTION_INPUT_DOSE_LOAD_STYLE); - } - else{ + appData._refDoseLoadStyle = argParser->get(argParser->OPTION_INPUT_DOSE_LOAD_STYLE); + } else { appData._refDoseFileName = argParser->get(argParser->OPTION_REF_DOSE_FILE); - appData._refDoseLoadStyle = argParser->get >(argParser->OPTION_REF_DOSE_LOAD_STYLE); + appData._refDoseLoadStyle = argParser->get(argParser->OPTION_REF_DOSE_LOAD_STYLE); } } } } } \ No newline at end of file diff --git a/apps/DoseMap/DoseMapApplicationData.h b/apps/DoseMap/DoseMapApplicationData.h index 3cebc22..517d754 100644 --- a/apps/DoseMap/DoseMapApplicationData.h +++ b/apps/DoseMap/DoseMapApplicationData.h @@ -1,77 +1,66 @@ // ----------------------------------------------------------------------- // 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) -*/ - #ifndef __DOSEMAP_APPLICATION_DATA_H #define __DOSEMAP_APPLICATION_DATA_H #include "mapRegistration.h" #include "rttbDoseAccessorInterface.h" namespace rttb { namespace apps { namespace doseMap { class DoseMapCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in DoseMap */ class ApplicationData { public: typedef map::core::Registration<3, 3> RegistrationType; - /**Vector of arguments used to specify the loading style (always the first argument) - * and, if needed, additional arguments for the specified loading style. - */ - typedef std::vector LoadingStyleArgType; /** Loaded Dose.*/ core::DoseAccessorInterface::DoseAccessorPointer _inputDose; std::string _inputDoseFileName; - LoadingStyleArgType _inputDoseLoadStyle; + std::string _inputDoseLoadStyle; core::DoseAccessorInterface::DoseAccessorPointer _refDose; std::string _refDoseFileName; - LoadingStyleArgType _refDoseLoadStyle; + std::string _refDoseLoadStyle; RegistrationType::Pointer _spReg; std::string _regFileName; std::string _outputFileName; std::string _interpolatorName; void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the DoseToolCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/DoseMap/DoseMapCmdLineParser.cpp b/apps/DoseMap/DoseMapCmdLineParser.cpp index 747af67..ac1c12b 100644 --- a/apps/DoseMap/DoseMapCmdLineParser.cpp +++ b/apps/DoseMap/DoseMapCmdLineParser.cpp @@ -1,115 +1,112 @@ // ----------------------------------------------------------------------- // 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: 1145 $ (last changed revision) -// @date $Date: 2015-10-12 17:06:10 +0200 (Mo, 12 Okt 2015) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "DoseMapCmdLineParser.h" namespace rttb { namespace apps { namespace doseMap { DoseMapCmdLineParser::DoseMapCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version) : CmdLineParserBase(name, version) { - std::vector defaultLoadingStyle; - defaultLoadingStyle.push_back("dicom"); - std::string doseLoadStyleDescription = "Indicates the load style that should be used for the input dose. Available styles: \"dicom\": normal dicom dose (default);" - "\"itk\": use itk image loading; \"helax\": load a helax dose (choosing this style, the dose path should only be a directory)."; + std::string defaultLoadingStyle; + defaultLoadingStyle = "dicom"; + std::string doseLoadStyleDescription = "Indicates the load style that should be used for the input dose. Available styles:" + "\ndicom: normal dicom dose (default)" + "\nitk: use itk image loading" + "\nitkDicom: use itk dicom image loading" + "\nhelax: load a helax dose (choosing this style, the dose path should only be a directory)."; addOption(OPTION_INPUT_DOSE_FILE_NAME, OPTION_GROUP_REQUIRED, "The name of the input dose file. Can be omitted if used as positional argument (see above).", 'd', true); addOption(OPTION_OUTPUT_FILE_NAME, OPTION_GROUP_REQUIRED, "The name of the output file. Can be omitted if used as positional argument (see above).", 'o', true); addOptionWithDefaultValue(OPTION_INTERPOLATOR, OPTION_GROUP_REQUIRED, "Specifies the interpolator that should be used for mapping." "Available options are: \"nn\": nearest neighbor,\"linear\": linear interpolation, \"rosu\" interpolation based on the concept of Rosu et al..", "linear", "linear", 'i', true); addOptionWithDefaultValue(OPTION_REG_FILE_NAME, OPTION_GROUP_REQUIRED, "Specifies name and location of the registration file that should be used to map the input dose. " "Default is no mapping, thus an identity transform is used. The registration should be stored as MatchPoint registration.", "", "no mapping", 'r',true); addOption(OPTION_REF_DOSE_FILE, OPTION_GROUP_OPTIONAL, "Specifies name and location of the dose file that should be the reference/template for the grid to map into. " "If flag is not specified, the input dose is the reference.", 't'); - addOptionWithDefaultValue >(OPTION_INPUT_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0),'l',true); + addOptionWithDefaultValue(OPTION_INPUT_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, doseLoadStyleDescription, + defaultLoadingStyle, defaultLoadingStyle, 'l', true); - addOptionWithDefaultValue >(OPTION_REF_DOSE_LOAD_STYLE, OPTION_GROUP_OPTIONAL, doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), 's', true); + addOptionWithDefaultValue(OPTION_REF_DOSE_LOAD_STYLE, OPTION_GROUP_OPTIONAL, doseLoadStyleDescription, + defaultLoadingStyle, defaultLoadingStyle, 's', true); addPositionalOption(OPTION_INPUT_DOSE_FILE_NAME, 1); addPositionalOption(OPTION_OUTPUT_FILE_NAME, 1); parse(argc, argv); } void DoseMapCmdLineParser::validateInput() const { auto interpolator = get(OPTION_INTERPOLATOR); if (interpolator != "nn" && interpolator != "linear" && interpolator != "rosu") { throw cmdlineparsing::InvalidConstraintException("Unknown interpolator: " + interpolator + ".\nPlease refer to the help for valid interpolator settings."); } - std::vector inputDoseLoadStyle = get >(OPTION_INPUT_DOSE_LOAD_STYLE); - std::string indoseLoadStyleAbbreviation = inputDoseLoadStyle.at(0); - if (indoseLoadStyleAbbreviation != "dicom" && indoseLoadStyleAbbreviation != "itk" && indoseLoadStyleAbbreviation != "helax") + std::string inputDoseLoadStyle = get(OPTION_INPUT_DOSE_LOAD_STYLE); + + if (inputDoseLoadStyle != "dicom" && inputDoseLoadStyle != "itk" && inputDoseLoadStyle != "itkDicom" && inputDoseLoadStyle != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for input dose file: " + - indoseLoadStyleAbbreviation + + inputDoseLoadStyle + ".\nPlease refer to the help for valid loading style settings."); } if (isSet(OPTION_REF_DOSE_FILE)){ - std::vector refDoseLoadStyle = get >(OPTION_REF_DOSE_LOAD_STYLE); - std::string refDoseLoadStyleAbbreviation = refDoseLoadStyle.at(0); - if (refDoseLoadStyleAbbreviation != "dicom" && refDoseLoadStyleAbbreviation != "itk" && refDoseLoadStyleAbbreviation != "helax") + std::string refDoseLoadStyle = get(OPTION_REF_DOSE_LOAD_STYLE); + + if (refDoseLoadStyle != "dicom" && refDoseLoadStyle != "itk" && refDoseLoadStyle != "itkDicom" && refDoseLoadStyle != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for reference dose file: " + - refDoseLoadStyleAbbreviation + + refDoseLoadStyle + ".\nPlease refer to the help for valid loading style settings."); } } } void DoseMapCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << "Example:" << std::endl << std::endl; std::cout << m_programName << " dose1.mhd result.mhd -r reg.mapr --" << OPTION_INPUT_DOSE_LOAD_STYLE << " itk --" << OPTION_REF_DOSE_LOAD_STYLE+ " itk" << std::endl << std::endl; std::cout << "This will map \"dose1.mhd\" by using \"reg.mapr\" into the grid geometry of the input dose. The resulting dose will be stored in \"result.mhd\"." << std::endl; } } } } diff --git a/apps/DoseTool/DoseTool.cpp b/apps/DoseTool/DoseTool.cpp index a12b793..7ea8b3d 100644 --- a/apps/DoseTool/DoseTool.cpp +++ b/apps/DoseTool/DoseTool.cpp @@ -1,170 +1,164 @@ // ----------------------------------------------------------------------- // 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: 1315 $ (last changed revision) -// @date $Date: 2016-04-12 14:18:24 +0200 (Di, 12 Apr 2016) $ (last change date) -// @author $Author: floca $ (last changed by) -*/ #include "DoseToolApplicationData.h" #include "DoseToolHelper.h" #include "DoseToolCmdLineParser.h" #include "boost/shared_ptr.hpp" #include "boost/make_shared.hpp" #include "RTToolboxConfigure.h" #include "rttbException.h" #include "rttbDoseLoader.cpp" #include "rttbStructLoader.cpp" /*! \file DoseTool.cpp main function for DoseTool */ int main(int argc, const char** argv) { int result = 0; rttb::apps::doseTool::ApplicationData appData; boost::shared_ptr argParser; const std::string appCategory = "RT-Toolbox App"; const std::string appName = "DoseTool"; const std::string appDesc = "An App to calculate the dose statistics and compute the DVH. The GUI for this app is currently under development and in an experimental state."; const std::string appContributor = "SIDT@DKFZ"; const std::string appVersion = RTTB_FULL_VERSION_STRING; try { argParser = boost::make_shared(argc, argv, appName, appVersion, appDesc, appContributor, appCategory); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 5; } // This is vital. The application needs to exit if the "help" or "version" parameter is set // because this means the other parameters won't be parsed. if (argParser->isSet(argParser->OPTION_HELP) || argParser->isSet(argParser->OPTION_VERSION) || argParser->isSet(argParser->OPTION_XML)) { return 0; } rttb::apps::doseTool::populateAppData(argParser, appData); std::cout << std::endl << "*******************************************" << std::endl; std::cout << "Dose file: " << appData._doseFileName << std::endl; std::cout << "Struct file: " << appData._structFileName << std::endl; std::cout << "Struct name: " << appData._structNameRegex << std::endl; if (appData._computeDoseStatistics) { std::cout << "Dose statistic output file: " << appData._doseStatisticOutputFileName << std::endl; std::cout << "Compute complex statistics: " << appData._computeComplexDoseStatistics << std::endl; if (appData._computeComplexDoseStatistics) { std::cout << "Prescribed dose: " << appData._prescribedDose << std::endl; } std::cout << "Allow self intersections: " << appData._allowSelfIntersection << std::endl; } if (appData._computeDVH) { std::cout << "DVH output file: " << appData._dvhOutputFilename << std::endl; } std::cout << std::endl << "read dose file... "; try { appData._dose = rttb::io::utils::loadDose(appData._doseFileName, appData._doseLoadStyle); std::cout << "done." << std::endl; } catch (rttb::core::Exception& e) { std::cerr << "RTTB Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 1; } catch (const std::exception& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 1; } catch (...) { std::cerr << "Error!!! unknown error while reading dose image." << std::endl; return 1; } //loading of structure file not necessary in ITK case as it can be used directly as mask input. - if (appData._structLoadStyle.front() != "itk") + if (appData._structLoadStyle != "itk" && appData._structLoadStyle != "itkDicom") { try { appData._struct = rttb::io::utils::loadStruct(appData._structFileName, appData._structLoadStyle, appData._structNameRegex); } catch (rttb::core::Exception& e) { std::cerr << "RTTB Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 2; } catch (const std::exception& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 2; } catch (...) { std::cerr << "Error!!! unknown error while reading struct image." << std::endl; return 2; } } try { rttb::apps::doseTool::processData(appData); } catch (rttb::core::Exception& e) { std::cerr << "RTTB Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 3; } catch (std::exception& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 3; } catch (...) { std::cerr << "Error!!! unknown error while processing the data or writing the image." << std::endl; return 3; } return result; } diff --git a/apps/DoseTool/DoseToolApplicationData.cpp b/apps/DoseTool/DoseToolApplicationData.cpp index 439ebd0..396f780 100644 --- a/apps/DoseTool/DoseToolApplicationData.cpp +++ b/apps/DoseTool/DoseToolApplicationData.cpp @@ -1,91 +1,75 @@ // ----------------------------------------------------------------------- // 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) -*/ #include "DoseToolApplicationData.h" #include "DoseToolCmdLineParser.h" namespace rttb { namespace apps { namespace doseTool { - ApplicationData:: - ApplicationData() - { + ApplicationData::ApplicationData() { this->reset(); } - void - ApplicationData:: - reset() - { + void ApplicationData::reset() { _doseFileName = ""; _structFileName = ""; _structNameRegex = ""; _doseStatisticOutputFileName = ""; _computeComplexDoseStatistics = false; _allowSelfIntersection = false; _structNames.clear(); _prescribedDose = 1.0; _multipleStructsMode = false; _computeDVH = false; _computeDoseStatistics = false; } - void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) - { + void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData._doseFileName = argParser->get(argParser->OPTION_DOSE_FILE); - appData._doseLoadStyle = argParser->get > + appData._doseLoadStyle = argParser->get (argParser->OPTION_DOSE_LOAD_STYLE); appData._structFileName = argParser->get(argParser->OPTION_STRUCT_FILE); - appData._structLoadStyle = argParser->get > + appData._structLoadStyle = argParser->get (argParser->OPTION_STRUCT_LOAD_STYLE); appData._structNameRegex = argParser->get(argParser->OPTION_STRUCT_NAME); appData._multipleStructsMode = argParser->isSet(argParser->OPTION_MULTIPLE_STRUCTS_MODE); - if (argParser->isSet(argParser->OPTION_DOSE_STATISTICS)) - { + if (argParser->isSet(argParser->OPTION_DOSE_STATISTICS)) { appData._computeDoseStatistics = true; appData._doseStatisticOutputFileName = argParser->get (argParser->OPTION_DOSE_STATISTICS); appData._computeComplexDoseStatistics = argParser->isSet(argParser->OPTION_COMPLEX_STATISTICS); appData._allowSelfIntersection = argParser->isSet(argParser->OPTION_ALLOW_SELF_INTERSECTION_STRUCT); } - if (argParser->isSet(argParser->OPTION_DVH)) - { + if (argParser->isSet(argParser->OPTION_DVH)) { appData._computeDVH = true; appData._dvhOutputFilename = argParser->get(argParser->OPTION_DVH); } - if (argParser->isSet(argParser->OPTION_DOSE_STATISTICS) - && argParser->isSet(argParser->OPTION_PRESCRIBED_DOSE)) - { + if (argParser->isSet(argParser->OPTION_DOSE_STATISTICS) && argParser->isSet(argParser->OPTION_PRESCRIBED_DOSE)) { appData._prescribedDose = argParser->get(argParser->OPTION_PRESCRIBED_DOSE); } } } } } diff --git a/apps/DoseTool/DoseToolApplicationData.h b/apps/DoseTool/DoseToolApplicationData.h index 945c80d..73c0d6a 100644 --- a/apps/DoseTool/DoseToolApplicationData.h +++ b/apps/DoseTool/DoseToolApplicationData.h @@ -1,77 +1,66 @@ // ----------------------------------------------------------------------- // 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) -*/ - #ifndef __DOSETOOL_APPLICATION_DATA_H #define __DOSETOOL_APPLICATION_DATA_H #include #include "rttbDoseAccessorInterface.h" #include "rttbStructureSetGeneratorInterface.h" namespace rttb { namespace apps { namespace doseTool { class DoseToolCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in DoseTool */ class ApplicationData { public: - /**Vector of arguments used to specify the loading style (always the first argument) - * and, if needed, additional arguments for the specified loading style. - */ - typedef std::vector LoadingStyleArgType; core::DoseAccessorInterface::DoseAccessorPointer _dose; core::StructureSetGeneratorInterface::StructureSetPointer _struct; std::string _structNameRegex; std::vector _structNames; - std::string _doseFileName; - std::string _structFileName; - LoadingStyleArgType _doseLoadStyle; - LoadingStyleArgType _structLoadStyle; + std::string _doseFileName; + std::string _structFileName; + std::string _doseLoadStyle; + std::string _structLoadStyle; bool _computeComplexDoseStatistics; DoseTypeGy _prescribedDose; - std::string _doseStatisticOutputFileName; + std::string _doseStatisticOutputFileName; bool _allowSelfIntersection; bool _multipleStructsMode; bool _computeDVH; bool _computeDoseStatistics; std::string _dvhOutputFilename; /*! @brief Resets the variables. _prescribedDose is set to 1.0 because it produces no exception then (as it is not needed). Consistency checks are done in DoseToolCmdLineParser::validateInput() */ void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the DoseToolCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/DoseTool/DoseToolCmdLineParser.cpp b/apps/DoseTool/DoseToolCmdLineParser.cpp index 7dee71c..757b638 100644 --- a/apps/DoseTool/DoseToolCmdLineParser.cpp +++ b/apps/DoseTool/DoseToolCmdLineParser.cpp @@ -1,185 +1,180 @@ // ----------------------------------------------------------------------- // 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: 1374 $ (last changed revision) -// @date $Date: 2016-05-30 14:15:42 +0200 (Mo, 30 Mai 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include "DoseToolCmdLineParser.h" namespace rttb { namespace apps { namespace doseTool { DoseToolCmdLineParser::DoseToolCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category) : CmdLineParserBase(name, version, description, contributor, category) { //REQUIRED using DoseTypeGy = double; addOption(OPTION_DOSE_FILE, OPTION_GROUP_REQUIRED, "The name of the dose file. Can be omitted if used as " "positional argument (see above).", 'd', true); addInformationForXML(OPTION_DOSE_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOption(OPTION_STRUCT_FILE, OPTION_GROUP_REQUIRED, "The name of the struct file. Can be omitted if used as " "positional argument (see above).", 's', true); addInformationForXML(OPTION_STRUCT_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, { "*" }); addOptionWithDefaultValue(OPTION_STRUCT_NAME, OPTION_GROUP_REQUIRED, "The name of the struct as regular expression. Can be omitted if used as " "positional argument or with itk struct loadingStyle (see above).", "", "", 'n', true); addInformationForXML(OPTION_STRUCT_NAME, cmdlineparsing::XMLGenerator::paramType::STRING); addPositionalOption(OPTION_DOSE_FILE, 1); addPositionalOption(OPTION_STRUCT_FILE, 1); addPositionalOption(OPTION_STRUCT_NAME, 1); addPositionalOption(OPTION_DOSE_STATISTICS, 1); - std::vector defaultLoadingStyle; - defaultLoadingStyle.push_back("dicom"); - std::string doseLoadStyleDescription = "\"dicom\": normal dicom dose\n" - "\"itk\": use itk image loading\n\"helax\": load a helax dose (choosing this style, the dose path should only be a directory)."; + std::string defaultLoadingStyle = "dicom"; + std::string doseLoadStyleDescription = "Available styles:" + "\ndicom: normal dicom dose (default)" + "\nitk: use itk image loading" + "\nitkDicom: use itk dicom image loading" + "\nhelax: load a helax dose (choosing this style, the dose path should only be a directory)."; - addOptionWithDefaultValue >(OPTION_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, + addOptionWithDefaultValue(OPTION_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, doseLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), + defaultLoadingStyle, defaultLoadingStyle, 't', true, true); - addInformationForXML(OPTION_DOSE_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom", "itk", "helax" }); + addInformationForXML(OPTION_DOSE_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRING); std::string structLoadStyleDescription = "\"dicom\": normal dicom dose\n" "\"itk\": use itk image loading\""; - addOptionWithDefaultValue >(OPTION_STRUCT_LOAD_STYLE, + addOptionWithDefaultValue(OPTION_STRUCT_LOAD_STYLE, OPTION_GROUP_REQUIRED, structLoadStyleDescription, - defaultLoadingStyle, defaultLoadingStyle.at(0), + defaultLoadingStyle, defaultLoadingStyle, 'u', true, true); - addInformationForXML(OPTION_STRUCT_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom", "itk"}); + addInformationForXML(OPTION_STRUCT_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRING); //OPTIONAL addOption(OPTION_DOSE_STATISTICS, OPTION_GROUP_OPTIONAL, "If dose statistics should be computed. The argument is the output file. Can be omitted if used as " "positional argument (see above).", 'y'); addInformationForXML(OPTION_DOSE_STATISTICS, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "*" }); addOption(OPTION_DVH, OPTION_GROUP_OPTIONAL, "If the DVH should be computed. The argument is the output file", 'z'); addInformationForXML(OPTION_DVH, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "*" }); addOption(OPTION_COMPLEX_STATISTICS, OPTION_GROUP_OPTIONAL, "If the complex dose statistics (Dx, Vx, MOHx, MOCx, MaxOHx, MinOCx) should be computed.", 'f'); addInformationForXML(OPTION_COMPLEX_STATISTICS, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_PRESCRIBED_DOSE, OPTION_GROUP_OPTIONAL, "The prescribed dose in Gy.", 'p'); addInformationForXML(OPTION_PRESCRIBED_DOSE, cmdlineparsing::XMLGenerator::paramType::DOUBLE); addOption(OPTION_ALLOW_SELF_INTERSECTION_STRUCT, OPTION_GROUP_OPTIONAL, "If a struct file contains self intersecting contours: Allow the processing of these structures and ignore potential problems." "WARNING: only use this parameter if you know what you are doing.", 'a'); addInformationForXML(OPTION_ALLOW_SELF_INTERSECTION_STRUCT, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_MULTIPLE_STRUCTS_MODE, OPTION_GROUP_OPTIONAL, "If the regex agrees with multiple structs: write a dose statistic for every struct file." "The struct name will be appended to the chosen output filename.", 'm'); addInformationForXML(OPTION_MULTIPLE_STRUCTS_MODE, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); parse(argc, argv); } void DoseToolCmdLineParser::validateInput() const { - std::vector doseLoadStyle = get >(OPTION_DOSE_LOAD_STYLE); - std::string doseLoadStyleAbbreviation = doseLoadStyle.at(0); + std::string doseLoadStyle = get(OPTION_DOSE_LOAD_STYLE); - if (doseLoadStyleAbbreviation != "dicom" - && doseLoadStyleAbbreviation != "itk" - && doseLoadStyleAbbreviation != "helax") + if (doseLoadStyle != "dicom" + && doseLoadStyle != "itk" + && doseLoadStyle != "itkDicom" + && doseLoadStyle != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for dose file:" + - doseLoadStyleAbbreviation + + doseLoadStyle + ".\nPlease refer to the help for valid loading style settings."); } - std::vector structLoadStyle = get >(OPTION_STRUCT_LOAD_STYLE); - std::string structLoadStyleAbbreviation = structLoadStyle.at(0); + std::string structLoadStyle = get(OPTION_STRUCT_LOAD_STYLE); - if (structLoadStyleAbbreviation != "dicom" - && structLoadStyleAbbreviation != "itk") + if (structLoadStyle != "dicom" + && structLoadStyle != "itk" + && structLoadStyle != "itkDicom") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for struct file:" + - structLoadStyleAbbreviation + + structLoadStyle + ".\nPlease refer to the help for valid loading style settings."); } - if (structLoadStyleAbbreviation == "dicom" - || structLoadStyleAbbreviation == "helax") + if (structLoadStyle == "dicom" || structLoadStyle == "helax") { if (get(OPTION_STRUCT_NAME) == "") { throw cmdlineparsing::InvalidConstraintException("The struct name (--" + OPTION_STRUCT_NAME + ") has to be defined for dicom or helax struct files."); } } if (!isSet(OPTION_DVH) && !isSet(OPTION_DOSE_STATISTICS)) { throw cmdlineparsing::InvalidConstraintException("Neither the Dose statistics (--" + OPTION_DOSE_STATISTICS + "), nor the DVH (--" + OPTION_DVH + ") option was used."); } if (isSet(OPTION_DOSE_STATISTICS) && isSet(OPTION_COMPLEX_STATISTICS)) { if (!isSet(OPTION_PRESCRIBED_DOSE)) { throw cmdlineparsing::InvalidConstraintException("The prescribed dose (--" + OPTION_PRESCRIBED_DOSE + ") has to be set for computation of complex dose statistics."); } else { if (get(OPTION_PRESCRIBED_DOSE) <= 0) { throw cmdlineparsing::InvalidConstraintException("The prescribed dose (--" + OPTION_PRESCRIBED_DOSE + ") has to be >0!"); } } } } void DoseToolCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << "Example:" << std::endl << std::endl; std::cout << m_programName << " dose.dcm struct.dcm Liver result.xml --" + OPTION_DVH + " dvh.xml" << std::endl << std::endl; std::cout << "This will calculate the Dose statistic for liver using \"dose.dcm\" and the struct file \"struct.dcm\" and will write the dose statistics to \"result.xml\". " " The DVH is computed as well, its values are written to \"dvh.xml\". " << std::endl; } } } } diff --git a/apps/DoseTool/DoseToolHelper.cpp b/apps/DoseTool/DoseToolHelper.cpp index 000f454..484298b 100644 --- a/apps/DoseTool/DoseToolHelper.cpp +++ b/apps/DoseTool/DoseToolHelper.cpp @@ -1,245 +1,199 @@ // ----------------------------------------------------------------------- // 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: 1374 $ (last changed revision) -// @date $Date: 2016-05-30 14:15:42 +0200 (Mo, 30 Mai 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ - #include "DoseToolHelper.h" #include "boost/make_shared.hpp" #include "boost/shared_ptr.hpp" #include "boost/property_tree/ptree.hpp" #include "boost/property_tree/xml_parser.hpp" #include "boost/filesystem.hpp" #include "DoseToolApplicationData.h" #include "rttbDicomFileStructureSetGenerator.h" #include "rttbITKImageFileMaskAccessorGenerator.h" #include "rttbDoseStatistics.h" #include "rttbDVH.h" #include "rttbDVHCalculator.h" #include "rttbDVHXMLFileWriter.h" #include "rttbDoseStatisticsCalculator.h" #include "rttbBoostMaskAccessor.h" #include "rttbGenericMaskedDoseIterator.h" #include "rttbDoseStatisticsXMLWriter.h" -std::vector -rttb::apps::doseTool::generateMasks( - rttb::apps::doseTool::ApplicationData& appData) -{ +std::vector rttb::apps::doseTool::generateMasks(rttb::apps::doseTool::ApplicationData& appData) { + std::vector maskAccessorPtrVector; - if (appData._structLoadStyle.front() == "itk") - { - maskAccessorPtrVector.push_back(rttb::io::itk::ITKImageFileMaskAccessorGenerator( - appData._structFileName).generateMaskAccessor()); + if (appData._structLoadStyle == "itk" || appData._structLoadStyle == "itkDicom") { + maskAccessorPtrVector.push_back(rttb::io::itk::ITKImageFileMaskAccessorGenerator(appData._structFileName).generateMaskAccessor()); appData._structNames.push_back(appData._structNameRegex); - } - else - { - if (appData._struct->getNumberOfStructures() > 0) { - //default behavior: read only first struct that matches the regex - unsigned int maxIterationCount = 1; - - //only if specified: read all structs that matches the regex - if (appData._multipleStructsMode) - { - maxIterationCount = appData._struct->getNumberOfStructures(); - } - - bool strict = !appData._allowSelfIntersection; - - for (size_t i = 0; i < maxIterationCount; i++) - { - maskAccessorPtrVector.emplace_back(boost::make_shared - (appData._struct->getStructure(i), appData._dose->getGeometricInfo(), strict)); - maskAccessorPtrVector.at(i)->updateMask(); - appData._structNames.push_back(appData._struct->getStructure(i)->getLabel()); - } - } - else { - std::cout << "no structures in structure set!" << std::endl; - } + } else { + if (appData._struct->getNumberOfStructures() > 0) { + //default behavior: read only first struct that matches the regex + unsigned int maxIterationCount = 1; + + //only if specified: read all structs that matches the regex + if (appData._multipleStructsMode) { + maxIterationCount = appData._struct->getNumberOfStructures(); + } + + bool strict = !appData._allowSelfIntersection; + + for (size_t i = 0; i < maxIterationCount; i++) { + maskAccessorPtrVector.emplace_back(boost::make_shared(appData._struct->getStructure(i), appData._dose->getGeometricInfo(), strict)); + maskAccessorPtrVector.at(i)->updateMask(); + appData._structNames.push_back(appData._struct->getStructure(i)->getLabel()); + } + } else { + std::cout << "no structures in structure set!" << std::endl; + } } return maskAccessorPtrVector; } -rttb::core::DoseIteratorInterface::DoseIteratorPointer -rttb::apps::doseTool::generateMaskedDoseIterator( - rttb::core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr, - rttb::core::DoseAccessorInterface::DoseAccessorPointer doseAccessorPtr) -{ - boost::shared_ptr maskedDoseIterator = - boost::make_shared(maskAccessorPtr, doseAccessorPtr); +rttb::core::DoseIteratorInterface::DoseIteratorPointer rttb::apps::doseTool::generateMaskedDoseIterator( + rttb::core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr, + rttb::core::DoseAccessorInterface::DoseAccessorPointer doseAccessorPtr) { + + boost::shared_ptr maskedDoseIterator = boost::make_shared(maskAccessorPtr, doseAccessorPtr); rttb::core::DoseIteratorInterface::DoseIteratorPointer doseIterator(maskedDoseIterator); return doseIterator; } -rttb::algorithms::DoseStatistics::DoseStatisticsPointer -calculateDoseStatistics( - rttb::core::DoseIteratorInterface::DoseIteratorPointer doseIterator, bool calculateComplexDoseStatistics, - rttb::DoseTypeGy prescribedDose) -{ +rttb::algorithms::DoseStatistics::DoseStatisticsPointer calculateDoseStatistics( + rttb::core::DoseIteratorInterface::DoseIteratorPointer doseIterator, + bool calculateComplexDoseStatistics, + rttb::DoseTypeGy prescribedDose) { + rttb::algorithms::DoseStatisticsCalculator doseStatsCalculator(doseIterator); - if (calculateComplexDoseStatistics) - { + if (calculateComplexDoseStatistics) { return doseStatsCalculator.calculateDoseStatistics(prescribedDose); - } - else - { + } else { return doseStatsCalculator.calculateDoseStatistics(); } } -rttb::core::DVH::DVHPointer calculateDVH( - rttb::core::DoseIteratorInterface::DoseIteratorPointer - doseIterator, rttb::IDType structUID, rttb::IDType doseUID) -{ +rttb::core::DVH::DVHPointer calculateDVH(rttb::core::DoseIteratorInterface::DoseIteratorPointer doseIterator, rttb::IDType structUID, rttb::IDType doseUID) { rttb::core::DVHCalculator calc(doseIterator, structUID, doseUID); rttb::core::DVH::DVHPointer dvh = calc.generateDVH(); return dvh; } -std::string rttb::apps::doseTool::assembleFilenameWithStruct(const std::string& originalFilename, - const std::string& structName) -{ +std::string rttb::apps::doseTool::assembleFilenameWithStruct(const std::string& originalFilename, const std::string& structName) { boost::filesystem::path originalFile(originalFilename); - std::string newFilename = originalFile.stem().string() + "_" + structName + - originalFile.extension().string(); + std::string newFilename = originalFile.stem().string() + "_" + structName + originalFile.extension().string(); boost::filesystem::path newFile(originalFile.parent_path() / newFilename); return newFile.string(); } /*! @brief Writes the dose statistics as XML to a file @details adds a .... part to the RTTB generated xml where the used files and struct names are stored. */ -void writeDoseStatisticsFile( - rttb::algorithms::DoseStatistics::DoseStatisticsPointer statistics, - const std::string& filename, const std::string& structName, - rttb::apps::doseTool::ApplicationData& appData) -{ +void writeDoseStatisticsFile(rttb::algorithms::DoseStatistics::DoseStatisticsPointer statistics, + const std::string& filename, + const std::string& structName, + rttb::apps::doseTool::ApplicationData& appData) { + boost::property_tree::ptree originalTree = rttb::io::other::writeDoseStatistics(statistics); //add config part to xml originalTree.add("statistics.config.requestedStructRegex", appData._structNameRegex); originalTree.add("statistics.config.structName", structName); originalTree.add("statistics.config.doseUID", appData._dose->getUID()); originalTree.add("statistics.config.doseFile", appData._doseFileName); originalTree.add("statistics.config.structFile", appData._structFileName); boost::property_tree::ptree reorderedTree, configTree, resultsTree; configTree = originalTree.get_child("statistics.config"); resultsTree = originalTree.get_child("statistics.results"); reorderedTree.add_child("statistics.config", configTree); reorderedTree.add_child("statistics.results", resultsTree); - boost::property_tree::write_xml(filename, reorderedTree, std::locale(), - boost::property_tree::xml_writer_make_settings('\t', 1)); - + boost::property_tree::write_xml(filename, reorderedTree, std::locale(), boost::property_tree::xml_writer_make_settings('\t', 1)); } -void writeDVHFile(rttb::core::DVH::DVHPointer dvh, const std::string& filename) -{ +void writeDVHFile(rttb::core::DVH::DVHPointer dvh, const std::string& filename) { rttb::DVHType typeCum = { rttb::DVHType::Cumulative }; rttb::io::other::DVHXMLFileWriter dvhWriter(filename, typeCum); dvhWriter.writeDVH(dvh); } -void -rttb::apps::doseTool::processData(rttb::apps::doseTool::ApplicationData& appData) -{ +void rttb::apps::doseTool::processData(rttb::apps::doseTool::ApplicationData& appData) { std::cout << std::endl << "generating masks... "; - std::vector maskAccessorPtrVector = generateMasks( - appData); + std::vector maskAccessorPtrVector = generateMasks(appData); std::cout << "done." << std::endl; - for (size_t i = 0; i < maskAccessorPtrVector.size(); i++) - { + for (size_t i = 0; i < maskAccessorPtrVector.size(); i++) { core::DoseIteratorInterface::DoseIteratorPointer spDoseIterator(generateMaskedDoseIterator( maskAccessorPtrVector.at(i), appData._dose)); - if (appData._computeDoseStatistics) - { + if (appData._computeDoseStatistics) { std::cout << std::endl << "computing dose statistics... "; algorithms::DoseStatistics::DoseStatisticsPointer statistics = calculateDoseStatistics( spDoseIterator, appData._computeComplexDoseStatistics, appData._prescribedDose); std::cout << "done." << std::endl; std::cout << std::endl << "writing dose statistics to file... "; std::string outputFilename; - if (appData._multipleStructsMode) - { + if (appData._multipleStructsMode) { outputFilename = assembleFilenameWithStruct(appData._doseStatisticOutputFileName, appData._structNames.at(i)); - } - else - { + } else { outputFilename = appData._doseStatisticOutputFileName; } writeDoseStatisticsFile(statistics, outputFilename, appData._structNames.at(i), appData); std::cout << "done." << std::endl; } - if (appData._computeDVH) - { + if (appData._computeDVH) { std::cout << std::endl << "computing DVH... "; rttb::IDType structUID; rttb::IDType doseUID; + //Generate random UID - if (appData._structLoadStyle.front() == "itk"){ + if (appData._structLoadStyle == "itk") { structUID = "struct42"; doseUID = "dose42"; - } - else { + } else { structUID = appData._struct->getUID(); doseUID = appData._dose->getUID(); } - core::DVH::DVHPointer dvh = calculateDVH(spDoseIterator, structUID, - doseUID); + core::DVH::DVHPointer dvh = calculateDVH(spDoseIterator, structUID, doseUID); std::cout << "done." << std::endl; std::cout << std::endl << "writing DVH to file... "; std::string outputFilename; - if (appData._multipleStructsMode) - { + if (appData._multipleStructsMode) { outputFilename = assembleFilenameWithStruct(appData._dvhOutputFilename, appData._structNames.at(i)); - } - else - { + } else { outputFilename = appData._dvhOutputFilename; } - writeDVHFile(dvh, outputFilename); std::cout << "done." << std::endl; } } - } diff --git a/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp b/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp index 68a0f6a..40228c3 100644 --- a/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp +++ b/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp @@ -1,93 +1,87 @@ // ----------------------------------------------------------------------- // 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) -*/ #include "VoxelizerToolApplicationData.h" #include "VoxelizerToolCmdLineParser.h" namespace rttb { namespace apps { namespace voxelizerTool { ApplicationData:: ApplicationData() { this->reset(); } void ApplicationData:: reset() { _structFile = ""; _referenceFile = ""; _outputFilename = ""; _regEx=""; _multipleStructs = false; _binaryVoxelization = false; _addStructures = false; - _noStrictVoxelization = false; + _noStrictVoxelization = false; } void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData._structFile = argParser->get(argParser->OPTION_STRUCT_FILE); appData._referenceFile = argParser->get(argParser->OPTION_REFERENCE_FILE); appData._outputFilename = argParser->get(argParser->OPTION_OUTPUT_FILE_NAME); - appData._referenceFileLoadStyle = argParser->get>(argParser->OPTION_REFERENCE_FILE_LOAD_STYLE); - //only valid option for reading structs is dicom until now. - appData._structFileLoadStyle.emplace_back("dicom"); + appData._referenceFileLoadStyle = argParser->get(argParser->OPTION_REFERENCE_FILE_LOAD_STYLE); + //only valid option for reading structs is dicom until now. + appData._structFileLoadStyle = "dicom"; appData._regEx = argParser->get(argParser->OPTION_REGEX); if (argParser->isSet(argParser->OPTION_MULTIPLE_STRUCTS)) { appData._multipleStructs = true; if (argParser->isSet(argParser->OPTION_ADDSTRUCTURES)) { appData._addStructures = true; } else { appData._addStructures = false; } } if (argParser->isSet(argParser->OPTION_BINARY_VOXELIZATION)) { appData._binaryVoxelization = true; } if (argParser->isSet(argParser->OPTION_ADDSTRUCTURES)) { appData._multipleStructs = false; appData._addStructures = true; } if (argParser->isSet(argParser->OPTION_NO_STRICT_VOXELIZATION)) { appData._noStrictVoxelization = true; } } } } } diff --git a/apps/VoxelizerTool/VoxelizerToolApplicationData.h b/apps/VoxelizerTool/VoxelizerToolApplicationData.h index 4155d42..f68ee09 100644 --- a/apps/VoxelizerTool/VoxelizerToolApplicationData.h +++ b/apps/VoxelizerTool/VoxelizerToolApplicationData.h @@ -1,73 +1,66 @@ // ----------------------------------------------------------------------- // 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) -*/ #ifndef __VoxelizerApplicationData_h #define __VoxelizerApplicationData_h #include "boost/shared_ptr.hpp" #include "rttbDoseAccessorInterface.h" #include "rttbStructureSetGeneratorInterface.h" #include #include namespace rttb { namespace apps { namespace voxelizerTool { class VoxelizerCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in VoxelizerTool */ class ApplicationData { public: - typedef std::vector LoadingStyleArgType; core::DoseAccessorInterface::DoseAccessorPointer _dose; core::StructureSetGeneratorInterface::StructureSetPointer _struct; std::string _structFile; std::string _referenceFile; std::string _outputFilename; std::string _regEx; - LoadingStyleArgType _referenceFileLoadStyle; - LoadingStyleArgType _structFileLoadStyle; + std::string _referenceFileLoadStyle; + std::string _structFileLoadStyle; bool _multipleStructs; bool _binaryVoxelization; bool _addStructures; bool _noStrictVoxelization; /*! @brief Resets the variables. */ void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the VoxelizerCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp index e0cb7a4..3dae3dd 100644 --- a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp +++ b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp @@ -1,124 +1,115 @@ // ----------------------------------------------------------------------- // 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: strubel $ (last changed by) -*/ #include "VoxelizerToolCmdLineParser.h" namespace rttb { namespace apps { namespace voxelizerTool { VoxelizerCmdLineParser::VoxelizerCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category) : CmdLineParserBase(name, version, description, contributor, category) { //REQUIRED addOption(OPTION_STRUCT_FILE, OPTION_GROUP_REQUIRED, "Filename of the structfile (*.dcm)", 's', true); addInformationForXML(OPTION_STRUCT_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, {"dcm", "*"}); addOption(OPTION_REFERENCE_FILE, OPTION_GROUP_REQUIRED, "Filename of the reference image (*.dcm)", 'r', true); addInformationForXML(OPTION_REFERENCE_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, { "dcm", "*" }); addOptionWithDefaultValue(OPTION_OUTPUT_FILE_NAME, OPTION_GROUP_REQUIRED, "Set output file name. Remark: if it used in conjunction with flag -m, it is only regarded as " "hint for the file name pattern. VoxelizerTool will add a suffix indicating the voxelized " "structure to each filename.","out.hdr","out.hdr", 'o', true); addInformationForXML(OPTION_OUTPUT_FILE_NAME, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "hdr", "nrrd", "*" }); addPositionalOption(OPTION_STRUCT_FILE,1); addPositionalOption(OPTION_REFERENCE_FILE, 1); addPositionalOption(OPTION_OUTPUT_FILE_NAME, 1); - - std::vector defaultLoadingStyle; - defaultLoadingStyle.push_back("dicom"); - addOptionWithDefaultValue(OPTION_REGEX, OPTION_GROUP_REQUIRED, - "set a regular expression describing the structs of interest", "", "",'e', true); + addOption(OPTION_REGEX, OPTION_GROUP_REQUIRED, + "set a regular expression describing the structs of interest",'e', true); addInformationForXML(OPTION_REGEX, cmdlineparsing::XMLGenerator::paramType::STRING); - addOptionWithDefaultValue>(OPTION_REFERENCE_FILE_LOAD_STYLE, OPTION_GROUP_REQUIRED, - "set the load style for the reference file. Available styles are: " - "dicom: normal dicom dose" - "itk: use itk image loading.", defaultLoadingStyle, defaultLoadingStyle.at(0), 'y', true); - addInformationForXML(OPTION_REFERENCE_FILE_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom", "itk" }); + addOptionWithDefaultValue(OPTION_REFERENCE_FILE_LOAD_STYLE, OPTION_GROUP_REQUIRED, + "set the load style for the reference file. Available styles are:" + "\ndicom: normal dicom dose" + "\nitk: use itk image loading" + "\nitkDicom: use itk dicom image loading", "dicom", "dicom", 'y', true); + addInformationForXML(OPTION_REFERENCE_FILE_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRING); //OPTIONAL addOption(OPTION_MULTIPLE_STRUCTS, OPTION_GROUP_OPTIONAL, "if multiple structs match the regular expression" + OPTION_STRUCT_FILE + ", save all in files\n" "If structures 'Kidney_left' and 'Kidney_right' are defined,\n" "both are written under the names outputFile_Kidney_left.mhd and outputFile_Kidney_right.mhd",'m'); addInformationForXML(OPTION_MULTIPLE_STRUCTS, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_BINARY_VOXELIZATION, OPTION_GROUP_OPTIONAL, "Determines if the voxelization should be binarized (only values 0 or 1), the threshold value is by 0.5",'z'); addInformationForXML(OPTION_BINARY_VOXELIZATION, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_ADDSTRUCTURES, OPTION_GROUP_OPTIONAL, "Voxelizes multiple structs in one result file.",'a'); addInformationForXML(OPTION_ADDSTRUCTURES, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_NO_STRICT_VOXELIZATION, OPTION_GROUP_OPTIONAL, "Deviations of wrong voxel volumes are tolerated and corrected.",'i'); addInformationForXML(OPTION_NO_STRICT_VOXELIZATION, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); parse(argc, argv); } void VoxelizerCmdLineParser::validateInput() const { - std::vector referenceLoadStyle = get >(OPTION_REFERENCE_FILE_LOAD_STYLE); - std::string referenceLoadStyleString = referenceLoadStyle.at(0); + std::string referenceLoadStyle = get(OPTION_REFERENCE_FILE_LOAD_STYLE); - if (referenceLoadStyleString != "dicom" && referenceLoadStyleString != "itk") + if (referenceLoadStyle != "dicom" && referenceLoadStyle != "itk" && referenceLoadStyle != "itkDicom") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for reference file:" + - referenceLoadStyleString+ + referenceLoadStyle + ".\nPlease refer to the help for valid loading style settings."); } if (get(OPTION_OUTPUT_FILE_NAME).find('.') == std::string::npos) { throw cmdlineparsing::InvalidConstraintException(OPTION_OUTPUT_FILE_NAME + " has to specify a file format (e.g. output.hdr). None is given: " + get(OPTION_OUTPUT_FILE_NAME) ); } } void VoxelizerCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << "Example: VoxelizerTool -s structFile.dcm -r referenceFile.dcm -e Kidney -o outputFile.mhd -m" << std::endl; std::cout << "Computes a voxelization file outputFile.mhd based on the DICOMRT-STRUCT structFile.dcm " "in the geometry of referenceFile.dcm where "; std::cout << "the name of the struct matches the regular expression 'Kidney'.\n"; std::cout << "If structures 'Kidney_left' and 'Kidney_right' are defined, "; std::cout << "both are written under the names outputFile_Kidney_left.mhd and outputFile_Kidney_right.mhd (parameter -m)." << std::endl; } } } } \ No newline at end of file diff --git a/code/io/itk/rttbITKIOHelper.cpp b/code/io/itk/rttbITKIOHelper.cpp index 74d9fe2..f9f56b6 100644 --- a/code/io/itk/rttbITKIOHelper.cpp +++ b/code/io/itk/rttbITKIOHelper.cpp @@ -1,170 +1,167 @@ // ----------------------------------------------------------------------- // 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 "rttbITKIOHelper.h" #include "rttbException.h" #include "rttbInvalidDoseException.h" #include "rttbInvalidParameterException.h" namespace rttb { namespace io { namespace itk { - ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile) + ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile, bool isDicom) { ITKImageType::Pointer itkDoubleImage; GenericImageReader::Pointer spReader = GenericImageReader::New(); + if (isDicom) { + spReader->setSeriesReadStyle(ImageSeriesReadStyle::Type::Dicom); + } spReader->setFileName(aITKImageFile); GenericImageReader::GenericOutputImageType::Pointer itkGenericImage; ITKImageType::ConstPointer itkDoubleImageConst; try { unsigned int loadedDimensions; GenericImageReader::LoadedPixelType loadedPixelType; GenericImageReader::LoadedComponentType loadedComponentType; itkGenericImage = spReader->GetOutput(loadedDimensions, loadedPixelType, loadedComponentType); if (loadedDimensions != 3) { throw core::InvalidParameterException("image dimensions != 3. Only dim = 3 supported."); } if (loadedPixelType != ::itk::ImageIOBase::SCALAR) { throw core::InvalidParameterException("image component type != SCALAR. Only SCALAR supported."); } if (loadedComponentType == ::itk::ImageIOBase::DOUBLE) { itkDoubleImage = dynamic_cast(itkGenericImage.GetPointer()); } else { itkDoubleImage = handleGenericImage(itkGenericImage, loadedComponentType); } if (itkDoubleImage.IsNull()) { throw core::InvalidDoseException("Error!!! unable to load input image. File is not existing or has an unsupported format."); } } catch (::itk::ExceptionObject& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e << std::endl; throw rttb::core::InvalidDoseException(e.GetDescription()); } return itkDoubleImage; } ITKImageType::Pointer handleGenericImage( GenericImageReader::GenericOutputImageType* itkGenericImage, ::itk::ImageIOBase::IOComponentType& loadedComponentType) { ITKImageType::Pointer itkDoubleImage; switch (loadedComponentType) { case ::itk::ImageIOBase::UCHAR: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::CHAR: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::USHORT: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::SHORT: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::UINT: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::INT: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::ULONG: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::LONG: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::FLOAT: { itkDoubleImage = doCasting(itkGenericImage); break; } case ::itk::ImageIOBase::DOUBLE: { itkDoubleImage = doCasting(itkGenericImage); break; } default: { throw core::InvalidParameterException("image type unknown"); } } return itkDoubleImage; } }//end namespace itk }//end namespace io }//end namespace rttb diff --git a/code/io/itk/rttbITKIOHelper.h b/code/io/itk/rttbITKIOHelper.h index 94d7fd3..eb5598b 100644 --- a/code/io/itk/rttbITKIOHelper.h +++ b/code/io/itk/rttbITKIOHelper.h @@ -1,65 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ + #ifndef __ITK_IO_HELPER_H #define __ITK_IO_HELPER_H #include "rttbBaseType.h" #include "rttbGenericImageReader.h" #include "itkImage.h" namespace rttb { namespace io { namespace itk { typedef ::itk::Image ITKImageType; /*! @brief Read a itk image file into itkImage */ - ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile); + ITKImageType::Pointer readITKDoubleImage(FileNameType aITKImageFile, bool isDicom = false); /*! @brief Converts a generic image to itkImage @param itkGenericImage the image read by GenericImageReader @param loadedComponentType the component type (used for casting later on) @exception InvalidParameterException if component type is not supported @sa GenericImageReader */ ITKImageType::Pointer handleGenericImage(GenericImageReader::GenericOutputImageType* itkGenericImage, ::itk::ImageIOBase::IOComponentType& loadedComponentType); /*! @brief Casts into itkImage */ template ITKImageType::Pointer doCasting( GenericImageReader::GenericOutputImageType* genericImage); }//end namespace itk }//end namespace io }//end namespace rttb #include "rttbITKIOHelper.tpp" #endif diff --git a/code/io/itk/rttbITKImageFileAccessorGenerator.cpp b/code/io/itk/rttbITKImageFileAccessorGenerator.cpp index a6a1096..0e11d04 100644 --- a/code/io/itk/rttbITKImageFileAccessorGenerator.cpp +++ b/code/io/itk/rttbITKImageFileAccessorGenerator.cpp @@ -1,56 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ #include #include #include "rttbITKImageFileAccessorGenerator.h" #include "rttbITKImageAccessorConverter.h" #include "rttbITKIOHelper.h" namespace rttb { namespace io { namespace itk { ITKImageFileAccessorGenerator::~ITKImageFileAccessorGenerator() = default; - ITKImageFileAccessorGenerator::ITKImageFileAccessorGenerator(const FileNameType& fileName) + ITKImageFileAccessorGenerator::ITKImageFileAccessorGenerator(const FileNameType& fileName, const bool& useDicom) { _fileName = fileName; + _useDicom = useDicom; } - rttb::core::DoseAccessorGeneratorBase::DoseAccessorPointer - ITKImageFileAccessorGenerator::generateDoseAccessor() - { - _itkDoubleImage = readITKDoubleImage(_fileName); + rttb::core::DoseAccessorGeneratorBase::DoseAccessorPointer ITKImageFileAccessorGenerator::generateDoseAccessor() { + _itkDoubleImage = readITKDoubleImage(_fileName, _useDicom); _doseAccessor = boost::make_shared(_itkDoubleImage.GetPointer()); return _doseAccessor; } }//end namespace itk }//end namespace io }//end namespace rttb diff --git a/code/io/itk/rttbITKImageFileAccessorGenerator.h b/code/io/itk/rttbITKImageFileAccessorGenerator.h index 1309b33..3425aa9 100644 --- a/code/io/itk/rttbITKImageFileAccessorGenerator.h +++ b/code/io/itk/rttbITKImageFileAccessorGenerator.h @@ -1,77 +1,73 @@ // ----------------------------------------------------------------------- // 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 __ITK_IMAGE_FILE_ACCESSOR_GENERATOR_H #define __ITK_IMAGE_FILE_ACCESSOR_GENERATOR_H #include "rttbDoseAccessorGeneratorBase.h" #include "rttbBaseType.h" #include "itkImage.h" namespace rttb { namespace io { namespace itk { /*! @class ITKImageFileAccessorGenerator @brief Load image data using the itk loading methods and wraps the resulting itk image in a ITKImageAccessor. * this can be used if dose distributions are stored in formats like meta image, nrrd... * @note it implies that the dose information is stored in absolute Gy values. */ class ITKImageFileAccessorGenerator: public core::DoseAccessorGeneratorBase { public: typedef ::itk::Image ITKImageType; using DoseAccessorPointer = DoseAccessorGeneratorBase::DoseAccessorPointer; private: FileNameType _fileName; /** @brief The dose as itkImage */ ITKImageType::Pointer _itkDoubleImage; + + bool _useDicom; ITKImageFileAccessorGenerator() = delete; public: ~ITKImageFileAccessorGenerator() override; - ITKImageFileAccessorGenerator(const FileNameType& fileName); + ITKImageFileAccessorGenerator(const FileNameType& fileName, const bool& useDicom = false); /*! @brief Generate DoseAccessor @return Return shared pointer of DoseAccessor. @exception InvalidDoseException Thrown if file could not be read @exception InvalidParameterException Thrown if file has imageDimension !=3 or image component type != SCALAR @details is always converted into a itkImage by using a CastImageFilter @sa doCasting, handleGenericImage */ DoseAccessorPointer generateDoseAccessor() override; - }; }//end namespace itk }//end namespace io }//end namespace rttb #endif diff --git a/code/io/utils/files.cmake b/code/io/utils/files.cmake index df811f2..6fe84d2 100644 --- a/code/io/utils/files.cmake +++ b/code/io/utils/files.cmake @@ -1,7 +1,9 @@ SET(CPP_FILES rttbDoseLoader.cpp rttbStructLoader.cpp ) SET(H_FILES + rttbDoseLoader.h + rttbStructLoader.h ) diff --git a/code/io/utils/rttbDoseLoader.cpp b/code/io/utils/rttbDoseLoader.cpp index 0596cbe..6c03757 100644 --- a/code/io/utils/rttbDoseLoader.cpp +++ b/code/io/utils/rttbDoseLoader.cpp @@ -1,105 +1,87 @@ // ----------------------------------------------------------------------- // 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 __RTTB_DOSE_LOADER_H -#define __RTTB_DOSE_LOADER_H +#include "rttbDoseLoader.h" -#include "rttbDoseIteratorInterface.h" #include "rttbExceptionMacros.h" #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbDicomHelaxFileDoseAccessorGenerator.h" #include "rttbITKImageFileAccessorGenerator.h" namespace rttb { namespace io { namespace utils { - /*! @brief loads a dicom dose from a file. - @exception Throws an rttb::Exception if loading fails - @sa DicomFileDoseAccessorGenerator - */ rttb::core::DoseAccessorInterface::DoseAccessorPointer loadDicomDose(const std::string& fileName) { rttb::io::dicom::DicomFileDoseAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); } - /*! @brief loads a helax dose from a file. - @exception Throws an rttb::Exception if loading fails - @sa DicomHelaxFileDoseAccessorGenerator - */ rttb::core::DoseAccessorInterface::DoseAccessorPointer loadHelaxDose(const std::string& path) { rttb::io::helax::DicomHelaxFileDoseAccessorGenerator generator(path); return generator.generateDoseAccessor(); } - /*! @brief loads an itk dose from a file. - @exception Throws an rttb::Exception if loading fails. - @details Might be of all formats that ITK know (*.mhd, *.nrrd, ...). The absolute image values are taken as dose. - @sa ITKImageFileAccessorGenerator - */ rttb::core::DoseAccessorInterface::DoseAccessorPointer loadITKDose(const std::string& fileName) { rttb::io::itk::ITKImageFileAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); } - /*! @brief loads a dose from a file based on the loadingStyle. - @params args[0]: determines the loadingStyle - @exception Throws an rttb::Exception if loading fails - */ + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadITKDicomDose(const std::string& fileName) { + rttb::io::itk::ITKImageFileAccessorGenerator generator(fileName, true); + return generator.generateDoseAccessor(); + } + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadDose(const std::string& fileName, - const std::vector& args) + const std::string& loadStyle) { rttb::core::DoseAccessorInterface::DoseAccessorPointer result; - if (args.empty() || args[0] == "dicom") + if (loadStyle == "" || loadStyle == "dicom") { result = loadDicomDose(fileName); } - else if (args[0] == "helax") + else if (loadStyle == "helax") { result = loadHelaxDose(fileName); } - else if (args[0] == "itk") + else if (loadStyle == "itk") { result = loadITKDose(fileName); } + else if (loadStyle == "itkDicom") + { + result = loadITKDicomDose(fileName); + } else { - rttbDefaultExceptionStaticMacro(<< "Unknown io style selected. Cannot load data. Selected style: " - << args[0]); + rttbDefaultExceptionStaticMacro(<< "Unknown io style selected. Cannot load data. Selected style: " << loadStyle); } return result; } } } } -#endif diff --git a/code/io/utils/rttbDoseLoader.h b/code/io/utils/rttbDoseLoader.h new file mode 100644 index 0000000..57ce35c --- /dev/null +++ b/code/io/utils/rttbDoseLoader.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. +// +//------------------------------------------------------------------------ + +#ifndef __RTTB_DOSE_LOADER_H +#define __RTTB_DOSE_LOADER_H + +#include "rttbDoseIteratorInterface.h" + +namespace rttb +{ + namespace io + { + namespace utils + { + /*! @brief loads a dicom dose from a file. + @exception Throws an rttb::Exception if loading fails + @sa DicomFileDoseAccessorGenerator + */ + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadDicomDose(const std::string& fileName); + + /*! @brief loads a helax dose from a file. + @exception Throws an rttb::Exception if loading fails + @sa DicomHelaxFileDoseAccessorGenerator + */ + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadHelaxDose(const std::string& path); + + /*! @brief loads an itk dose from a file. + @exception Throws an rttb::Exception if loading fails. + @details Might be of all formats that ITK know (*.mhd, *.nrrd, ...). The absolute image values are taken as dose. + @sa ITKImageFileAccessorGenerator + */ + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadITKDose(const std::string& fileName); + + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadITKDicomDose(const std::string& fileName); + + /*! @brief loads a dose from a file based on the loadingStyle. + @params args[0]: determines the loadingStyle + @exception Throws an rttb::Exception if loading fails + */ + rttb::core::DoseAccessorInterface::DoseAccessorPointer loadDose(const std::string& fileName, const std::string& loadStyle = "dicom"); + } + } +} +#endif diff --git a/code/io/utils/rttbStructLoader.cpp b/code/io/utils/rttbStructLoader.cpp index 897ebc4..b7f71dd 100644 --- a/code/io/utils/rttbStructLoader.cpp +++ b/code/io/utils/rttbStructLoader.cpp @@ -1,86 +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 __RTTB_STRUCT_LOADER_H -#define __RTTB_STRUCT_LOADER_H - -#include "rttbDicomFileStructureSetGenerator.h" +#include "rttbStructLoader.h" #include "rttbExceptionMacros.h" namespace rttb { namespace io { namespace utils { - using LoadingStyleArgType = std::vector; - - /*! @brief loads a dicom struct from a file. - You may pass a structure name regex. If is not empty, it will be used to filter structure in the - loading process. Only structures with a name matching the reg ex will be loaded. This speeds up the - loading process significantly if you need only one structure out of a structure set. - @exception Throws an rttb::Exception if loading fails - @sa DicomFileStructureSetGenerator - */ rttb::core::StructureSetGeneratorInterface::StructureSetPointer loadDicomStruct( - const std::string& fileName, const std::string& structNameRegex = "") + const std::string& fileName, const std::string& structNameRegex) { rttb::io::dicom::DicomFileStructureSetGenerator generator(fileName); if (!structNameRegex.empty()) { generator.setStructureLabelFilterActive(true); generator.setFilterRegEx(structNameRegex); } return generator.generateStructureSet(); } - /*! @brief loads a struct from a file based on the loadingStyle. - You may pass a structure name regex. If is not empty, it will be used to filter structure in the - loading process. Only structures with a name matching the reg ex will be loaded. This speeds up the - loading process significantly if you need only one structure out of a structure set. - @exception Throws an rttb::Exception if loading fails - @details voxelized itk images are read in generateMask() directly - */ rttb::core::StructureSetGeneratorInterface::StructureSetPointer loadStruct( - const std::string& fileName, const LoadingStyleArgType& args, const std::string& structNameRegex = "") + const std::string& fileName, const std::string& loadStyle, const std::string& structNameRegex) { rttb::core::StructureSetGeneratorInterface::StructureSetPointer result; - if (args.empty() || args[0] == "dicom") + if (loadStyle == "" || loadStyle == "dicom") { result = rttb::io::utils::loadDicomStruct(fileName, structNameRegex); } else { - rttbDefaultExceptionStaticMacro(<< "Unknown io style selected. Cannot load data. Selected style: " - << args[0]); + rttbDefaultExceptionStaticMacro(<< "Unknown io style selected. Cannot load data. Selected style: " << loadStyle); } return result; } } } } -#endif diff --git a/code/io/utils/rttbStructLoader.h b/code/io/utils/rttbStructLoader.h new file mode 100644 index 0000000..f9da50e --- /dev/null +++ b/code/io/utils/rttbStructLoader.h @@ -0,0 +1,52 @@ +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ + +#ifndef __RTTB_STRUCT_LOADER_H +#define __RTTB_STRUCT_LOADER_H + +#include "rttbDicomFileStructureSetGenerator.h" + +namespace rttb { + + namespace io { + + namespace utils { + + /*! @brief loads a dicom struct from a file. + You may pass a structure name regex. If is not empty, it will be used to filter structure in the + loading process. Only structures with a name matching the reg ex will be loaded. This speeds up the + loading process significantly if you need only one structure out of a structure set. + @exception Throws an rttb::Exception if loading fails + @sa DicomFileStructureSetGenerator + */ + rttb::core::StructureSetGeneratorInterface::StructureSetPointer loadDicomStruct(const std::string& fileName, const std::string& structNameRegex = ""); + + + /*! @brief loads a struct from a file based on the loadingStyle. + You may pass a structure name regex. If is not empty, it will be used to filter structure in the + loading process. Only structures with a name matching the reg ex will be loaded. This speeds up the + loading process significantly if you need only one structure out of a structure set. + @exception Throws an rttb::Exception if loading fails + @details voxelized itk images are read in generateMask() directly + */ + rttb::core::StructureSetGeneratorInterface::StructureSetPointer loadStruct( + const std::string& fileName, + const std::string& loadStyle = "dicom", + const std::string& structNameRegex = "" + ); + } + } +} +#endif diff --git a/testing/apps/VoxelizerTool/CMakeLists.txt b/testing/apps/VoxelizerTool/CMakeLists.txt index a5bc8bf..34179ff 100644 --- a/testing/apps/VoxelizerTool/CMakeLists.txt +++ b/testing/apps/VoxelizerTool/CMakeLists.txt @@ -1,29 +1,31 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/rttbVoxelizerToolTests) SET(TEST_DATA ${RTToolbox_BINARY_DIR}/testing/apps/VoxelizerTool) IF (WIN32) SET(VOXELIZERTOOL_EXE "VoxelizerTool") ELSE (WIN32) SET(VOXELIZERTOOL_EXE "./VoxelizerTool") ENDIF (WIN32) SET(STRUCT_FILE "${TEST_DATA_ROOT}/StructureSet/DICOM/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm") SET(REFERENCE_FILE "${TEST_DATA_ROOT}/Dose/DICOM/ConstantTwo.dcm") #----------------------------------------------------------------------------- ADD_TEST(VoxelizerToolIncorrectCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolIncorrectCommandsTest "${VOXELIZERTOOL_EXE}" ${STRUCT_FILE} "${TEST_DATA_ROOT}/StructureSet/DICOM/Wrong_Data_Struct_file.dicom" ${REFERENCE_FILE} "${TEST_DATA_ROOT}/Dose/DICOM/Wrong_Reference_file.dicom" "Rueckenmark" "blabla") ADD_TEST(VoxelizerToolVoxelizerAllStructsTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerAllStructsTest "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} ) +ADD_TEST(VoxelizerToolVoxelizerStructTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerStructTest +"${VOXELIZERTOOL_EXE}" ${TEST_DATA} "${TEST_DATA_ROOT}/StructureSet/ITK/singleFiles/rtss.dcm" "${TEST_DATA_ROOT}/StructureSet/ITK/singleFiles/ct.0" ) ADD_TEST(VoxelizerToolDifferentCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolDifferentCommandsTest "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE}) ADD_TEST(VoxelizerToolVoxelValueTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelValue "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} "Leber") RTTB_CREATE_APPLICATION_TESTS(VoxelizerTool PACKAGE_DEPENDS Litmus ITK BoostBinaries RTTBData) diff --git a/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp b/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp index 8854518..616fa8f 100644 --- a/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp +++ b/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp @@ -1,68 +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: 1127 $ (last changed revision) -// @date $Date: 2015-10-01 13:33:33 +0200 (Do, 01 Okt 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 { const char* _callingAppPath = nullptr; void registerTests() { LIT_REGISTER_TEST(VoxelizerToolDifferentCommandsTest); LIT_REGISTER_TEST(VoxelizerToolVoxelValue); LIT_REGISTER_TEST(VoxelizerToolIncorrectCommandsTest); LIT_REGISTER_TEST(VoxelizerToolVoxelizerAllStructsTest); + LIT_REGISTER_TEST(VoxelizerToolVoxelizerStructTest); } } } int main(int argc, char* argv[]) { int result = 0; rttb::testing::registerTests(); if (argc > 0) { rttb::testing::_callingAppPath = argv[0]; } try { result = lit::multiTestsMain(argc, argv); } catch (...) { result = -1; } return result; } diff --git a/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp b/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp index 74fa813..3167347 100644 --- a/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp +++ b/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp @@ -1,104 +1,98 @@ // ----------------------------------------------------------------------- // 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: 1333 $ (last changed revision) -// @date $Date: 2016-04-22 11:12:14 +0200 (Fr, 22 Apr 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include #include "litCheckMacros.h" #include #include /*! @brief VoxelizerToolTest. Tests a selection of structs. */ namespace rttb { namespace testing { //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) extern const char* _callingAppPath; int VoxelizerToolVoxelizerAllStructsTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; std::string voxelizerToolExe; std::string tempDirectory; std::string structFile; std::string referenceFile; if (argc > 4) { voxelizerToolExe = argv[1]; tempDirectory = argv[2]; structFile = argv[3]; referenceFile = argv[4]; } boost::filesystem::path callingPath(_callingAppPath); std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; std::vector structNames; structNames.push_back("Niere.*"); structNames.push_back("Magen/DD"); structNames.push_back("PTV"); std::string baseCommand = voxelizerToolExeWithPath; baseCommand += " -s \"" + structFile + "\""; baseCommand += " -r \"" + referenceFile + "\""; baseCommand += " -o outputAllStructs.hdr"; baseCommand += " -e \""; for (size_t i = 0; i < structNames.size(); i++) { std::string command = baseCommand + structNames.at(i) + "\""; std::cout << "Command line call: " + command << std::endl; int returnValue = system(command.c_str()); CHECK_EQUAL(returnValue, 0); boost::filesystem::path HDRFile(tempDirectory); HDRFile /= "outputAllStructs.hdr"; boost::filesystem::path IMGFile(tempDirectory); IMGFile /= "outputAllStructs.img"; CHECK_EQUAL( boost::filesystem::exists(HDRFile), true); CHECK_EQUAL( boost::filesystem::exists(IMGFile), true); if (boost::filesystem::exists(IMGFile)) { boost::filesystem::remove(IMGFile); } if (boost::filesystem::exists(HDRFile)) { boost::filesystem::remove(HDRFile); } } RETURN_AND_REPORT_TEST_SUCCESS; } } } diff --git a/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp b/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerStructTest.cpp similarity index 53% copy from testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp copy to testing/apps/VoxelizerTool/VoxelizerToolVoxelizerStructTest.cpp index 74fa813..a42560c 100644 --- a/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerAllStructsTest.cpp +++ b/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerStructTest.cpp @@ -1,104 +1,98 @@ -// ----------------------------------------------------------------------- -// 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: 1333 $ (last changed revision) -// @date $Date: 2016-04-22 11:12:14 +0200 (Fr, 22 Apr 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ - -#include -#include "litCheckMacros.h" -#include -#include - -/*! @brief VoxelizerToolTest. -Tests a selection of structs. -*/ - -namespace rttb -{ - namespace testing - { - //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) - extern const char* _callingAppPath; - int VoxelizerToolVoxelizerAllStructsTest(int argc, char* argv[]) - { - PREPARE_DEFAULT_TEST_REPORTING; - - std::string voxelizerToolExe; - std::string tempDirectory; - std::string structFile; - std::string referenceFile; - - if (argc > 4) - { - voxelizerToolExe = argv[1]; - tempDirectory = argv[2]; - structFile = argv[3]; - referenceFile = argv[4]; - } - - boost::filesystem::path callingPath(_callingAppPath); - std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; - - std::vector structNames; - structNames.push_back("Niere.*"); - structNames.push_back("Magen/DD"); - structNames.push_back("PTV"); - - std::string baseCommand = voxelizerToolExeWithPath; - baseCommand += " -s \"" + structFile + "\""; - baseCommand += " -r \"" + referenceFile + "\""; - baseCommand += " -o outputAllStructs.hdr"; - baseCommand += " -e \""; - - for (size_t i = 0; i < structNames.size(); i++) - { - std::string command = baseCommand + structNames.at(i) + "\""; - std::cout << "Command line call: " + command << std::endl; - int returnValue = system(command.c_str()); - - CHECK_EQUAL(returnValue, 0); - - boost::filesystem::path HDRFile(tempDirectory); - HDRFile /= "outputAllStructs.hdr"; - - boost::filesystem::path IMGFile(tempDirectory); - IMGFile /= "outputAllStructs.img"; - - CHECK_EQUAL( - boost::filesystem::exists(HDRFile), - true); - CHECK_EQUAL( - boost::filesystem::exists(IMGFile), - true); - - - if (boost::filesystem::exists(IMGFile)) - { - boost::filesystem::remove(IMGFile); - } - - if (boost::filesystem::exists(HDRFile)) - { - boost::filesystem::remove(HDRFile); - } - } - - RETURN_AND_REPORT_TEST_SUCCESS; - } - } -} +// ----------------------------------------------------------------------- +// 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. +// +//------------------------------------------------------------------------ + +#include +#include "litCheckMacros.h" +#include + +/*! @brief VoxelizerToolTest. + Tests a struct with multiple files and a single file +*/ + +namespace rttb +{ + namespace testing + { + //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; + int VoxelizerToolVoxelizerStructTest(int argc, char* argv[]) { + PREPARE_DEFAULT_TEST_REPORTING; + + std::string voxelizerToolExe; + std::string tempDirectory; + std::string structFile; + std::string referenceFile; + + boost::filesystem::path HDRFile(tempDirectory); + HDRFile /= "outputSingleStruct.hdr"; + + boost::filesystem::path IMGFile(tempDirectory); + IMGFile /= "outputSingleStruct.img"; + + if (argc > 4) { + voxelizerToolExe = argv[1]; + tempDirectory = argv[2]; + structFile = argv[3]; + referenceFile = argv[4]; + } + + boost::filesystem::path callingPath(_callingAppPath); + std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; + + std::string structName = "Heart"; + + std::string baseCommand = voxelizerToolExeWithPath; + baseCommand += " -s \"" + structFile + "\""; + baseCommand += " -r \"" + referenceFile + "\""; + baseCommand += " -o outputSingleStruct.hdr"; + baseCommand += " -y itkDicom"; + baseCommand += " -e \""; + + std::string command = baseCommand + structName + "\""; + std::cout << "Command line call: " + command << std::endl; + int returnValue = system(command.c_str()); + + CHECK_EQUAL(returnValue, 0); + + CHECK_EQUAL(boost::filesystem::exists(HDRFile), true); + CHECK_EQUAL(boost::filesystem::exists(IMGFile), true); + + + + baseCommand = voxelizerToolExeWithPath; + baseCommand += " -s \"" + structFile + "\""; + baseCommand += " -r \"" + HDRFile.string() + "\""; + baseCommand += " -o outputSingleStruct.hdr"; + baseCommand += " -y itk"; + baseCommand += " -e \""; + + command = baseCommand + structName + "\""; + std::cout << "Command line call: " + command << std::endl; + returnValue = system(command.c_str()); + + CHECK_EQUAL(returnValue, 0); + + if (boost::filesystem::exists(IMGFile)) { + boost::filesystem::remove(IMGFile); + } + + if (boost::filesystem::exists(HDRFile)) { + boost::filesystem::remove(HDRFile); + } + + RETURN_AND_REPORT_TEST_SUCCESS; + } + } +} diff --git a/testing/apps/VoxelizerTool/files.cmake b/testing/apps/VoxelizerTool/files.cmake index 46961ff..ebcabaf 100644 --- a/testing/apps/VoxelizerTool/files.cmake +++ b/testing/apps/VoxelizerTool/files.cmake @@ -1,7 +1,8 @@ SET(CPP_FILES VoxelizerToolTests.cpp VoxelizerToolDifferentCommandsTest.cpp VoxelizerToolIncorrectCommandsTest.cpp VoxelizerToolVoxelizerAllStructsTest.cpp + VoxelizerToolVoxelizerStructTest.cpp VoxelizerToolVoxelValueTest.cpp )