diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.cpp b/demoapps/VoxelizerTool/rttbCommandOptions.cpp index 911efc6..6c9756f 100644 --- a/demoapps/VoxelizerTool/rttbCommandOptions.cpp +++ b/demoapps/VoxelizerTool/rttbCommandOptions.cpp @@ -1,196 +1,142 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include #include "rttbCommandOptions.h" #include "rttbVoxelizerHelper.h" namespace rttb { namespace apps { namespace voxelizer { CommandOptions::CommandOptions(): PARAM_HELP("help"), PARAM_STRUCT_FILE("structFile"), PARAM_REFERENCE_FILE("referenceFile"), PARAM_OUT_FILE("output"), PARAM_REGEX("struct"), PARAM_MULTISTRUCT("multipleStructs"), - PARAM_LEGACY("legacyVoxelization"), - PARAM_BOOST("boostVoxelization"), - PARAM_BOOLEANVOXELIZATION("booleanVoxelization"), + PARAM_LEGACY_VOXELIZATION("legacyVoxelization"), + PARAM_BOOST_VOXELIZATION("boostVoxelization"), + PARAM_BOOLEAN_VOXELIZATION("booleanVoxelization"), PARAM_ADDSTRUCTURES("addStructures") { - params.multipleStructs = false; - params.legacyVoxelization = false; - params.booleanVoxelization = false; - params.addStructures = false; + _params.multipleStructs = false; + _params.legacyVoxelization = false; + _params.booleanVoxelization = false; + _params.addStructures = false; po::options_description required("Required arguments"); - addOption(required, PARAM_STRUCT_FILE, "s", po::value(¶ms.structFile), + addOption(required, PARAM_STRUCT_FILE, "s", po::value(&_params.structFile)->required(), "Filename of the structfile (*.dcm)"); - addOption(required, PARAM_REFERENCE_FILE, "r", po::value(¶ms.referenceFile), + addOption(required, PARAM_REFERENCE_FILE, "r", po::value(&_params.referenceFile)->required(), "Filename of the reference image (*.dcm)"); - addOption(required, PARAM_REGEX, "e", - po::value>(¶ms.regEx)->multitoken(), + po::value>(&_params.regEx)->multitoken()->required(), "set a regular expression describing the structs of interest"); + addOption(required, PARAM_OUT_FILE, "o", + po::value(&_params.outputFilename)->default_value("out.hdr")->required(), "set output file name "); + addOption(required, PARAM_BOOST_VOXELIZATION, "b", po::bool_switch()->default_value(true), "to use boost voxelization"); po::options_description optional("Optional arguments"); addOption(optional, PARAM_HELP, "h", nullptr, "Display help message"); - addOption(optional, PARAM_OUT_FILE, "o", - po::value(¶ms.outputFilename)->default_value("out.hdr"), "set output file name "); - addOption(optional, PARAM_MULTISTRUCT, "m", nullptr, - "if multiple structs are found, save all in files"); - addOption(optional, PARAM_BOOST, "b", nullptr, "for boost voxelization"); - addOption(optional, PARAM_LEGACY, "l", nullptr, - "for legacy voxelization"); - addOption(optional, PARAM_BOOLEANVOXELIZATION, "v", nullptr, - "Determines if the voxelization should have only boolean values (0 or 1)"); - addOption(optional, PARAM_ADDSTRUCTURES, "a", nullptr, - ""); - - description.add(required).add(optional); + addOption(optional, PARAM_MULTISTRUCT, "m", po::bool_switch(&_params.multipleStructs)->default_value(false), + "if multiple structs match the regular expression (--struct), save all in files"); + addOption(optional, PARAM_LEGACY_VOXELIZATION, "l", po::bool_switch(&_params.legacyVoxelization)->default_value(false), + "to use legacy voxelization"); + addOption(optional, PARAM_BOOLEAN_VOXELIZATION, "v", + po::bool_switch(&_params.booleanVoxelization)->default_value(false), + "Determines if the voxelization should be binarized (only values 0 or 1)"); + addOption(optional, PARAM_ADDSTRUCTURES, "a", nullptr, ""); + + _description.add(required).add(optional); } void CommandOptions::addOption(po::options_description& o, const std::string& name, const std::string& shortcut, const po::value_semantic* valueSemantic, const std::string& description) { if (valueSemantic) { o.add_options()((name + std::string(",") + shortcut).c_str(), valueSemantic, description.c_str()); } else { o.add_options()((name + std::string(",") + shortcut).c_str(), description.c_str()); } } - void CommandOptions::showHelp()const + void CommandOptions::showHelp() const { - std::cout << "Usage: VoxelizerTool -s -r [optional] \n"; - std::cout << description << std::endl; + std::cout << "Usage: VoxelizerTool [options] \n"; + std::cout << _description << std::endl; std::cout << "Example: VoxelizerTool -s structFile.dcm -r referenceFile.dcm -e Kidney -o outputFile.mhd -m" << std::endl; std::cout << "Computes a voxelization file outputFile.mhd based on the DICOMRT-STRUCT structFile.dcm in the geometry of referenceFile.dcm where"; std::cout << "the name of the struct matches the regular expression 'Kidney'." << std::endl; std::cout << "If structures 'Kidney_left' and 'Kidney_right' are defined, "; std::cout << "both are written under the names outputFile_Kidney_left.mhd and outputFile_Kidney_right.mhd (parameter -m)." << std::endl; } bool CommandOptions::command(int argc, char* argv[]) { try { po::variables_map var; - _minArguments = 7; - po::store(po::command_line_parser(argc, argv).options(description).run(), var); - po::notify(var); - - if (argc < _minArguments) - { - showHelp(); - return false; - } + po::store(po::command_line_parser(argc, argv).options(_description).run(), var); if (var.count(PARAM_HELP)) { showHelp(); return true; } - if (!var.count(PARAM_STRUCT_FILE)) - { - throw std::runtime_error("Please use the parameter -s or --structfile"); - } - else - { - if (getFileEnding(params.structFile) != ".dcm") - { - throw std::runtime_error("Please check your struct file: " + params.structFile); - } - } - - if (!var.count(PARAM_REFERENCE_FILE)) - { - throw std::runtime_error("Please use the parameter -r or --referencefile"); - } - else - { - if (getFileEnding(params.referenceFile) != ".dcm") - { - throw std::runtime_error("Please check your reference file: " + params.referenceFile); - } - } - - if (!var.count(PARAM_OUT_FILE)) - { - params.outputFilename = "out.hdr"; - } - - if (var.count(PARAM_REGEX)) - { - - if (var.count(PARAM_MULTISTRUCT)) - { - params.multipleStructs = true; - } - else - { - params.multipleStructs = false; - } - } - - if (var.count(PARAM_LEGACY)) - { - params.legacyVoxelization = true; - } + po::notify(var); - if (var.count(PARAM_BOOLEANVOXELIZATION)) + if (var.count(PARAM_BOOST_VOXELIZATION)) { - params.booleanVoxelization = true; + _params.legacyVoxelization = false; } if (var.count(PARAM_ADDSTRUCTURES)) { - params.addStructures = true; - params.multipleStructs = false; + _params.addStructures = true; + _params.multipleStructs = false; } } catch (const std::exception& e) { std::cout << "Error: " << e.what() << std::endl; return false; } return true; } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.h b/demoapps/VoxelizerTool/rttbCommandOptions.h index 1005838..30d6698 100644 --- a/demoapps/VoxelizerTool/rttbCommandOptions.h +++ b/demoapps/VoxelizerTool/rttbCommandOptions.h @@ -1,121 +1,121 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5506 $ (last changed revision) // @date $Date: 2015-07-30 14:45:24 +0200 (Do, 30 Jul 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __CommandOptions_h #define __CommandOptions_h #include namespace rttb { namespace apps { namespace voxelizer { namespace po = boost::program_options; /** @brief Simple struct holding all variables. */ struct Parameters { /** @brief Filename of the StructFile*/ std::string structFile; /** @brief Filename of the ReferenceFile*/ std::string referenceFile; /** @brief Output Filename*/ std::string outputFilename; /** @brief Expressions from User*/ std::vector regEx; /** @brief for more than one struct*/ bool multipleStructs; /** @brief add: legacyVoxelization=false means boostVoxelization is turned on*/ bool legacyVoxelization; /** @brief voxelization should be binarized to value 0 or 1 */ bool booleanVoxelization ; /** @brief multiple structures voxelization should be combined in one file*/ bool addStructures; }; /*! @class CommandOptions @brief CommandOptions Class, everything about the command line */ class CommandOptions { public: /** @details add the description for command line options * add parameter --h or --help for help informations, * --Structfile= to set a struct file, * --Reference= to set the reference file, * --Output= to set an output file name and * --struct= to add an expression like(SPINE). */ CommandOptions(); /** @brief Validates the given input parameters and fills the corresponding variables. @param argc Number of arguments. @param argv Array of individual arguments. @return true if all arguments were valid (i.e. none were missing or incorrect), otherwise false. */ bool command(int argc, char* argv[]); const Parameters& getParameters() const { - return params; + return _params; } private: /** *@brief Adds an option to the given option container. *@param o Option container the new option should be added to. *@param name Name of the new option (i.e. the actual parameter, e.g. "test" adds the option with the parameter "--test"). *@param shortcut A single letter that is used as a shortcut for this option (e.g. if the name is "test, the shortcut might be "t", so you can call the parameter with "-t" instead of "--test"). *@param valueSemantic The desired value semantic object, i.e. the object that binds this option's value to a variable. *@param description The description text for this option. */ void addOption(po::options_description& o, const std::string& name, const std::string& shortcut, const po::value_semantic* valueSemantic, const std::string& description); /*! @brief print out the dicription.*/ void showHelp()const; const std::string PARAM_STRUCT_FILE; const std::string PARAM_REFERENCE_FILE; const std::string PARAM_OUT_FILE; const std::string PARAM_REGEX; const std::string PARAM_MULTISTRUCT; const std::string PARAM_HELP; - const std::string PARAM_LEGACY; - const std::string PARAM_BOOST; - const std::string PARAM_BOOLEANVOXELIZATION; + const std::string PARAM_LEGACY_VOXELIZATION; + const std::string PARAM_BOOST_VOXELIZATION; + const std::string PARAM_BOOLEAN_VOXELIZATION; const std::string PARAM_ADDSTRUCTURES; /*! create description object */ - po::options_description description; - Parameters params; + po::options_description _description; + Parameters _params; /**@brief minimum arguments that must be present on the Command Line*/ int _minArguments; }; } } } #endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskProcess.cpp b/demoapps/VoxelizerTool/rttbMaskProcess.cpp index cce4188..8c1906c 100644 --- a/demoapps/VoxelizerTool/rttbMaskProcess.cpp +++ b/demoapps/VoxelizerTool/rttbMaskProcess.cpp @@ -1,67 +1,64 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbMaskProcess.h" #include #include "rttbBoostMaskAccessor.h" namespace rttb { namespace apps { namespace voxelizer { MaskProcess::MaskProcess(StructureSetPointer rtStructureSet, DoseAccessorPointer doseAccessor, bool legacy) : _rtStructureSet(rtStructureSet), _doseAccessor(doseAccessor), _legacyVoxelization(legacy) { } - MaskProcess::MaskAccessorPointer MaskProcess::createMask(unsigned int indexOfStruktur) + MaskProcess::MaskAccessorPointer MaskProcess::createMask(unsigned int indexOfStructure) const { MaskAccessorPointer maskAccessorPtr; - if (_doseAccessor != NULL) + if (_doseAccessor != NULL && _rtStructureSet != NULL) { if (_legacyVoxelization) { maskAccessorPtr = boost::make_shared - (_rtStructureSet->getStructure(indexOfStruktur), _doseAccessor->getGeometricInfo()); + (_rtStructureSet->getStructure(indexOfStructure), _doseAccessor->getGeometricInfo()); } else { maskAccessorPtr = boost::make_shared - (_rtStructureSet->getStructure(indexOfStruktur), _doseAccessor->getGeometricInfo()); + (_rtStructureSet->getStructure(indexOfStructure), _doseAccessor->getGeometricInfo()); } maskAccessorPtr->updateMask(); - return maskAccessorPtr; - - } - else - { - return maskAccessorPtr; } + + return maskAccessorPtr; + } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskProcess.h b/demoapps/VoxelizerTool/rttbMaskProcess.h index 6b9a0bb..72aa0c4 100644 --- a/demoapps/VoxelizerTool/rttbMaskProcess.h +++ b/demoapps/VoxelizerTool/rttbMaskProcess.h @@ -1,62 +1,62 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5506 $ (last changed revision) // @date $Date: 2015-07-30 14:45:24 +0200 (Do, 30 Jul 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __MaskProcess_h #define __MaskProcess_h #include "rttbDicomFileStructureSetGenerator.h" #include "rttbOTBMaskAccessor.h" namespace rttb { namespace apps { namespace voxelizer { /*! @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); /**@brief create a mask with _rtStructureSet and _doseAccessor object. @return a mask object */ - MaskAccessorPointer createMask(unsigned int numberOfStruktur); + MaskAccessorPointer createMask(unsigned int numberOfStructure) const; private: StructureSetPointer _rtStructureSet; DoseAccessorPointer _doseAccessor; bool _legacyVoxelization; }; } } } #endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskWriter.cpp b/demoapps/VoxelizerTool/rttbMaskWriter.cpp index 3f762e3..64e3af5 100644 --- a/demoapps/VoxelizerTool/rttbMaskWriter.cpp +++ b/demoapps/VoxelizerTool/rttbMaskWriter.cpp @@ -1,158 +1,158 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbMaskWriter.h" #include "itkImage.h" #include "itkImageFileWriter.h" #include "itkBinaryThresholdImageFilter.h" #include "itkAddImageFilter.h" namespace rttb { namespace apps { namespace voxelizer { MaskWriter::MaskWriter(std::vector maskPointer, - bool voxelization) : _MaskPointerList(maskPointer), _booleanvoxelization(voxelization) + bool voxelization) : _maskPointerVector(maskPointer), _booleanvoxelization(voxelization) { } - void MaskWriter::writeMaskToFile(const std::string& outputFileName) + void MaskWriter::writeMaskToFile(const std::string& outputFileName) const { - if (!_MaskPointerList.empty()) + if (!_maskPointerVector.empty()) { ITKImageTypeConstPointer itkImage; - if (_MaskPointerList.size() > 1) + if (_maskPointerVector.size() > 1) { - itkImage = AddMultipleStructsToImage(); + itkImage = addMultipleStructsToImage(); } else { - io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_MaskPointerList.at(0)); + io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_maskPointerVector.at(0)); maskAccessorConverter.process(); itkImage = maskAccessorConverter.getITKImage(); } if (_booleanvoxelization) { - itkImage = ApplyThresholdFilter(itkImage); + itkImage = applyThresholdFilter(itkImage); } - WriteITKImageToFile(itkImage, outputFileName); + writeITKImageToFile(itkImage, outputFileName); } } - MaskWriter::ITKImageTypeConstPointer MaskWriter::AddMultipleStructsToImage() + MaskWriter::ITKImageTypeConstPointer MaskWriter::addMultipleStructsToImage() const { std::vector listOfITKImages; - for (int i = 0; i < _MaskPointerList.size(); i++) + for (int i = 0; i < _maskPointerVector.size(); i++) { - io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_MaskPointerList.at(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)); try { addFilter->Update(); } catch (itk::ExceptionObject& err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; + return NULL; } filterResult = addFilter->GetOutput(); } return filterResult; } - MaskWriter::ITKImageTypeConstPointer MaskWriter::ApplyThresholdFilter( - ITKImageTypeConstPointer itkImage) + 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->SetOutsideValue(0.0); filter->SetInsideValue(1.0); try { filter->Update(); } catch (itk::ExceptionObject& err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; + return NULL; } return filter->GetOutput(); } - void MaskWriter::WriteITKImageToFile(ITKImageTypeConstPointer itkImage, - const std::string& outputfilename) + void MaskWriter::writeITKImageToFile(ITKImageTypeConstPointer itkImage, + const std::string& outputfilename) const { typedef itk::ImageFileWriter< ITKMaskImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputfilename); writer->SetInput(itkImage); try { writer->Update(); } catch (itk::ExceptionObject& err) { std::cerr << "ExceptionObject caught !" << std::endl; std::cerr << err << std::endl; - } } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskWriter.h b/demoapps/VoxelizerTool/rttbMaskWriter.h index 5add79c..549c7b5 100644 --- a/demoapps/VoxelizerTool/rttbMaskWriter.h +++ b/demoapps/VoxelizerTool/rttbMaskWriter.h @@ -1,70 +1,70 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __MaskWriter_h #define __MaskWriter_h #include "rttbITKImageMaskAccessorConverter.h" #include "rttbITKImageFileMaskAccessorGenerator.h" namespace rttb { namespace apps { namespace voxelizer { /*! @class MaskWriter @brief MaskWriter write 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); + void writeMaskToFile(const std::string& outputFileName) const; private: - ITKImageTypeConstPointer AddMultipleStructsToImage(); - ITKImageTypeConstPointer ApplyThresholdFilter(ITKImageTypeConstPointer itkImage); - void WriteITKImageToFile(ITKImageTypeConstPointer itkImage, const std::string& outputfilename); + ITKImageTypeConstPointer addMultipleStructsToImage() const; + ITKImageTypeConstPointer applyThresholdFilter(ITKImageTypeConstPointer itkImage) const; + void writeITKImageToFile(ITKImageTypeConstPointer itkImage, const std::string& outputfilename) const; //MaskAccessorPointer _maskAccessorPtr; bool _booleanvoxelization; - std::vector _MaskPointerList; + std::vector _maskPointerVector; }; } } } #endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbStructDataReader.cpp b/demoapps/VoxelizerTool/rttbStructDataReader.cpp index bb79579..31b76c9 100644 --- a/demoapps/VoxelizerTool/rttbStructDataReader.cpp +++ b/demoapps/VoxelizerTool/rttbStructDataReader.cpp @@ -1,100 +1,81 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbStructDataReader.h" #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbInvalidParameterException.h" namespace rttb { namespace apps { namespace voxelizer { StructDataReader::StructDataReader(const std::string& structfile, const std::string& reference) { - _doseAccessor = readReferenceFile(reference); _rtStructureSet = readStructFile(structfile); } - std::vector StructDataReader::getAllLabels() + std::vector StructDataReader::getAllLabels() const { std::vector allLabels; - if (_rtStructureSet != NULL && _rtStructureSet->getNumberOfStructures() > 0) + if (_rtStructureSet != NULL) { for (int j = 0; j < _rtStructureSet->getNumberOfStructures(); j++) { allLabels.push_back(_rtStructureSet->getStructure(j)->getLabel()); } } return allLabels; } - StructDataReader::StructureSetPointer StructDataReader::getStructureSetPointer() + StructDataReader::StructureSetPointer StructDataReader::getStructureSetPointer() const { return _rtStructureSet; } - StructDataReader::DoseAccessorPointer StructDataReader::getDoseAccessorPointer() + StructDataReader::DoseAccessorPointer StructDataReader::getDoseAccessorPointer() const { return _doseAccessor; } StructDataReader::DoseAccessorPointer StructDataReader::readReferenceFile( - const std::string& referencefile) + const std::string& referencefile) const { - try - { - rttb::io::dicom::DicomFileDoseAccessorGenerator doseAccessorGenerator1(referencefile.c_str()); - DoseAccessorPointer doseAccessor(doseAccessorGenerator1.generateDoseAccessor()); - return doseAccessor; - } - catch (rttb::core::InvalidParameterException& e) - { - std::cerr << "ExceptionObject caught !" << std::endl; - std::cerr << e.what() << std::endl; - return NULL; - } + rttb::io::dicom::DicomFileDoseAccessorGenerator doseAccessorGenerator1(referencefile.c_str()); + DoseAccessorPointer doseAccessor(doseAccessorGenerator1.generateDoseAccessor()); + return doseAccessor; } StructDataReader::StructureSetPointer StructDataReader::readStructFile( - const std::string& structfile) + const std::string& structfile) const { - try - { - StructureSetPointer rtStructureSet = rttb::io::dicom::DicomFileStructureSetGenerator( - structfile.c_str()).generateStructureSet(); - return rtStructureSet; - } - catch (rttb::core::InvalidParameterException& e) - { - std::cerr << "ExceptionObject caught !" << std::endl; - std::cerr << e.what() << std::endl; - return NULL; - } + StructureSetPointer rtStructureSet = rttb::io::dicom::DicomFileStructureSetGenerator( + structfile.c_str()).generateStructureSet(); + return rtStructureSet; } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbStructDataReader.h b/demoapps/VoxelizerTool/rttbStructDataReader.h index f97e2de..5b49bf0 100644 --- a/demoapps/VoxelizerTool/rttbStructDataReader.h +++ b/demoapps/VoxelizerTool/rttbStructDataReader.h @@ -1,79 +1,79 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #ifndef __StructDataReader_h #define __StructDataReader_h #include "rttbDicomFileStructureSetGenerator.h" #include "rttbOTBMaskAccessor.h" namespace rttb { namespace apps { namespace voxelizer { /*! @class StructDataReader @brief StructDataReader read struct and reference file */ class StructDataReader { public: typedef rttb::core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; typedef rttb::core::StructureSetGeneratorInterface::StructureSetPointer StructureSetPointer; /*!@brief Constructor @details calls readStructFile and readReferenceFile method and save the result in _rtStructureSet and _doseAccessor @param structfile @param referencefile */ StructDataReader(const std::string& structfile, const std::string& referencefile); /**@brief read all labels an save it in a vector. @return a vector of all labels */ - std::vector getAllLabels(); + std::vector getAllLabels() const; /**@brief @return the objekt _rtStructureSet */ - StructureSetPointer getStructureSetPointer(); + StructureSetPointer getStructureSetPointer() const; /**@brief @return the objekt _doseAccessor */ - DoseAccessorPointer getDoseAccessorPointer(); + DoseAccessorPointer getDoseAccessorPointer() const; private: /**@brief read a referencefile @return the result as object */ - DoseAccessorPointer readReferenceFile(const std::string& referencefile); + DoseAccessorPointer readReferenceFile(const std::string& referencefile) const; /**@brief read a structfile @return the result as object */ - StructureSetPointer readStructFile(const std::string& structfile); + StructureSetPointer readStructFile(const std::string& structfile) const; StructureSetPointer _rtStructureSet; DoseAccessorPointer _doseAccessor; }; } } } #endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp b/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp index 09c07d1..59fc5ae 100644 --- a/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp +++ b/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp @@ -1,88 +1,82 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include "rttbVoxelizerHelper.h" #include #include #include +#include namespace rttb { namespace apps { namespace voxelizer { - std::vector filterForExpression(std::vector listOfExpressions, - std::string inputExpression) + std::vector filterForExpression(const std::vector& listOfExpressions, + const std::string& inputExpression) { std::vector listOfFoundElements; for (int j = 0; j < listOfExpressions.size(); j++) { boost::regex e(boost::algorithm::to_lower_copy(inputExpression)); - std::string StringInList = boost::algorithm::to_lower_copy(listOfExpressions.at(j)); + std::string s = boost::algorithm::to_lower_copy(listOfExpressions.at(j)); - if (boost::regex_match(StringInList, e)) + if (boost::regex_match(s, e)) { listOfFoundElements.push_back(j); } } return listOfFoundElements; } std::string getLabelFromList(std::vector listOfExpressions, int j) { + //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) + listOfExpressions.at(j).replace(listOfExpressions.at(j).find("/"), 1, "_"); - if (listOfExpressions.at(j).find("/") != std::string::npos) + if (listOfExpressions.at(j).substr(listOfExpressions.at(j).size() - 1) == ".") { - /*has one of the label a "/" in string for example "Magen/DD" - so the program thinks "Magen" is a directory and will create the file in it. - this method replace the "/" to "_" - */ - return listOfExpressions.at(j).replace(listOfExpressions.at(j).find("/"), 1, "_"); - } - else if (listOfExpressions.at(j).substr(listOfExpressions.at(j).size() - 1) == ".") - { - return listOfExpressions.at(j).replace(listOfExpressions.at(j).size() - 1, 1, ""); - } - else - { - return listOfExpressions.at(j); + listOfExpressions.at(j).replace(listOfExpressions.at(j).size() - 1, 1, ""); } + + std::cout << listOfExpressions.at(j) << std::endl; + return listOfExpressions.at(j); } - std::string getFilenameWithoutEnding(std::string outfilename) + std::string getFilenameWithoutEnding(const std::string& outfilename) { boost::filesystem::path p(outfilename); return p.stem().string(); } - std::string getFileEnding(std::string outfilename) + std::string getFileEnding(const std::string& outfilename) { boost::filesystem::path p(outfilename); return p.extension().string(); } } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbVoxelizerHelper.h b/demoapps/VoxelizerTool/rttbVoxelizerHelper.h index 21f8e6c..328a111 100644 --- a/demoapps/VoxelizerTool/rttbVoxelizerHelper.h +++ b/demoapps/VoxelizerTool/rttbVoxelizerHelper.h @@ -1,45 +1,44 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include #include namespace rttb { namespace apps { namespace voxelizer { - /**@brief ListofExpression contains inputexpression + /**@brief ListofExpression contains input expression @return a vector of found labels */ - std::vector filterForExpression(std::vector listOfExpressions, - std::string inputExpression); - /**@brief Search the labe with the posion from index - @return a lable from the list as string + 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 */ std::string getLabelFromList(std::vector listOfExpressions, int index); - std::string getFilenameWithoutEnding(std::string outfilename); - std::string getFileEnding(std::string outfilename); - bool checkFileEnding(const std::string& filename, const std::string& fileEnding); + std::string getFilenameWithoutEnding(const std::string& outfilename); + std::string getFileEnding(const std::string& outfilename); } } } \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp b/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp index 831765b..efb28d7 100644 --- a/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp +++ b/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp @@ -1,135 +1,156 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 5603 $ (last changed revision) // @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) // @author $Author: strubel $ (last changed by) */ #include #include "rttbVoxelizerHelper.h" #include "rttbMaskProcess.h" #include "rttbMaskWriter.h" #include "rttbStructDataReader.h" #include "rttbCommandOptions.h" int main(int argc, char* argv[]) { typedef rttb::core::MaskAccessorInterface::MaskAccessorPointer MaskAccessorPointer; - boost::shared_ptr CO = + boost::shared_ptr co = boost::make_shared(); - if (!CO->command(argc, argv)) + if (!co->command(argc, argv)) { return EXIT_FAILURE; } - rttb::apps::voxelizer::Parameters params = CO->getParameters(); + rttb::apps::voxelizer::Parameters params = co->getParameters(); if (!params.structFile.empty() && !params.referenceFile.empty()) { - boost::shared_ptr SDR = - boost::make_shared(params.structFile, - params.referenceFile); + boost::shared_ptr SDR; - std::vector ListOfCorrectElements; + try + { + SDR = boost::make_shared(params.structFile, + params.referenceFile); + } + catch (rttb::core::Exception& e) + { + std::cerr << "RTTB Error!!!" << std::endl; + std::cerr << e.what() << std::endl; + return 1; + } + catch (const std::exception& e) + { + std::cerr << "Error!!!" << std::endl; + std::cerr << e.what() << std::endl; + return 1; + } + catch (...) + { + std::cerr << "Error!!! unknown error while reading input image." << std::endl; + return 1; + } + + std::vector listOfCorrectElements; for (int i = 0; i < params.regEx.size(); i++) { - std::vector IndexOfCorrectElements; - IndexOfCorrectElements = rttb::apps::voxelizer::filterForExpression(SDR->getAllLabels(), + std::vector indexOfCorrectElements; + indexOfCorrectElements = rttb::apps::voxelizer::filterForExpression(SDR->getAllLabels(), params.regEx.at(i)); - for (int k = 0 ; k < IndexOfCorrectElements.size() ; k++) + for (int k = 0 ; k < indexOfCorrectElements.size() ; k++) { - ListOfCorrectElements.push_back(IndexOfCorrectElements.at(k)); + listOfCorrectElements.push_back(indexOfCorrectElements.at(k)); } } boost::shared_ptr MP = boost::make_shared(SDR->getStructureSetPointer(), SDR->getDoseAccessorPointer(), params.legacyVoxelization); - if (!ListOfCorrectElements.empty()) + if (!listOfCorrectElements.empty()) { - std::string FileName = rttb::apps::voxelizer::getFilenameWithoutEnding( + std::string fileName = rttb::apps::voxelizer::getFilenameWithoutEnding( params.outputFilename); - std::string FileEnding = rttb::apps::voxelizer::getFileEnding(params.outputFilename); + std::string fileEnding = rttb::apps::voxelizer::getFileEnding(params.outputFilename); - std::vector MaskPointer; + std::vector maskPointer; if (params.addStructures) { - std::string LabelName; + std::string labelName; - for (int i = 0; i < ListOfCorrectElements.size(); i++) + for (int i = 0; i < listOfCorrectElements.size(); i++) { - MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(i))); + maskPointer.push_back(MP->createMask(listOfCorrectElements.at(i))); - LabelName += "_" + rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), - ListOfCorrectElements.at(i)); + labelName += "_" + rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + listOfCorrectElements.at(i)); } boost::shared_ptr MW = - boost::make_shared(MaskPointer, + boost::make_shared(maskPointer, params.booleanVoxelization); - MW->writeMaskToFile(FileName + LabelName + FileEnding); + MW->writeMaskToFile(fileName + labelName + fileEnding); } else { - std::string LabelName; + std::string labelName; if (params.multipleStructs) { - for (unsigned int i = 0; i < ListOfCorrectElements.size(); i++) + for (unsigned int i = 0; i < listOfCorrectElements.size(); i++) { - MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(i))); + maskPointer.push_back(MP->createMask(listOfCorrectElements.at(i))); - LabelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), - ListOfCorrectElements.at(i)); + labelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + listOfCorrectElements.at(i)); boost::shared_ptr MW = - boost::make_shared(MaskPointer, + boost::make_shared(maskPointer, params.booleanVoxelization); - MW->writeMaskToFile(FileName + "_" + LabelName + FileEnding); + MW->writeMaskToFile(fileName + "_" + labelName + fileEnding); } } else { - MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(0))); + maskPointer.push_back(MP->createMask(listOfCorrectElements.at(0))); - LabelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), - ListOfCorrectElements.at(0)); + labelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + listOfCorrectElements.at(0)); boost::shared_ptr MW = - boost::make_shared(MaskPointer, + boost::make_shared(maskPointer, params.booleanVoxelization); - MW->writeMaskToFile(FileName + "_" + LabelName + FileEnding); + MW->writeMaskToFile(fileName + "_" + labelName + fileEnding); } } } else { std::cout << "No struct found" << std::endl; } } return EXIT_SUCCESS; } diff --git a/testing/demoapps/VoxelizerTool/CMakeLists.txt b/testing/demoapps/VoxelizerTool/CMakeLists.txt index b943c2d..1bbb2fd 100644 --- a/testing/demoapps/VoxelizerTool/CMakeLists.txt +++ b/testing/demoapps/VoxelizerTool/CMakeLists.txt @@ -1,27 +1,27 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(VoxelizerTool_TESTS ${EXECUTABLE_OUTPUT_PATH}/RTTBVoxelizerToolTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEST_DATA ${RTToolbox_BINARY_DIR}/Testing/demoapps/VoxelizerTool) SET(VOXELIZERTOOL_EXE "VoxelizerTool") SET(STRUCT_FILE "${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm") SET(REFERENCE_FILE "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo.dcm") #----------------------------------------------------------------------------- ADD_TEST(rttbVoxelizerToolIncorrectCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolIncorrectCommandsTest "${VOXELIZERTOOL_EXE}" ${STRUCT_FILE} "${TEST_DATA_ROOT}/DICOM/StructureSet/Wrong_Data_Struct_file.dicom" ${REFERENCE_FILE} "${TEST_DATA_ROOT}/DICOM/TestDose/Wrong_Reference_file.dicom" "Rueckenmark" "blabla") ADD_TEST(rttbVoxelizerToolVoxelizerAllStructsTest ${VoxelizerTool_TESTS} VoxelizerToolVoxelizerAllStructsTest "${VOXELIZERTOOL_EXE}" ${TEST_DATA} ${STRUCT_FILE} ${REFERENCE_FILE} ) -ADD_TEST(rttbVoxelizerToolDifferentCommandsTest ${VoxelizerTool_TESTS} VoxelizerToolDifferentCommandsTest -"${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") +#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) diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp deleted file mode 100644 index 4ff267c..0000000 --- a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp +++ /dev/null @@ -1,131 +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: 5603 $ (last changed revision) -// @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) -// @author $Author: strubel $ (last changed by) -*/ - -#include "litCheckMacros.h" -#include -#include "itkImage.h" -#include "itkImageFileReader.h" -#include - -/*! @brief VoxelizerToolTest5. -Search the coordinate at the Image and return the Voxel(Pixel) value. -*/ - -namespace rttb -{ - namespace testing - { - - int VoxelizerToolVoxelPixelValue(int argc, char* argv[]) - { - PREPARE_DEFAULT_TEST_REPORTING; - - typedef itk::Image< double, 3 > ImageType; - typedef itk::ImageFileReader ReaderType; - - if (argc > 3) - { - const std::string pathToBinaryDirectory = argv[1]; - const std::string pathToTestDirectory = argv[2]; - const std::string RTToolBoxTestingDirectory = argv[3]; - - const std::string StructCommand = pathToBinaryDirectory + - "/Release/RTTBVoxelizerTool -s " + RTToolBoxTestingDirectory + - "/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + - RTToolBoxTestingDirectory + "/DICOM/TestDose/ConstantTwo.dcm -e Leber"; - int returnValue = system(StructCommand.c_str()); - CHECK_EQUAL(returnValue, 0); - - std::string pathToFile = pathToTestDirectory + "/out_Leber.hdr"; - - ImageType::IndexType pixelWithOne_1 = {{20, 30, 30}}; - ImageType::IndexType pixelWithOne_2 = {{30, 10, 40}}; - - ImageType::IndexType pixelWithZero_1 = {{40, 30, 30}}; - ImageType::IndexType pixelWithZero_2 = {{10, 40, 30}}; - - ImageType::IndexType pixelAtBorder_1 = {{12, 23, 27}}; - ImageType::IndexType pixelAtBorder_2 = {{34, 21, 31}}; - - std::vector pixelWithOne; - std::vector pixelWithZero; - std::vector pixelAtBorder; - - pixelWithOne.push_back(pixelWithOne_1); - pixelWithOne.push_back(pixelWithOne_2); - - pixelWithZero.push_back(pixelWithZero_1); - pixelWithZero.push_back(pixelWithZero_2); - - pixelAtBorder.push_back(pixelAtBorder_1); - pixelAtBorder.push_back(pixelAtBorder_2); - - if (boost::filesystem::exists(pathToFile)) - { - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(pathToFile); - reader->Update(); - - auto image = reader->GetOutput(); - ImageType::PixelType pixelValue; - - for (int i = 0; i < pixelWithOne.size(); i++) - { - pixelValue = image->GetPixel(pixelWithOne.at(i)); - CHECK_EQUAL(pixelValue, 1.0); - } - - for (int i = 0; i < pixelWithZero.size(); i++) - { - pixelValue = image->GetPixel(pixelWithZero.at(i)); - CHECK_EQUAL(pixelValue, 0.0); - } - - for (int i = 0; i < pixelAtBorder.size(); i++) - { - pixelValue = image->GetPixel(pixelAtBorder.at(i)); - - if (i == 0) - { - CHECK_CLOSE(pixelValue, 0.265865, 1e-3); - } - else if (i == 1) - { - CHECK_CLOSE(pixelValue, 0.819613, 1e-3); - } - } - - if (boost::filesystem::exists(pathToTestDirectory + "/out_Leber.img")) - { - boost::filesystem::remove(pathToTestDirectory + "/out_Leber.img"); - } - - if (boost::filesystem::exists(pathToTestDirectory + "/out_Leber.hdr")) - { - boost::filesystem::remove(pathToTestDirectory + "/out_Leber.hdr"); - } - } - } - - RETURN_AND_REPORT_TEST_SUCCESS; - } - } -} \ No newline at end of file