diff --git a/code/io/other/rttbDVHTxtFileReader.cpp b/code/io/other/rttbDVHTxtFileReader.cpp deleted file mode 100644 index 3c37889..0000000 --- a/code/io/other/rttbDVHTxtFileReader.cpp +++ /dev/null @@ -1,256 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ - -#include "rttbDVHTxtFileReader.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include "rttbInvalidParameterException.h" - -namespace rttb -{ - namespace io - { - namespace other - { - - DVHTxtFileReader::DVHTxtFileReader(FileNameString aFileName) - { - _fileName = aFileName; - _resetFile = true; - } - - DVHTxtFileReader::~DVHTxtFileReader() = default; - - void DVHTxtFileReader::resetFileName(FileNameString aFileName) - { - _fileName = aFileName; - _resetFile = true; - } - - void DVHTxtFileReader::createDVH() - { - std::ifstream dvh_ifstr(this->_fileName.c_str(), std::ios::in); - - std::string structureLabel; - std::string dvhType; - unsigned int numberOfBins; - DoseTypeGy prescribedDose=-1; - double estimated_max_dose_prescribed_dose_ratio=1.0; - std::deque dataDifferential; - std::deque dataCumulative; - - DoseTypeGy deltaD = 0; - DoseVoxelVolumeType deltaV = 0; - IDType strID; - IDType doseID; - - enum dataTypes { _deltaV, _deltaD, _strID, _doseID, _numberOfBins, _dvhType, _prescribedDose, _estimated_max_dose_prescribed_dose_ratio}; - std::map mapTypes; - - mapTypes["DeltaV"] = _deltaV; - mapTypes["DeltaD"] = _deltaD; - mapTypes["StructureID"] = _strID; - mapTypes["DoseID"] = _doseID; - mapTypes["Number of bins"] = _numberOfBins; - mapTypes["DVH Type"] = _dvhType; - mapTypes["Prescribed Dose"] = _prescribedDose; - mapTypes["Estimated_max_dose_prescribed_dose_ratio"] = _estimated_max_dose_prescribed_dose_ratio; - - bool isDifferential = false; - - if (!dvh_ifstr.is_open()) - { - throw core::InvalidParameterException("DVH file name invalid: could not open the dvh file!"); - } - else - { - bool data_begin = false; - - while (!dvh_ifstr.eof()) - { - std::string line; - std::getline(dvh_ifstr, line); - - if (!data_begin) - { - std::vector buffer; - boost::split(buffer, line, boost::is_any_of(":")); - - if (buffer.size() != 2) - { - throw core::InvalidParameterException("Error while splitting the line..."); - } - - if (buffer.at(0) == "DVH Data") - { - data_begin = true; - } - else - { - std::string key = buffer.at(0); - std::string value = buffer.at(1); - - boost::trim(key); - boost::trim(value); - - switch (mapTypes.at(key)) - { - case _deltaD: - deltaD = boost::lexical_cast(value); - break; - case _deltaV: - deltaV = boost::lexical_cast(value); - break; - case _strID: - strID = value; - break; - case _doseID: - doseID = value; - break; - case _numberOfBins: - numberOfBins = boost::lexical_cast(value); - case _dvhType: - dvhType = value; - if (dvhType == "DIFFERENTIAL") - { - isDifferential = true; - } - break; - case _prescribedDose: - prescribedDose = boost::lexical_cast(value); - break; - case _estimated_max_dose_prescribed_dose_ratio: - estimated_max_dose_prescribed_dose_ratio = boost::lexical_cast(value); - break; - } - } - } - else - { - if (line.empty()) - { - break; - } - else - { - if (isDifferential) - { - loadData(line, dataDifferential); - } - else - { - loadData(line, dataCumulative); - } - } - } - } - } - - numberOfBins = static_cast(std::max(dataDifferential.size(), dataCumulative.size())); - - if (numberOfBins == 0) - { - throw core::InvalidParameterException("Invalid dvh file: empty dvh data!"); - } - - if (!isDifferential) - { - calculateDataCumulative(dataCumulative, dataDifferential, numberOfBins); - } - - if (deltaD == 0) - { - deltaD = prescribedDose * estimated_max_dose_prescribed_dose_ratio / numberOfBins; - - if (deltaD == 0) - { - throw core::InvalidParameterException("Invalid dvh file: deltaD or deltaV must not be zero!"); - } - } - - if (deltaV == 0) - { - deltaV = 0.027; - } - - _dvh = boost::make_shared(dataDifferential, deltaD, deltaV, strID, doseID); - _resetFile = false; - } - - DVHTxtFileReader::DVHPointer DVHTxtFileReader::generateDVH() - { - if (_resetFile) - { - this->createDVH(); - } - - return _dvh; - } - - void DVHTxtFileReader::calculateDataCumulative(const std::deque& dataCumulative, - std::deque& dataDifferential, unsigned int numberOfBins) const - { - DoseCalcType differentialDVHi = 0; - std::deque::const_iterator it; - - for (it = dataCumulative.cbegin(); it != dataCumulative.cend(); ++it) - { - if (dataDifferential.size() == numberOfBins - 1) - { - differentialDVHi = *it; - } - else - { - differentialDVHi = *it - *(it + 1); - } - - dataDifferential.push_back(differentialDVHi); - } - } - - void DVHTxtFileReader::loadData(const std::string& line, std::deque& data) const - { - std::vector dataBuffer; - boost::split(dataBuffer, line, boost::is_any_of(",")); - - if (dataBuffer.size() != 2) - { - throw core::InvalidParameterException("Error while splitting the line..."); - } - - boost::trim(dataBuffer.at(1)); - - auto dvh_i = boost::lexical_cast(dataBuffer.at(1)); - - data.push_back(dvh_i); - } - }//end namespace other - }//end namespace io -}//end namespace rttb - diff --git a/code/io/other/rttbDVHTxtFileReader.h b/code/io/other/rttbDVHTxtFileReader.h deleted file mode 100644 index ad215c1..0000000 --- a/code/io/other/rttbDVHTxtFileReader.h +++ /dev/null @@ -1,79 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ -#ifndef __DVH_TXT_FILE_READER_H -#define __DVH_TXT_FILE_READER_H - -#include "rttbBaseType.h" -#include "rttbDVHGeneratorInterface.h" - -namespace rttb -{ - namespace io - { - namespace other - { - - /*! @class DVHTxtFileReader - @brief Reads DVH data from txt files. - @deprecated Please use DVHXMLFileReader. - */ - class DVHTxtFileReader: public core::DVHGeneratorInterface - { - - - private: - FileNameString _fileName; - bool _resetFile; - - /*! @brief Create new DVH object using the info from dvh txt file - @exception InvalidParameterException Thrown if _fileName invalid - */ - void createDVH(); - - void calculateDataCumulative(const std::deque& dataCumulative, std::deque& dataDifferential, unsigned int numberOfBins) const; - - /*! @brief Load the DVH data either in a vector for differential data or in one for cumulative data - @exception InvalidParameterException Thrown if splitting of a line in the file is invalid - */ - void loadData(const std::string& line, std::deque& data) const; - - public: - /*! @brief Constructor. - */ - DVHTxtFileReader(FileNameString aFileName); - - ~DVHTxtFileReader(); - - /*! @brief Change file name. - */ - void resetFileName(FileNameString aFileName); - - /*! @brief Generate DVH, createDVH() will be called - @return Return new shared pointer of DVH. - @exception InvalidParameterException Thrown if _fileName invalid - */ - DVHPointer generateDVH() override; - }; - } - } -} - -#endif diff --git a/code/io/other/rttbDVHTxtFileWriter.cpp b/code/io/other/rttbDVHTxtFileWriter.cpp deleted file mode 100644 index ac87321..0000000 --- a/code/io/other/rttbDVHTxtFileWriter.cpp +++ /dev/null @@ -1,130 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ - -#include -#include - -#include "rttbDVHTxtFileWriter.h" -#include "rttbNullPointerException.h" -#include "rttbInvalidParameterException.h" -#include "rttbException.h" - -namespace rttb -{ - namespace io - { - namespace other - { - - DVHTxtFileWriter::DVHTxtFileWriter(FileNameString aFileName, DVHType aDVHType) - { - this->setFileName(aFileName); - this->setDVHType(aDVHType); - } - - void DVHTxtFileWriter::setDVHType(DVHType aDVHType) - { - _dvhType = aDVHType; - } - - FileNameString DVHTxtFileWriter::getFileName() const - { - return _fileName; - } - - void DVHTxtFileWriter::setFileName(FileNameString aFileName) - { - _fileName = aFileName; - } - - DVHType DVHTxtFileWriter::getDVHType() const - { - return _dvhType; - } - - void DVHTxtFileWriter::writeDVH(DVHPointer aDvh, bool normalized) - { - if (aDvh == nullptr) - { - throw core::NullPointerException("aDvh must not be nullptr! "); - } - - if (normalized) { - throw core::InvalidParameterException("DVHTxtFileWriter doesnt support normalized DVH output."); - } - - std::ofstream out_dvh_ofstream(this->_fileName.c_str(), std::ios::out); - - if (!out_dvh_ofstream.is_open() || !out_dvh_ofstream.good()) - { - throw core::InvalidParameterException("Invalid dvh file name: could not open write file"); - } - else - { - //setting string stream precission explicitly is mandatory to guarantee that tests - //run sucessfully on different systems! - out_dvh_ofstream.precision(10); - - if (_dvhType.Type != DVHType::Differential && _dvhType.Type != DVHType::Cumulative) - { - throw core::InvalidParameterException("DVH Type not acceptable: Only: DIFFERENTIAL/CUMULATIVE!"); - } - - if (_dvhType.Type == DVHType::Differential) - { - out_dvh_ofstream << "DVH Type: DIFFERENTIAL\n"; - } - else if (_dvhType.Type == DVHType::Cumulative) - { - out_dvh_ofstream << "DVH Type: CUMULATIVE\n"; - } - - out_dvh_ofstream << "DeltaD: " << aDvh->getDeltaD() << "\n"; - out_dvh_ofstream << "DeltaV: " << aDvh->getDeltaV() << "\n"; - out_dvh_ofstream << "StructureID: " << aDvh->getStructureID() << "\n"; - out_dvh_ofstream << "DoseID: " << aDvh->getDoseID() << "\n"; - out_dvh_ofstream << "DVH Data: " << "\n"; - - if (_dvhType.Type == DVHType::Differential) - { - DataDifferentialType dataDifferential = aDvh->getDataDifferential(); - - for (size_t i = 0; i < dataDifferential.size(); i++) - { - out_dvh_ofstream << i << "," << dataDifferential[i] << "\n"; - } - } - else if (_dvhType.Type == DVHType::Cumulative) - { - DataDifferentialType dataCumulative = aDvh->getDataCumulative(); - - for (size_t i = 0; i < dataCumulative.size(); i++) - { - out_dvh_ofstream << i << "," << dataCumulative[i] << "\n"; - } - } - - - } - } - } - } -} diff --git a/code/io/other/rttbDVHTxtFileWriter.h b/code/io/other/rttbDVHTxtFileWriter.h deleted file mode 100644 index 1c7ff50..0000000 --- a/code/io/other/rttbDVHTxtFileWriter.h +++ /dev/null @@ -1,75 +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$ (last changed revision) -// @date $Date$ (last change date) -// @author $Author$ (last changed by) -*/ -#ifndef __DVH_TXT_FILE_WRITER_H -#define __DVH_TXT_FILE_WRITER_H - - -#include "rttbDVH.h" -#include "../rttbDVHWriterInterface.h" -#include "rttbBaseType.h" - -namespace rttb -{ - namespace io - { - namespace other - { - - /*! @class DVHTxtFileWriter - @brief Writes DVHs to simple text files. - @deprecated Please use DVHXMLFileWriter. - */ - class DVHTxtFileWriter: public DVHWriterInterface - { - public: - using DataDifferentialType = core::DVH::DataDifferentialType; - using DVHPointer = core::DVH::DVHPointer; - - private: - FileNameString _fileName; - DVHType _dvhType; - - public: - /*! @brief Constructor - @param aFileName a .txt file name to write the DVH to aDVHType: DIFFERENTIAL or CUMULATIVE. - */ - DVHTxtFileWriter(FileNameString aFileName, DVHType aDVHType); - - void setFileName(FileNameString aFileName); - FileNameString getFileName() const; - - void setDVHType(DVHType aDVHType); - DVHType getDVHType() const; - - /*! @brief Write aDvh to txt file with the name: _fileName - @exception NullPointerException Thrown if _aDvh is nullptr - @exception InvalidParameterException Thrown if _fileName invalid: could not open; - or if _dvhType invalid: only DIFFERENTIAL or CUMULATIVE is accepted! - @exception Exception thrown if dvh init error - @exception InvalidParameterException Thrown if normalized is true. - This feature is not implemented because this Writer is deprecated. - */ - void writeDVH(DVHPointer aDvh, bool normalized = false) override; - }; - } - } -} -#endif