diff --git a/apps/DoseAcc/DoseAccCmdLineParser.cpp b/apps/DoseAcc/DoseAccCmdLineParser.cpp index 6788b1e..8603721 100644 --- a/apps/DoseAcc/DoseAccCmdLineParser.cpp +++ b/apps/DoseAcc/DoseAccCmdLineParser.cpp @@ -1,167 +1,175 @@ // ----------------------------------------------------------------------- // 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, bool virtuosSupport) : CmdLineParserBase(name, version), _virtuosSupport(virtuosSupport) { addOption(OPTION_DOSE1_FILENAME, OPTION_GROUP_REQUIRED, "File path to the first dose.", 'd', true); addOption(OPTION_DOSE2_FILENAME, OPTION_GROUP_REQUIRED, "File path to the second dose.", 'e', true); addOption(OPTION_OUTPUT_FILENAME, OPTION_GROUP_REQUIRED, "File path where the output should be stored.", '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..", "linear", "linear", 'i', true); addOptionWithDefaultValue(OPTION_WEIGHT1, OPTION_GROUP_REQUIRED, "Specifies the weight for dose 1.", 1.0, "1.0", 'w', true); addOptionWithDefaultValue(OPTION_WEIGHT2, OPTION_GROUP_REQUIRED, "Specifies the weight for dose 2.", 1.0, "1.0", 'z', true); 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); 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)."; if (_virtuosSupport) { doseLoadStyleDescription += "\n" "\"virtuos\": load of a virtuos dose (This style is a multi argument. The second argument specifies the virtuos plan file, e.g. : \"--" + OPTION_LOAD_STYLE_DOSE1 + " or " + OPTION_LOAD_STYLE_DOSE2 + " virtuos myFavorite.pln\")"; } addOptionWithDefaultValue >(OPTION_LOAD_STYLE_DOSE1, OPTION_GROUP_REQUIRED, "Load style for dose 1. "+ doseLoadStyleDescription, defaultLoadingStyle, defaultLoadingStyle.at(0), 't', true, true); addOptionWithDefaultValue >(OPTION_LOAD_STYLE_DOSE2, OPTION_GROUP_REQUIRED, "Load style for dose 2. See " + OPTION_LOAD_STYLE_DOSE1, defaultLoadingStyle, defaultLoadingStyle.at(0), 'u', true, true); addOptionWithDefaultValue(OPTION_OPERATOR, OPTION_GROUP_REQUIRED, - "Specifies the operator used. Available operators are '+' and '*'.", + "Specifies the operator used. Available operators are '+' and '*'. Operator '*' has implemented no weight option.", "+", "+", 'p', true); 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); if (doseLoadStyleAbbreviation1 != "dicom" && (!_virtuosSupport || doseLoadStyleAbbreviation1 != "virtuos") && doseLoadStyleAbbreviation1 != "itk" && doseLoadStyleAbbreviation1 != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for dose1 file: " + doseLoadStyleAbbreviation1 + ".\nPlease refer to the help for valid loading style settings."); } if (_virtuosSupport && doseLoadStyleAbbreviation1 == "virtuos") { if (doseLoadStyle1.size() < 2) { throw cmdlineparsing::InvalidConstraintException("Cannot load virtuos dose. Plan file is missing. Specify plan file as 2nd io style argument."); } } std::vector doseLoadStyle2 = get >(OPTION_LOAD_STYLE_DOSE2); std::string doseLoadStyleAbbreviation2 = doseLoadStyle2.at(0); if (doseLoadStyleAbbreviation2 != "dicom" && (!_virtuosSupport || doseLoadStyleAbbreviation2 != "virtuos") && doseLoadStyleAbbreviation2 != "itk" && doseLoadStyleAbbreviation2 != "helax") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for dose2 file: " + doseLoadStyleAbbreviation2 + ".\nPlease refer to the help for valid loading style settings."); } if (_virtuosSupport && doseLoadStyleAbbreviation2 == "virtuos") { if (doseLoadStyle2.size() < 2) { throw cmdlineparsing::InvalidConstraintException("Cannot load virtuos dose. Plan file is missing. Specify plan file as 2nd io style argument."); } } 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; if (_virtuosSupport){ std::cout << " DoseAcc dose1.dcm dose2.dos.gz result.mhd --" + OPTION_LOAD_STYLE_DOSE2 + " virtuos dose2.pln -r reg.mapr" << std::endl << std::endl; std::cout << " This will accumulate \"dose1.dcm\" (using default dicom io) and \"dose2.dos.gz\" (using virtuos io and plan file dose2.pln)"; std::cout << " by using \"reg.mapr\" to map dose 2. The resulting dose will be stored in \"result.mhd\"." << std::endl; } } } } } diff --git a/apps/DoseAcc/DoseAccHelper.cpp b/apps/DoseAcc/DoseAccHelper.cpp index ee7f05e..29ea61a 100644 --- a/apps/DoseAcc/DoseAccHelper.cpp +++ b/apps/DoseAcc/DoseAccHelper.cpp @@ -1,246 +1,242 @@ // ----------------------------------------------------------------------- // 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: 1132 $ (last changed revision) // @date $Date: 2015-10-06 14:48:56 +0200 (Di, 06 Okt 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include "DoseAccHelper.h" #include "mapRegistrationFileReader.h" #include "itkImageFileWriter.h" #include "rttbExceptionMacros.h" #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbDicomHelaxFileDoseAccessorGenerator.h" #include "rttbITKImageAccessorConverter.h" #include "rttbSimpleMappableDoseAccessor.h" #include "rttbMatchPointTransformation.h" #include "rttbLinearInterpolation.h" #include "rttbNearestNeighborInterpolation.h" #include "rttbRosuMappableDoseAccessor.h" #include "rttbITKImageFileAccessorGenerator.h" #include "rttbArithmetic.h" #include "rttbBinaryFunctorAccessor.h" rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseAcc::loadDose(const std::string& fileName, const rttb::apps::doseAcc::ApplicationData::LoadingStyleArgType& args) { rttb::core::DoseAccessorInterface::DoseAccessorPointer result; std::cout << std::endl << "read dose file... "; if (args.empty() || args[0] == "dicom") { std::cout << "use RTTB dicom IO... "; result = loadDicomDose(fileName); } else if (args[0] == "helax") { std::cout << "use RTTB Helax IO... "; result = loadHelaxDose(fileName); } else if (args[0] == "itk") { std::cout << "use RTTB itk IO... "; result = loadITKDose(fileName); } else { rttbDefaultExceptionStaticMacro( << "Unknown io style selected. Cannot load data. Selected style: " << args[0]); } std::cout << "done." << std::endl; return result; }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseAcc::loadDicomDose(const std::string& fileName) { rttb::io::dicom::DicomFileDoseAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseAcc::loadHelaxDose(const std::string& path) { rttb::io::helax::DicomHelaxFileDoseAccessorGenerator generator(path); return generator.generateDoseAccessor(); }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseAcc::loadITKDose(const std::string& fileName) { rttb::io::itk::ITKImageFileAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); }; rttb::apps::doseAcc::ApplicationData::RegistrationType::Pointer rttb::apps::doseAcc::loadRegistration(const std::string& fileName) { map::io::RegistrationFileReader::Pointer spRegReader = map::io::RegistrationFileReader::New(); map::io::RegistrationFileReader::LoadedRegistrationPointer spReg; std::cout << std::endl << "read registration file... "; spReg = spRegReader->read(fileName); std::cout << "done." << std::endl; ApplicationData::RegistrationType::Pointer resultPtr = dynamic_cast(spReg.GetPointer()); if (resultPtr.IsNull()) { rttbDefaultExceptionStaticMacro( << "Loaded registration cannot be used. Only 3D 3D registrations are allowed."); } return resultPtr; }; rttb::core::DoseAccessorInterface::DoseAccessorPointer generateNNMappableAccessor( const rttb::core::GeometricInfo& geoInfoTargetImage, const rttb::core::DoseAccessorInterface::DoseAccessorPointer doseMovingImage, const rttb::interpolation::TransformationInterface::Pointer aTransformation) { rttb::interpolation::InterpolationBase::Pointer interpolate = rttb::interpolation::NearestNeighborInterpolation::Pointer(new rttb::interpolation::NearestNeighborInterpolation()); return rttb::core::DoseAccessorInterface::DoseAccessorPointer( new rttb::interpolation::SimpleMappableDoseAccessor(geoInfoTargetImage, doseMovingImage, aTransformation, interpolate)); } rttb::core::DoseAccessorInterface::DoseAccessorPointer generateLinearMappableAccessor( const rttb::core::GeometricInfo& geoInfoTargetImage, const rttb::core::DoseAccessorInterface::DoseAccessorPointer doseMovingImage, const rttb::interpolation::TransformationInterface::Pointer aTransformation) { rttb::interpolation::InterpolationBase::Pointer interpolate = rttb::interpolation::LinearInterpolation::Pointer(new rttb::interpolation::LinearInterpolation()); return rttb::core::DoseAccessorInterface::DoseAccessorPointer( new rttb::interpolation::SimpleMappableDoseAccessor(geoInfoTargetImage, doseMovingImage, aTransformation, interpolate)); } rttb::core::DoseAccessorInterface::DoseAccessorPointer generateRosuMappableAccessor( const rttb::core::GeometricInfo& geoInfoTargetImage, const rttb::core::DoseAccessorInterface::DoseAccessorPointer doseMovingImage, const rttb::interpolation::TransformationInterface::Pointer aTransformation) { return rttb::core::DoseAccessorInterface::DoseAccessorPointer( new rttb::interpolation::RosuMappableDoseAccessor(geoInfoTargetImage, doseMovingImage, aTransformation)); } /**Private helper function for processData(). Generates a suitable output accessor * (depending on the configuration in appData a suitable accessor pipeline is established) * which performs the accumulation of the doses and returns the output.to */ rttb::core::DoseAccessorInterface::DoseAccessorPointer assembleOutputAccessor(rttb::apps::doseAcc::ApplicationData& appData) { rttb::core::DoseAccessorInterface::DoseAccessorPointer dose2Accessor = appData._dose2; if (appData._spReg.IsNotNull()) { rttb::interpolation::TransformationInterface::Pointer transform = rttb::interpolation::TransformationInterface::Pointer(new rttb::interpolation::MatchPointTransformation(appData._spReg)); if (appData._interpolatorName == "rosu") { dose2Accessor = generateRosuMappableAccessor(appData._dose1->getGeometricInfo(), appData._dose2, transform); } else if (appData._interpolatorName == "nn") { dose2Accessor = generateNNMappableAccessor(appData._dose1->getGeometricInfo(), appData._dose2, transform); } else if (appData._interpolatorName == "linear") { dose2Accessor = generateLinearMappableAccessor(appData._dose1->getGeometricInfo(), appData._dose2, transform); } else { rttbDefaultExceptionStaticMacro( << "Unkown interpolation type selected. Cannot map dose. Interpolation type: " << appData._interpolatorName); } } rttb::core::DoseAccessorInterface::DoseAccessorPointer outputAccessor; if (appData._operator == "+") { rttb::algorithms::arithmetic::doseOp::AddWeighted addOp(appData._weightDose1, appData._weightDose2); - outputAccessor = - rttb::core::DoseAccessorInterface::DoseAccessorPointer(new - rttb::algorithms::BinaryFunctorAccessor - (appData._dose1, dose2Accessor, addOp)); + outputAccessor = boost::make_shared >(appData._dose1, dose2Accessor, addOp); } else if (appData._operator == "*") { outputAccessor = - rttb::core::DoseAccessorInterface::DoseAccessorPointer(new - rttb::algorithms::BinaryFunctorAccessor - (appData._dose1, dose2Accessor, rttb::algorithms::arithmetic::doseOp::Multiply())); + boost::make_shared > + (appData._dose1, dose2Accessor, rttb::algorithms::arithmetic::doseOp::Multiply()); } else { rttbDefaultExceptionStaticMacro( << "Unkown operator selected. Cannot map dose. Operator: " << appData._interpolatorName); } return outputAccessor; } void rttb::apps::doseAcc::processData(rttb::apps::doseAcc::ApplicationData& appData) { rttb::core::DoseAccessorInterface::DoseAccessorPointer outputAccessor = assembleOutputAccessor( appData); std::cout << std::endl << "generate output image... "; io::itk::ITKImageAccessorConverter converter(outputAccessor); converter.setFailOnInvalidIDs(true); converter.process(); io::itk::ITKImageAccessorConverter::ITKImageType::Pointer itkImage = converter.getITKImage(); std::cout << "done." << std::endl; typedef ::itk::ImageFileWriter WriterType; std::cout << std::endl << "write output image... "; WriterType::Pointer writer = WriterType::New(); writer->SetInput(itkImage); writer->SetFileName(appData._outputFileName); writer->SetUseCompression(true); writer->Write(); std::cout << "done." << std::endl; }; diff --git a/testing/apps/DoseAcc/CMakeLists.txt b/testing/apps/DoseAcc/CMakeLists.txt index 68b903e..dfc3b55 100644 --- a/testing/apps/DoseAcc/CMakeLists.txt +++ b/testing/apps/DoseAcc/CMakeLists.txt @@ -1,29 +1,30 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(DOSEACC_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbDoseAccTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- IF(MSVC) ADD_DEFINITIONS(/bigobj) ENDIF() IF (WIN32) SET(DOSEACCEXE "DoseAcc.exe") ELSE (WIN32) SET(DOSEACCEXE "./DoseAcc") ENDIF (WIN32) ADD_TEST(DoseAccInvalidParametersTest ${DOSEACC_TEST} DoseAccInvalidParametersTest ${DOSEACCEXE}) ADD_TEST(DoseAccSimpleTest ${DOSEACC_TEST} DoseAccSimpleTest ${DOSEACCEXE} "${TEST_DATA_ROOT}/Dose/DICOM/ConstantTwo.dcm" "${TEST_DATA_ROOT}/Dose/DICOM/ConstantFifty.dcm" "${TEST_DATA_ROOT}/images/ITK/doseAccReference.nrrd") +ADD_TEST(DoseAccNeutralWeightTest ${DOSEACC_TEST} DoseAccNeutralWeightTest ${DOSEACCEXE} "${TEST_DATA_ROOT}/Dose/DICOM/ConstantFifty.dcm" "${TEST_DATA_ROOT}/Dose/ITK/constantFifty.nrrd" "${TEST_DATA_ROOT}/Dose/ITK/constant2500.nrrd") RTTB_CREATE_APPLICATION_TESTS(DoseAcc DEPENDS RTTBITKIO PACKAGE_DEPENDS Litmus ITK BoostBinaries) diff --git a/testing/apps/DoseAcc/DoseAccInvalidParametersTest.cpp b/testing/apps/DoseAcc/DoseAccInvalidParametersTest.cpp index 13bcf17..b6bd47f 100644 --- a/testing/apps/DoseAcc/DoseAccInvalidParametersTest.cpp +++ b/testing/apps/DoseAcc/DoseAccInvalidParametersTest.cpp @@ -1,97 +1,103 @@ // ----------------------------------------------------------------------- // 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. DoseTool is in the same directory (Debug/Release) extern const char* _callingAppPath; int DoseAccInvalidParametersTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; std::string doseAccExecutable; if (argc > 1) { doseAccExecutable = argv[1]; } boost::filesystem::path callingPath(_callingAppPath); std::string doseAccExeWithPath = callingPath.parent_path().string() + "/" + doseAccExecutable; //call with too few parameters std::string toofewParametersCommand = doseAccExeWithPath; toofewParametersCommand += " test"; std::cout << "Command line call: " + toofewParametersCommand << std::endl; CHECK_EQUAL(system(toofewParametersCommand.c_str()) != 0, true); toofewParametersCommand = doseAccExeWithPath; toofewParametersCommand += " test test"; std::cout << "Command line call: " + toofewParametersCommand << std::endl; CHECK_EQUAL(system(toofewParametersCommand.c_str()) != 0, true); toofewParametersCommand = doseAccExeWithPath; toofewParametersCommand += " -d test"; toofewParametersCommand += " -e test"; std::cout << "Command line call: " + toofewParametersCommand << std::endl; CHECK_EQUAL(system(toofewParametersCommand.c_str()) != 0, true); std::string minimalCLI = doseAccExeWithPath + " test test test "; //call with invalid interpolator std::string invalidInterpolatorOption = minimalCLI; invalidInterpolatorOption += "-i wrongInterpolator"; std::cout << "Command line call: " + invalidInterpolatorOption << std::endl; CHECK_EQUAL(system(invalidInterpolatorOption.c_str()) != 0, true); //call with invalid operator std::string invalidOperatorOption = minimalCLI; invalidOperatorOption += "-p -"; std::cout << "Command line call: " + invalidOperatorOption << std::endl; CHECK_EQUAL(system(invalidOperatorOption.c_str()) != 0, true); + //call with operator* and weight + std::string invalidOperatorMultWithWeightOption = minimalCLI; + invalidOperatorMultWithWeightOption += "-p * --weight1 2.0"; + std::cout << "Command line call: " + invalidOperatorMultWithWeightOption << std::endl; + CHECK_EQUAL(system(invalidOperatorMultWithWeightOption.c_str()) != 0, true); + //call with invalid dose1 load option std::string invalidDose1LoadOption = minimalCLI; invalidDose1LoadOption += "-t invalidLoadStyleOption"; std::cout << "Command line call: " + invalidDose1LoadOption << std::endl; CHECK_EQUAL(system(invalidDose1LoadOption.c_str()) != 0, true); //call with invalid dose2 load option std::string invalidDose2LoadOption = minimalCLI; invalidDose2LoadOption += "-u invalidLoadStyleOption"; std::cout << "Command line call: " + invalidDose2LoadOption << std::endl; CHECK_EQUAL(system(invalidDose2LoadOption.c_str()) != 0, true); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace rttb diff --git a/testing/apps/DoseAcc/DoseAccNeutralWeightTest.cpp b/testing/apps/DoseAcc/DoseAccNeutralWeightTest.cpp new file mode 100644 index 0000000..647a407 --- /dev/null +++ b/testing/apps/DoseAcc/DoseAccNeutralWeightTest.cpp @@ -0,0 +1,108 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 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 "litCheckMacros.h" +#include "litImageTester.h" + +#include "boost/filesystem.hpp" + +#include "itkImage.h" + +#include "rttbITKIOHelper.h" + +namespace rttb +{ + namespace testing + { + + //path to the current running directory. DoseTool is in the same directory (Debug/Release) + extern const char* _callingAppPath; + + int DoseAccNeutralWeightTest(int argc, char* argv[]) + { + PREPARE_DEFAULT_TEST_REPORTING; + + std::string doseAccExecutable; + std::string doseFilename; + std::string referenceFilename; + std::string reference2Filename; + + boost::filesystem::path callingPath(_callingAppPath); + + + if (argc > 4) + { + doseAccExecutable = argv[1]; + doseFilename = argv[2]; + referenceFilename = argv[3]; + reference2Filename = argv[4]; + } + + std::string doseAccExeWithPath = callingPath.parent_path().string() + "/" + doseAccExecutable; + + const std::string defaultOutputAddFilename = "doseAccAddOutput.nrrd"; + const std::string defaultOutputMultFilename = "doseAccMultOutput.nrrd"; + + std::string baseCommand = doseAccExeWithPath; + baseCommand += " -d " + doseFilename; + baseCommand += " -e " + doseFilename; + + std::string defaultDoseAccAddCommand = baseCommand + " -o " + defaultOutputAddFilename + " --weight1 0.0"; + std::cout << "Command line call: " + defaultDoseAccAddCommand << std::endl; + CHECK_EQUAL(system(defaultDoseAccAddCommand.c_str()), 0); + + CHECK_EQUAL(boost::filesystem::exists(defaultOutputAddFilename), true); + + std::string defaultDoseAccMultCommand = baseCommand + " -o " + defaultOutputMultFilename + " --operator *"; + std::cout << "Command line call: " + defaultDoseAccMultCommand << std::endl; + CHECK_EQUAL(system(defaultDoseAccMultCommand.c_str()), 0); + + CHECK_EQUAL(boost::filesystem::exists(defaultOutputMultFilename), true); + + // Check result against reference + typedef ::itk::Image TestImageType; + + TestImageType::Pointer referenceAddImage = io::itk::readITKDoubleImage(referenceFilename); + TestImageType::Pointer outputAddImage = io::itk::readITKDoubleImage(defaultOutputAddFilename); + + lit::ImageTester tester; + tester.setExpectedImage(referenceAddImage); + tester.setActualImage(outputAddImage); + tester.setCheckThreshold(1e-5); + + CHECK_TESTER(tester); + + TestImageType::Pointer referenceMultImage = io::itk::readITKDoubleImage(reference2Filename); + TestImageType::Pointer outputMultImage = io::itk::readITKDoubleImage(defaultOutputMultFilename); + + tester.setExpectedImage(referenceMultImage); + tester.setActualImage(outputMultImage); + tester.setCheckThreshold(1e-5); + + CHECK_TESTER(tester); + + CHECK_EQUAL(std::remove(defaultOutputAddFilename.c_str()), 0); + CHECK_EQUAL(std::remove(defaultOutputMultFilename.c_str()), 0); + + RETURN_AND_REPORT_TEST_SUCCESS; + } + } //namespace testing +} //namespace rttb diff --git a/testing/apps/DoseAcc/DoseAccSimpleTest.cpp b/testing/apps/DoseAcc/DoseAccSimpleTest.cpp index 56f0d45..be2d9d5 100644 --- a/testing/apps/DoseAcc/DoseAccSimpleTest.cpp +++ b/testing/apps/DoseAcc/DoseAccSimpleTest.cpp @@ -1,97 +1,92 @@ // ----------------------------------------------------------------------- // 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 "litImageTester.h" #include "boost/filesystem.hpp" -#include "boost/algorithm/string.hpp" #include "itkImage.h" #include "rttbITKIOHelper.h" namespace rttb { namespace testing { //path to the current running directory. DoseTool is in the same directory (Debug/Release) extern const char* _callingAppPath; int DoseAccSimpleTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; std::string doseAccExecutable; std::string dose1Filename; std::string dose2Filename; std::string referenceFilename; boost::filesystem::path callingPath(_callingAppPath); if (argc > 4) { doseAccExecutable = argv[1]; dose1Filename = argv[2]; dose2Filename = argv[3]; referenceFilename = argv[4]; } std::string doseAccExeWithPath = callingPath.parent_path().string() + "/" + doseAccExecutable; std::string defaultOutputFilename = "doseAccOutput.nrrd"; std::string baseCommand = doseAccExeWithPath; baseCommand += " -d " + dose1Filename; baseCommand += " -e " + dose2Filename; baseCommand += " -o " + defaultOutputFilename; std::string defaultDoseAccCommand = baseCommand + " --weight1 2.0"; std::cout << "Command line call: " + defaultDoseAccCommand << std::endl; CHECK_EQUAL(system(defaultDoseAccCommand.c_str()), 0); CHECK_EQUAL(boost::filesystem::exists(defaultOutputFilename), true); // Check result against reference typedef ::itk::Image TestImageType; TestImageType::Pointer referenceImage = io::itk::readITKDoubleImage(referenceFilename); TestImageType::Pointer outputImage = io::itk::readITKDoubleImage(defaultOutputFilename); lit::ImageTester tester; tester.setExpectedImage(referenceImage); tester.setActualImage(outputImage); tester.setCheckThreshold(0.0); CHECK_TESTER(tester); CHECK_EQUAL(std::remove(defaultOutputFilename.c_str()), 0); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace rttb diff --git a/testing/apps/DoseAcc/DoseAccTests.cpp b/testing/apps/DoseAcc/DoseAccTests.cpp index aba4b58..1ec199a 100644 --- a/testing/apps/DoseAcc/DoseAccTests.cpp +++ b/testing/apps/DoseAcc/DoseAccTests.cpp @@ -1,70 +1,71 @@ // ----------------------------------------------------------------------- // 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(DoseAccInvalidParametersTest); LIT_REGISTER_TEST(DoseAccSimpleTest); + LIT_REGISTER_TEST(DoseAccNeutralWeightTest); } } //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/DoseAcc/files.cmake b/testing/apps/DoseAcc/files.cmake index cb2ae19..33064b3 100644 --- a/testing/apps/DoseAcc/files.cmake +++ b/testing/apps/DoseAcc/files.cmake @@ -1,8 +1,9 @@ SET(CPP_FILES DoseAccSimpleTest.cpp + DoseAccNeutralWeightTest.cpp DoseAccInvalidParametersTest.cpp DoseAccTests.cpp ) SET(H_FILES )