diff --git a/apps/DoseMap/DoseMapCmdLineParser.cpp b/apps/DoseMap/DoseMapCmdLineParser.cpp new file mode 100644 index 0000000..f2b5350 --- /dev/null +++ b/apps/DoseMap/DoseMapCmdLineParser.cpp @@ -0,0 +1,121 @@ +// ----------------------------------------------------------------------- +// 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, bool virtuosSupport) : + CmdLineParserBase(name, version), _virtuosSupport(virtuosSupport) + { + typedef double DoseTypeGy; + + 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)."; + + 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 neighbour,\"linear\": linear interpolation, \"rosu\" interpolation based on the concept of Rosu et al.. Default interpolator is \"linear\".", + "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.", "", "", '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 mapp into. " + "If flag is not specified, the input dose is the reference.", 't');//?? + + addOptionWithDefaultValue >(OPTION_INPUT_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, "Indicates the load style that should be used for the input dose." + "Available styles: \"dicom\": normal dicom dose (default); \"virtuos\": load of a virtuos dose (This style is a multi argument. The second argument specifies " + "the virtuos plan file, e.g. : \"--loadStyle1 virtuos myFavorite.pln\"); \"itk\": use itk image loading; \"helax\": load a helax dose (choosing this style, the dose path should only be a directory)." + ,defaultLoadingStyle, defaultLoadingStyle.at(0),'l',true); + addOptionWithDefaultValue >(OPTION_REF_DOSE_LOAD_STYLE, OPTION_GROUP_REQUIRED, "Indicates the load style that should be used for the reference dose." + "Available styles: \"dicom\": normal dicom dose (default); \"virtuos\": load of a virtuos dose (This style is a multi argument. The second argument specifies the virtuos plan file, e.g. : \"--loadStyle2 virtuos myFavorite.pln\"); \"itk\": use itk image loading; \"helax\": load a helax dose (choosing this style, the dose path should only be a directory)." + , defaultLoadingStyle, defaultLoadingStyle.at(0), '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 indoseLoadStyle = get >(OPTION_INPUT_DOSE_LOAD_STYLE); + std::string indoseLoadStyleAbbreviation = indoseLoadStyle.at(0); + if (indoseLoadStyleAbbreviation != "dicom" && indoseLoadStyleAbbreviation != "virtuos" + && indoseLoadStyleAbbreviation != "itk" && indoseLoadStyleAbbreviation != "helax") + { + throw cmdlineparsing::InvalidConstraintException("Unknown load style for input dose file:" + + indoseLoadStyleAbbreviation + + ".\nPlease refer to the help for valid loading style settings."); + } + + std::vector refdoseLoadStyle = get >(OPTION_REF_DOSE_LOAD_STYLE); + std::string refdoseLoadStyleAbbreviation = refdoseLoadStyle.at(0); + if (refdoseLoadStyleAbbreviation != "dicom" && refdoseLoadStyleAbbreviation != "virtuos" + && refdoseLoadStyleAbbreviation != "itk" && refdoseLoadStyleAbbreviation != "helax") + { + throw cmdlineparsing::InvalidConstraintException("Unknown load style for referenz dose file:" + + refdoseLoadStyleAbbreviation + + ".\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 --inputDoseLoadStyle itk --loadStyleReference 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/DoseMap/DoseMapCmdLineParser.h b/apps/DoseMap/DoseMapCmdLineParser.h new file mode 100644 index 0000000..7989736 --- /dev/null +++ b/apps/DoseMap/DoseMapCmdLineParser.h @@ -0,0 +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_CMD_LINE_PARSER +#define __DOSEMAP_CMD_LINE_PARSER + +#include "CmdLineParserBase.h" +namespace rttb +{ + namespace apps + { + namespace doseMap + { + /*! @class BioModelCmdLineParser + @brief Argument parsing is parametrized here based on ArgParserLib + @see cmdlineparsing::CmdLineParserBase + */ + class DoseMapCmdLineParser : public cmdlineparsing::CmdLineParserBase + { + public: + DoseMapCmdLineParser(int argc, const char** argv, const std::string& name, + const std::string& version, bool virtuosSupport = false); + void validateInput() const; + void printHelp() const; + + // Option groups + const std::string OPTION_GROUP_REQUIRED = "Required Arguments"; + const std::string OPTION_GROUP_OPTIONAL = "Optional Arguments"; + + // Parameters + const std::string OPTION_INPUT_DOSE_FILE_NAME = "inputDoseFileName"; + const std::string OPTION_OUTPUT_FILE_NAME = "outputFileName"; + const std::string OPTION_INTERPOLATOR = "interpolator"; + const std::string OPTION_REG_FILE_NAME = "regFileName"; + const std::string OPTION_REF_DOSE_FILE = "refDoseFile"; + const std::string OPTION_REF_DOSE_LOAD_STYLE = "refDoseLoadStyle"; + const std::string OPTION_INPUT_DOSE_LOAD_STYLE = "inputDoseLoadStyle"; + + + bool _virtuosSupport; + }; + + } + } +} + +#endif \ No newline at end of file diff --git a/testing/apps/DoseMap/CMakeLists.txt b/testing/apps/DoseMap/CMakeLists.txt new file mode 100644 index 0000000..7e1ab18 --- /dev/null +++ b/testing/apps/DoseMap/CMakeLists.txt @@ -0,0 +1,30 @@ +#----------------------------------------------------------------------------- +# Setup the system information test. Write out some basic failsafe +# information in case the test doesn't run. +#----------------------------------------------------------------------------- + + +SET(DOSEMAP_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbDoseMapTests) + +SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) + +SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) + + +#----------------------------------------------------------------------------- + +IF(MSVC) + ADD_DEFINITIONS(/bigobj) +ENDIF() + +IF (WIN32) + SET(DOSEMAPEXE "DoseMap.exe") +ELSE (WIN32) + SET(DOSEMAPEXE "./DoseMap") +ENDIF (WIN32) + +ADD_TEST(DoseMapInvalidParametersTest ${DOSEMAP_TEST} DoseMapInvalidParametersTest ${DOSEMAPEXE}) +ADD_TEST(DoseMapSimpleTest ${DOSEMAP_TEST} DoseMapSimpleTest ${DOSEMAPEXE} "${TEST_DATA_ROOT}/DoseMap/input.mhd" "${TEST_DATA_ROOT}/DoseMap/outputfile.mhd" "-l itk" "-r ${TEST_DATA_ROOT}/DoseMap/Identity.mapr" ) + + +RTTB_CREATE_APPLICATION_TESTS(DoseMap PACKAGE_DEPENDS Litmus BoostBinaries) diff --git a/testing/apps/DoseMap/DoseMapInvalidParametersTest.cpp b/testing/apps/DoseMap/DoseMapInvalidParametersTest.cpp new file mode 100644 index 0000000..e924586 --- /dev/null +++ b/testing/apps/DoseMap/DoseMapInvalidParametersTest.cpp @@ -0,0 +1,78 @@ +// ----------------------------------------------------------------------- +// 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 + +#include "litCheckMacros.h" + +#include "boost/filesystem.hpp" + +namespace rttb +{ + namespace testing + { + + //path to the current running directory. DoseMap is in the same directory (Debug/Release) + extern const char* _callingAppPath; + + int DoseMapInvalidParametersTest(int argc, char* argv[]) + { + PREPARE_DEFAULT_TEST_REPORTING; + + std::string doseMapExecutable; + + if (argc > 1) + { + doseMapExecutable = argv[1]; + } + + boost::filesystem::path callingPath(_callingAppPath); + std::string doseMapExeWithPath = callingPath.parent_path().string() + "/" + doseMapExecutable; + + //call with too few parameters + std::string toofewParametersCommand = doseMapExeWithPath; + toofewParametersCommand += " -d test"; + std::cout << "Command line call: " + toofewParametersCommand << std::endl; + CHECK_EQUAL(system(toofewParametersCommand.c_str()) != 0, true); + + toofewParametersCommand = doseMapExeWithPath; + toofewParametersCommand += " test"; + std::cout << "Command line call: " + toofewParametersCommand << std::endl; + CHECK_EQUAL(system(toofewParametersCommand.c_str()) != 0, true); + + + //call with invalid dose load option + std::string minimalCLI = doseMapExeWithPath + " test test "; + std::string invalidDoseLoadOption = minimalCLI; + invalidDoseLoadOption += "-l wrongOption"; + std::cout << "Command line call: " + invalidDoseLoadOption << std::endl; + CHECK_EQUAL(system(invalidDoseLoadOption.c_str()) != 0, true); + + //call with invalid interpolator + std::string invalidStructLoadOption = minimalCLI; + invalidStructLoadOption += "-i wrongOption"; + std::cout << "Command line call: " + invalidStructLoadOption << std::endl; + CHECK_EQUAL(system(invalidStructLoadOption.c_str()) != 0, true); + + RETURN_AND_REPORT_TEST_SUCCESS; + } + } //namespace testing +} //namespace rttb diff --git a/testing/apps/DoseMap/DoseMapSimpleTest.cpp b/testing/apps/DoseMap/DoseMapSimpleTest.cpp new file mode 100644 index 0000000..eb143c2 --- /dev/null +++ b/testing/apps/DoseMap/DoseMapSimpleTest.cpp @@ -0,0 +1,99 @@ +// ----------------------------------------------------------------------- +// 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 +#include +#include + +#include "litCheckMacros.h" + +#include "boost/filesystem.hpp" +#include "boost/algorithm/string.hpp" + +namespace rttb +{ + namespace testing + { + + //path to the current running directory. DoseMap is in the same directory (Debug/Release) + extern const char* _callingAppPath; + + static std::string readFile(const std::string& filename); + + int DoseMapSimpleTest(int argc, char* argv[]) + { + PREPARE_DEFAULT_TEST_REPORTING; + + std::string doseMapExecutable; + std::string regFilename; + std::string inputFilename; + std::string outputFilename; + std::string refDoseLoadStyle; + std::string inputDoseLoadStyle; + + + boost::filesystem::path callingPath(_callingAppPath); + + + if (argc > 5 ) + { + doseMapExecutable = argv[1]; + inputFilename = argv[2]; + outputFilename = argv[3]; + inputDoseLoadStyle = argv[4]; + regFilename = argv[5]; + //refDoseLoadStyle = argv[5]; + } + + + //check if file exists + std::cout << "outputFilename" << outputFilename << std::endl <<"inputfilename"<< inputFilename << std::endl; + + CHECK_EQUAL(boost::filesystem::exists(outputFilename), true); + CHECK_EQUAL(boost::filesystem::exists(inputFilename), true); + + std::string doseToolExeWithPath = callingPath.parent_path().string() + "/" + doseMapExecutable; + std::string baseCommand = doseToolExeWithPath +" "+ inputFilename +" "+ outputFilename; + + + + std::string defaultDoseStatisticsCommand = baseCommand+" "+ inputDoseLoadStyle; + std::cout << "Command line call: " + defaultDoseStatisticsCommand << std::endl; + CHECK_EQUAL(system(defaultDoseStatisticsCommand.c_str()), 0); + + + std::string defaultDoseStatisticsCommandwithregistration = defaultDoseStatisticsCommand+ " " + regFilename; + std::cout << "Command line call: " + defaultDoseStatisticsCommandwithregistration << std::endl; + CHECK_EQUAL(system(defaultDoseStatisticsCommandwithregistration.c_str()), 0); + + + RETURN_AND_REPORT_TEST_SUCCESS; + } + + std::string readFile(const std::string& filename) + { + std::ifstream fileStream(filename.c_str()); + std::string content((std::istreambuf_iterator(fileStream)), + (std::istreambuf_iterator())); + return content; + } + } //namespace testing +} //namespace rttb diff --git a/testing/apps/DoseMap/DoseMapTests.cpp b/testing/apps/DoseMap/DoseMapTests.cpp new file mode 100644 index 0000000..6606858 --- /dev/null +++ b/testing/apps/DoseMap/DoseMapTests.cpp @@ -0,0 +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: 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) +*/ + +// 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" + +#include "RTToolboxConfigure.h" + +namespace rttb +{ + namespace testing + { + + const char* _callingAppPath = NULL; + + void registerTests() + { + LIT_REGISTER_TEST(DoseMapInvalidParametersTest); + LIT_REGISTER_TEST(DoseMapSimpleTest); + } + + } //namespace testing +} //namespace map + + +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/DoseMap/files.cmake b/testing/apps/DoseMap/files.cmake new file mode 100644 index 0000000..5169ca5 --- /dev/null +++ b/testing/apps/DoseMap/files.cmake @@ -0,0 +1,8 @@ +SET(CPP_FILES + DoseMapInvalidParametersTest.cpp + DoseMapSimpleTest.cpp + DoseMapTests.cpp + ) + +SET(H_FILES +)