diff --git a/demoapps/CMakeLists.txt b/demoapps/CMakeLists.txt index 22ca34d..7f73a72 100644 --- a/demoapps/CMakeLists.txt +++ b/demoapps/CMakeLists.txt @@ -1,6 +1,11 @@ MESSAGE(STATUS "processing RTToolbox demo apps") OPTION(BUILD_DemoApp_DoseAcc "Determine if the demo application DoseAcc will be generated." OFF) IF(BUILD_DemoApp_DoseAcc) ADD_SUBDIRECTORY(DoseAcc) ENDIF(BUILD_DemoApp_DoseAcc) + +OPTION(BUILD_DemoApp_VoxelizerTool "Determine if the demo application VoxelizerTool will be generated." OFF) +IF(BUILD_DemoApp_VoxelizerTool) +ADD_SUBDIRECTORY(VoxelizerTool) +ENDIF(BUILD_DemoApp_VoxelizerTool) \ No newline at end of file diff --git a/demoapps/VoxelizerTool/CMakeLists.txt b/demoapps/VoxelizerTool/CMakeLists.txt new file mode 100644 index 0000000..228b64e --- /dev/null +++ b/demoapps/VoxelizerTool/CMakeLists.txt @@ -0,0 +1,3 @@ +MESSAGE (STATUS "generating demo app: VoxelizerTool - simple dose accumulation tool example") + +RTTB_CREATE_APPLICATION(RTTBVoxelizerTool DEPENDS RTTBITKIO RTTBOTBMask RTTBBoostMask RTTBDicomIO RTTBMasks RTTBAlgorithms RTTBInterpolation RTTBCore PACKAGE_DEPENDS MatchPoint ITK) \ No newline at end of file diff --git a/demoapps/VoxelizerTool/files.cmake b/demoapps/VoxelizerTool/files.cmake new file mode 100644 index 0000000..2130aec --- /dev/null +++ b/demoapps/VoxelizerTool/files.cmake @@ -0,0 +1,19 @@ +SET(CPP_FILES +rttbVoxelizerTool.cpp +rttbCommandOptions.cpp +rttbMaskProcess.cpp +rttbMaskWriter.cpp +rttbStructDataReader.cpp +rttbVoxelizerHelper.cpp +) + +SET(H_FILES +rttbCommandOptions.h +rttbMaskProcess.h +rttbMaskWriter.h +rttbStructDataReader.h +rttbVoxelizerHelper.h +) + +SET(TPP_FILES +) diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.cpp b/demoapps/VoxelizerTool/rttbCommandOptions.cpp new file mode 100644 index 0000000..0ef5f8c --- /dev/null +++ b/demoapps/VoxelizerTool/rttbCommandOptions.cpp @@ -0,0 +1,187 @@ +// ----------------------------------------------------------------------- +// 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_ADDSTRUCTURES("addStructures") + { + + params.multipleStructs = false; + params.legacyVoxelization = false; + params.booleanVoxelization = false; + params.addStructures = false; + + po::options_description required("Required arguments"); + addOption(required, PARAM_STRUCT_FILE, "s", po::value(¶ms.structFile), + "Filename of the structfile (*.dcm)"); + addOption(required, PARAM_REFERENCE_FILE, "r", po::value(¶ms.referenceFile), + "Filename of the reference image (*.dcm)"); + + addOption(required, PARAM_REGEX, "e", + po::value>(¶ms.regEx)->multitoken(), + "set a regular expression describing the structs of interest"); + + po::options_description optional("Optional arguments"); + addOption(optional, PARAM_HELP, "h", nullptr, "Display help message"); + addOption(optional, PARAM_OUT_FILE, "o", + po::value(¶ms.outputFilename)->default_value("out.hdr"), "set output file name "); + addOption(optional, PARAM_MULTISTRUCT, "m", nullptr, + "if multiple structs are found, save all in files"); + addOption(optional, PARAM_BOOST, "b", nullptr, "for boost voxelization"); + addOption(optional, PARAM_LEGACY, "l", nullptr, + "for legacy voxelization"); + addOption(optional, PARAM_BOOLEANVOXELIZATION, "v", nullptr, + "Determines if the voxelization should have only boolean values (0 or 1)"); + addOption(optional, PARAM_ADDSTRUCTURES, "a", nullptr, + ""); + + description.add(required).add(optional); + } + + void CommandOptions::addOption(po::options_description& o, const std::string& name, + const std::string& shortcut, const po::value_semantic* valueSemantic, + const std::string& description) + { + if (valueSemantic) + { + o.add_options()((name + std::string(",") + shortcut).c_str(), valueSemantic, description.c_str()); + } + else + { + o.add_options()((name + std::string(",") + shortcut).c_str(), description.c_str()); + } + } + + void CommandOptions::showHelp()const + { + std::cout << "Usage: VoxelizerTool structfile reference [optional] \n"; + std::cout << description << std::endl; + } + + bool CommandOptions::command(int argc, char* argv[]) + { + try + { + po::variables_map var; + _minArguments = 7; + po::store(po::command_line_parser(argc, argv).options(description).run(), var); + po::notify(var); + + if (argc < _minArguments) + { + showHelp(); + return false; + } + + if (var.count(PARAM_HELP)) + { + showHelp(); + return true; + } + + if (!var.count(PARAM_STRUCT_FILE)) + { + throw std::runtime_error("Please use the parameter -s or --Structfile"); + } + else + { + if (getFileEnding(params.structFile) != ".dcm") + { + throw std::runtime_error("Please check your Structfile: " + 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 Referencefile: " + params.referenceFile); + } + } + + if (!var.count(PARAM_OUT_FILE)) + { + params.outputFilename = "out.hdr"; + } + + if (var.count(PARAM_REGEX)) + { + + if (var.count(PARAM_MULTISTRUCT)) + { + params.multipleStructs = true; + } + else + { + params.multipleStructs = false; + } + } + + if (var.count(PARAM_LEGACY)) + { + params.legacyVoxelization = true; + } + + if (var.count(PARAM_BOOLEANVOXELIZATION)) + { + params.booleanVoxelization = true; + } + + if (var.count(PARAM_ADDSTRUCTURES)) + { + params.addStructures = true; + params.multipleStructs = false; + } + } + catch (const std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; + return false; + } + + return true; + } + } + } +} \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbCommandOptions.h b/demoapps/VoxelizerTool/rttbCommandOptions.h new file mode 100644 index 0000000..001e174 --- /dev/null +++ b/demoapps/VoxelizerTool/rttbCommandOptions.h @@ -0,0 +1,121 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 5506 $ (last changed revision) +// @date $Date: 2015-07-30 14:45:24 +0200 (Do, 30 Jul 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ +#ifndef __CommandOptions_h +#define __CommandOptions_h + +#include + +namespace rttb +{ + namespace apps + { + namespace voxelizer + { + namespace po = boost::program_options; + + /** @brief Simple struct holding all variables. */ + struct Parameters + { + /** @brief Filename of the StructFile*/ + std::string structFile; + /** @brief Filename of the ReferenceFile*/ + std::string referenceFile; + /** @brief Output Filename*/ + std::string outputFilename; + /** @brief Expressions from User*/ + std::vector regEx; + /** @brief for more than one struct*/ + bool multipleStructs; + /** @brief add: legacyVoxelization=false means boostVoxelization is turned on*/ + bool legacyVoxelization; + /** @brief voxelization should be binarized to value 0 or 1 */ + bool booleanVoxelization ; + /** @brief multiple structures voxelization should be combined in one file*/ + bool addStructures; + + }; + + /*! @class CommandOptions + @brief CommandOptions Class, everything about the commandline + */ + class CommandOptions + { + + public: + /*!@brief Constructor + @details add the dicription for commandline options + * add parameter --h or --help for help informations, + * --Structfile= to set a structfile, + * --Reference= to set the referencefile, + * --Output= to set an output file name and + * --struct= to add an expression like(SPINE). + */ + CommandOptions(); + /** + @brief Validates the given input parameters and fills the corresponding variables. + @param argc Number of arguments. + @param argv Array of individual arguments. + @return true if all arguments were valid (i.e. none were missing or incorrect), otherwise false. + */ + bool command(int argc, char* argv[]); + + const Parameters& getParameters() const + { + return params; + } + + private: + /** + *@brief Adds an option to the given option container. + *@param o Option container the new option should be added to. + *@param name Name of the new option (i.e. the actual parameter, e.g. "test" adds the option with the parameter "--test"). + *@param shortcut A single letter that is used as a shortcut for this option (e.g. if the name is "test, the shortcut might be "t", so you can call the parameter with "-t" instead of "--test"). + *@param valueSemantic The desired value semantic object, i.e. the object that binds this option's value to a variable. + *@param description The description text for this option. + */ + void addOption(po::options_description& o, const std::string& name, const std::string& shortcut, + const po::value_semantic* valueSemantic, const std::string& description); + + /*! @brief print out the dicription.*/ + void showHelp()const; + + const std::string PARAM_STRUCT_FILE; + const std::string PARAM_REFERENCE_FILE; + const std::string PARAM_OUT_FILE; + const std::string PARAM_REGEX; + const std::string PARAM_MULTISTRUCT; + const std::string PARAM_HELP; + const std::string PARAM_LEGACY; + const std::string PARAM_BOOST; + const std::string PARAM_BOOLEANVOXELIZATION; + const std::string PARAM_ADDSTRUCTURES; + + /*! create description object */ + po::options_description description; + Parameters params; + + /**@brief minimum arguments that must be present on the Command Line*/ + int _minArguments; + }; + } + } +} +#endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskProcess.cpp b/demoapps/VoxelizerTool/rttbMaskProcess.cpp new file mode 100644 index 0000000..cce4188 --- /dev/null +++ b/demoapps/VoxelizerTool/rttbMaskProcess.cpp @@ -0,0 +1,67 @@ +// ----------------------------------------------------------------------- +// 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) + { + MaskAccessorPointer maskAccessorPtr; + + if (_doseAccessor != NULL) + { + if (_legacyVoxelization) + { + maskAccessorPtr = boost::make_shared + (_rtStructureSet->getStructure(indexOfStruktur), _doseAccessor->getGeometricInfo()); + } + else + { + maskAccessorPtr = boost::make_shared + (_rtStructureSet->getStructure(indexOfStruktur), _doseAccessor->getGeometricInfo()); + } + + maskAccessorPtr->updateMask(); + return maskAccessorPtr; + + } + else + { + return maskAccessorPtr; + } + } + } + } +} \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbMaskProcess.h b/demoapps/VoxelizerTool/rttbMaskProcess.h new file mode 100644 index 0000000..6b9a0bb --- /dev/null +++ b/demoapps/VoxelizerTool/rttbMaskProcess.h @@ -0,0 +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); + 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 new file mode 100644 index 0000000..3f762e3 --- /dev/null +++ b/demoapps/VoxelizerTool/rttbMaskWriter.cpp @@ -0,0 +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) + { + } + + void MaskWriter::writeMaskToFile(const std::string& outputFileName) + { + if (!_MaskPointerList.empty()) + { + ITKImageTypeConstPointer itkImage; + + if (_MaskPointerList.size() > 1) + { + itkImage = AddMultipleStructsToImage(); + } + else + { + io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_MaskPointerList.at(0)); + maskAccessorConverter.process(); + itkImage = maskAccessorConverter.getITKImage(); + } + + if (_booleanvoxelization) + { + itkImage = ApplyThresholdFilter(itkImage); + } + + WriteITKImageToFile(itkImage, outputFileName); + } + } + + MaskWriter::ITKImageTypeConstPointer MaskWriter::AddMultipleStructsToImage() + { + std::vector listOfITKImages; + + for (int i = 0; i < _MaskPointerList.size(); i++) + { + io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(_MaskPointerList.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; + } + + filterResult = addFilter->GetOutput(); + } + + return filterResult; + } + + MaskWriter::ITKImageTypeConstPointer MaskWriter::ApplyThresholdFilter( + ITKImageTypeConstPointer itkImage) + { + + 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 filter->GetOutput(); + } + + void MaskWriter::WriteITKImageToFile(ITKImageTypeConstPointer itkImage, + const std::string& outputfilename) + { + 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 new file mode 100644 index 0000000..5add79c --- /dev/null +++ b/demoapps/VoxelizerTool/rttbMaskWriter.h @@ -0,0 +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); + + private: + + ITKImageTypeConstPointer AddMultipleStructsToImage(); + ITKImageTypeConstPointer ApplyThresholdFilter(ITKImageTypeConstPointer itkImage); + void WriteITKImageToFile(ITKImageTypeConstPointer itkImage, const std::string& outputfilename); + + //MaskAccessorPointer _maskAccessorPtr; + bool _booleanvoxelization; + std::vector _MaskPointerList; + }; + } + } +} +#endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbStructDataReader.cpp b/demoapps/VoxelizerTool/rttbStructDataReader.cpp new file mode 100644 index 0000000..bb79579 --- /dev/null +++ b/demoapps/VoxelizerTool/rttbStructDataReader.cpp @@ -0,0 +1,100 @@ +// ----------------------------------------------------------------------- +// 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 allLabels; + + if (_rtStructureSet != NULL && _rtStructureSet->getNumberOfStructures() > 0) + { + for (int j = 0; j < _rtStructureSet->getNumberOfStructures(); j++) + { + allLabels.push_back(_rtStructureSet->getStructure(j)->getLabel()); + } + } + + return allLabels; + } + + StructDataReader::StructureSetPointer StructDataReader::getStructureSetPointer() + { + return _rtStructureSet; + } + + StructDataReader::DoseAccessorPointer StructDataReader::getDoseAccessorPointer() + { + return _doseAccessor; + } + + StructDataReader::DoseAccessorPointer StructDataReader::readReferenceFile( + const std::string& referencefile) + { + 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; + } + } + + StructDataReader::StructureSetPointer StructDataReader::readStructFile( + const std::string& structfile) + { + 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; + } + } + + } + } +} \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbStructDataReader.h b/demoapps/VoxelizerTool/rttbStructDataReader.h new file mode 100644 index 0000000..f97e2de --- /dev/null +++ b/demoapps/VoxelizerTool/rttbStructDataReader.h @@ -0,0 +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(); + /**@brief + @return the objekt _rtStructureSet + */ + StructureSetPointer getStructureSetPointer(); + /**@brief + @return the objekt _doseAccessor + */ + DoseAccessorPointer getDoseAccessorPointer(); + + private: + + /**@brief read a referencefile + @return the result as object + */ + DoseAccessorPointer readReferenceFile(const std::string& referencefile); + /**@brief read a structfile + @return the result as object + */ + StructureSetPointer readStructFile(const std::string& structfile); + + StructureSetPointer _rtStructureSet; + DoseAccessorPointer _doseAccessor; + }; + } + } +} +#endif \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp b/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp new file mode 100644 index 0000000..09c07d1 --- /dev/null +++ b/demoapps/VoxelizerTool/rttbVoxelizerHelper.cpp @@ -0,0 +1,88 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 5603 $ (last changed revision) +// @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ + +#include "rttbVoxelizerHelper.h" +#include +#include +#include + +namespace rttb +{ + namespace apps + { + namespace voxelizer + { + + std::vector filterForExpression(std::vector listOfExpressions, + 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)); + + if (boost::regex_match(StringInList, e)) + { + listOfFoundElements.push_back(j); + } + } + + return listOfFoundElements; + } + + std::string getLabelFromList(std::vector listOfExpressions, int j) + { + + if (listOfExpressions.at(j).find("/") != std::string::npos) + { + /*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); + } + } + + std::string getFilenameWithoutEnding(std::string outfilename) + { + boost::filesystem::path p(outfilename); + return p.stem().string(); + } + + std::string getFileEnding(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 new file mode 100644 index 0000000..21f8e6c --- /dev/null +++ b/demoapps/VoxelizerTool/rttbVoxelizerHelper.h @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------- +// 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 + @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::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); + } + } +} \ No newline at end of file diff --git a/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp b/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp new file mode 100644 index 0000000..831765b --- /dev/null +++ b/demoapps/VoxelizerTool/rttbVoxelizerTool.cpp @@ -0,0 +1,135 @@ +// ----------------------------------------------------------------------- +// 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::make_shared(); + + if (!CO->command(argc, argv)) + { + return EXIT_FAILURE; + } + + 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); + + std::vector ListOfCorrectElements; + + for (int i = 0; i < params.regEx.size(); i++) + { + std::vector IndexOfCorrectElements; + IndexOfCorrectElements = rttb::apps::voxelizer::filterForExpression(SDR->getAllLabels(), + params.regEx.at(i)); + + for (int k = 0 ; k < IndexOfCorrectElements.size() ; k++) + { + ListOfCorrectElements.push_back(IndexOfCorrectElements.at(k)); + } + } + + boost::shared_ptr MP = + boost::make_shared(SDR->getStructureSetPointer(), + SDR->getDoseAccessorPointer(), + params.legacyVoxelization); + + if (!ListOfCorrectElements.empty()) + { + std::string FileName = rttb::apps::voxelizer::getFilenameWithoutEnding( + params.outputFilename); + std::string FileEnding = rttb::apps::voxelizer::getFileEnding(params.outputFilename); + + std::vector MaskPointer; + + if (params.addStructures) + { + std::string LabelName; + + for (int i = 0; i < ListOfCorrectElements.size(); i++) + { + MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(i))); + + LabelName += "_" + rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + ListOfCorrectElements.at(i)); + } + + boost::shared_ptr MW = + boost::make_shared(MaskPointer, + params.booleanVoxelization); + MW->writeMaskToFile(FileName + LabelName + FileEnding); + } + else + { + + std::string LabelName; + + if (params.multipleStructs) + { + for (unsigned int i = 0; i < ListOfCorrectElements.size(); i++) + { + MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(i))); + + LabelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + ListOfCorrectElements.at(i)); + boost::shared_ptr MW = + boost::make_shared(MaskPointer, + params.booleanVoxelization); + MW->writeMaskToFile(FileName + "_" + LabelName + FileEnding); + } + } + else + { + MaskPointer.push_back(MP->createMask(ListOfCorrectElements.at(0))); + + LabelName = rttb::apps::voxelizer::getLabelFromList(SDR->getAllLabels(), + ListOfCorrectElements.at(0)); + boost::shared_ptr MW = + boost::make_shared(MaskPointer, + params.booleanVoxelization); + MW->writeMaskToFile(FileName + "_" + LabelName + FileEnding); + + } + + } + } + else + { + std::cout << "No struct found" << std::endl; + } + } + + return EXIT_SUCCESS; +} + diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index dd17f67..f317d0d 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -1,67 +1,70 @@ MESSAGE(STATUS "processing RTToolbox testing code") # Testing branch PROJECT(RTTBTesting) #----------------------------------------------------------------------------- # Find Litmus. #----------------------------------------------------------------------------- MESSAGE(STATUS "searching Litmus") FIND_PACKAGE(Litmus) IF(Litmus_FOUND) INCLUDE(${Litmus_USE_FILE}) SET(ADDITIONAL_TEST_INCLUDES ${Litmus_USE_FILE}) ELSE(Litmus_FOUND) MESSAGE(FATAL_ERROR "Cannot build without Litmus. Please set Litmus_DIR.") ENDIF(Litmus_FOUND) #----------------------------------------------------------------------------- # Configure Testing branch #----------------------------------------------------------------------------- MAKE_DIRECTORY(${RTTBTesting_BINARY_DIR}/Temporary) MESSAGE(STATUS "Process All Tests...") #----------------------------------------------------------------------------- # Include sub directories #----------------------------------------------------------------------------- OPTION(BUILD_RTToolbox_core_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_Test_examples "build project on/off" OFF) OPTION(BUILD_RTToolbox_algorithms_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_models_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_io_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_masks_Tester "build project on/off" OFF) OPTION(BUILD_RTToolbox_interpolation_Tester "build project on/off" OFF) +OPTION(BUILD_RTToolbox_demoapps_VoxelizerTool_Tester "build project on/off" OFF) IF(${BUILD_RTToolbox_core_Tester} STREQUAL ON) ADD_SUBDIRECTORY(core) ENDIF(${BUILD_RTToolbox_core_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_Test_examples} STREQUAL ON) ADD_SUBDIRECTORY(examples) ENDIF(${BUILD_RTToolbox_Test_examples} STREQUAL ON) IF(${BUILD_RTToolbox_algorithms_Tester} STREQUAL ON) ADD_SUBDIRECTORY(algorithms) ENDIF(${BUILD_RTToolbox_algorithms_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_models_Tester} STREQUAL ON) ADD_SUBDIRECTORY(models) ENDIF(${BUILD_RTToolbox_models_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_io_Tester} STREQUAL ON) ADD_SUBDIRECTORY(io) ENDIF(${BUILD_RTToolbox_io_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_masks_Tester} STREQUAL ON) ADD_SUBDIRECTORY(masks) ENDIF(${BUILD_RTToolbox_masks_Tester} STREQUAL ON) IF(${BUILD_RTToolbox_interpolation_Tester} STREQUAL ON) ADD_SUBDIRECTORY(interpolation) ENDIF(${BUILD_RTToolbox_interpolation_Tester} STREQUAL ON) - +IF(${BUILD_RTToolbox_demoapps_VoxelizerTool_Tester} STREQUAL ON) +ADD_SUBDIRECTORY(interpolation) +ENDIF(${BUILD_RTToolbox_demoapps_VoxelizerTool_Tester} STREQUAL ON) diff --git a/testing/demoapps/VoxelizerTool/CMakeLists.txt b/testing/demoapps/VoxelizerTool/CMakeLists.txt new file mode 100644 index 0000000..02ff805 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/CMakeLists.txt @@ -0,0 +1,32 @@ +#----------------------------------------------------------------------------- +# Setup the system information test. Write out some basic failsafe +# information in case the test doesn't run. +#----------------------------------------------------------------------------- + + +SET(CORE_TEST_EXAMPLES ${EXECUTABLE_OUTPUT_PATH}/rttbExamplesTests) + +SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) + +SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) + + +#----------------------------------------------------------------------------- +ADD_TEST(rttbVoxelizerToolDifferentCommandsTest ${CORE_TEST_EXAMPLES} RTBioModelExampleTest + +ADD_TEST(rttbVoxelizerToolIncorrectCommandsTest ${CORE_TEST_EXAMPLES} DVHCalculatorExampleTest + +ADD_TEST(rttbVoxelizerToolVoxelizerAllStuctsTest ${CORE_TEST_EXAMPLES} RTDoseIndexTest + +ADD_TEST(rttbVoxelizerToolVoxelizerBoostLegacyTest ${CORE_TEST_EXAMPLES} RTDoseStatisticsTest + +ADD_TEST(rttbVoxelizerToolVoxelPixelValueTest ${CORE_TEST_EXAMPLES} RTDVHTest "${TEST_DATA_ROOT}/TestDVH/dvh_test.txt") + +RTTB_CREATE_TEST_MODULE(rttbDemoappsVoxelizertool DEPENDS RTTBCore RTTBAlgorithms RTTBMasks RTTBOTBMask RTTBBoostMask RTTBIndices RTTBDicomIO RTTBVirtuosIO RTTBOtherIO RTTBModels PACKAGE_DEPENDS Litmus) + + + + + + + \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/files.cmake b/testing/demoapps/VoxelizerTool/files.cmake new file mode 100644 index 0000000..a08a587 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/files.cmake @@ -0,0 +1,7 @@ +SET(CPP_FILES + rttbVoxelizerToolDifferentCommandsTest.cpp + rttbVoxelizerToolIncorrectCommandsTest.cpp + rttbVoxelizerToolVoxelizerAllStuctsTest.cpp + rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp + rttbVoxelizerToolVoxelPixelValueTest.cpp + ) diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp new file mode 100644 index 0000000..807a2fa --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolDifferentCommandsTest.cpp @@ -0,0 +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: 5603 $ (last changed revision) +// @date $Date: 2015-08-24 15:17:30 +0200 (Mo, 24 Aug 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ + +#include "litCheckMacros.h" +#include +#include +#include + +/*! @brief VoxelizerToolTest3. +Test the output, multipleStructs and the booleanVoxelization parameter. +*/ + +int main(int argc, char* argv[]) +{ + PREPARE_DEFAULT_TEST_REPORTING; + + if (argc > 3) + { + const std::string PathToBinaryDirectory = argv[1]; + const std::string path = argv[2]; + const std::string RTToolBoxTestingDirectory = argv[3]; + + std::vector commands; + commands.push_back(".*"); + commands.push_back(".* -m -o M.hdr"); + commands.push_back("Niere.* -m -o Test.hdr"); + commands.push_back("Leber -o Boolean.hdr -v"); + + std::vector structures; + structures.push_back("M_Aussenkontur"); + structures.push_back("M_Rueckenmark"); + structures.push_back("M_Niere re"); + structures.push_back("M_Niere li"); + structures.push_back("M_Magen_DD"); + structures.push_back("M_Leber"); + structures.push_back("M_Darm"); + structures.push_back("M_Ref.Pkt"); + structures.push_back("M_PTV"); + structures.push_back("M_Boost"); + structures.push_back("out_Aussenkontur"); + structures.push_back("Test_Niere li"); + structures.push_back("Test_Niere re"); + structures.push_back("Boolean_Leber"); + + const std::string baseCommand = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/DICOM/TestDose/ConstantTwo.dcm -e "; + + for (int i = 0; i < commands.size(); i++) + { + std::string command = baseCommand + commands.at(i); + int returnValue = system(command.c_str()); + CHECK_EQUAL(returnValue, 0); + } + + + for (int i = 0; i < structures.size(); i++) + { + std::string IMGfileName = path + "/" + structures.at(i) + ".img"; + std::string HDRfileName = path + "/" + structures.at(i) + ".hdr"; + + CHECK_EQUAL(boost::filesystem::exists(HDRfileName), true); + CHECK_EQUAL(boost::filesystem::exists(IMGfileName), true); + + boost::filesystem::path imgFile(IMGfileName); + + if (boost::filesystem::exists(imgFile)) + { + boost::filesystem::remove(imgFile); + } + + boost::filesystem::path hdrFile(HDRfileName); + + if (boost::filesystem::exists(hdrFile)) + { + boost::filesystem::remove(hdrFile); + } + + } + } + + RETURN_AND_REPORT_TEST_SUCCESS; +} + + diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp new file mode 100644 index 0000000..6baa821 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolIncorrectCommandsTest.cpp @@ -0,0 +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 +#include "litCheckMacros.h" +#include +#include + +/*! @brief VoxelizerToolTest4. +Test incorrect commands with a wrong structfile, referencefile and a wrong struct. +if the command return one, the program could not run to the end. +return zero the command is correct +*/ + +int main(int argc, char* argv[]) +{ + PREPARE_DEFAULT_TEST_REPORTING; + + if (argc > 3) + { + const std::string PathToBinaryDirectory = argv[1]; + const std::string RTToolBoxTestingDirectory = argv[3]; + + const std::string StructCommand = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/Wrong_Data_Struct_file.dicom -r " + RTToolBoxTestingDirectory + + "data/DICOM/TestDose/ConstantTwo.dcm -e Rueckenmark"; + CHECK_EQUAL(system(StructCommand.c_str()), 1); + + const std::string ReferenceCommand = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/DICOM/TestDose/Wrong_Reference_file.dicom -e Rueckenmark"; + CHECK_EQUAL(system(ReferenceCommand.c_str()), 1); + + const std::string Structure = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/DICOM/TestDose/ConstantTwo.dcm -e blablabla"; + CHECK_EQUAL(system(Structure.c_str()), 0); + } + + RETURN_AND_REPORT_TEST_SUCCESS; +} + + diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp new file mode 100644 index 0000000..5acf1f6 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelPixelValueTest.cpp @@ -0,0 +1,123 @@ +// ----------------------------------------------------------------------- +// 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. +*/ +int main(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/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/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 diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp new file mode 100644 index 0000000..52992b9 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerAllStuctsTest.cpp @@ -0,0 +1,106 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 5503 $ (last changed revision) +// @date $Date: 2015-07-24 12:33:26 +0200 (Fr, 24 Jul 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ + +#include +#include "litCheckMacros.h" +#include +#include + +/*! @brief VoxelizerToolTest. +Test all structs. +*/ + +int main(int argc, char* argv[]) +{ + PREPARE_DEFAULT_TEST_REPORTING; + + if (argc > 3) + { + const std::string PathToBinaryDirectory = argv[1]; + const std::string tempDirectory = argv[2]; + const std::string RTToolBoxTestingDirectory = argv[3]; + + std::vector structs; + structs.push_back("Aussenkontur"); + structs.push_back("Rueckenmark"); + structs.push_back("Niere re."); + structs.push_back("Niere li."); + structs.push_back("Magen/DD"); + structs.push_back("Leber"); + structs.push_back("Darm"); + structs.push_back("Ref.Pkt."); + structs.push_back("PTV"); + structs.push_back("Boost"); + + std::vector filenames; + filenames.push_back("Aussenkontur"); + filenames.push_back("Rueckenmark"); + filenames.push_back("Niere re"); + filenames.push_back("Niere li"); + filenames.push_back("Magen_DD"); + filenames.push_back("Leber"); + filenames.push_back("Darm"); + filenames.push_back("Ref.Pkt"); + filenames.push_back("PTV"); + filenames.push_back("Boost"); + + const std::string baseCommand = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/DICOM/TestDose/ConstantTwo.dcm -e \""; + + + + for (int i = 0; i < structs.size(); i++) + { + std::string command = baseCommand + structs.at(i) + "\""; + int returnValue = system(command.c_str()); + + CHECK_EQUAL(returnValue, 0); + + std::string HDRfileName = tempDirectory + "\\out_" + filenames.at(i) + ".hdr"; + std::string IMGfileName = tempDirectory + "\\out_" + filenames.at(i) + ".img"; + + CHECK_EQUAL( + boost::filesystem::exists(HDRfileName), + true); + CHECK_EQUAL( + boost::filesystem::exists(IMGfileName), + true); + + boost::filesystem::path imgFile(IMGfileName); + + if (boost::filesystem::exists(imgFile)) + { + boost::filesystem::remove(imgFile); + } + + boost::filesystem::path hdrFile(HDRfileName); + + if (boost::filesystem::exists(hdrFile)) + { + boost::filesystem::remove(hdrFile); + } + } + } + + RETURN_AND_REPORT_TEST_SUCCESS; +} \ No newline at end of file diff --git a/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp new file mode 100644 index 0000000..5e6b1a7 --- /dev/null +++ b/testing/demoapps/VoxelizerTool/rttbVoxelizerToolVoxelizerBoostLegacyTest.cpp @@ -0,0 +1,86 @@ +// ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See rttbCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/rttb/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: 5503 $ (last changed revision) +// @date $Date: 2015-07-24 12:33:26 +0200 (Fr, 24 Jul 2015) $ (last change date) +// @author $Author: strubel $ (last changed by) +*/ + +#include "litCheckMacros.h" +#include +#include +#include + +/*! @brief VoxelizerToolTest5. +Test the paramter boost and legacy Voxelization. +*/ + +int main(int argc, char* argv[]) +{ + PREPARE_DEFAULT_TEST_REPORTING; + + if (argc > 3) + { + const std::string PathToBinaryDirectory = argv[1]; + const std::string PathToTestingDirectory = argv[2]; + const std::string RTToolBoxTestingDirectory = argv[3]; + + std::vector OutputVoxelization; + OutputVoxelization.push_back("Rueckenmark -o Test.hdr"); + OutputVoxelization.push_back("Leber -l"); + OutputVoxelization.push_back("Darm -b"); + OutputVoxelization.push_back("Leber -o Legacy.hdr -l"); + OutputVoxelization.push_back("Darm -o Boost.hdr -b"); + + std::vector OutputFiles; + OutputFiles.push_back("/Boost_Darm.hdr"); + OutputFiles.push_back("/Boost_Darm.img"); + OutputFiles.push_back("/Legacy_Leber.hdr"); + OutputFiles.push_back("/Legacy_Leber.img"); + OutputFiles.push_back("/out_Darm.hdr"); + OutputFiles.push_back("/out_Darm.img"); + OutputFiles.push_back("/out_Leber.hdr"); + OutputFiles.push_back("/out_Leber.img"); + OutputFiles.push_back("/Test_Rueckenmark.hdr"); + OutputFiles.push_back("/Test_Rueckenmark.img"); + + const std::string baseCommand = PathToBinaryDirectory + + "Release/VoxelizerTool -s " + RTToolBoxTestingDirectory + + "data/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm -r " + + RTToolBoxTestingDirectory + "data/DICOM/TestDose/ConstantTwo.dcm -e "; + + for (int i = 0 ; i < OutputVoxelization.size(); i++) + { + std::string Command = baseCommand + OutputVoxelization.at(i); + int returnValue = system(Command.c_str()); + CHECK_EQUAL(returnValue, 0); + } + + for (int i = 0; i < OutputFiles.size(); i++) + { + std::string pathToFile = PathToTestingDirectory + OutputFiles.at(i); + + CHECK_EQUAL(boost::filesystem::exists(pathToFile), true); + + if (boost::filesystem::exists(pathToFile)) + { + boost::filesystem::remove(pathToFile); + } + } + } + + RETURN_AND_REPORT_TEST_SUCCESS; +} \ No newline at end of file