diff --git a/apps/VoxelizerTool/CMakeLists.txt b/apps/VoxelizerTool/CMakeLists.txt index ccaca69..9c99444 100644 --- a/apps/VoxelizerTool/CMakeLists.txt +++ b/apps/VoxelizerTool/CMakeLists.txt @@ -1,4 +1,4 @@ MESSAGE (STATUS "generating app: VoxelizerTool - voxelize RTSRUCT files") SET(RTTB_Boost_ADDITIONAL_COMPONENT program_options) -RTTB_CREATE_APPLICATION(VoxelizerTool DEPENDS RTTBITKIO RTTBBoostMask RTTBDicomIO RTTBMasks RTTBCore PACKAGE_DEPENDS ArgumentParsingLib ITK BoostBinaries) +RTTB_CREATE_APPLICATION(VoxelizerTool DEPENDS RTTBBoostMask RTTBMasks RTTBCore RTTBUtilsIO PACKAGE_DEPENDS ArgumentParsingLib ITK BoostBinaries) diff --git a/apps/VoxelizerTool/VoxelizerTool.cpp b/apps/VoxelizerTool/VoxelizerTool.cpp index ee1ac90..211eef0 100644 --- a/apps/VoxelizerTool/VoxelizerTool.cpp +++ b/apps/VoxelizerTool/VoxelizerTool.cpp @@ -1,213 +1,147 @@ // ----------------------------------------------------------------------- // 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" + +#include "rttbDoseLoader.cpp" +#include "rttbStructLoader.cpp" int main(int argc, const char** argv) { rttb::apps::voxelizerTool::ApplicationData appData; - 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 << "Add structures: " << appData._addStructures << std::endl; std::cout << "Multiple Struct: " << appData._multipleStructs << std::endl; std::cout << "No Strict voxelization: " << appData._noStrictVoxelization << std::endl << std::endl; - boost::shared_ptr reader = - boost::make_shared(appData._structFile, - 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._noStrictVoxelization); - - if (!listOfCorrectElements.empty()) - { - try - { - std::vector maskVector; - - std::vector labelVector = reader->getAllLabels(); - - if (appData._addStructures) - { - for (unsigned int i = 0; i < listOfCorrectElements.size(); i++) - { - unsigned int labelIndex = listOfCorrectElements.at(i); - maskVector.push_back(maskProcessor->createMask(labelIndex)); - } - - boost::shared_ptr writer = - boost::make_shared(maskVector, - appData._booleanVoxelization); - writer->writeMaskToFile(appData._outputFilename); - - } - 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 writer = - boost::make_shared(maskVector, - appData._booleanVoxelization); - - - std::string outputName = appData._outputFilename; - - if (appData._multipleStructs) - { - std::string fileName = rttb::apps::voxelizerTool::getFilenameWithoutEnding( - appData._outputFilename); - std::string fileEnding = rttb::apps::voxelizerTool::getFileEnding(appData._outputFilename); - outputName = fileName + "_" + labelOfInterest + fileEnding; - } - writer->writeMaskToFile(outputName); - } - - } - } - catch (rttb::core::Exception& e) - { - std::cerr << "RTTB Error while doing voxelization!!!" << std::endl; - std::cerr << e.what() << std::endl; - return 2; - } - 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 doing voxelization." << std::endl; - return 3; - } - } - else - { - std::cout << "No struct found" << std::endl; - } - + try + { + appData._dose = rttb::io::utils::loadDose(appData._referenceFile, appData._referenceFileLoadStyle); + } + 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 dose image." << std::endl; + return 2; + } + + try + { + appData._struct = rttb::io::utils::loadStruct(appData._structFile, appData._referenceFileLoadStyle, appData._regEx); + } + 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 struct image." << std::endl; + return 2; + } + + try + { + rttb::apps::voxelizerTool::processData(appData); + } + catch (rttb::core::Exception& e) + { + std::cerr << "RTTB Error while doing voxelization!!!" << std::endl; + std::cerr << e.what() << std::endl; + return 2; + } + 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 doing voxelization." << std::endl; + return 3; + } return 0; } diff --git a/apps/VoxelizerTool/VoxelizerToolApplicationData.h b/apps/VoxelizerTool/VoxelizerToolApplicationData.h index 1d08649..c173be6 100644 --- a/apps/VoxelizerTool/VoxelizerToolApplicationData.h +++ b/apps/VoxelizerTool/VoxelizerToolApplicationData.h @@ -1,67 +1,72 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1221 $ (last changed revision) // @date $Date: 2015-12-01 13:43:31 +0100 (Di, 01 Dez 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #ifndef __VoxelizerApplicationData_h #define __VoxelizerApplicationData_h #include "boost/shared_ptr.hpp" +#include "rttbDoseAccessorInterface.h" +#include "rttbStructureSetGeneratorInterface.h" + #include #include namespace rttb { namespace apps { namespace voxelizerTool { class VoxelizerCmdLineParser; /*! @class ApplicationData @brief Class for storing all relevant variables needed in VoxelizerTool */ class ApplicationData { public: - + typedef std::vector LoadingStyleArgType; + core::DoseAccessorInterface::DoseAccessorPointer _dose; + core::StructureSetGeneratorInterface::StructureSetPointer _struct; std::string _structFile; std::string _referenceFile; - std::vector _referenceFileLoadStyle; std::string _outputFilename; - std::string _regEx; + std::string _regEx; + LoadingStyleArgType _referenceFileLoadStyle; bool _multipleStructs; bool _booleanVoxelization; bool _addStructures; bool _noStrictVoxelization; /*! @brief Resets the variables. */ void reset(); ApplicationData(); }; /*! @brief Reads the necessary arguments from the VoxelizerCmdLineParser and writes them in the respective variables of ApplicationData. */ void populateAppData(boost::shared_ptr argParser, ApplicationData& appData); } } } #endif diff --git a/apps/VoxelizerTool/VoxelizerToolHelper.cpp b/apps/VoxelizerTool/VoxelizerToolHelper.cpp index f06811c..fc598ab 100644 --- a/apps/VoxelizerTool/VoxelizerToolHelper.cpp +++ b/apps/VoxelizerTool/VoxelizerToolHelper.cpp @@ -1,83 +1,285 @@ // ----------------------------------------------------------------------- // 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) */ +#include + +#include "rttbBoostMaskAccessor.h" + +#include "itkMacro.h" #include "VoxelizerToolHelper.h" +#include "VoxelizerToolApplicationData.h" + +#include "rttbITKImageMaskAccessorConverter.h" +#include "rttbImageWriter.h" +#include "itkBinaryThresholdImageFilter.h" +#include "itkAddImageFilter.h" #include #include #include -namespace rttb +#include "rttbDicomFileStructureSetGenerator.h" + +std::vector rttb::apps::voxelizerTool::filterForExpression(const std::vector& listOfExpressions, + const std::string& inputExpression) { - namespace apps + std::vector listOfFoundElements; + + for (unsigned int j = 0; j < listOfExpressions.size(); j++) { - namespace voxelizerTool - { + std::regex e(boost::algorithm::to_lower_copy(inputExpression)); + std::string s = boost::algorithm::to_lower_copy(listOfExpressions.at(j)); - std::vector filterForExpression(const std::vector& listOfExpressions, - const std::string& inputExpression) - { - std::vector listOfFoundElements; - - for (unsigned int j = 0; j < listOfExpressions.size(); j++) - { - std::regex e(boost::algorithm::to_lower_copy(inputExpression)); - std::string s = boost::algorithm::to_lower_copy(listOfExpressions.at(j)); - - if (std::regex_match(s, e)) - { - listOfFoundElements.push_back(j); - } - } - - return listOfFoundElements; - } - - void removeSpecialCharacters(std::string& label) - { - - //Replace / to avoid problems with directories (struct "Magen/DD" --> Magen/DD.mhd), delete trailing . to avoid filenames with two trailing points (Niere re. --> Niere re..mhd) - while (label.find("/") != std::string::npos) - { - label.replace(label.find("/"), 1, "_"); - } - - if (*label.rbegin() == '.') - { - label.replace(label.size() - 1, 1, ""); - } - } - - std::string getFilenameWithoutEnding(const std::string& outfilename) - { - boost::filesystem::path p(outfilename); - return p.replace_extension("").string(); - } - - std::string getFileEnding(const std::string& outfilename) - { - boost::filesystem::path p(outfilename); - return p.extension().string(); - } + if (std::regex_match(s, e)) + { + listOfFoundElements.push_back(j); } } + + return listOfFoundElements; +} + +void rttb::apps::voxelizerTool::removeSpecialCharacters(std::string& label) +{ + + //Replace / to avoid problems with directories (struct "Magen/DD" --> Magen/DD.mhd), delete trailing . to avoid filenames with two trailing points (Niere re. --> Niere re..mhd) + while (label.find("/") != std::string::npos) + { + label.replace(label.find("/"), 1, "_"); + } + + if (*label.rbegin() == '.') + { + label.replace(label.size() - 1, 1, ""); + } +} + +std::string rttb::apps::voxelizerTool::getFilenameWithoutEnding(const std::string& outfilename) +{ + boost::filesystem::path p(outfilename); + return p.replace_extension("").string(); +} + +std::string rttb::apps::voxelizerTool::getFileEnding(const std::string& outfilename) +{ + boost::filesystem::path p(outfilename); + return p.extension().string(); +} + +std::vector rttb::apps::voxelizerTool::getAllLabels( + core::StructureSetGeneratorInterface::StructureSetPointer& structureSetPtr) +{ + std::vector allLabels; + + if (structureSetPtr != NULL) + { + for (int j = 0; j < structureSetPtr->getNumberOfStructures(); j++) + { + allLabels.push_back(structureSetPtr->getStructure(j)->getLabel()); + } + } + + return allLabels; +} + +rttb::core::MaskAccessorInterface::MaskAccessorPointer rttb::apps::voxelizerTool::createMask( + rttb::core::DoseAccessorInterface::DoseAccessorPointer& doseAccessorPtr, + rttb::core::StructureSetGeneratorInterface::StructureSetPointer& structureSetPtr, + bool strict, unsigned int indexOfStructure) +{ + rttb::core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr; + + if (doseAccessorPtr != nullptr && structureSetPtr != nullptr) + { + maskAccessorPtr = boost::make_shared + (structureSetPtr->getStructure(indexOfStructure), doseAccessorPtr->getGeometricInfo(), + strict); + + maskAccessorPtr->updateMask(); + } + + return maskAccessorPtr; +} + +void rttb::apps::voxelizerTool::writeMaskToFile(std::vector& maskVector, + const std::string& outputFileName, bool voxelization) +{ + if (!maskVector.empty()) + { + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer itkImage; + + if (maskVector.size() > 1) + { + itkImage = addMultipleStructsToImage(maskVector); + } + else + { + io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(maskVector.at(0)); + maskAccessorConverter.process(); + itkImage = maskAccessorConverter.getITKImage(); + } + + if (voxelization) + { + itkImage = applyThresholdFilter(itkImage); + } + + io::itk::ImageWriter writer(outputFileName, itkImage); + writer.writeFile(); + } +} + +rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer rttb::apps::voxelizerTool::addMultipleStructsToImage( + std::vector& maskVector) +{ + std::vector listOfITKImages; + + for (int i = 0; i < maskVector.size(); i++) + { + io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(maskVector.at(i)); + maskAccessorConverter.process(); + listOfITKImages.push_back(maskAccessorConverter.getITKImage()); + } + + itk::AddImageFilter , itk::Image>::Pointer addFilter = + itk::AddImageFilter , itk::Image>::New(); + io::itk::ITKImageMaskAccessor::ITKMaskImageType::Pointer filterResult; + + for (int k = 1; k < listOfITKImages.size(); k++) + { + if (k == 1) + { + addFilter->SetInput1(listOfITKImages.at(0)); + } + else + { + addFilter->SetInput1(filterResult); + } + + addFilter->SetInput2(listOfITKImages.at(k)); + + addFilter->Update(); + + filterResult = addFilter->GetOutput(); + } + + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer filterResultConst(filterResult); + return filterResultConst; +} + +rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer rttb::apps::voxelizerTool::applyThresholdFilter( + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer& itkImage) +{ + itk::BinaryThresholdImageFilter< itk::Image, itk::Image >::Pointer filter = + itk::BinaryThresholdImageFilter< itk::Image, itk::Image >::New(); + + filter->SetInput(itkImage); + filter->SetLowerThreshold(0.5); + filter->SetUpperThreshold(1.0); + filter->SetInsideValue(1.0); + + filter->Update(); + + return filter->GetOutput(); +} + +void rttb::apps::voxelizerTool::writeITKImageToFile(io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer& itkImage, + const std::string& outputfilename, bool useCompression) +{ + itk::ImageFileWriter< itk::Image >::Pointer writer = + itk::ImageFileWriter< itk::Image >::New(); + writer->SetFileName(outputfilename); + writer->SetUseCompression(useCompression); + writer->SetInput(itkImage); + + writer->Update(); +} + +void rttb::apps::voxelizerTool::processData(rttb::apps::voxelizerTool::ApplicationData& appData) { + + std::cout << "done." << std::endl; + + std::cout << "searching for structs..."; + + std::vector listOfCorrectElements, indexOfCorrectElements; + + std::vector labelVector = getAllLabels(appData._struct); + + indexOfCorrectElements = filterForExpression(labelVector, appData._regEx); + std::copy(indexOfCorrectElements.begin(), indexOfCorrectElements.end(), + std::back_inserter(listOfCorrectElements)); + + std::cout << "done." << std::endl; + + if (!listOfCorrectElements.empty()) + { + std::vector maskVector; + + if (appData._addStructures) + { + for (unsigned int i = 0; i < listOfCorrectElements.size(); i++) + { + unsigned int labelIndex = listOfCorrectElements.at(i); + maskVector.push_back(createMask(appData._dose, appData._struct, + !appData._noStrictVoxelization, labelIndex)); + } + + writeMaskToFile(maskVector, appData._outputFilename, appData._booleanVoxelization); + + } + 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(createMask(appData._dose, appData._struct, + !appData._noStrictVoxelization, listOfCorrectElements.at(i))); + std::cout << "done" << std::endl; + int labelIndex = listOfCorrectElements.at(i); + std::string labelOfInterest = labelVector.at(labelIndex); + rttb::apps::voxelizerTool::removeSpecialCharacters(labelOfInterest); + + std::string outputName = appData._outputFilename; + + if (appData._multipleStructs) + { + std::string fileName = rttb::apps::voxelizerTool::getFilenameWithoutEnding( + appData._outputFilename); + std::string fileEnding = rttb::apps::voxelizerTool::getFileEnding(appData._outputFilename); + outputName = fileName + "_" + labelOfInterest + fileEnding; + } + writeMaskToFile(maskVector, outputName, appData._booleanVoxelization); + } + } + } + else + { + std::cout << "No struct found" << std::endl; + } } \ No newline at end of file diff --git a/apps/VoxelizerTool/VoxelizerToolHelper.h b/apps/VoxelizerTool/VoxelizerToolHelper.h index 76b41be..ae3ba7e 100644 --- a/apps/VoxelizerTool/VoxelizerToolHelper.h +++ b/apps/VoxelizerTool/VoxelizerToolHelper.h @@ -1,44 +1,78 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 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) */ #include #include +#include "rttbStructureSetGeneratorInterface.h" +#include "rttbMaskAccessorInterface.h" +#include "rttbITKImageMaskAccessor.h" +#include "rttbDoseAccessorInterface.h" + namespace rttb { namespace apps { namespace voxelizerTool { + class ApplicationData; + + + void processData(ApplicationData& appData); + /**@brief ListofExpression contains input expression @return a vector of found labels */ std::vector filterForExpression(const std::vector& listOfExpressions, const std::string& inputExpression); /**@brief Search the label with the position from index @return a label from the list as string */ void removeSpecialCharacters(std::string& label); + + std::vector getAllLabels(rttb::core::StructureSetGeneratorInterface::StructureSetPointer& structureSetPtr); + + /**@brief create a mask with _rtStructureSet and _doseAccessor object. + @return a mask object + */ + core::MaskAccessorInterface::MaskAccessorPointer createMask( + core::DoseAccessorInterface::DoseAccessorPointer& doseAccessorPtr, + core::StructureSetGeneratorInterface::StructureSetPointer& structureSetPtr, + bool strict, unsigned int indexOfStructure); + + /**@brief write the mask into the outputfile + @param Outputfilename + */ + void writeMaskToFile(std::vector& maskVector, + const std::string& outputFileName, bool voxelization); + + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer addMultipleStructsToImage( + std::vector& maskVector); + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer applyThresholdFilter( + io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer& itkImage); + void writeITKImageToFile(io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer& itkImage, + const std::string& outputfilename, bool useCompression); + std::string getFilenameWithoutEnding(const std::string& outfilename); std::string getFileEnding(const std::string& outfilename); } } } \ No newline at end of file diff --git a/apps/VoxelizerTool/files.cmake b/apps/VoxelizerTool/files.cmake index de9747a..1a369d3 100644 --- a/apps/VoxelizerTool/files.cmake +++ b/apps/VoxelizerTool/files.cmake @@ -1,21 +1,15 @@ SET(CPP_FILES VoxelizerTool.cpp -rttbMaskProcess.cpp -rttbMaskWriter.cpp -rttbStructDataReader.cpp VoxelizerToolHelper.cpp VoxelizerToolCmdLineParser.cpp VoxelizerToolApplicationData.cpp ) SET(H_FILES VoxelizerToolApplicationData.h -rttbMaskProcess.h -rttbMaskWriter.h -rttbStructDataReader.h VoxelizerToolHelper.h VoxelizerToolCmdLineParser.h ) SET(TPP_FILES ) diff --git a/apps/VoxelizerTool/rttbMaskProcess.cpp b/apps/VoxelizerTool/rttbMaskProcess.cpp deleted file mode 100644 index 3bdee8f..0000000 --- a/apps/VoxelizerTool/rttbMaskProcess.cpp +++ /dev/null @@ -1,58 +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: 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 "boost/make_shared.hpp" - -#include "rttbStructureSet.h" -#include "rttbBoostMaskAccessor.h" - -namespace rttb -{ - namespace apps - { - namespace voxelizerTool - { - MaskProcess::MaskProcess(StructureSetPointer rtStructureSet, DoseAccessorPointer doseAccessor, - bool strict) : _rtStructureSet(rtStructureSet), - _doseAccessor(doseAccessor), _strict(strict) - { - } - - MaskProcess::MaskAccessorPointer MaskProcess::createMask(unsigned int indexOfStructure) const - { - MaskAccessorPointer maskAccessorPtr; - - if (_doseAccessor != nullptr && _rtStructureSet != nullptr) - { - maskAccessorPtr = boost::make_shared - (_rtStructureSet->getStructure(indexOfStructure), _doseAccessor->getGeometricInfo(), - _strict); - - maskAccessorPtr->updateMask(); - } - - return maskAccessorPtr; - - } - } - } -} \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbMaskProcess.h b/apps/VoxelizerTool/rttbMaskProcess.h deleted file mode 100644 index 6e121c4..0000000 --- a/apps/VoxelizerTool/rttbMaskProcess.h +++ /dev/null @@ -1,63 +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: 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 "rttbStructureSetGeneratorInterface.h" -#include "rttbMaskAccessorInterface.h" -#include "rttbGenericDoseIterator.h" - -namespace rttb -{ - namespace apps - { - namespace voxelizerTool - { - /*! @class MaskProcess - @brief Creates 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 strict); - /**@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 _strict; - }; - } - } -} -#endif \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbMaskWriter.cpp b/apps/VoxelizerTool/rttbMaskWriter.cpp deleted file mode 100644 index 26f0e49..0000000 --- a/apps/VoxelizerTool/rttbMaskWriter.cpp +++ /dev/null @@ -1,137 +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: 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 "rttbMaskWriter.h" - -#include "rttbITKImageMaskAccessorConverter.h" -#include "rttbITKImageFileMaskAccessorGenerator.h" -#include "rttbImageWriter.h" - -#include "itkImage.h" -#include "itkBinaryThresholdImageFilter.h" -#include "itkAddImageFilter.h" - -namespace rttb -{ - namespace apps - { - namespace voxelizerTool - { - MaskWriter::MaskWriter(std::vector maskPointer, - bool voxelization) : _maskPointerVector(maskPointer), _booleanvoxelization(voxelization) - { - } - - void MaskWriter::writeMaskToFile(const std::string& outputFileName) const - { - if (!_maskPointerVector.empty()) - { - ITKImageTypeConstPointer itkImage; - - if (_maskPointerVector.size() > 1) - { - itkImage = addMultipleStructsToImage(); - } - else - { - io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_maskPointerVector.at(0)); - maskAccessorConverter.process(); - itkImage = maskAccessorConverter.getITKImage(); - } - - if (_booleanvoxelization) - { - itkImage = applyThresholdFilter(itkImage); - } - - io::itk::ImageWriter writer(outputFileName, itkImage); - writer.writeFile(); - } - } - - MaskWriter::ITKImageTypeConstPointer MaskWriter::addMultipleStructsToImage() const - { - std::vector listOfITKImages; - - for (int i = 0; i < _maskPointerVector.size(); i++) - { - io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_maskPointerVector.at(i)); - maskAccessorConverter.process(); - listOfITKImages.push_back(maskAccessorConverter.getITKImage()); - } - - typedef itk::AddImageFilter AddImageFilterType; - - AddImageFilterType::Pointer addFilter = AddImageFilterType::New(); - ITKImageTypePointer filterResult; - - for (int k = 1; k < listOfITKImages.size(); k++) - { - if (k == 1) - { - addFilter->SetInput1(listOfITKImages.at(0)); - } - else - { - addFilter->SetInput1(filterResult); - } - - addFilter->SetInput2(listOfITKImages.at(k)); - - addFilter->Update(); - - filterResult = addFilter->GetOutput(); - } - - ITKImageTypeConstPointer filterResultConst(filterResult); - return filterResultConst; - } - - MaskWriter::ITKImageTypeConstPointer MaskWriter::applyThresholdFilter( - ITKImageTypeConstPointer itkImage) const - { - - typedef itk::BinaryThresholdImageFilter< ITKMaskImageType, ITKMaskImageType > FilterType; - FilterType::Pointer filter = FilterType::New(); - - filter->SetInput(itkImage); - filter->SetLowerThreshold(0.5); - filter->SetUpperThreshold(1.0); - filter->SetInsideValue(1.0); - - filter->Update(); - - return filter->GetOutput(); - } - - void MaskWriter::writeITKImageToFile(ITKImageTypeConstPointer itkImage, - const std::string& outputfilename, bool useCompression) const - { - typedef itk::ImageFileWriter< ITKMaskImageType > WriterType; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputfilename); - writer->SetUseCompression(useCompression); - writer->SetInput(itkImage); - - writer->Update(); - } - } - } -} diff --git a/apps/VoxelizerTool/rttbMaskWriter.h b/apps/VoxelizerTool/rttbMaskWriter.h deleted file mode 100644 index a8fed3d..0000000 --- a/apps/VoxelizerTool/rttbMaskWriter.h +++ /dev/null @@ -1,68 +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: 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 __MaskWriter_h -#define __MaskWriter_h - -#include "rttbITKImageMaskAccessor.h" - -namespace rttb -{ - namespace apps - { - namespace voxelizerTool - { - /*! @class MaskWriter - @brief Writes a mask into a file - */ - class MaskWriter - { - public: - typedef core::MaskAccessorInterface::MaskAccessorPointer MaskAccessorPointer; - typedef io::itk::ITKImageMaskAccessor::ITKMaskImageType::Pointer ITKImageTypePointer; - typedef io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer ITKImageTypeConstPointer; - typedef itk::Image ITKMaskImageType; - - - /*!@brief Constructor - @details save the object parameter into _maskAccessorPtr objekt - @param vector with MaskAccessorPointer object/s - */ - MaskWriter(std::vector maskPointer, bool voxelization); - - /**@brief write the mask into the outputfile - @param Outputfilename - */ - void writeMaskToFile(const std::string& outputFileName) const; - - private: - - ITKImageTypeConstPointer addMultipleStructsToImage() const; - ITKImageTypeConstPointer applyThresholdFilter(ITKImageTypeConstPointer itkImage) const; - void writeITKImageToFile(ITKImageTypeConstPointer itkImage, const std::string& outputfilename, - bool useCompression = true) const; - - bool _booleanvoxelization; - std::vector _maskPointerVector; - }; - } - } -} -#endif \ No newline at end of file diff --git a/apps/VoxelizerTool/rttbStructDataReader.cpp b/apps/VoxelizerTool/rttbStructDataReader.cpp deleted file mode 100644 index dbefca1..0000000 --- a/apps/VoxelizerTool/rttbStructDataReader.cpp +++ /dev/null @@ -1,124 +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: 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, const std::string& structRegex) : _referenceFilename(referenceFileName), - _structFilename(structFileName), _referenceFileLoadingStyle(referenceFileLoadingStyle), _structRegex(structRegex) - { - } - - void StructDataReader::read() - { - _doseAccessor = readReferenceFile(_referenceFilename, _referenceFileLoadingStyle); - _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 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 std::string& structNameRegex) const - { - rttb::io::dicom::DicomFileStructureSetGenerator generator(fileName); - - if (!structNameRegex.empty()) - { - generator.setStructureLabelFilterActive(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 deleted file mode 100644 index 757b103..0000000 --- a/apps/VoxelizerTool/rttbStructDataReader.h +++ /dev/null @@ -1,89 +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: 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 "rttbStructureSetGeneratorInterface.h" -#include "rttbGenericDoseIterator.h" - -namespace rttb -{ - namespace apps - { - namespace voxelizerTool - { - /*! @class StructDataReader - @brief Reads 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::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 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