diff --git a/demoapps/VoxelizerTool/CMakeLists.txt b/demoapps/VoxelizerTool/CMakeLists.txt index 228b64e..921bec6 100644 --- a/demoapps/VoxelizerTool/CMakeLists.txt +++ b/demoapps/VoxelizerTool/CMakeLists.txt @@ -1,3 +1,3 @@ -MESSAGE (STATUS "generating demo app: VoxelizerTool - simple dose accumulation tool example") +MESSAGE (STATUS "generating demo app: VoxelizerTool - writing files of voxelized structures") -RTTB_CREATE_APPLICATION(RTTBVoxelizerTool DEPENDS RTTBITKIO RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBMasks RTTBAlgorithms RTTBInterpolation RTTBCore PACKAGE_DEPENDS MatchPoint ITK) \ No newline at end of file +RTTB_CREATE_APPLICATION(VoxelizerTool DEPENDS RTTBITKIO RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBMasks RTTBCore PACKAGE_DEPENDS MatchPoint ITK) \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.cpp b/demoapps/VoxelizerTool/rttbCommandOptions.cpp index 0ef5f8c..911efc6 100644 --- a/demoapps/VoxelizerTool/rttbCommandOptions.cpp +++ b/demoapps/VoxelizerTool/rttbCommandOptions.cpp @@ -1,187 +1,196 @@ // ----------------------------------------------------------------------- // 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: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include #include "rttbCommandOptions.h" #include "rttbVoxelizerHelper.h" namespace rttb { namespace apps { namespace voxelizer { CommandOptions::CommandOptions(): PARAM_HELP("help"), - PARAM_STRUCT_FILE("structfile"), - PARAM_REFERENCE_FILE("referencefile"), + PARAM_STRUCT_FILE("structFile"), + PARAM_REFERENCE_FILE("referenceFile"), PARAM_OUT_FILE("output"), PARAM_REGEX("struct"), PARAM_MULTISTRUCT("multipleStructs"), PARAM_LEGACY("legacyVoxelization"), PARAM_BOOST("boostVoxelization"), PARAM_BOOLEANVOXELIZATION("booleanVoxelization"), PARAM_ADDSTRUCTURES("addStructures") { params.multipleStructs = false; params.legacyVoxelization = false; params.booleanVoxelization = false; params.addStructures = false; po::options_description required("Required arguments"); addOption(required, PARAM_STRUCT_FILE, "s", po::value(¶ms.structFile), "Filename of the structfile (*.dcm)"); addOption(required, PARAM_REFERENCE_FILE, "r", po::value(¶ms.referenceFile), "Filename of the reference image (*.dcm)"); addOption(required, PARAM_REGEX, "e", po::value>(¶ms.regEx)->multitoken(), "set a regular expression describing the structs of interest"); po::options_description optional("Optional arguments"); addOption(optional, PARAM_HELP, "h", nullptr, "Display help message"); addOption(optional, PARAM_OUT_FILE, "o", po::value(¶ms.outputFilename)->default_value("out.hdr"), "set output file name "); addOption(optional, PARAM_MULTISTRUCT, "m", nullptr, "if multiple structs are found, save all in files"); addOption(optional, PARAM_BOOST, "b", nullptr, "for boost voxelization"); addOption(optional, PARAM_LEGACY, "l", nullptr, "for legacy voxelization"); addOption(optional, PARAM_BOOLEANVOXELIZATION, "v", nullptr, "Determines if the voxelization should have only boolean values (0 or 1)"); addOption(optional, PARAM_ADDSTRUCTURES, "a", nullptr, ""); description.add(required).add(optional); } void CommandOptions::addOption(po::options_description& o, const std::string& name, const std::string& shortcut, const po::value_semantic* valueSemantic, const std::string& description) { if (valueSemantic) { o.add_options()((name + std::string(",") + shortcut).c_str(), valueSemantic, description.c_str()); } else { o.add_options()((name + std::string(",") + shortcut).c_str(), description.c_str()); } } void CommandOptions::showHelp()const { - std::cout << "Usage: VoxelizerTool structfile reference [optional] \n"; + std::cout << "Usage: VoxelizerTool -s -r [optional] \n"; std::cout << description << std::endl; + 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'." << std::endl; + 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; } bool CommandOptions::command(int argc, char* argv[]) { try { po::variables_map var; _minArguments = 7; po::store(po::command_line_parser(argc, argv).options(description).run(), var); po::notify(var); if (argc < _minArguments) { showHelp(); return false; } if (var.count(PARAM_HELP)) { showHelp(); return true; } if (!var.count(PARAM_STRUCT_FILE)) { - throw std::runtime_error("Please use the parameter -s or --Structfile"); + throw std::runtime_error("Please use the parameter -s or --structfile"); } else { if (getFileEnding(params.structFile) != ".dcm") { - throw std::runtime_error("Please check your Structfile: " + params.structFile); + throw std::runtime_error("Please check your struct file: " + params.structFile); } } if (!var.count(PARAM_REFERENCE_FILE)) { - throw std::runtime_error("Please use the parameter -r or --Referencefile"); + throw std::runtime_error("Please use the parameter -r or --referencefile"); } else { if (getFileEnding(params.referenceFile) != ".dcm") { - throw std::runtime_error("Please check your Referencefile: " + params.referenceFile); + throw std::runtime_error("Please check your reference file: " + params.referenceFile); } } if (!var.count(PARAM_OUT_FILE)) { params.outputFilename = "out.hdr"; } if (var.count(PARAM_REGEX)) { if (var.count(PARAM_MULTISTRUCT)) { params.multipleStructs = true; } else { params.multipleStructs = false; } } if (var.count(PARAM_LEGACY)) { params.legacyVoxelization = true; } if (var.count(PARAM_BOOLEANVOXELIZATION)) { params.booleanVoxelization = true; } if (var.count(PARAM_ADDSTRUCTURES)) { params.addStructures = true; params.multipleStructs = false; } } catch (const std::exception& e) { std::cout << "Error: " << e.what() << std::endl; return false; } return true; } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.h b/demoapps/VoxelizerTool/rttbCommandOptions.h index 001e174..1005838 100644 --- a/demoapps/VoxelizerTool/rttbCommandOptions.h +++ b/demoapps/VoxelizerTool/rttbCommandOptions.h @@ -1,121 +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: 5506 $ (last changed revision) // @date $Date: 2015-07-30 14:45:24 +0200 (Do, 30 Jul 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __CommandOptions_h #define __CommandOptions_h #include namespace rttb { namespace apps { namespace voxelizer { namespace po = boost::program_options; /** @brief Simple struct holding all variables. */ struct Parameters { /** @brief Filename of the StructFile*/ std::string structFile; /** @brief Filename of the ReferenceFile*/ std::string referenceFile; /** @brief Output Filename*/ std::string outputFilename; /** @brief Expressions from User*/ std::vector regEx; /** @brief for more than one struct*/ bool multipleStructs; /** @brief add: legacyVoxelization=false means boostVoxelization is turned on*/ bool legacyVoxelization; /** @brief voxelization should be binarized to value 0 or 1 */ bool booleanVoxelization ; /** @brief multiple structures voxelization should be combined in one file*/ bool addStructures; }; /*! @class CommandOptions - @brief CommandOptions Class, everything about the commandline + @brief CommandOptions Class, everything about the command line */ class CommandOptions { public: - /*!@brief Constructor - @details add the dicription for commandline options + /** + @details add the description for command line options * add parameter --h or --help for help informations, - * --Structfile= to set a structfile, - * --Reference= to set the referencefile, + * --Structfile= to set a struct file, + * --Reference= to set the reference file, * --Output= to set an output file name and * --struct= to add an expression like(SPINE). */ CommandOptions(); /** @brief Validates the given input parameters and fills the corresponding variables. @param argc Number of arguments. @param argv Array of individual arguments. @return true if all arguments were valid (i.e. none were missing or incorrect), otherwise false. */ bool command(int argc, char* argv[]); const Parameters& getParameters() const { return params; } private: /** *@brief Adds an option to the given option container. *@param o Option container the new option should be added to. *@param name Name of the new option (i.e. the actual parameter, e.g. "test" adds the option with the parameter "--test"). *@param shortcut A single letter that is used as a shortcut for this option (e.g. if the name is "test, the shortcut might be "t", so you can call the parameter with "-t" instead of "--test"). *@param valueSemantic The desired value semantic object, i.e. the object that binds this option's value to a variable. *@param description The description text for this option. */ void addOption(po::options_description& o, const std::string& name, const std::string& shortcut, const po::value_semantic* valueSemantic, const std::string& description); /*! @brief print out the dicription.*/ void showHelp()const; const std::string PARAM_STRUCT_FILE; const std::string PARAM_REFERENCE_FILE; const std::string PARAM_OUT_FILE; const std::string PARAM_REGEX; const std::string PARAM_MULTISTRUCT; const std::string PARAM_HELP; const std::string PARAM_LEGACY; const std::string PARAM_BOOST; const std::string PARAM_BOOLEANVOXELIZATION; const std::string PARAM_ADDSTRUCTURES; /*! create description object */ po::options_description description; Parameters params; /**@brief minimum arguments that must be present on the Command Line*/ int _minArguments; }; } } } #endif \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/CMakeLists.txt b/testing/demoapps/VoxelizerTool/CMakeLists.txt index 55f6304..b943c2d 100644 --- a/testing/demoapps/VoxelizerTool/CMakeLists.txt +++ b/testing/demoapps/VoxelizerTool/CMakeLists.txt @@ -1,22 +1,27 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- -SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/Release/RTTBDemoappsVoxelizertoolTests) +SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/RTTBVoxelizerToolTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEST_DATA ${RTToolbox_BINARY_DIR}/Testing/demoapps/VoxelizerTool) +SET(VOXELIZERTOOL_EXE "VoxelizerTool") +SET(STRUCT_FILE "${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm") +SET(REFERENCE_FILE "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo.dcm") + #----------------------------------------------------------------------------- ADD_TEST(rttbVoxelizerToolIncorrectCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolIncorrectCommandsTest -${EXECUTABLE_OUTPUT_PATH} ${TEST_DATA} ${TEST_DATA_ROOT}) -ADD_TEST(rttbVoxelizerToolVoxelizerAllStuctsTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerAllStructsTest -${EXECUTABLE_OUTPUT_PATH} ${TEST_DATA} ${TEST_DATA_ROOT}) +"${VOXELIZERTOOL_EXE}" ${STRUCT_FILE} "${TEST_DATA_ROOT}/DICOM/StructureSet/Wrong_Data_Struct_file.dicom" +${REFERENCE_FILE} "${TEST_DATA_ROOT}/DICOM/TestDose/Wrong_Reference_file.dicom" "Rueckenmark" "blabla") +ADD_TEST(rttbVoxelizerToolVoxelizerAllStructsTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerAllStructsTest +"${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} ) ADD_TEST(rttbVoxelizerToolDifferentCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolDifferentCommandsTest -${EXECUTABLE_OUTPUT_PATH} ${TEST_DATA} ${TEST_DATA_ROOT}) +"${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE}) ADD_TEST(rttbVoxelizerToolVoxelizerBoostLegacyTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerBoostLegacy -${EXECUTABLE_OUTPUT_PATH} ${TEST_DATA} ${TEST_DATA_ROOT}) -ADD_TEST(rttbVoxelizerToolVoxelPixelValueTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelPixelValue -${EXECUTABLE_OUTPUT_PATH} ${TEST_DATA} ${TEST_DATA_ROOT}) +"${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE}) +ADD_TEST(rttbVoxelizerToolVoxelValueTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelValue +"${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} "Leber") -RTTB_CREATE_TEST_MODULE(RTTBDemoappsVoxelizertool DEPENDS RTTBITKIO RTTBCore RTTBAlgorithms RTTBMasks RTTBOTBMask RTTBBoostMask RTTBIndices RTTBDicomIO RTTBOtherIO PACKAGE_DEPENDS Litmus) +RTTB_CREATE_TEST_MODULE(RTTBVoxelizerTool DEPENDS RTTBITKIO RTTBCore RTTBMasks RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBOtherIO PACKAGE_DEPENDS Litmus) diff --git a/testing/demoapps/VoxelizerTool/files.cmake b/testing/demoapps/VoxelizerTool/files.cmake index 49fd13b..249086e 100644 --- a/testing/demoapps/VoxelizerTool/files.cmake +++ b/testing/demoapps/VoxelizerTool/files.cmake @@ -1,8 +1,8 @@ SET(CPP_FILES rttbVoxelizerToolTests.cpp rttbVoxelizerToolDifferentCommandsTest.cpp rttbVoxelizerToolIncorrectCommandsTest.cpp - rttbVoxelizerToolVoxelizerAllStuctsTest.cpp + rttbVoxelizerToolVoxelizerAllStructsTest.cpp rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp - rttbVoxelizerToolVoxelPixelValueTest.cpp + rttbVoxelizerToolVoxelValueTest.cpp ) diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp index b0f3075..7052e2b 100644 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp @@ -1,108 +1,105 @@ // ----------------------------------------------------------------------- // 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: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "litCheckMacros.h" #include #include #include /*! @brief VoxelizerToolTest3. Test the output, multipleStructs and the booleanVoxelization parameter. */ namespace rttb { namespace testing { + //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; int VoxelizerToolDifferentCommandsTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; - if (argc > 3) + std::string voxelizerToolExe; + std::string tempDirectory; + std::string structFile; + std::string referenceFile; + + if (argc > 4) { - const std::string PathToBinaryDirectory = argv[1]; - const std::string path = argv[2]; - const std::string RTToolBoxTestingDirectory = argv[3]; - - std::vector commands; - commands.push_back(".*"); - commands.push_back(".* -m -o M.hdr"); - commands.push_back("Niere.* -m -o Test.hdr"); - commands.push_back("Leber -o Boolean.hdr -v"); - - std::vector structures; - structures.push_back("M_Aussenkontur"); - structures.push_back("M_Rueckenmark"); - structures.push_back("M_Niere re"); - structures.push_back("M_Niere li"); - structures.push_back("M_Magen_DD"); - structures.push_back("M_Leber"); - structures.push_back("M_Darm"); - structures.push_back("M_Ref.Pkt"); - structures.push_back("M_PTV"); - structures.push_back("M_Boost"); - structures.push_back("out_Aussenkontur"); - structures.push_back("Test_Niere li"); - structures.push_back("Test_Niere re"); - structures.push_back("Boolean_Leber"); - - const std::string baseCommand = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e "; - - for (int i = 0; i < commands.size(); i++) - { - std::string command = baseCommand + commands.at(i); - int returnValue = system(command.c_str()); - CHECK_EQUAL(returnValue, 0); - } + voxelizerToolExe = argv[1]; + tempDirectory = argv[2]; + structFile = argv[3]; + referenceFile = argv[4]; + } + std::vector commands; + commands.push_back("\"Niere.*\" -m -o Test.hdr"); + commands.push_back("\"Leber\" -o Boolean.hdr -v"); - for (int i = 0; i < structures.size(); i++) - { - std::string IMGfileName = path + "/" + structures.at(i) + ".img"; - std::string HDRfileName = path + "/" + structures.at(i) + ".hdr"; + std::vector filenames; + filenames.push_back("Test_Niere li"); + filenames.push_back("Test_Niere re"); + filenames.push_back("Boolean_Leber"); + + boost::filesystem::path callingPath(_callingAppPath); + std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; + + std::string baseCommand = voxelizerToolExeWithPath; + baseCommand += " -s " + structFile; + baseCommand += " -r " + referenceFile; + baseCommand += " -e "; - CHECK_EQUAL(boost::filesystem::exists(HDRfileName), true); - CHECK_EQUAL(boost::filesystem::exists(IMGfileName), true); + for (int i = 0; i < commands.size(); i++) + { + std::string command = baseCommand + commands.at(i); + int returnValue = system(command.c_str()); + std::cout << "Command line call: " + command << std::endl; + CHECK_EQUAL(returnValue, 0); + } - boost::filesystem::path imgFile(IMGfileName); - if (boost::filesystem::exists(imgFile)) - { - boost::filesystem::remove(imgFile); - } + for (int i = 0; i < filenames.size(); i++) + { + const std::string HDRfileName = tempDirectory + "/" + filenames.at(i) + ".hdr"; + boost::filesystem::path HDRFile(HDRfileName); - boost::filesystem::path hdrFile(HDRfileName); + const std::string IMGfileName = tempDirectory + "/" + filenames.at(i) + ".img"; + boost::filesystem::path IMGFile(IMGfileName); - if (boost::filesystem::exists(hdrFile)) - { - boost::filesystem::remove(hdrFile); - } + 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/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp index 5d791e1..806fb02 100644 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp @@ -1,70 +1,88 @@ // ----------------------------------------------------------------------- // 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: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include #include "litCheckMacros.h" #include -#include /*! @brief VoxelizerToolTest4. Test incorrect commands with a wrong structfile, referencefile and a wrong struct. if the command return one, the program could not run to the end. return zero the command is correct */ namespace rttb { namespace testing { - + //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; int VoxelizerToolIncorrectCommandsTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; - if (argc > 3) + std::string voxelizerToolExe; + std::string structFile; + std::string invalidStructFile; + std::string invalidReferenceFile; + std::string referenceFile; + std::string structureName; + std::string invalidStructureName; + + if (argc > 7) { - const std::string PathToBinaryDirectory = argv[1]; - const std::string RTToolBoxTestingDirectory = argv[3]; + voxelizerToolExe = argv[1]; + structFile = argv[2]; + invalidStructFile = argv[3]; + referenceFile = argv[4]; + invalidReferenceFile = argv[5]; + structureName = argv[6]; + invalidStructureName = argv[7]; + } - const std::string StructCommand = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/Wrong_Data_Struct_file.dicom -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e Rueckenmark"; + boost::filesystem::path callingPath(_callingAppPath); + std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; - CHECK_EQUAL(system(StructCommand.c_str()), 1); + std::string StructCommand = voxelizerToolExeWithPath; + StructCommand += " -s " + invalidStructFile; + StructCommand += " -r " + referenceFile; + StructCommand += " -e " + structureName; + std::cout << "Command line call: " + StructCommand << std::endl; + CHECK_EQUAL(system(StructCommand.c_str()), 1); - const std::string ReferenceCommand = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/Wrong_Reference_file.dicom -e Rueckenmark"; - CHECK_EQUAL(system(ReferenceCommand.c_str()), 1); + std::string ReferenceCommand = voxelizerToolExeWithPath; + ReferenceCommand += " -s " + structFile; + ReferenceCommand += " -r " + invalidReferenceFile; + ReferenceCommand += " -e " + structureName; + std::cout << "Command line call: " + ReferenceCommand << std::endl; + CHECK_EQUAL(system(ReferenceCommand.c_str()), 1); - const std::string Structure = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e blablabla"; - CHECK_EQUAL(system(Structure.c_str()), 0); - } + std::string Structure = voxelizerToolExeWithPath; + Structure += " -s " + structFile; + Structure += " -r " + referenceFile; + Structure += +" -e " + invalidStructureName; + std::cout << "Command line call: " + Structure << std::endl; + CHECK_EQUAL(system(Structure.c_str()), 0); RETURN_AND_REPORT_TEST_SUCCESS; } } } diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolTests.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolTests.cpp index fe93e7f..7663ed4 100644 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolTests.cpp +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolTests.cpp @@ -1,64 +1,69 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 707 $ (last changed revision) // @date $Date: 2014-09-04 16:37:24 +0200 (Do, 04 Sep 2014) $ (last change date) // @author $Author: floca $ (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 = NULL; void registerTests() { LIT_REGISTER_TEST(VoxelizerToolDifferentCommandsTest); LIT_REGISTER_TEST(VoxelizerToolVoxelizerBoostLegacy); - LIT_REGISTER_TEST(VoxelizerToolVoxelPixelValue); + LIT_REGISTER_TEST(VoxelizerToolVoxelValue); LIT_REGISTER_TEST(VoxelizerToolIncorrectCommandsTest); LIT_REGISTER_TEST(VoxelizerToolVoxelizerAllStructsTest); } } } 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/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelValueTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelValueTest.cpp new file mode 100644 index 0000000..cf6bb5f --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelValueTest.cpp @@ -0,0 +1,132 @@ +// ----------------------------------------------------------------------- +// 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: 5603 $ (last changed revision) +// @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ + +#include "litCheckMacros.h" +#include +#include "itkImage.h" +#include "itkImageFileReader.h" +#include +#include + +/*! @brief VoxelizerToolTest5. +Search the coordinate at the Image and return the Voxel(Pixel) value. +*/ + +namespace rttb +{ + namespace testing + { + //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; + int VoxelizerToolVoxelValue(int argc, char* argv[]) + { + PREPARE_DEFAULT_TEST_REPORTING; + + typedef itk::Image< double, 3 > ImageType; + typedef itk::ImageFileReader ReaderType; + + std::string voxelizerToolExe; + std::string tempDirectory; + std::string structFile; + std::string referenceFile; + std::string structName; + + if (argc > 5) + { + voxelizerToolExe = argv[1]; + tempDirectory = argv[2]; + structFile = argv[3]; + referenceFile = argv[4]; + structName = argv[5]; + } + + boost::filesystem::path callingPath(_callingAppPath); + std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; + + std::string command = voxelizerToolExeWithPath; + command += " -s " + structFile; + command += " -r " + referenceFile; + command += " -e " + structName; + + int returnValue = system(command.c_str()); + CHECK_EQUAL(returnValue, 0); + + //image values taken in Mevislab + //Index inside + ImageType::IndexType voxelInside1 = {{20, 30, 30}}; + ImageType::IndexType voxelInside2 = {{30, 10, 40}}; + + //Outside index + ImageType::IndexType voxelOutside1 = {{40, 30, 30}}; + ImageType::IndexType voxelOutside2 = {{10, 40, 30}}; + + //Border index + ImageType::IndexType voxelBorder1 = {{12, 23, 27}}; + ImageType::IndexType voxelBorder2 = {{34, 21, 31}}; + + std::vector voxelIndices = boost::assign::list_of(voxelInside1)(voxelInside2)(voxelOutside1)( + voxelOutside2)(voxelBorder1)(voxelBorder2); + + std::vector expectedVoxelValues = boost::assign::list_of(1.0)(1.0)(0.0)(0.0)(0.265865)(0.819613); + + std::string filenameHDRWithVoxelization = tempDirectory + "/out_" + structName + ".hdr"; + std::string filenameIMGWithVoxelization = tempDirectory + "/out_" + structName + ".img"; + CHECK(boost::filesystem::exists(filenameHDRWithVoxelization)); + CHECK(boost::filesystem::exists(filenameIMGWithVoxelization)); + + if (boost::filesystem::exists(filenameHDRWithVoxelization)) + { + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(filenameHDRWithVoxelization); + reader->Update(); + + auto image = reader->GetOutput(); + + for (int i = 0; i < voxelIndices.size(); i++) + { + ImageType::PixelType voxelValue = image->GetPixel(voxelIndices.at(i)); + ImageType::PixelType expectedVoxelValue = expectedVoxelValues.at(i); + + if (expectedVoxelValue == 0.0 || expectedVoxelValue == 1.0) + { + CHECK_EQUAL(voxelValue, expectedVoxelValue); + } + else + { + CHECK_CLOSE(voxelValue, expectedVoxelValue, 1e-4); + } + } + + if (boost::filesystem::exists(filenameHDRWithVoxelization)) + { + boost::filesystem::remove(filenameHDRWithVoxelization); + } + + if (boost::filesystem::exists(filenameIMGWithVoxelization)) + { + boost::filesystem::remove(filenameIMGWithVoxelization); + } + } + + RETURN_AND_REPORT_TEST_SUCCESS; + } + } +} \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStructsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStructsTest.cpp new file mode 100644 index 0000000..172cadd --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStructsTest.cpp @@ -0,0 +1,109 @@ +// ----------------------------------------------------------------------- +// 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: 5503 $ (last changed revision) +// @date $Date: 2015-07-24 12:33:26 +0200 (Fr, 24 Jul 2015) $ (last change date) +// @author $Author: strubel $ (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 > 3) + { + 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 re."); + structNames.push_back("Magen/DD"); + structNames.push_back("PTV"); + + //structure names will be used for file naming, BUT '.' in the end will be cropped and '/' will be replaced by '_'. Thus, the different filenames. + std::vector filenames; + filenames.push_back("Niere re"); + filenames.push_back("Magen_DD"); + filenames.push_back("PTV"); + + std::string baseCommand = voxelizerToolExeWithPath; + baseCommand += " -s " + structFile; + baseCommand += " -r " + referenceFile; + baseCommand += " -e \""; + + for (int 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); + + const std::string HDRfileName = tempDirectory + "/out_" + filenames.at(i) + ".hdr"; + boost::filesystem::path HDRFile(HDRfileName); + + const std::string IMGfileName = tempDirectory + "/out_" + filenames.at(i) + ".img"; + boost::filesystem::path IMGFile(IMGfileName); + + 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; + } + } +} \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp deleted file mode 100644 index 95d27b7..0000000 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// ----------------------------------------------------------------------- -// 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: 5503 $ (last changed revision) -// @date $Date: 2015-07-24 12:33:26 +0200 (Fr, 24 Jul 2015) $ (last change date) -// @author $Author: strubel $ (last changed by) -*/ - -#include -#include "litCheckMacros.h" -#include -#include - -/*! @brief VoxelizerToolTest. -Test all structs. -*/ - -namespace rttb -{ - namespace testing - { - - int VoxelizerToolVoxelizerAllStructsTest(int argc, char* argv[]) - { - PREPARE_DEFAULT_TEST_REPORTING; - - if (argc > 3) - { - const std::string PathToBinaryDirectory = argv[1]; - const std::string tempDirectory = argv[2]; - const std::string RTToolBoxTestingDirectory = argv[3]; - - std::vector structs; - structs.push_back("Aussenkontur"); - structs.push_back("Rueckenmark"); - structs.push_back("Niere re."); - structs.push_back("Niere li."); - structs.push_back("Magen/DD"); - structs.push_back("Leber"); - structs.push_back("Darm"); - structs.push_back("Ref.Pkt."); - structs.push_back("PTV"); - structs.push_back("Boost"); - - std::vector filenames; - filenames.push_back("Aussenkontur"); - filenames.push_back("Rueckenmark"); - filenames.push_back("Niere re"); - filenames.push_back("Niere li"); - filenames.push_back("Magen_DD"); - filenames.push_back("Leber"); - filenames.push_back("Darm"); - filenames.push_back("Ref.Pkt"); - filenames.push_back("PTV"); - filenames.push_back("Boost"); - - const std::string baseCommand = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e \""; - - for (int i = 0; i < structs.size(); i++) - { - std::string command = baseCommand + structs.at(i) + "\""; - int returnValue = system(command.c_str()); - - CHECK_EQUAL(returnValue, 0); - - std::string HDRfileName = tempDirectory + "\\out_" + filenames.at(i) + ".hdr"; - std::string IMGfileName = tempDirectory + "\\out_" + filenames.at(i) + ".img"; - - CHECK_EQUAL( - boost::filesystem::exists(HDRfileName), - true); - CHECK_EQUAL( - boost::filesystem::exists(IMGfileName), - true); - - boost::filesystem::path imgFile(IMGfileName); - - if (boost::filesystem::exists(imgFile)) - { - boost::filesystem::remove(imgFile); - } - - boost::filesystem::path hdrFile(HDRfileName); - - if (boost::filesystem::exists(hdrFile)) - { - boost::filesystem::remove(hdrFile); - } - } - } - - RETURN_AND_REPORT_TEST_SUCCESS; - } - } -} \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp index 28ff466..47b2473 100644 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp @@ -1,94 +1,104 @@ // ----------------------------------------------------------------------- // 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: 5503 $ (last changed revision) // @date $Date: 2015-07-24 12:33:26 +0200 (Fr, 24 Jul 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "litCheckMacros.h" #include #include #include /*! @brief VoxelizerToolTest5. Test the paramter boost and legacy Voxelization. */ namespace rttb { namespace testing { - + //path to the current running directory. VoxelizerTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; int VoxelizerToolVoxelizerBoostLegacy(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; - if (argc > 3) + 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]; + } + + std::vector commands; + commands.push_back("PTV -o Legacy.hdr -l"); + commands.push_back("PTV -o Boost.hdr -b"); + + std::vector filenames; + filenames.push_back("Boost_PTV"); + filenames.push_back("Legacy_PTV"); + + boost::filesystem::path callingPath(_callingAppPath); + std::string voxelizerToolExeWithPath = callingPath.parent_path().string() + "/" + voxelizerToolExe; + + std::string baseCommand = voxelizerToolExeWithPath; + baseCommand += " -s " + structFile; + baseCommand += " -r " + referenceFile; + baseCommand += " -e "; + + for (int i = 0; i < commands.size(); i++) { - const std::string PathToBinaryDirectory = argv[1]; - const std::string PathToTestingDirectory = argv[2]; - const std::string RTToolBoxTestingDirectory = argv[3]; - - std::vector OutputVoxelization; - OutputVoxelization.push_back("Rueckenmark -o Test.hdr"); - OutputVoxelization.push_back("Leber -l"); - OutputVoxelization.push_back("Darm -b"); - OutputVoxelization.push_back("Leber -o Legacy.hdr -l"); - OutputVoxelization.push_back("Darm -o Boost.hdr -b"); - - std::vector OutputFiles; - OutputFiles.push_back("/Boost_Darm.hdr"); - OutputFiles.push_back("/Boost_Darm.img"); - OutputFiles.push_back("/Legacy_Leber.hdr"); - OutputFiles.push_back("/Legacy_Leber.img"); - OutputFiles.push_back("/out_Darm.hdr"); - OutputFiles.push_back("/out_Darm.img"); - OutputFiles.push_back("/out_Leber.hdr"); - OutputFiles.push_back("/out_Leber.img"); - OutputFiles.push_back("/Test_Rueckenmark.hdr"); - OutputFiles.push_back("/Test_Rueckenmark.img"); - - const std::string baseCommand = PathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e "; - - for (int i = 0 ; i < OutputVoxelization.size(); i++) + std::string command = baseCommand + commands.at(i); + int returnValue = system(command.c_str()); + std::cout << "Command line call: " + command << std::endl; + CHECK_EQUAL(returnValue, 0); + } + + for (int i = 0; i < filenames.size(); i++) + { + const std::string HDRfileName = tempDirectory + "/" + filenames.at(i) + ".hdr"; + boost::filesystem::path HDRFile(HDRfileName); + + const std::string IMGfileName = tempDirectory + "/" + filenames.at(i) + ".img"; + boost::filesystem::path IMGFile(IMGfileName); + + CHECK_EQUAL(boost::filesystem::exists(HDRFile), true); + CHECK_EQUAL(boost::filesystem::exists(IMGFile), true); + + if (boost::filesystem::exists(IMGFile)) { - std::string Command = baseCommand + OutputVoxelization.at(i); - int returnValue = system(Command.c_str()); - CHECK_EQUAL(returnValue, 0); + boost::filesystem::remove(IMGFile); } - for (int i = 0; i < OutputFiles.size(); i++) + if (boost::filesystem::exists(HDRFile)) { - std::string pathToFile = PathToTestingDirectory + OutputFiles.at(i); - - CHECK_EQUAL(boost::filesystem::exists(pathToFile), true); - - if (boost::filesystem::exists(pathToFile)) - { - boost::filesystem::remove(pathToFile); - } + boost::filesystem::remove(HDRFile); } } RETURN_AND_REPORT_TEST_SUCCESS; } } } \ No newline at end of file