diff --git a/code/io/other/rttbDVHTxtFileReader.cpp b/code/io/other/rttbDVHTxtFileReader.cpp index 6606938..76e478b 100644 --- a/code/io/other/rttbDVHTxtFileReader.cpp +++ b/code/io/other/rttbDVHTxtFileReader.cpp @@ -1,196 +1,196 @@ // ----------------------------------------------------------------------- // 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 #include "rttbDVHTxtFileReader.h" #include "rttbInvalidParameterException.h" #include "rttbBaseType.h" namespace rttb{ namespace io{ namespace other{ DVHTxtFileReader::DVHTxtFileReader(FileNameString aFileName){ _fileName=aFileName; _resetFile=true; } DVHTxtFileReader::~DVHTxtFileReader(){} 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; int numberOfBins; DoseTypeGy prescribedDose; double _estimated_max_dose_prescribed_dose_ratio; int voxelsInStructure; std::deque dataDifferential; std::deque dataCumulative; DoseTypeGy deltaD=0; DoseVoxelVolumeType deltaV=0; IDType strID; IDType doseID; 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(line.find("DVH Data:")!= std::string::npos) data_begin=true; if(data_begin && (line.find(",")!= std::string::npos)) { std::stringstream ss(line.substr(line.find(",")+1)); DoseCalcType dvh_i; ss >> dvh_i; if(dvhType=="DIFFERENTIAL") { dataDifferential.push_back(dvh_i); } else if(dvhType=="CUMULATIVE") { dataCumulative.push_back(dvh_i); } } if(line.find("DeltaD: ")!= std::string::npos) { std::stringstream ss(line.substr(8)); ss >> deltaD; } if(line.find("DeltaV: ")!= std::string::npos) { std::stringstream ss(line.substr(8)); ss >> deltaV; } if(line.find("StructureID: ")!= std::string::npos) { std::stringstream ss(line.substr(13)); ss >> strID; } if(line.find("DoseID: ")!= std::string::npos) { std::stringstream ss(line.substr(8)); ss >> doseID; } if(line.find("Number of bins: ")!= std::string::npos) { std::stringstream ss(line.substr(16)); ss >> numberOfBins; } if(line.find("Structure Label: ")!= std::string::npos) { std::stringstream ss(line.substr(17)); ss >> structureLabel; } if(line.find("DVH Type: ")!= std::string::npos) { std::stringstream ss(line.substr(10)); ss >> dvhType; } if(line.find("Prescribed Dose: ")!=std::string::npos) { std::stringstream ss(line.substr(17)); ss >> prescribedDose; } if(line.find("Estimated_max_dose_prescribed_dose_ratio: ")!=std::string::npos) { std::stringstream ss(line.substr(42)); ss >> _estimated_max_dose_prescribed_dose_ratio; } if(line.find("Voxels In Structure: ")!=std::string::npos) { std::stringstream ss(line.substr(21)); ss >> voxelsInStructure; } } } numberOfBins=std::max(dataDifferential.size(),dataCumulative.size()); if(dvhType=="CUMULATIVE") { DoseCalcType differentialDVHi = 0; std::deque::iterator it; for(it=dataCumulative.begin();it!=dataCumulative.end();it++ ) { if(dataDifferential.size()==numberOfBins-1) { differentialDVHi=*it; } else{ differentialDVHi = *it-*(it+1); } - dataDifferential.push_front(differentialDVHi); + dataDifferential.push_back(differentialDVHi); } } if(numberOfBins==0) { throw core::InvalidParameterException("Invalid dvh file: empty dvh data!"); } if(deltaD==0) { deltaD=prescribedDose*_estimated_max_dose_prescribed_dose_ratio/numberOfBins; } if(deltaV==0) { deltaV=0.027; } if(deltaD==0 || deltaV==0) { throw core::InvalidParameterException("Invalid dvh file: deltaD or deltaV must not be zero!"); } _dvh=boost::make_shared(dataDifferential,deltaD,deltaV,strID,doseID); _resetFile=false; } DVHTxtFileReader::DVHPointer DVHTxtFileReader::generateDVH(){ if(_resetFile){ this->createDVH(); } return _dvh; } }//end namepsace other }//end namespace io }//end namespace rttb diff --git a/code/io/other/rttbDVHXMLFileReader.cpp b/code/io/other/rttbDVHXMLFileReader.cpp index 8701787..8f25c67 100644 --- a/code/io/other/rttbDVHXMLFileReader.cpp +++ b/code/io/other/rttbDVHXMLFileReader.cpp @@ -1,134 +1,134 @@ // ----------------------------------------------------------------------- // 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 #include #include "rttbDVHXMLFileReader.h" #include "rttbInvalidParameterException.h" #include "rttbBaseType.h" namespace rttb{ namespace io{ namespace other{ DVHXMLFileReader::DVHXMLFileReader(FileNameString aFileName){ _fileName=aFileName; _resetFile=true; } DVHXMLFileReader::~DVHXMLFileReader(){} void DVHXMLFileReader::resetFileName(FileNameString aFileName){ _fileName=aFileName; _resetFile=true; } void DVHXMLFileReader::createDVH(){ using boost::property_tree::ptree; ptree pt; // Load the XML file into the property tree. If reading fails // (cannot open file, parse error), an exception is thrown. try{ read_xml(_fileName, pt); } catch(boost::property_tree::xml_parser_error &e){ throw rttb::core::InvalidParameterException("DVH file name invalid: could not open the xml file!"); } std::string structureLabel; std::string dvhType; int numberOfBins; DoseTypeGy prescribedDose; double _estimated_max_dose_prescribed_dose_ratio; int voxelsInStructure; std::deque dataDifferential; std::deque dataCumulative; DoseTypeGy deltaD=0; DoseVoxelVolumeType deltaV=0; IDType strID; IDType doseID; dvhType=pt.get("dvh.type"); deltaD=pt.get("dvh.deltaD"); deltaV=pt.get("dvh.deltaV"); strID=pt.get("dvh.structureID"); doseID=pt.get("dvh.doseID"); if(dvhType!="DIFFERENTIAL" && dvhType!="CUMULATIVE"){ throw core::InvalidParameterException("DVH Type invalid! Only: DIFFERENTIAL/CUMULATIVE!"); } int count=0; BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("dvh.data")){ if(count%2==1){ if(dvhType=="DIFFERENTIAL"){ dataDifferential.push_back( boost::lexical_cast(v.second.data())); } else if(dvhType=="CUMULATIVE"){ dataCumulative.push_back(boost::lexical_cast(v.second.data())); } } count++; } numberOfBins=std::max(dataDifferential.size(),dataCumulative.size()); if(dvhType=="CUMULATIVE")//dataDifferential should be calculated { DoseCalcType differentialDVHi = 0; std::deque::iterator it; for(it=dataCumulative.begin();it!=dataCumulative.end();it++ ) { if(dataDifferential.size()==numberOfBins-1) { differentialDVHi=*it; } else{ differentialDVHi = *it-*(it+1); } - dataDifferential.push_front(differentialDVHi); + dataDifferential.push_back(differentialDVHi); } } _dvh=boost::make_shared(dataDifferential,deltaD,deltaV,strID,doseID); _resetFile=false; } DVHXMLFileReader::DVHPointer DVHXMLFileReader::generateDVH(){ if(_resetFile){ this->createDVH(); } return _dvh; } }//end namepsace other }//end namespace io }//end namespace rttb diff --git a/testing/io/other/CMakeLists.txt b/testing/io/other/CMakeLists.txt index 5c69bad..fd92ebb 100644 --- a/testing/io/other/CMakeLists.txt +++ b/testing/io/other/CMakeLists.txt @@ -1,23 +1,23 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(OTHERIO_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbOtherIOTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- ADD_TEST(DoseStatisticsIOTest ${OTHERIO_TEST} DoseStatisticsIOTest) ADD_TEST(DVHXMLIOTest ${OTHERIO_TEST} DVHXMLIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") -ADD_TEST(OtherIOTest ${OTHERIO_TEST} OtherIOTest) +ADD_TEST(DVHTXTIOTest ${OTHERIO_TEST} DVHTXTIOTest "${TEST_DATA_ROOT}/TestDVH/dvh_1.txt") RTTB_CREATE_TEST_MODULE(rttbOtherIO DEPENDS RTTBOtherIO PACKAGE_DEPENDS Boost Litmus) diff --git a/testing/io/other/CompareDVH.cpp b/testing/io/other/CompareDVH.cpp new file mode 100644 index 0000000..75381d7 --- /dev/null +++ b/testing/io/other/CompareDVH.cpp @@ -0,0 +1,53 @@ +// ----------------------------------------------------------------------- +// 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 "CompareDVH.h" + + + +namespace rttb{ + + namespace testing{ + + bool checkEqualDVH(DVHPointer aDVH1, DVHPointer aDVH2){ + + bool result; + const double errorConstant = 1e-7; + result = lit::AreClose(aDVH1->getDeltaD(), aDVH2->getDeltaD(), errorConstant); + result = result && lit::AreClose(aDVH1->getDeltaV(), aDVH2->getDeltaV(), errorConstant); + result = result && (aDVH1->getDoseID() == aDVH2->getDoseID()); + result = result && (aDVH1->getStructureID() == aDVH2->getStructureID()); + result = result && lit::AreClose(aDVH1->getMaximum(), aDVH2->getMaximum(), errorConstant); + result = result && lit::AreClose(aDVH1->getMinimum(), aDVH2->getMinimum(), errorConstant); + result = result && lit::AreClose(aDVH1->getMean(), aDVH2->getMean(), errorConstant); + result = result && (aDVH1->getDataDifferential().size() == aDVH2->getDataDifferential().size()); + for(int i=0; igetDataDifferential().size(); i++){ + result = result && lit::AreClose(aDVH1->getDataDifferential().at(i), aDVH2->getDataDifferential().at(i), errorConstant); + } + + return result; + + } + + }//testing +}//rttb + diff --git a/testing/io/other/rttbIOTests.cpp b/testing/io/other/CompareDVH.h similarity index 57% copy from testing/io/other/rttbIOTests.cpp copy to testing/io/other/CompareDVH.h index b902728..a1cba2b 100644 --- a/testing/io/other/rttbIOTests.cpp +++ b/testing/io/other/CompareDVH.h @@ -1,60 +1,42 @@ -// ----------------------------------------------------------------------- -// 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) -*/ - -// this file defines the rttbCoreTests for the test driver -// and all it expects is that you have a function called RegisterTests - -#if defined(_MSC_VER) -#pragma warning ( disable : 4786 ) -#endif - -#include "litMultiTestsMain.h" - -namespace rttb{ - namespace testing{ - - void registerTests() - { - LIT_REGISTER_TEST(DoseStatisticsIOTest); - LIT_REGISTER_TEST(DVHXMLIOTest); - LIT_REGISTER_TEST(OtherIOTest); - } - } -} - -int main(int argc, char* argv[]) -{ - int result = 0; - - rttb::testing::registerTests(); - - try - { - result = lit::multiTestsMain(argc,argv); - } - - catch(...) - { - result = -1; - } - - return result; -} +// ----------------------------------------------------------------------- +// 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 "litCheckMacros.h" + +#include "rttbDVH.h" + + + +namespace rttb{ + + namespace testing{ + + typedef core::DVH::DVHPointer DVHPointer; + + /*! Compare 2 dvhs and return the results. + @result Indicates if the test was successfull (true) or if it failed (false) + */ + bool checkEqualDVH(DVHPointer aDVH1, DVHPointer aDVH2); + + }//testing +}//rttb + diff --git a/testing/io/other/OtherIOTest.cpp b/testing/io/other/DVHTXTIOTest.cpp similarity index 60% copy from testing/io/other/OtherIOTest.cpp copy to testing/io/other/DVHTXTIOTest.cpp index 86cbf30..e6460a1 100644 --- a/testing/io/other/OtherIOTest.cpp +++ b/testing/io/other/DVHTXTIOTest.cpp @@ -1,116 +1,150 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // -// (c) Copyright 2007, DKFZ, Heidelberg, Germany -// ALL RIGHTS RESERVED +// 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 FILE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF DKFZ. -// ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR -// DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY PROHIBITED -// WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF DKFZ. +// 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 zhangl (last changed by) -// @author *none* (Reviewer) -// @author zhangl (Programmer) -// -// Subversion HeadURL: $HeadURL: http://sidt-hpc1/dkfz_repository/NotMeVisLab/SIDT/RTToolbox/trunk/testing/core/DVHCalculatorTest.cpp $ +// @date $Date$ (last change date) +// @author $Author$ (last changed by) */ // this file defines the rttbCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #include #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbDVH.h" #include "rttbDVHSet.h" #include "rttbDVHTxtFileReader.h" #include "rttbDVHTxtFileWriter.h" #include "rttbInvalidParameterException.h" #include "rttbNullPointerException.h" #include "../../core/DummyDVHGenerator.h" +#include "CompareDVH.h" namespace rttb{ namespace testing{ - /*! @brief OtherIOTest - test the IO for DVH txt data + /*! @brief DVHTXTIOTest - test the IO for DVH txt data 1) test writing dvh to text file 2) test reading DVH from text file + 3) test reading and writing the same dvh */ - int OtherIOTest(int argc, char* argv[] ) + int DVHTXTIOTest(int argc, char* argv[] ) { typedef core::DVHSet::DVHSetType DVHSetType; typedef core::DVH::DVHPointer DVHPointer; PREPARE_DEFAULT_TEST_REPORTING; + std::string DVHTXT_FILENAME; + + if (argc>1) + { + DVHTXT_FILENAME = argv[1]; + } + /* generate dummy DVH */ const IDType structureIDPrefix = "myStructure"; const IDType doseID = "myDose"; DummyDVHGenerator dvhGenerator; DVHPointer spMyDVH = boost::make_shared(dvhGenerator.generateDVH(structureIDPrefix,doseID)); // 1) test writing DVH to text file DVHType typeCum = {DVHType::Cumulative}; DVHType typeDiff = {DVHType::Differential}; FileNameString fN1 = "test.txt"; CHECK_NO_THROW(io::other::DVHTxtFileWriter(fN1, typeDiff)); CHECK_NO_THROW(io::other::DVHTxtFileWriter(fN1, typeCum)); io::other::DVHTxtFileWriter dvhWriter (fN1, typeCum); CHECK_EQUAL(fN1, dvhWriter.getFileName()); FileNameString fN2 = "otherFile.txt"; CHECK_NO_THROW(dvhWriter.setFileName(fN2)); CHECK_EQUAL(fN2, dvhWriter.getFileName()); CHECK_EQUAL(DVHType::Cumulative, dvhWriter.getDVHType().Type); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_EQUAL(DVHType::Differential, dvhWriter.getDVHType().Type); DVHPointer emptyDvh; CHECK_THROW_EXPLICIT(dvhWriter.writeDVH(emptyDvh),core::NullPointerException); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_NO_THROW(dvhWriter.writeDVH(spMyDVH)); // 2) test reading DVH from text file CHECK_NO_THROW(io::other::DVHTxtFileReader dvhReader(fN1)); io::other::DVHTxtFileReader dvhReaderTest(fN1); CHECK_THROW_EXPLICIT(dvhReaderTest.generateDVH(),core::InvalidParameterException); CHECK_NO_THROW(io::other::DVHTxtFileReader dvhReader(fN2)); io::other::DVHTxtFileReader dvhReader(fN2); CHECK_NO_THROW(dvhReader.resetFileName(fN1)); CHECK_THROW_EXPLICIT(dvhReader.generateDVH(), core::InvalidParameterException); CHECK_NO_THROW(dvhReader.resetFileName(fN2)); CHECK_NO_THROW(dvhReader.generateDVH()); DVHPointer importedDVH = dvhReader.generateDVH(); CHECK_EQUAL(*importedDVH, *spMyDVH); + // 3) test reading and writing the same dvh + //read dvh from a txt file + io::other::DVHTxtFileReader dvhReader_R(DVHTXT_FILENAME); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_R = dvhReader_R.generateDVH(); + + //write the dvh to another file as cumulative + io::other::DVHTxtFileWriter dvhWriter_R_Cum("test_Cum.txt", typeCum); + dvhWriter_R_Cum.writeDVH(dvhP_R); + + //read the file + io::other::DVHTxtFileReader dvhReader_W_Cum("test_Cum.txt"); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_W_Cum = dvhReader_W_Cum.generateDVH(); + + //check equal + CHECK(checkEqualDVH(dvhP_R, dvhP_W_Cum)); + + //write the dvh to another file as differential + io::other::DVHTxtFileWriter dvhWriter_R_Diff("test_Diff.txt", typeDiff); + dvhWriter_R_Diff.writeDVH(dvhP_R); + + //read the file + io::other::DVHTxtFileReader dvhReader_W_Diff("test_Diff.txt"); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_W_Diff = dvhReader_W_Diff.generateDVH(); + + //check equal + CHECK(checkEqualDVH(dvhP_R, dvhP_W_Diff)); + RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/other/DVHXMLIOTest.cpp b/testing/io/other/DVHXMLIOTest.cpp index 39d0fb8..62eb112 100644 --- a/testing/io/other/DVHXMLIOTest.cpp +++ b/testing/io/other/DVHXMLIOTest.cpp @@ -1,139 +1,138 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // -// (c) Copyright 2007, DKFZ, Heidelberg, Germany -// ALL RIGHTS RESERVED +// 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 FILE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF DKFZ. -// ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR -// DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY PROHIBITED -// WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF DKFZ. +// 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 zhangl (last changed by) -// @author *none* (Reviewer) -// @author zhangl (Programmer) -// -// Subversion HeadURL: $HeadURL: http://sidt-hpc1/dkfz_repository/NotMeVisLab/SIDT/RTToolbox/trunk/testing/core/DVHCalculatorTest.cpp $ +// @author $Author$ (last changed by) */ // this file defines the rttbCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #include #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbDVH.h" #include "rttbDVHSet.h" #include "rttbDVHTxtFileReader.h" #include "rttbDVHTxtFileWriter.h" #include "rttbDVHXMLFileReader.h" #include "rttbDVHXMLFileWriter.h" #include "rttbInvalidParameterException.h" #include "rttbNullPointerException.h" #include "../../core/DummyDVHGenerator.h" +#include "CompareDVH.h" namespace rttb{ namespace testing{ /*! @brief DVHXMLIOTest - test the IO for DVH xml data 1) test writing dvh to xml file 2) test reading DVH from xml file 3) test reading dvh from txt file and writing to xml, check equal */ int DVHXMLIOTest(int argc, char* argv[] ) { typedef core::DVHSet::DVHSetType DVHSetType; typedef core::DVH::DVHPointer DVHPointer; PREPARE_DEFAULT_TEST_REPORTING; std::string DVHTXT_FILENAME; if (argc>1) { DVHTXT_FILENAME = argv[1]; } /* generate dummy DVH */ const IDType structureIDPrefix = "myStructure"; const IDType doseID = "myDose"; DummyDVHGenerator dvhGenerator; DVHPointer spMyDVH = boost::make_shared(dvhGenerator.generateDVH(structureIDPrefix,doseID)); // 1) test writing DVH to xml file DVHType typeCum = {DVHType::Cumulative}; DVHType typeDiff = {DVHType::Differential}; FileNameString fN1 = "test.xml"; CHECK_NO_THROW(io::other::DVHXMLFileWriter(fN1, typeDiff)); CHECK_NO_THROW(io::other::DVHXMLFileWriter(fN1, typeCum)); io::other::DVHXMLFileWriter dvhWriter (fN1, typeCum); CHECK_EQUAL(fN1, dvhWriter.getFileName()); FileNameString fN2 = "otherFile.xml"; CHECK_NO_THROW(dvhWriter.setFileName(fN2)); CHECK_EQUAL(fN2, dvhWriter.getFileName()); CHECK_EQUAL(DVHType::Cumulative, dvhWriter.getDVHType().Type); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_EQUAL(DVHType::Differential, dvhWriter.getDVHType().Type); DVHPointer emptyDvh; CHECK_THROW_EXPLICIT(dvhWriter.writeDVH(emptyDvh), core::NullPointerException); //CHECK_THROW_EXPLICIT(dvhWriter.writeDVH(spMyDVH), core::InvalidParameterException); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_NO_THROW(dvhWriter.writeDVH(spMyDVH)); // 2) test reading DVH from xml file io::other::DVHXMLFileReader dvhReader(fN2); DVHPointer importedDVH = dvhReader.generateDVH(); CHECK_EQUAL(*importedDVH, *spMyDVH); //3) test reading dvh from txt file and writing to xml io::other::DVHTxtFileReader dvhReader2(DVHTXT_FILENAME); DVHPointer importedDVH2 = dvhReader2.generateDVH(); - FileNameString toWrite = "test.xml"; - io::other::DVHXMLFileWriter xmlWriter(toWrite, typeDiff); + + //write dvh to a xml file as differential + FileNameString toWrite_diff = "test_diff.xml"; + io::other::DVHXMLFileWriter xmlWriter(toWrite_diff, typeDiff); xmlWriter.writeDVH(importedDVH2); - io::other::DVHXMLFileReader xmlReader(toWrite); - DVHPointer readDVH=xmlReader.generateDVH(); - const double errorConstant = 1e-7; - - CHECK_CLOSE(importedDVH2->getDeltaD(), readDVH->getDeltaD(), errorConstant); - CHECK_CLOSE(importedDVH2->getDeltaV(), readDVH->getDeltaV(), errorConstant); - CHECK(importedDVH2->getDoseID() == readDVH->getDoseID()); - CHECK(importedDVH2->getStructureID() == readDVH->getStructureID()); - CHECK_CLOSE(importedDVH2->getMaximum(), readDVH->getMaximum(), errorConstant); - CHECK_CLOSE(importedDVH2->getMinimum(), readDVH->getMinimum(), errorConstant); - CHECK_CLOSE(importedDVH2->getMean(), readDVH->getMean(), errorConstant); - CHECK(importedDVH2->getDataDifferential().size() == readDVH->getDataDifferential().size()); - for(int i=0; igetDataDifferential().size(); i++){ - CHECK_CLOSE(importedDVH2->getDataDifferential().at(i), readDVH->getDataDifferential().at(i), errorConstant); - } + io::other::DVHXMLFileReader xmlReader(toWrite_diff); + DVHPointer readDVH = xmlReader.generateDVH(); + + CHECK(checkEqualDVH(importedDVH2, readDVH)); + + //write dvh to a xml file as cummulative + FileNameString toWrite_cum = "test_cum.xml"; + io::other::DVHXMLFileWriter xmlWriter_cum(toWrite_cum, typeCum); + xmlWriter_cum.writeDVH(importedDVH2); + + io::other::DVHXMLFileReader xmlReader_cum(toWrite_cum); + DVHPointer readDVH_cum = xmlReader_cum.generateDVH(); + CHECK(checkEqualDVH(importedDVH2, readDVH_cum)); RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/other/OtherIOTest.cpp b/testing/io/other/OtherIOTest.cpp index 86cbf30..dc33b8e 100644 --- a/testing/io/other/OtherIOTest.cpp +++ b/testing/io/other/OtherIOTest.cpp @@ -1,116 +1,174 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // (c) Copyright 2007, DKFZ, Heidelberg, Germany // ALL RIGHTS RESERVED // // THIS FILE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF DKFZ. // ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR // DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY PROHIBITED // WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF DKFZ. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author zhangl (last changed by) // @author *none* (Reviewer) // @author zhangl (Programmer) // // Subversion HeadURL: $HeadURL: http://sidt-hpc1/dkfz_repository/NotMeVisLab/SIDT/RTToolbox/trunk/testing/core/DVHCalculatorTest.cpp $ */ // this file defines the rttbCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #include #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbDVH.h" #include "rttbDVHSet.h" #include "rttbDVHTxtFileReader.h" #include "rttbDVHTxtFileWriter.h" #include "rttbInvalidParameterException.h" #include "rttbNullPointerException.h" #include "../../core/DummyDVHGenerator.h" namespace rttb{ namespace testing{ /*! @brief OtherIOTest - test the IO for DVH txt data 1) test writing dvh to text file 2) test reading DVH from text file + 3) test reading and writing the same dvh */ int OtherIOTest(int argc, char* argv[] ) { typedef core::DVHSet::DVHSetType DVHSetType; typedef core::DVH::DVHPointer DVHPointer; PREPARE_DEFAULT_TEST_REPORTING; + std::string DVHTXT_FILENAME; + + if (argc>1) + { + DVHTXT_FILENAME = argv[1]; + } + /* generate dummy DVH */ const IDType structureIDPrefix = "myStructure"; const IDType doseID = "myDose"; DummyDVHGenerator dvhGenerator; DVHPointer spMyDVH = boost::make_shared(dvhGenerator.generateDVH(structureIDPrefix,doseID)); // 1) test writing DVH to text file DVHType typeCum = {DVHType::Cumulative}; DVHType typeDiff = {DVHType::Differential}; FileNameString fN1 = "test.txt"; CHECK_NO_THROW(io::other::DVHTxtFileWriter(fN1, typeDiff)); CHECK_NO_THROW(io::other::DVHTxtFileWriter(fN1, typeCum)); io::other::DVHTxtFileWriter dvhWriter (fN1, typeCum); CHECK_EQUAL(fN1, dvhWriter.getFileName()); FileNameString fN2 = "otherFile.txt"; CHECK_NO_THROW(dvhWriter.setFileName(fN2)); CHECK_EQUAL(fN2, dvhWriter.getFileName()); CHECK_EQUAL(DVHType::Cumulative, dvhWriter.getDVHType().Type); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_EQUAL(DVHType::Differential, dvhWriter.getDVHType().Type); DVHPointer emptyDvh; CHECK_THROW_EXPLICIT(dvhWriter.writeDVH(emptyDvh),core::NullPointerException); CHECK_NO_THROW(dvhWriter.setDVHType(typeDiff)); CHECK_NO_THROW(dvhWriter.writeDVH(spMyDVH)); // 2) test reading DVH from text file CHECK_NO_THROW(io::other::DVHTxtFileReader dvhReader(fN1)); io::other::DVHTxtFileReader dvhReaderTest(fN1); CHECK_THROW_EXPLICIT(dvhReaderTest.generateDVH(),core::InvalidParameterException); CHECK_NO_THROW(io::other::DVHTxtFileReader dvhReader(fN2)); io::other::DVHTxtFileReader dvhReader(fN2); CHECK_NO_THROW(dvhReader.resetFileName(fN1)); CHECK_THROW_EXPLICIT(dvhReader.generateDVH(), core::InvalidParameterException); CHECK_NO_THROW(dvhReader.resetFileName(fN2)); CHECK_NO_THROW(dvhReader.generateDVH()); DVHPointer importedDVH = dvhReader.generateDVH(); CHECK_EQUAL(*importedDVH, *spMyDVH); + // 3) test reading and writing the same dvh + //read dvh from a txt file + io::other::DVHTxtFileReader dvhReader_R(DVHTXT_FILENAME); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_R = dvhReader_R.generateDVH(); + + //write the dvh to another file as cumulative + io::other::DVHTxtFileWriter dvhWriter_R_Cum("test_Cum.txt", typeCum); + dvhWriter_R_Cum.writeDVH(dvhP_R); + + //read the file + io::other::DVHTxtFileReader dvhReader_W_Cum("test_Cum.txt"); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_W_Cum = dvhReader_W_Cum.generateDVH(); + + //check equal + const double errorConstant = 1e-7; + CHECK_CLOSE(dvhP_R->getDeltaD(), dvhP_W_Cum->getDeltaD(), errorConstant); + CHECK_CLOSE(dvhP_R->getDeltaV(), dvhP_W_Cum->getDeltaV(), errorConstant); + CHECK(dvhP_R->getDoseID() == dvhP_W_Cum->getDoseID()); + CHECK(dvhP_R->getStructureID() == dvhP_W_Cum->getStructureID()); + CHECK_CLOSE(dvhP_R->getMaximum(), dvhP_W_Cum->getMaximum(), errorConstant); + CHECK_CLOSE(dvhP_R->getMinimum(), dvhP_W_Cum->getMinimum(), errorConstant); + CHECK_CLOSE(dvhP_R->getMean(), dvhP_W_Cum->getMean(), errorConstant); + CHECK(dvhP_R->getDataDifferential().size() == dvhP_W_Cum->getDataDifferential().size()); + for(int i=0; igetDataDifferential().size(); i++){ + CHECK_CLOSE(dvhP_R->getDataDifferential().at(i), dvhP_W_Cum->getDataDifferential().at(i), errorConstant); + } + + + //write the dvh to another file as differential + io::other::DVHTxtFileWriter dvhWriter_R_Diff("test_Diff.txt", typeDiff); + dvhWriter_R_Diff.writeDVH(dvhP_R); + + //read the file + io::other::DVHTxtFileReader dvhReader_W_Diff("test_Diff.txt"); + rttb::core::DVHGeneratorInterface::DVHPointer dvhP_W_Diff = dvhReader_W_Diff.generateDVH(); + + //check equal + CHECK_CLOSE(dvhP_R->getDeltaD(), dvhP_W_Diff->getDeltaD(), errorConstant); + CHECK_CLOSE(dvhP_R->getDeltaV(), dvhP_W_Diff->getDeltaV(), errorConstant); + CHECK(dvhP_R->getDoseID() == dvhP_W_Diff->getDoseID()); + CHECK(dvhP_R->getStructureID() == dvhP_W_Diff->getStructureID()); + CHECK_CLOSE(dvhP_R->getMaximum(), dvhP_W_Diff->getMaximum(), errorConstant); + CHECK_CLOSE(dvhP_R->getMinimum(), dvhP_W_Diff->getMinimum(), errorConstant); + CHECK_CLOSE(dvhP_R->getMean(), dvhP_W_Diff->getMean(), errorConstant); + CHECK(dvhP_R->getDataDifferential().size() == dvhP_W_Diff->getDataDifferential().size()); + for(int i=0; igetDataDifferential().size(); i++){ + CHECK_CLOSE(dvhP_R->getDataDifferential().at(i), dvhP_W_Diff->getDataDifferential().at(i), errorConstant); + } + + RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/other/files.cmake b/testing/io/other/files.cmake index e1ecb94..5903009 100644 --- a/testing/io/other/files.cmake +++ b/testing/io/other/files.cmake @@ -1,13 +1,15 @@ SET(CPP_FILES ../../core/DummyDoseAccessor.cpp ../../core/DummyDVHGenerator.cpp + CompareDVH.cpp DoseStatisticsIOTest.cpp DVHXMLIOTest.cpp - OtherIOTest.cpp + DVHTXTIOTest.cpp rttbIOTests.cpp ) SET(H_FILES ../../core/DummyDoseAccessor.h ../../core/DummyDVHGenerator.h + CompareDVH.h ) diff --git a/testing/io/other/rttbIOTests.cpp b/testing/io/other/rttbIOTests.cpp index b902728..7d012b6 100644 --- a/testing/io/other/rttbIOTests.cpp +++ b/testing/io/other/rttbIOTests.cpp @@ -1,60 +1,60 @@ // ----------------------------------------------------------------------- // 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) */ // this file defines the rttbCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "litMultiTestsMain.h" namespace rttb{ namespace testing{ void registerTests() { LIT_REGISTER_TEST(DoseStatisticsIOTest); LIT_REGISTER_TEST(DVHXMLIOTest); - LIT_REGISTER_TEST(OtherIOTest); + LIT_REGISTER_TEST(DVHTXTIOTest); } } } int main(int argc, char* argv[]) { int result = 0; rttb::testing::registerTests(); try { result = lit::multiTestsMain(argc,argv); } catch(...) { result = -1; } return result; }