diff --git a/apps/VoxelizerTool/VoxelizerToolHelper.cpp b/apps/VoxelizerTool/VoxelizerToolHelper.cpp index 5eda333..cbeb35c 100644 --- a/apps/VoxelizerTool/VoxelizerToolHelper.cpp +++ b/apps/VoxelizerTool/VoxelizerToolHelper.cpp @@ -1,227 +1,216 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 1127 $ (last changed revision) // @date $Date: 2015-10-01 13:33:33 +0200 (Do, 01 Okt 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include #include "rttbBoostMaskAccessor.h" #include "itkMacro.h" #include "VoxelizerToolHelper.h" #include "VoxelizerToolApplicationData.h" #include "rttbITKImageMaskAccessorConverter.h" #include "rttbImageWriter.h" #include "itkBinaryThresholdImageFilter.h" #include "itkAddImageFilter.h" #include #include -#include + +#include "rttbUtils.h" #include "rttbDicomFileStructureSetGenerator.h" void rttb::apps::voxelizerTool::removeSpecialCharacters(std::string& label) { //Replace / to avoid problems with directories (struct "Magen/DD" --> Magen/DD.mhd), delete trailing . to avoid filenames with two trailing points (Niere re. --> Niere re..mhd) while (label.find("/") != std::string::npos) { label.replace(label.find("/"), 1, "_"); } if (*label.rbegin() == '.') { label.replace(label.size() - 1, 1, ""); } } -std::string rttb::apps::voxelizerTool::getFilenameWithoutEnding(const std::string& outfilename) -{ - boost::filesystem::path p(outfilename); - return p.replace_extension("").string(); -} - -std::string rttb::apps::voxelizerTool::getFileEnding(const std::string& outfilename) -{ - boost::filesystem::path p(outfilename); - return p.extension().string(); -} - rttb::core::MaskAccessorInterface::MaskAccessorPointer rttb::apps::voxelizerTool::createMask( rttb::core::DoseAccessorInterface::DoseAccessorPointer doseAccessorPtr, rttb::core::Structure::StructTypePointer structurePtr, bool strict) { rttb::core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr; if (doseAccessorPtr != nullptr && structurePtr != nullptr) { maskAccessorPtr = boost::make_shared (structurePtr, doseAccessorPtr->getGeometricInfo(), strict); maskAccessorPtr->updateMask(); } return maskAccessorPtr; } void rttb::apps::voxelizerTool::writeMaskToFile(std::vector maskVector, const std::string& outputFileName, bool voxelization) { if (!maskVector.empty()) { io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer itkImage; if (maskVector.size() > 1) { itkImage = addMultipleStructsToImage(maskVector); } else { io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(maskVector.at(0)); maskAccessorConverter.process(); itkImage = maskAccessorConverter.getITKImage(); } if (voxelization) { itkImage = applyThresholdFilter(itkImage); } io::itk::ImageWriter writer(outputFileName, itkImage); writer.writeFile(); } } rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer rttb::apps::voxelizerTool::addMultipleStructsToImage( std::vector maskVector) { std::vector listOfITKImages; for (const auto & i : maskVector) { io::itk::ITKImageMaskAccessorConverter maskAccessorConverter(i); maskAccessorConverter.process(); listOfITKImages.push_back(maskAccessorConverter.getITKImage()); } itk::AddImageFilter , itk::Image>::Pointer addFilter = itk::AddImageFilter , itk::Image>::New(); io::itk::ITKImageMaskAccessor::ITKMaskImageType::Pointer filterResult; for (int k = 1; k < listOfITKImages.size(); k++) { if (k == 1) { addFilter->SetInput1(listOfITKImages.at(0)); } else { addFilter->SetInput1(filterResult); } addFilter->SetInput2(listOfITKImages.at(k)); addFilter->Update(); filterResult = addFilter->GetOutput(); } return filterResult.GetPointer(); } rttb::io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer rttb::apps::voxelizerTool::applyThresholdFilter( io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer itkImage) { itk::BinaryThresholdImageFilter< itk::Image, itk::Image >::Pointer filter = itk::BinaryThresholdImageFilter< itk::Image, itk::Image >::New(); filter->SetInput(itkImage); filter->SetLowerThreshold(0.5); filter->SetUpperThreshold(1.0); filter->SetInsideValue(1.0); filter->Update(); return filter->GetOutput(); } void rttb::apps::voxelizerTool::processData(rttb::apps::voxelizerTool::ApplicationData& appData) { if (appData._struct->getNumberOfStructures()>0) { std::vector maskVector; if (appData._addStructures) { for (size_t i=0; igetNumberOfStructures(); i++ ) { std::cout << "creating mask #" << i << "..."; maskVector.push_back(createMask(appData._dose, appData._struct->getStructure(i), !appData._noStrictVoxelization)); std::cout << "done" << std::endl; } std::cout << "writing mask to file..."; writeMaskToFile(maskVector, appData._outputFilename, appData._binaryVoxelization); std::cout << "done" << std::endl; } else { //default behavior: read only first struct that matches the regex unsigned int maxIterationCount = 1; //only if specified: read all structs that matches the regex if (appData._multipleStructs) { maxIterationCount = appData._struct->getNumberOfStructures(); } for (size_t i = 0; igetStructure(i), !appData._noStrictVoxelization); std::cout << "done" << std::endl; std::string labelOfInterest = appData._struct->getStructure(i)->getLabel(); removeSpecialCharacters(labelOfInterest); std::string outputName = appData._outputFilename; if (appData._multipleStructs) { - std::string fileName = getFilenameWithoutEnding( + std::string fileName = rttb::core::getFilenameWithoutEnding( appData._outputFilename); - std::string fileEnding = getFileEnding(appData._outputFilename); + std::string fileEnding = rttb::core::getFileEnding(appData._outputFilename); outputName = fileName + "_" + labelOfInterest + fileEnding; } std::vector currenMaskVector{ currentMask }; std::cout << "writing mask #" << i << " to file..."; writeMaskToFile(currenMaskVector, outputName, appData._binaryVoxelization); std::cout << "done" << std::endl; } } } else { std::cout << "No struct found" << std::endl; } } \ No newline at end of file diff --git a/apps/VoxelizerTool/VoxelizerToolHelper.h b/apps/VoxelizerTool/VoxelizerToolHelper.h index 429046e..312777a 100644 --- a/apps/VoxelizerTool/VoxelizerToolHelper.h +++ b/apps/VoxelizerTool/VoxelizerToolHelper.h @@ -1,69 +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: 1127 $ (last changed revision) // @date $Date: 2015-10-01 13:33:33 +0200 (Do, 01 Okt 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include #include #include "rttbStructure.h" #include "rttbMaskAccessorInterface.h" #include "rttbITKImageMaskAccessor.h" #include "rttbDoseAccessorInterface.h" namespace rttb { namespace apps { namespace voxelizerTool { class ApplicationData; void processData(ApplicationData& appData); /**@brief Search the label with the position from index @return a label from the list as string */ void removeSpecialCharacters(std::string& label); /**@brief create a mask with _rtStructureSet and _doseAccessor object. @return a mask object */ core::MaskAccessorInterface::MaskAccessorPointer createMask( core::DoseAccessorInterface::DoseAccessorPointer doseAccessorPtr, rttb::core::Structure::StructTypePointer structurePtr, bool strict); /**@brief write the mask into the outputfile @param Outputfilename */ void writeMaskToFile(std::vector maskVector, const std::string& outputFileName, bool voxelization); io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer addMultipleStructsToImage( std::vector maskVector); io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer applyThresholdFilter( io::itk::ITKImageMaskAccessor::ITKMaskImageType::ConstPointer itkImage); - std::string getFilenameWithoutEnding(const std::string& outfilename); - std::string getFileEnding(const std::string& outfilename); } } } \ No newline at end of file diff --git a/code/core/rttbUtils.cpp b/code/core/rttbUtils.cpp index 364ef90..28e9988 100644 --- a/code/core/rttbUtils.cpp +++ b/code/core/rttbUtils.cpp @@ -1,51 +1,72 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ -/*! -// @file -// @version $Revision: 1674 $ (last changed revision) -// @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #include +#include namespace rttb { + namespace core { - bool isKey(const std::map& values, const double value) { - for (auto const& collectionElements : values) { - if (std::abs(collectionElements.first - value) <= errorConstant) - { - return true; - } + + bool isKey(const std::map& values, const double value) { + for (auto const& collectionElements : values) { + if (std::abs(collectionElements.first - value) <= errorConstant) { + return true; } - return false; } - bool isKey(const std::vector& values, double value) { - for (auto const& collectionElement : values) { - if (std::abs(collectionElement - value) <= errorConstant) - { - return true; - } + return false; + } + + bool isKey(const std::vector& values, double value) { + for (auto const& collectionElement : values) { + if (std::abs(collectionElement - value) <= errorConstant) { + return true; } - return false; } + return false; + } bool valueIsClose(double value1, double value2, double specificErrorConstant) { - return std::abs(value1 - value2) < specificErrorConstant; + return std::abs(value1 - value2) < specificErrorConstant; } + + bool isFile(FileNameType aName) { + boost::filesystem::path path = boost::filesystem::path(aName); + + return (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path)); + } + + bool isDirectory(FileNameType aName) { + boost::filesystem::path path = boost::filesystem::path(aName); + + return (boost::filesystem::exists(path) && boost::filesystem::is_directory(path)); + } + + std::string getFilenameWithoutEnding(const std::string& outfilename) { + boost::filesystem::path p(outfilename); + + return p.replace_extension("").string(); + } + + std::string getFileEnding(const std::string& outfilename) { + boost::filesystem::path p(outfilename); + + return p.extension().string(); + } + } } diff --git a/code/core/rttbUtils.h b/code/core/rttbUtils.h index 22e3d6b..806d282 100644 --- a/code/core/rttbUtils.h +++ b/code/core/rttbUtils.h @@ -1,44 +1,47 @@ // ----------------------------------------------------------------------- // 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: 1674 $ (last changed revision) -// @date $Date: 2017-01-27 10:34:46 +0100 (Fr, 27 Jan 2017) $ (last change date) -// @author $Author: hentsch $ (last changed by) -*/ #ifndef __RTTB_UTILS_H #define __RTTB_UTILS_H #include #include #include #include "RTTBCoreExports.h" namespace rttb { namespace core { - bool RTTBCore_EXPORT isKey(const std::map& values, double value); + bool RTTBCore_EXPORT isKey(const std::map& values, double value); - bool RTTBCore_EXPORT isKey(const std::vector& values, double value); + bool RTTBCore_EXPORT isKey(const std::vector& values, double value); - bool RTTBCore_EXPORT valueIsClose(double value1, double value2, double specificErrorConstant = 1e-5); + bool RTTBCore_EXPORT valueIsClose(double value1, double value2, double specificErrorConstant = 1e-5); + + bool RTTBCore_EXPORT isFile(FileNameType aName); + + bool RTTBCore_EXPORT isDirectory(FileNameType aName); + + std::string RTTBCore_EXPORT getFilenameWithoutEnding(const std::string& outfilename); + + std::string RTTBCore_EXPORT getFileEnding(const std::string& outfilename); + } } #endif diff --git a/code/io/dicom/rttbDicomFileDoseAccessorGenerator.cpp b/code/io/dicom/rttbDicomFileDoseAccessorGenerator.cpp index d6a685c..422d923 100644 --- a/code/io/dicom/rttbDicomFileDoseAccessorGenerator.cpp +++ b/code/io/dicom/rttbDicomFileDoseAccessorGenerator.cpp @@ -1,108 +1,103 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ -/*! -// @file -// @version $Revision$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ #include #include #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbDicomDoseAccessor.h" #include "rttbNullPointerException.h" #include "rttbInvalidDoseException.h" #include "rttbDcmrtException.h" #include "rttbIndexOutOfBoundsException.h" #include "rttbDicomFileReaderHelper.h" #include "rttbInvalidParameterException.h" +#include "rttbUtils.h" namespace rttb { namespace io { namespace dicom { DicomFileDoseAccessorGenerator::~DicomFileDoseAccessorGenerator() = default; DicomFileDoseAccessorGenerator::DicomFileDoseAccessorGenerator(FileNameType aDICOMRTDoseFileName) { _dicomDoseFileName = aDICOMRTDoseFileName; } core::DoseAccessorGeneratorInterface::DoseAccessorPointer DicomFileDoseAccessorGenerator::generateDoseAccessor() { std::vector fileVector; //if a file - if (isFile(_dicomDoseFileName)) + if (core::isFile(_dicomDoseFileName)) { fileVector.push_back(_dicomDoseFileName); } //if a directory - else if (isDirectory(_dicomDoseFileName)) + else if (core::isDirectory(_dicomDoseFileName)) { rttb::io::dicom::Modality doseModality = {rttb::io::dicom::Modality::RTDOSE}; fileVector = getFileNamesWithSameUID(_dicomDoseFileName, doseModality); } else { throw rttb::core::InvalidParameterException("Invalid file/directory name!"); } if (fileVector.size() < 1) { throw rttb::core::InvalidParameterException("There is no structure set files in the directory!"); } OFCondition status; DcmFileFormat fileformat; DRTDoseIODPtr dose = boost::make_shared(); status = fileformat.loadFile(fileVector.at(0).c_str()); if (!status.good()) { std::cerr << "Error: load rtdose loadFile(" << fileVector.at(0) << ") failed!" << std::endl; throw core::InvalidDoseException("Invalid dicom dose!"); } DcmItemPtr dataSet = boost::make_shared(*fileformat.getDataset()); status = dose->read(*dataSet); if (!status.good()) { std::cerr << "Error: read DRTDoseIOD failed!" << std::endl; throw core::InvalidDoseException("Invalid dicom dose!"); } _doseAccessor = boost::make_shared(dose, dataSet); return _doseAccessor; } } } } diff --git a/code/io/dicom/rttbDicomFileReaderHelper.cpp b/code/io/dicom/rttbDicomFileReaderHelper.cpp index 703d41d..cace20d 100644 --- a/code/io/dicom/rttbDicomFileReaderHelper.cpp +++ b/code/io/dicom/rttbDicomFileReaderHelper.cpp @@ -1,251 +1,219 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ #include "rttbDicomFileReaderHelper.h" #include #include #include #include "boost/filesystem/operations.hpp" #include "boost/filesystem/path.hpp" #include "rttbDcmrtException.h" #include "rttbInvalidParameterException.h" +#include "rttbUtils.h" namespace rttb { namespace io { namespace dicom { - bool isFile(FileNameType aName) - { - boost::filesystem::path path = boost::filesystem::path(aName); - - if (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path)) - { - return true; - } - else - { - return false; - } - } - - bool isDirectory(FileNameType aName) - { - boost::filesystem::path path = boost::filesystem::path(aName); - - if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path)) - { - return true; - } - else - { - return false; - } - } OFString getModality(DcmDataSetPtr aDcmDataSet) { OFString modality; OFCondition status; status = aDcmDataSet->findAndGetOFString(DcmTagKey(0x0008, 0x0060), modality); if (!status.good()) { throw DcmrtException("Error: get modality failed!"); } return modality; } OFString getUID(DcmDataSetPtr aDcmDataSet) { OFString uid; OFCondition status; status = aDcmDataSet->findAndGetOFString(DcmTagKey(0x0020, 0x000e), uid); if (!status.good()) { throw DcmrtException("Error: get uid failed!"); } return uid; } std::vector getFileNamesWithSameUID(FileNameType aDirName, Modality aModality) { std::vector fileNameVector; std::string modalityStrArray[] = {"RTDOSE", "RTSTRUCT", "RTPLAN"}; boost::filesystem::path path = boost::filesystem::path(aDirName); OFCondition status; DcmFileFormat fileformat; IDType uid = ""; DcmDataSetPtr datasetPtr; if (aModality.Type != 1 && aModality.Type != 2 && aModality.Type != 3) { throw core::InvalidParameterException("Error: invalid modality! The modality should be RTDOSE(1)/RTSTRUCT(2)/RTPLAN(3)."); } //if a directory - if (isDirectory(aDirName)) + if (core::isDirectory(aDirName)) { boost::filesystem::directory_iterator end_iter; bool isFirst = true; for (boost::filesystem::directory_iterator dir_itr(path); dir_itr != end_iter; ++dir_itr) { if (boost::filesystem::is_regular_file(dir_itr->status())) { boost::filesystem::path filePath(dir_itr->path().filename().string()); filePath = boost::filesystem::system_complete(dir_itr->path()); status = fileformat.loadFile(filePath.string().c_str()); if (!status.good()) { throw DcmrtException("Error: load dose file " + filePath.string() + " failed!"); } datasetPtr = boost::make_shared(*fileformat.getDataset()); OFString modalityOFS = getModality(datasetPtr); for (unsigned int i = 0; i < 3; i++) { if (aModality.Type == (i + 1) && modalityOFS == modalityStrArray[i].c_str()) { OFString currentUID = getUID(datasetPtr); //get the first uid of the given modality if (isFirst) { uid = currentUID.c_str(); isFirst = false; } if (uid == currentUID.c_str()) { fileNameVector.emplace_back(filePath.string().c_str()); } break; } } } } } - else if (isFile(aDirName)) + else if (core::isFile(aDirName)) { std::cout << "Important: the given name " + aDirName + " is a file name, not a directory name. Given modality will be ignored, use the modality of the file." << std::endl; fileNameVector = getFileNames(aDirName); } else { throw core::InvalidParameterException("Error: file/directory does not exist!"); } return fileNameVector; } std::vector getFileNames(FileNameType aFileName) { - if (!isFile(aFileName)) + if (!core::isFile(aFileName)) { throw core::InvalidParameterException("Error: file does not exist!"); } std::vector fileNameVector; boost::filesystem::path path = boost::filesystem::path(aFileName); OFCondition status; DcmFileFormat fileformat; DcmDataSetPtr datasetPtr; OFString modality;//modality of the given file OFString uid;//uid of the given file status = fileformat.loadFile(aFileName.c_str()); if (!status.good()) { throw DcmrtException("Error: fileformat.loadFile failed!"); } datasetPtr = boost::make_shared(*fileformat.getDataset()); modality = getModality(datasetPtr); uid = getUID(datasetPtr); //get parent directory boost::filesystem::path parentDir = path.parent_path(); if (boost::filesystem::is_directory(parentDir)) { boost::filesystem::directory_iterator end_iter; for (boost::filesystem::directory_iterator dir_itr(parentDir); dir_itr != end_iter; ++dir_itr) { if (boost::filesystem::is_regular_file(dir_itr->status())) { boost::filesystem::path currentFilePath(dir_itr->path().filename().string()); currentFilePath = boost::filesystem::system_complete(dir_itr->path()); status = fileformat.loadFile(currentFilePath.string().c_str()); if (!status.good()) { throw DcmrtException("Error: load dose fileformat.loadFile failed!"); } datasetPtr = boost::make_shared(*fileformat.getDataset()); OFString currentModality = getModality(datasetPtr); OFString currentUID = getUID(datasetPtr); //if the same modality if (modality == currentModality && uid == currentUID) { fileNameVector.emplace_back(currentFilePath.string().c_str()); } } } } return fileNameVector; } } } } diff --git a/code/io/dicom/rttbDicomFileReaderHelper.h b/code/io/dicom/rttbDicomFileReaderHelper.h index ab55f3e..63e067a 100644 --- a/code/io/dicom/rttbDicomFileReaderHelper.h +++ b/code/io/dicom/rttbDicomFileReaderHelper.h @@ -1,88 +1,75 @@ // ----------------------------------------------------------------------- // 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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ + #ifndef __DICOM_FILE_READER_HELPER_H #define __DICOM_FILE_READER_HELPER_H #include #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ #include "drtdose.h" #include "rttbBaseType.h" #include "boost/shared_ptr.hpp" namespace rttb { namespace io { namespace dicom { struct Modality { enum Type { RTDOSE = 1, RTSTRUCT = 2, RTPLAN = 3, UserDefined = 128 } Type; }; using DRTDoseIODPtr = boost::shared_ptr; using DcmDataSetPtr = boost::shared_ptr; /*! Return the vector of all files with the same UID in the given directory, the UID is defined by the first file with the modality. @exception InvalidParameterException thrown if the file/directory does not exist or the modality is invalid @exception DcmrtException thrown if load/read file failed */ std::vector getFileNamesWithSameUID(FileNameType aDirName, Modality aModality); /*! Return the vector of all files with the same UID in the directory of the given file @exception InvalidParameterException thrown if the file does not exist @exception DcmrtException thrown if load/read file failed */ std::vector getFileNames(FileNameType aFileName); - /*! Return if the given name is a file - */ - bool isFile(FileNameType aName); - - /*! Return if the given name is a directory - */ - bool isDirectory(FileNameType aName); - /*! Return modality DcmTagKey(0x0008, 0x0060) @exception DcmrtException thrown if reading modality failed*/ OFString getModality(DcmDataSetPtr aDcmDataSet); /*! Return uid DcmTagKey(0x0020, 0x000e) @exception DcmrtException thrown if reading uid failed*/ OFString getUID(DcmDataSetPtr aDcmDataSet); }; } } #endif diff --git a/code/io/dicom/rttbDicomFileStructureSetGenerator.cpp b/code/io/dicom/rttbDicomFileStructureSetGenerator.cpp index f7e31e3..05252d8 100644 --- a/code/io/dicom/rttbDicomFileStructureSetGenerator.cpp +++ b/code/io/dicom/rttbDicomFileStructureSetGenerator.cpp @@ -1,110 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ #include #include #include #include #include "rttbInvalidParameterException.h" #include "rttbStructure.h" #include "rttbDicomFileStructureSetGenerator.h" #include "rttbDicomIODStructureSetGenerator.h" #include "rttbDcmrtException.h" #include "rttbDicomFileReaderHelper.h" +#include "rttbUtils.h" namespace rttb { namespace io { namespace dicom { DicomFileStructureSetGenerator::DicomFileStructureSetGenerator(DICOMRTFileNameString aDICOMRTStrSetFileName) { _fileName = aDICOMRTStrSetFileName; } - DicomFileStructureSetGenerator::~DicomFileStructureSetGenerator() - = default; + DicomFileStructureSetGenerator::~DicomFileStructureSetGenerator() = default; DicomFileStructureSetGenerator::StructureSetPointer DicomFileStructureSetGenerator::generateStructureSet() { std::vector fileVector; //if a file - if (isFile(_fileName)) + if (core::isFile(_fileName)) { fileVector.push_back(_fileName); } //if a directory - else if (isDirectory(_fileName)) + else if (core::isDirectory(_fileName)) { rttb::io::dicom::Modality strModality = {rttb::io::dicom::Modality::RTSTRUCT}; fileVector = getFileNamesWithSameUID(_fileName, strModality); } else { throw rttb::core::InvalidParameterException("Invalid file/directory name!"); } if (fileVector.size() < 1) { throw rttb::core::InvalidParameterException("There is no structure set files in the directory!"); } OFCondition status; DcmFileFormat fileformat; DRTStrSetIODPtr drtStrSetIODPtr = boost::make_shared(); //get the first structure set file status = fileformat.loadFile(fileVector.at(0).c_str()); if (!status.good()) { throw DcmrtException("Load rt structure set loadFile() failed!"); } status = drtStrSetIODPtr->read(*fileformat.getDataset()); if (!status.good()) { throw DcmrtException("Read DRTStructureSetIOD DRTStructureSetIOD.read() failed!"); } - io::dicom::DicomIODStructureSetGenerator iodGenerator(drtStrSetIODPtr); - iodGenerator.setStructureLabelFilterActive(this->getStructureLabelFilterActive()); - iodGenerator.setFilterRegEx(this->getFilterRegEx()); + io::dicom::DicomIODStructureSetGenerator iodGenerator(drtStrSetIODPtr); + iodGenerator.setStructureLabelFilterActive(this->getStructureLabelFilterActive()); + iodGenerator.setFilterRegEx(this->getFilterRegEx()); return iodGenerator.generateStructureSet(); } }//end namespace dicom }//end namespace io }//end namespace rttb