diff --git a/apps/VoxelizerTool/CMakeLists.txt b/apps/VoxelizerTool/CMakeLists.txt index 4ba9471..844787b 100644 --- a/apps/VoxelizerTool/CMakeLists.txt +++ b/apps/VoxelizerTool/CMakeLists.txt @@ -1,7 +1,7 @@ MESSAGE (STATUS "generating app: VoxelizerTool - writing files of voxelized structures") -RTTB_CREATE_APPLICATION(VoxelizerTool DEPENDS RTTBITKIO RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBMasks RTTBCore PACKAGE_DEPENDS ArgumentParsingLib ITK BoostBinaries) +RTTB_CREATE_APPLICATION(VoxelizerTool DEPENDS RTTBITKIO RTTBBoostMask RTTBDicomIO RTTBMasks RTTBCore PACKAGE_DEPENDS ArgumentParsingLib ITK BoostBinaries) IF (NOT WIN32) #CMake 3.1 provides target_compile_features(RTTB_Interpolation cxx_auto_type cxx_nullptr cxx_override) to automatically add required compiler flags set(CMAKE_CXX_FLAGS "-std=c++11 -fpermissive") ENDIF() diff --git a/apps/VoxelizerTool/VoxelizerTool.cpp b/apps/VoxelizerTool/VoxelizerTool.cpp index 133cfa2..4b2b714 100644 --- a/apps/VoxelizerTool/VoxelizerTool.cpp +++ b/apps/VoxelizerTool/VoxelizerTool.cpp @@ -1,205 +1,207 @@ // ----------------------------------------------------------------------- // 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: 1390 $ (last changed revision) // @date $Date: 2016-07-13 09:57:44 +0200 (Mi, 13 Jul 2016) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include +#include "boost/make_shared.hpp" + #include "itkMacro.h" #include "VoxelizerToolHelper.h" #include "rttbMaskProcess.h" #include "rttbMaskWriter.h" #include "rttbStructDataReader.h" +#include "rttbException.h" #include "VoxelizerToolCmdLineParser.h" #include "VoxelizerToolApplicationData.h" #include "RTToolboxConfigure.h" rttb::apps::voxelizerTool::ApplicationData appData; int main(int argc, const char** argv) { typedef rttb::core::MaskAccessorInterface::MaskAccessorPointer MaskAccessorPointer; const std::string appCategory = "RT-Toolbox App"; const std::string appName = "VoxelizerTool"; const std::string appDesc = "An App to voxelize RT structures in a reference image."; const std::string appContributor = "SIDT@DKFZ"; const std::string appVersion = RTTB_FULL_VERSION_STRING; boost::shared_ptr argParser; try { argParser = boost::make_shared(argc, argv, appName, appVersion, appDesc, appContributor, appCategory); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 5; } // This is vital. The application needs to exit if the "help" or "version" parameter is set // because this means the other parameters won't be parsed. if (argParser->isSet(argParser->OPTION_HELP) || argParser->isSet(argParser->OPTION_VERSION) || argParser->isSet(argParser->OPTION_XML)) { return 0; } rttb::apps::voxelizerTool::populateAppData(argParser, appData); std::cout << std::endl << "*******************************************" << std::endl; std::cout << "Struct file: " << appData._structFile << std::endl; std::cout << "Reference Image: " << appData._referenceFile << std::endl; std::cout << "Output file: " << appData._outputFilename << std::endl; std::cout << "Struct regex: " << appData._regEx << std::endl; - std::cout << "Legacy Voxelization: " << appData._legacyVoxelization << std::endl; std::cout << "Add structures: " << appData._addStructures << std::endl; std::cout << "Multiple Struct: " << appData._multipleStructs << std::endl << std::endl; boost::shared_ptr reader = boost::make_shared(appData._structFile, - appData._referenceFile, appData._referenceFileLoadStyle); + appData._referenceFile, appData._referenceFileLoadStyle, appData._regEx); std::cout << "reading reference and structure file..." << std::endl; try { reader->read(); } catch (rttb::core::Exception& e) { std::cerr << "RTTB Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 2; } catch (const std::exception& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 2; } catch (...) { std::cerr << "Error!!! unknown error while reading input image." << std::endl; return 2; } std::cout << "done." << std::endl; std::cout << "searching for structs..."; std::vector listOfCorrectElements; std::vector indexOfCorrectElements; indexOfCorrectElements = rttb::apps::voxelizerTool::filterForExpression(reader->getAllLabels(), appData._regEx); std::copy(indexOfCorrectElements.begin(), indexOfCorrectElements.end(), std::back_inserter(listOfCorrectElements)); std::cout << "done." << std::endl; boost::shared_ptr maskProcessor = boost::make_shared(reader->getStructureSetPointer(), reader->getDoseAccessorPointer(), - appData._legacyVoxelization, appData._allowSelfIntersections); + appData._allowSelfIntersections); if (!listOfCorrectElements.empty()) { std::string fileName = rttb::apps::voxelizerTool::getFilenameWithoutEnding( appData._outputFilename); std::string fileEnding = rttb::apps::voxelizerTool::getFileEnding(appData._outputFilename); std::vector maskVector; std::vector labelVector = reader->getAllLabels(); if (appData._addStructures) { std::string labelName; for (unsigned int i = 0; i < listOfCorrectElements.size(); i++) { int labelIndex = listOfCorrectElements.at(i); maskVector.push_back(maskProcessor->createMask(labelIndex)); std::string labelOfInterest = labelVector.at(labelIndex); rttb::apps::voxelizerTool::removeSpecialCharacters(labelOfInterest); labelName += "_" + labelOfInterest; } boost::shared_ptr writer = boost::make_shared(maskVector, appData._booleanVoxelization); writer->writeMaskToFile(fileName + labelName + fileEnding); } else { unsigned int maxIterationCount = 1; if (appData._multipleStructs) { maxIterationCount = listOfCorrectElements.size(); } for (unsigned int i = 0; i < maxIterationCount; i++) { std::cout << "creating mask..."; maskVector.push_back(maskProcessor->createMask(listOfCorrectElements.at(i))); std::cout << "done" << std::endl; int labelIndex = listOfCorrectElements.at(i); std::string labelOfInterest = labelVector.at(labelIndex); rttb::apps::voxelizerTool::removeSpecialCharacters(labelOfInterest); boost::shared_ptr MW = boost::make_shared(maskVector, appData._booleanVoxelization); try { MW->writeMaskToFile(fileName + "_" + labelOfInterest + fileEnding); } catch (itk::ExceptionObject& err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; return 3; } catch (const std::exception& e) { std::cerr << "Error!!!" << std::endl; std::cerr << e.what() << std::endl; return 3; } catch (...) { std::cerr << "Error!!! unknown error while reading input image." << std::endl; return 3; } } } } else { std::cout << "No struct found" << std::endl; } return 0; } diff --git a/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp b/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp index 1fbf60a..9e0d4ed 100644 --- a/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp +++ b/apps/VoxelizerTool/VoxelizerToolApplicationData.cpp @@ -1,98 +1,89 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1221 $ (last changed revision) // @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include "VoxelizerToolApplicationData.h" namespace rttb { namespace apps { namespace voxelizerTool { ApplicationData:: ApplicationData() { this->reset(); } void ApplicationData:: reset() { _structFile = ""; _referenceFile = ""; _outputFilename = ""; _regEx=""; _multipleStructs = false; - _legacyVoxelization = false; _booleanVoxelization = false; _addStructures = false; _allowSelfIntersections = false; } void populateAppData(boost::shared_ptr argParser, ApplicationData& appData) { appData._structFile = argParser->get(argParser->OPTION_STRUCT_FILE); appData._referenceFile = argParser->get(argParser->OPTION_REFERENCE_FILE); appData._outputFilename = argParser->get(argParser->OPTION_OUTPUT_FILE_NAME); appData._referenceFileLoadStyle = argParser->get>(argParser->OPTION_REFERENCE_FILE_LOAD_STYLE); appData._regEx = argParser->get(argParser->OPTION_REGEX); if (argParser->isSet(argParser->OPTION_MULTIPLE_STRUCTS)) { appData._multipleStructs = true; if (argParser->isSet(argParser->OPTION_ADDSTRUCTURES)) { appData._addStructures = true; } else { appData._addStructures = false; } } - if (argParser->isSet(argParser->OPTION_LEGACY_VOXELIZATION)) - { - appData._legacyVoxelization = true; - } - else { - appData._legacyVoxelization = false; - } - if (argParser->isSet(argParser->OPTION_BOOLEAN_VOXELIZATION)) { appData._booleanVoxelization = true; } if (argParser->isSet(argParser->OPTION_ADDSTRUCTURES)) { appData._multipleStructs = false; appData._addStructures = true; } if (argParser->isSet(argParser->OPTION_ALLOW_SELF_INTERSECTIONS)) { appData._allowSelfIntersections = true; } } } } } diff --git a/apps/VoxelizerTool/VoxelizerToolApplicationData.h b/apps/VoxelizerTool/VoxelizerToolApplicationData.h index 5d22eca..62d5b55 100644 --- a/apps/VoxelizerTool/VoxelizerToolApplicationData.h +++ b/apps/VoxelizerTool/VoxelizerToolApplicationData.h @@ -1,66 +1,65 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1221 $ (last changed revision) // @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __VoxelizerApplicationData_h #define __VoxelizerApplicationData_h #include #include "VoxelizerToolCmdLineParser.h" namespace rttb { namespace apps { namespace voxelizerTool { /*! @class ApplicationData @brief Class for storing all relevant variables needed in DoseTool */ class ApplicationData { public: std::string _structFile; std::string _referenceFile; std::vector _referenceFileLoadStyle; std::string _outputFilename; std::string _regEx; bool _multipleStructs; - bool _legacyVoxelization; bool _booleanVoxelization; bool _addStructures; bool _allowSelfIntersections; /*! @brief Resets the variables. */ void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the VoxelizerCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp index 46cd7d3..3e4775e 100644 --- a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp +++ b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.cpp @@ -1,125 +1,122 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1221 $ (last changed revision) // @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "VoxelizerToolCmdLineParser.h" namespace rttb { namespace apps { namespace voxelizerTool { VoxelizerCmdLineParser::VoxelizerCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category) : CmdLineParserBase(name, version, description, contributor, category) { //REQUIRED addOption(OPTION_STRUCT_FILE, OPTION_GROUP_REQUIRED, "Filename of the structfile (*.dcm)", 's', true); addInformationForXML(OPTION_STRUCT_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, {"dcm"}); addOption(OPTION_REFERENCE_FILE, OPTION_GROUP_REQUIRED, "Filename of the reference image (*.dcm)", 'r', true); addInformationForXML(OPTION_REFERENCE_FILE, cmdlineparsing::XMLGenerator::paramType::INPUT, { "dcm" }); addOptionWithDefaultValue(OPTION_OUTPUT_FILE_NAME, OPTION_GROUP_REQUIRED, "set output file name","out.hdr","out.hdr", 'o', true); addInformationForXML(OPTION_OUTPUT_FILE_NAME, cmdlineparsing::XMLGenerator::paramType::OUTPUT, { "nrrd", "hdr" }); addPositionalOption(OPTION_STRUCT_FILE,1); addPositionalOption(OPTION_REFERENCE_FILE, 1); addPositionalOption(OPTION_OUTPUT_FILE_NAME, 1); std::vector defaultLoadingStyle; defaultLoadingStyle.push_back("dicom"); addOptionWithDefaultValue(OPTION_REGEX, OPTION_GROUP_REQUIRED, "set a regular expression describing the structs of interest", "", "",'e', true); addInformationForXML(OPTION_REGEX, cmdlineparsing::XMLGenerator::paramType::STRING); addOptionWithDefaultValue>(OPTION_REFERENCE_FILE_LOAD_STYLE, OPTION_GROUP_REQUIRED, "set the load style for the reference file. Available styles are: " "dicom: normal dicom dose" "itk: use itk image loading.", defaultLoadingStyle, defaultLoadingStyle.at(0), 'y', true); addInformationForXML(OPTION_REFERENCE_FILE_LOAD_STYLE, cmdlineparsing::XMLGenerator::paramType::STRINGENUMERATION, { "dicom", "itk" }); //OPTIONAL addOption(OPTION_MULTIPLE_STRUCTS, OPTION_GROUP_OPTIONAL, "if multiple structs match the regular expression" + OPTION_STRUCT_FILE + ", save all in files\n" "If structures 'Kidney_left' and 'Kidney_right' are defined,\n" "both are written under the names outputFile_Kidney_left.mhd and outputFile_Kidney_right.mhd",'m'); addInformationForXML(OPTION_MULTIPLE_STRUCTS, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); - addOption(OPTION_LEGACY_VOXELIZATION, OPTION_GROUP_OPTIONAL, - "to use legacy voxelization",'l'); - addInformationForXML(OPTION_LEGACY_VOXELIZATION, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_BOOLEAN_VOXELIZATION, OPTION_GROUP_OPTIONAL, "Determines if the voxelization should be binarized (only values 0 or 1), the threshold value is by 0.5",'z'); addInformationForXML(OPTION_BOOLEAN_VOXELIZATION, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_ADDSTRUCTURES, OPTION_GROUP_OPTIONAL, "Voxelizes multiple structs in one result file.",'a'); addInformationForXML(OPTION_ADDSTRUCTURES, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); addOption(OPTION_ALLOW_SELF_INTERSECTIONS, OPTION_GROUP_OPTIONAL, "If self intersections of polygons should be tolerated.",'i'); addInformationForXML(OPTION_ALLOW_SELF_INTERSECTIONS, cmdlineparsing::XMLGenerator::paramType::BOOLEAN); parse(argc, argv); } void VoxelizerCmdLineParser::validateInput() const { std::vector referenceLoadStyle = get >(OPTION_REFERENCE_FILE_LOAD_STYLE); std::string referenceLoadStyleString = referenceLoadStyle.at(0); if (referenceLoadStyleString != "dicom" && referenceLoadStyleString != "itk") { throw cmdlineparsing::InvalidConstraintException("Unknown load style for reference file:" + referenceLoadStyleString+ ".\nPlease refer to the help for valid loading style settings."); } if (get(OPTION_OUTPUT_FILE_NAME).find('.') == std::string::npos) { throw cmdlineparsing::InvalidConstraintException(OPTION_OUTPUT_FILE_NAME + " has to specify a file format (e.g. output.hdr). None is given: " + get(OPTION_OUTPUT_FILE_NAME) ); } } void VoxelizerCmdLineParser::printHelp() const { cmdlineparsing::CmdLineParserBase::printHelp(); std::cout << "Example: VoxelizerTool -s structFile.dcm -r referenceFile.dcm -e Kidney -o outputFile.mhd -m" << std::endl; std::cout << "Computes a voxelization file outputFile.mhd based on the DICOMRT-STRUCT structFile.dcm " "in the geometry of referenceFile.dcm where "; std::cout << "the name of the struct matches the regular expression 'Kidney'.\n"; std::cout << "If structures 'Kidney_left' and 'Kidney_right' are defined, "; std::cout << "both are written under the names outputFile_Kidney_left.mhd and outputFile_Kidney_right.mhd (parameter -m)." << std::endl; } } } } \ No newline at end of file diff --git a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.h b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.h index df33792..e7898d6 100644 --- a/apps/VoxelizerTool/VoxelizerToolCmdLineParser.h +++ b/apps/VoxelizerTool/VoxelizerToolCmdLineParser.h @@ -1,66 +1,65 @@ // ----------------------------------------------------------------------- // 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 __VoxelizerCmdLineParser_h #define __VoxelizerCmdLineParser_h #include "CmdLineParserBase.h" namespace rttb { namespace apps { namespace voxelizerTool { /*! @class rttbVoxelizerCmdLineParser @brief Argument parsing is parametrized here based on ArgParserLib @see cmdlineparsing::CmdLineParserBase */ class VoxelizerCmdLineParser : public cmdlineparsing::CmdLineParserBase { public: VoxelizerCmdLineParser(int argc, const char** argv, const std::string& name, const std::string& version, const std::string& description, const std::string& contributor, const std::string& category); void validateInput() const override; void printHelp() const override; // Option groups const std::string OPTION_GROUP_REQUIRED = "Required Arguments"; const std::string OPTION_GROUP_OPTIONAL = "Optional Arguments"; // Parameters const std::string OPTION_STRUCT_FILE = "structFile"; const std::string OPTION_REFERENCE_FILE = "referenceFile"; const std::string OPTION_REFERENCE_FILE_LOAD_STYLE = "referenceFileLoadStyle"; const std::string OPTION_OUTPUT_FILE_NAME = "output"; const std::string OPTION_REGEX = "struct"; const std::string OPTION_MULTIPLE_STRUCTS = "multipleStructs"; - const std::string OPTION_LEGACY_VOXELIZATION = "legacyVoxelization"; const std::string OPTION_BOOLEAN_VOXELIZATION = "booleanVoxelization"; const std::string OPTION_ADDSTRUCTURES = "addStructures"; const std::string OPTION_ALLOW_SELF_INTERSECTIONS = "allowSelfIntersections"; }; } } } #endif \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbMaskProcess.cpp b/apps/VoxelizerTool/rttbMaskProcess.cpp index 7c26bd1..7b9287b 100644 --- a/apps/VoxelizerTool/rttbMaskProcess.cpp +++ b/apps/VoxelizerTool/rttbMaskProcess.cpp @@ -1,66 +1,57 @@ // ----------------------------------------------------------------------- // 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: 1377 $ (last changed revision) // @date $Date: 2016-06-07 10:26:43 +0200 (Di, 07 Jun 2016) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbMaskProcess.h" -#include +#include "boost/make_shared.hpp" #include "rttbBoostMaskAccessor.h" namespace rttb { namespace apps { namespace voxelizerTool { MaskProcess::MaskProcess(StructureSetPointer rtStructureSet, DoseAccessorPointer doseAccessor, - bool legacy, bool allowSelfIntersection) : _rtStructureSet(rtStructureSet), - _doseAccessor(doseAccessor), - _legacyVoxelization(legacy), _allowSelfIntersection(allowSelfIntersection) + bool allowSelfIntersection) : _rtStructureSet(rtStructureSet), + _doseAccessor(doseAccessor), _allowSelfIntersection(allowSelfIntersection) { } MaskProcess::MaskAccessorPointer MaskProcess::createMask(unsigned int indexOfStructure) const { MaskAccessorPointer maskAccessorPtr; - if (_doseAccessor != NULL && _rtStructureSet != NULL) + if (_doseAccessor != nullptr && _rtStructureSet != nullptr) { - if (_legacyVoxelization) - { - maskAccessorPtr = boost::make_shared - (_rtStructureSet->getStructure(indexOfStructure), _doseAccessor->getGeometricInfo()); - } - else - { - maskAccessorPtr = boost::make_shared + maskAccessorPtr = boost::make_shared (_rtStructureSet->getStructure(indexOfStructure), _doseAccessor->getGeometricInfo(), !_allowSelfIntersection); - } maskAccessorPtr->updateMask(); } return maskAccessorPtr; } } } } \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbMaskProcess.h b/apps/VoxelizerTool/rttbMaskProcess.h index 0367175..aff80db 100644 --- a/apps/VoxelizerTool/rttbMaskProcess.h +++ b/apps/VoxelizerTool/rttbMaskProcess.h @@ -1,63 +1,63 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1377 $ (last changed revision) // @date $Date: 2016-06-07 10:26:43 +0200 (Di, 07 Jun 2016) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __MaskProcess_h #define __MaskProcess_h -#include "rttbDicomFileStructureSetGenerator.h" -#include "rttbOTBMaskAccessor.h" +#include "rttbStructureSetGeneratorInterface.h" +#include "rttbMaskAccessorInterface.h" +#include "rttbGenericDoseIterator.h" namespace rttb { namespace apps { namespace voxelizerTool { /*! @class MaskProcess @brief MaskProcess create a Mask with the struct and reference object */ class MaskProcess { public: typedef core::MaskAccessorInterface::MaskAccessorPointer MaskAccessorPointer; typedef core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; typedef core::StructureSetGeneratorInterface::StructureSetPointer StructureSetPointer; /*!@brief Constructor @details save the rtStructureSet (structfile) object into _rtStructureSet and * doseAccessor (referencefile) object into _doseAccessor */ MaskProcess(StructureSetPointer rtStructureSet, DoseAccessorPointer doseAccessor, - bool legacyVoxelization, bool allowSelfIntersection); + bool allowSelfIntersection); /**@brief create a mask with _rtStructureSet and _doseAccessor object. @return a mask object */ MaskAccessorPointer createMask(unsigned int numberOfStructure) const; private: StructureSetPointer _rtStructureSet; DoseAccessorPointer _doseAccessor; - bool _legacyVoxelization; bool _allowSelfIntersection; }; } } } #endif \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbStructDataReader.cpp b/apps/VoxelizerTool/rttbStructDataReader.cpp index 6026559..350879f 100644 --- a/apps/VoxelizerTool/rttbStructDataReader.cpp +++ b/apps/VoxelizerTool/rttbStructDataReader.cpp @@ -1,117 +1,124 @@ // ----------------------------------------------------------------------- // 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: 1377 $ (last changed revision) // @date $Date: 2016-06-07 10:26:43 +0200 (Di, 07 Jun 2016) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbStructDataReader.h" #include "rttbDicomFileDoseAccessorGenerator.h" +#include "rttbDicomFileStructureSetGenerator.h" #include "rttbITKImageFileAccessorGenerator.h" #include "rttbInvalidParameterException.h" namespace rttb { namespace apps { namespace voxelizerTool { StructDataReader::StructDataReader(const std::string& structFileName, const std::string& referenceFileName, - const std::vector& referenceFileLoadingStyle) : _referenceFilename(referenceFileName), - _structFilename(structFileName), _referenceFileLoadingStyle(referenceFileLoadingStyle) + const std::vector& referenceFileLoadingStyle, const std::string& structRegex) : _referenceFilename(referenceFileName), + _structFilename(structFileName), _referenceFileLoadingStyle(referenceFileLoadingStyle), _structRegex(structRegex) { } void StructDataReader::read() { _doseAccessor = readReferenceFile(_referenceFilename, _referenceFileLoadingStyle); - _rtStructureSet = readStructFile(_structFilename); + _rtStructureSet = readStructFile(_structFilename, _structRegex); } std::vector StructDataReader::getAllLabels() const { std::vector allLabels; if (_rtStructureSet != NULL) { for (int j = 0; j < _rtStructureSet->getNumberOfStructures(); j++) { allLabels.push_back(_rtStructureSet->getStructure(j)->getLabel()); } } return allLabels; } StructDataReader::StructureSetPointer StructDataReader::getStructureSetPointer() const { return _rtStructureSet; } StructDataReader::DoseAccessorPointer StructDataReader::getDoseAccessorPointer() const { return _doseAccessor; } StructDataReader::DoseAccessorPointer StructDataReader::readReferenceFile( const std::string& filename, const std::vector& fileLoadingStyle) const { if (fileLoadingStyle.at(0) == "dicom") { return readDicomFile(filename); } else if (fileLoadingStyle.at(0) == "itk") { return readITKFile(filename); } else { - return NULL; + return nullptr; } } StructDataReader::DoseAccessorPointer StructDataReader::readDicomFile( const std::string& filename) const { rttb::io::dicom::DicomFileDoseAccessorGenerator doseAccessorGenerator(filename.c_str()); return doseAccessorGenerator.generateDoseAccessor(); } StructDataReader::DoseAccessorPointer StructDataReader::readITKFile(const std::string& filename) const { rttb::io::itk::ITKImageFileAccessorGenerator generator(filename); return generator.generateDoseAccessor(); } - StructDataReader::StructureSetPointer StructDataReader::readStructFile( - const std::string& filename) const - { - StructureSetPointer rtStructureSet = rttb::io::dicom::DicomFileStructureSetGenerator( - filename.c_str()).generateStructureSet(); - return rtStructureSet; - } + StructDataReader::StructureSetPointer StructDataReader::readStructFile( + const std::string& fileName, const std::string& structNameRegex) const + { + rttb::io::dicom::DicomFileStructureSetGenerator generator(fileName); + + if (!structNameRegex.empty()) + { + generator.setStructureLableFilterActive(true); + generator.setFilterRegEx(structNameRegex); + } + + return generator.generateStructureSet(); + } } } } \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbStructDataReader.h b/apps/VoxelizerTool/rttbStructDataReader.h index 261b153..691e047 100644 --- a/apps/VoxelizerTool/rttbStructDataReader.h +++ b/apps/VoxelizerTool/rttbStructDataReader.h @@ -1,88 +1,90 @@ // ----------------------------------------------------------------------- // 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: 1377 $ (last changed revision) // @date $Date: 2016-06-07 10:26:43 +0200 (Di, 07 Jun 2016) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __StructDataReader_h #define __StructDataReader_h -#include "rttbDicomFileStructureSetGenerator.h" -#include "rttbOTBMaskAccessor.h" +#include "rttbStructureSetGeneratorInterface.h" +#include "rttbMaskAccessorInterface.h" +#include "rttbGenericDoseIterator.h" namespace rttb { namespace apps { namespace voxelizerTool { /*! @class StructDataReader @brief StructDataReader read struct and reference file */ class StructDataReader { public: typedef rttb::core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; typedef rttb::core::StructureSetGeneratorInterface::StructureSetPointer StructureSetPointer; StructDataReader(const std::string& structFileName, const std::string& referenceFileName, - const std::vector& referenceFileLoadingStyle); + const std::vector& referenceFileLoadingStyle, const std::string& structRegex); /*!@brief Reads structure and reference file and saves the result in variables */ void read(); /**@brief read all labels an save it in a vector. @return a vector of all labels */ std::vector getAllLabels() const; /**@brief @return the object _rtStructureSet */ StructureSetPointer getStructureSetPointer() const; /**@brief @return the object _doseAccessor */ DoseAccessorPointer getDoseAccessorPointer() const; private: /**@brief read a reference file @return the result as object */ DoseAccessorPointer readReferenceFile(const std::string& filename, const std::vector& fileLoadingStyle) const; DoseAccessorPointer readDicomFile(const std::string& filename) const; DoseAccessorPointer readITKFile(const std::string& filename) const; /**@brief read a struct file @return the result as object */ - StructureSetPointer readStructFile(const std::string& filename) const; + StructureSetPointer readStructFile(const std::string& fileName, const std::string& structNameRegex) const; StructureSetPointer _rtStructureSet; DoseAccessorPointer _doseAccessor; std::string _structFilename; std::string _referenceFilename; + std::string _structRegex; std::vector _referenceFileLoadingStyle; }; } } } #endif \ No newline at end of file diff --git a/testing/apps/VoxelizerTool/CMakeLists.txt b/testing/apps/VoxelizerTool/CMakeLists.txt index 9f45d9d..a3906c6 100644 --- a/testing/apps/VoxelizerTool/CMakeLists.txt +++ b/testing/apps/VoxelizerTool/CMakeLists.txt @@ -1,32 +1,30 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- -SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/RTTBVoxelizerToolTests) +SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/rttbVoxelizerToolTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEST_DATA ${RTToolbox_BINARY_DIR}/testing/apps/VoxelizerTool) IF (WIN32) SET(VOXELIZERTOOL_EXE "VoxelizerTool") ELSE (WIN32) SET(VOXELIZERTOOL_EXE "./VoxelizerTool") ENDIF (WIN32) SET(STRUCT_FILE "${TEST_DATA_ROOT}/StructureSet/DICOM/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm") SET(REFERENCE_FILE "${TEST_DATA_ROOT}/Dose/DICOM/ConstantTwo.dcm") #----------------------------------------------------------------------------- ADD_TEST(rttbVoxelizerToolIncorrectCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolIncorrectCommandsTest "${VOXELIZERTOOL_EXE}" ${STRUCT_FILE} "${TEST_DATA_ROOT}/StructureSet/DICOM/Wrong_Data_Struct_file.dicom" ${REFERENCE_FILE} "${TEST_DATA_ROOT}/Dose/DICOM/Wrong_Reference_file.dicom" "Rueckenmark" "blabla") ADD_TEST(rttbVoxelizerToolVoxelizerAllStructsTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerAllStructsTest "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} ) ADD_TEST(rttbVoxelizerToolDifferentCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolDifferentCommandsTest "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE}) -ADD_TEST(rttbVoxelizerToolVoxelizerBoostLegacyTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerBoostLegacy -"${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(RTTBVoxelizerTool DEPENDS RTTBITKIO RTTBCore RTTBMasks RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBOtherIO PACKAGE_DEPENDS Litmus) +RTTB_CREATE_TEST_MODULE(RTTBVoxelizerTool PACKAGE_DEPENDS Litmus ITK BoostBinaries) diff --git a/testing/apps/VoxelizerTool/VoxelizerToolDifferentCommandsTest.cpp b/testing/apps/VoxelizerTool/VoxelizerToolDifferentCommandsTest.cpp index 94d0c87..cfae715 100644 --- a/testing/apps/VoxelizerTool/VoxelizerToolDifferentCommandsTest.cpp +++ b/testing/apps/VoxelizerTool/VoxelizerToolDifferentCommandsTest.cpp @@ -1,104 +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: 1333 $ (last changed revision) // @date $Date: 2016-04-22 11:12:14 +0200 (Fr, 22 Apr 2016) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include "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; 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("\"Niere.*\" -m -o Test.hdr"); - commands.push_back("\"Leber\" -o Boolean.hdr -z"); + commands.push_back("\"Rueckenmark\" -o Boolean.hdr -z"); std::vector filenames; filenames.push_back("Test_Niere li"); filenames.push_back("Test_Niere re"); - filenames.push_back("Boolean_Leber"); + filenames.push_back("Boolean_Rueckenmark"); 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 (size_t 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); } for (size_t 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)) { boost::filesystem::remove(IMGFile); } if (boost::filesystem::exists(HDRFile)) { boost::filesystem::remove(HDRFile); } } RETURN_AND_REPORT_TEST_SUCCESS; } } } diff --git a/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp b/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp index 2a55383..1248b72 100644 --- a/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp +++ b/testing/apps/VoxelizerTool/VoxelizerToolTests.cpp @@ -1,69 +1,68 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1127 $ (last changed revision) // @date $Date: 2015-10-01 13:33:33 +0200 (Do, 01 Okt 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ // this file defines the rttbCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "litMultiTestsMain.h" namespace rttb { namespace testing { const char* _callingAppPath = NULL; void registerTests() { LIT_REGISTER_TEST(VoxelizerToolDifferentCommandsTest); - LIT_REGISTER_TEST(VoxelizerToolVoxelizerBoostLegacy); 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/apps/VoxelizerTool/VoxelizerToolVoxelizerBoostLegacyTest.cpp b/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerBoostLegacyTest.cpp deleted file mode 100644 index 7deb1e6..0000000 --- a/testing/apps/VoxelizerTool/VoxelizerToolVoxelizerBoostLegacyTest.cpp +++ /dev/null @@ -1,104 +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: 1333 $ (last changed revision) -// @date $Date: 2016-04-22 11:12:14 +0200 (Fr, 22 Apr 2016) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ - -#include "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; - - 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"); - - 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 (size_t 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); - } - - for (size_t 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)) - { - boost::filesystem::remove(IMGFile); - } - - if (boost::filesystem::exists(HDRFile)) - { - boost::filesystem::remove(HDRFile); - } - } - - RETURN_AND_REPORT_TEST_SUCCESS; - } - - } -} diff --git a/testing/apps/VoxelizerTool/files.cmake b/testing/apps/VoxelizerTool/files.cmake index 90d7a19..46961ff 100644 --- a/testing/apps/VoxelizerTool/files.cmake +++ b/testing/apps/VoxelizerTool/files.cmake @@ -1,8 +1,7 @@ SET(CPP_FILES VoxelizerToolTests.cpp VoxelizerToolDifferentCommandsTest.cpp VoxelizerToolIncorrectCommandsTest.cpp VoxelizerToolVoxelizerAllStructsTest.cpp - VoxelizerToolVoxelizerBoostLegacyTest.cpp VoxelizerToolVoxelValueTest.cpp )