diff --git a/demoapps/DoseTool/DoseToolHelper.cpp b/demoapps/DoseTool/DoseToolHelper.cpp index 4b89ea9..9f1724b 100644 --- a/demoapps/DoseTool/DoseToolHelper.cpp +++ b/demoapps/DoseTool/DoseToolHelper.cpp @@ -1,251 +1,251 @@ // ----------------------------------------------------------------------- // 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: 1095 $ (last changed revision) // @date $Date: 2015-09-11 11:12:40 +0200 (Fr, 11 Sep 2015) $ (last change date) // @author $Author: hentsch $ (last changed by) */ #include "DoseToolHelper.h" #include "boost/make_shared.hpp" #include "boost/shared_ptr.hpp" #include "boost/property_tree/ptree.hpp" #include "rttbExceptionMacros.h" #include "rttbVirtuosPlanFileDoseAccessorGenerator.h" #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbDicomHelaxFileDoseAccessorGenerator.h" #include "rttbITKImageFileAccessorGenerator.h" #include "rttbStructureSetGeneratorInterface.h" #include "rttbDicomFileStructureSetGenerator.h" #include "rttbVirtuosFileStructureSetGenerator.h" #include "rttbITKImageFileMaskAccessorGenerator.h" #include "rttbDoseStatisticsCalculator.h" #include "rttbBoostMaskAccessor.h" #include "rttbGenericMaskedDoseIterator.h" #include "rttbDoseStatisticsXMLWriter.h" #include "rttbVOIindexIdentifier.h" rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseTool::loadDose(const std::string& fileName, const rttb::apps::doseTool::ApplicationData::LoadingStyleArgType& args) { rttb::core::DoseAccessorInterface::DoseAccessorPointer result; std::cout << std::endl << "read dose file... "; if (args.empty() || args[0] == "dicom") { std::cout << "use RTTB dicom IO... "; result = loadDicomDose(fileName); } else if (args[0] == "helax") { std::cout << "use RTTB Helax IO... "; result = loadHelaxDose(fileName); } else if (args[0] == "itk") { std::cout << "use RTTB itk IO... "; result = loadITKDose(fileName); } else if (args[0] == "virtuos") { if (args.size() < 2) { rttbDefaultExceptionStaticMacro( << "Cannot load virtuos dose. Plan file is missing. Specify plan file as 2nd io stlye argument."); } std::cout << "use RTTB virtuos IO... " << std::endl; std::cout << " virtuos plan file: " << args[1] << " ... "; result = loadVirtuosDose(fileName, args[1]); } else { rttbDefaultExceptionStaticMacro( << "Unknown io style selected. Cannot load data. Selected style: " << args[0]); } std::cout << "done." << std::endl; return result; }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseTool::loadDicomDose(const std::string& fileName) { rttb::io::dicom::DicomFileDoseAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseTool::loadHelaxDose(const std::string& path) { rttb::io::helax::DicomHelaxFileDoseAccessorGenerator generator(path); return generator.generateDoseAccessor(); }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseTool::loadITKDose(const std::string& fileName) { rttb::io::itk::ITKImageFileAccessorGenerator generator(fileName); return generator.generateDoseAccessor(); }; rttb::core::DoseAccessorInterface::DoseAccessorPointer rttb::apps::doseTool::loadVirtuosDose(const std::string& fileName, const std::string& planFileName) { rttb::io::virtuos::VirtuosPlanFileDoseAccessorGenerator generator(fileName, planFileName); return generator.generateDoseAccessor(); }; rttb::core::StructureSetGeneratorInterface::StructureSetPointer rttb::apps::doseTool::loadStruct( const std::string& fileName, const ApplicationData::LoadingStyleArgType& args) { rttb::core::StructureSetGeneratorInterface::StructureSetPointer result; std::cout << std::endl << "read struct file... "; if (args.empty() || args[0] == "dicom") { std::cout << "use RTTB dicom IO... "; result = loadDicomStruct(fileName); } else if (args[0] == "virtuos") { std::cout << "use RTTB virtuos IO... " << std::endl; std::cout << " virtuos CTX file: " << args[1] << " ... "; result = loadVirtuosStruct(fileName, args[1]); } else { rttbDefaultExceptionStaticMacro( << "Unknown io style selected. Cannot load data. Selected style: " << args[0]); } std::cout << "done." << std::endl; return result; } rttb::core::StructureSetGeneratorInterface::StructureSetPointer rttb::apps::doseTool::loadDicomStruct( const std::string& fileName) { rttb::io::dicom::DicomFileStructureSetGenerator generator(fileName); return generator.generateStructureSet(); } rttb::core::StructureSetGeneratorInterface::StructureSetPointer rttb::apps::doseTool::loadVirtuosStruct( const std::string& fileName, const std::string& ctxFileName) { rttb::io::virtuos::VirtuosFileStructureSetGenerator generator(fileName, ctxFileName.c_str()); return generator.generateStructureSet(); } void rttb::apps::doseTool::processData(rttb::apps::doseTool::ApplicationData& appData) { std::cout << std::endl << "generating mask... "; core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr = generateMask(appData); core::DoseIteratorInterface::DoseIteratorPointer spDoseIterator(generateMaskedDoseIterator(maskAccessorPtr, appData._dose)); std::cout << "done." << std::endl; std::cout << std::endl << "computing dose statistics... "; algorithms::DoseStatistics::DoseStatisticsPointer statistics = computeDoseStatistics(spDoseIterator, appData._computeComplexDoseStatistics); std::cout << "done." << std::endl; std::cout << std::endl << "writing dose statistics to file... "; writeDoseStatisticsFile(statistics, appData); std::cout << "done." << std::endl; }; void rttb::apps::doseTool::determineStructIndex(rttb::apps::doseTool::ApplicationData& appData) { unsigned int index = rttb::masks::VOIindexIdentifier::getIndexByVoiName(appData._struct, appData._structNameRegex); appData._structIndex = index; appData._structNameActual = appData._struct->getStructure(index)->getLabel(); } rttb::core::MaskAccessorInterface::MaskAccessorPointer rttb::apps::doseTool::generateMask( rttb::apps::doseTool::ApplicationData& appData) { core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr; if (appData._structLoadStyle.front() == "itk") { maskAccessorPtr = rttb::io::itk::ITKImageFileMaskAccessorGenerator(appData._structFileName).generateMaskAccessor(); } else { determineStructIndex(appData); bool strict = !appData._allowSelfIntersection; maskAccessorPtr = boost::make_shared (appData._struct->getStructure(appData._structIndex), appData._dose->getGeometricInfo(), strict); } maskAccessorPtr->updateMask(); return maskAccessorPtr; } rttb::core::DoseIteratorInterface::DoseIteratorPointer rttb::apps::doseTool::generateMaskedDoseIterator( rttb::core::MaskAccessorInterface::MaskAccessorPointer maskAccessorPtr, rttb::core::DoseAccessorInterface::DoseAccessorPointer doseAccessorPtr) { boost::shared_ptr maskedDoseIterator = boost::make_shared(maskAccessorPtr, doseAccessorPtr); rttb::core::DoseIteratorInterface::DoseIteratorPointer doseIterator(maskedDoseIterator); return doseIterator; } rttb::algorithms::DoseStatistics::DoseStatisticsPointer rttb::apps::doseTool::computeDoseStatistics( core::DoseIteratorInterface::DoseIteratorPointer doseIterator, bool computeComplexDoseStatistics) { rttb::algorithms::DoseStatisticsCalculator doseStatsCalculator(doseIterator); return doseStatsCalculator.calculateDoseStatistics(computeComplexDoseStatistics); } void rttb::apps::doseTool::writeDoseStatisticsFile(rttb::algorithms::DoseStatistics::DoseStatisticsPointer statistics, rttb::apps::doseTool::ApplicationData& appData) { - boost::property_tree::ptree originalTree = rttb::io::other::writeDoseStatistics(statistics, appData._prescribedDose); + boost::property_tree::ptree originalTree = rttb::io::other::writeDoseStatistics(statistics); //add config part to xml originalTree.add("statistics.config.requestedStructRegex", appData._structNameRegex); originalTree.add("statistics.config.structName", appData._structNameActual); originalTree.add("statistics.config.doseUID", appData._dose->getUID()); originalTree.add("statistics.config.doseFile", appData._doseFileName); originalTree.add("statistics.config.structFile", appData._structFileName); boost::property_tree::ptree reorderedTree, configTree, resultsTree; configTree = originalTree.get_child("statistics.config"); resultsTree = originalTree.get_child("statistics.results"); reorderedTree.add_child("statistics.config", configTree); reorderedTree.add_child("statistics.results", resultsTree); boost::property_tree::write_xml(appData._outputFileName, reorderedTree, std::locale(), boost::property_tree::xml_writer_make_settings('\t', 1)); } diff --git a/testing/examples/CMakeLists.txt b/testing/examples/CMakeLists.txt index d1d5de7..d36fa75 100644 --- a/testing/examples/CMakeLists.txt +++ b/testing/examples/CMakeLists.txt @@ -1,47 +1,42 @@ #----------------------------------------------------------------------------- # 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(RTBioModelExampleTest ${CORE_TEST_EXAMPLES} RTBioModelExampleTest "${TEST_DATA_ROOT}/TestDVH/dvh_PTV_HIT.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT1.txt" -"${TEST_DATA_ROOT}/TestDVH/dvh_test_HT2.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT3.txt" -"${TEST_DATA_ROOT}/TestDVH/dvh_test_TV.txt" "${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/dvh_diff_trunk6.txt" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/dvh_diff_trunk8.txt") -ADD_TEST(DVHCalculatorExampleTest ${CORE_TEST_EXAMPLES} DVHCalculatorExampleTest +"${TEST_DATA_ROOT}/TestDVH/dvh_test_HT2.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT3.txt" +"${TEST_DATA_ROOT}/TestDVH/dvh_test_TV.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_virtuos_diff_trunk6.txt" +"${TEST_DATA_ROOT}/TestDVH/dvh_virtuos_diff_trunk8.txt") +ADD_TEST(DVHCalculatorExampleTest ${CORE_TEST_EXAMPLES} DVHCalculatorExampleTest "${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwoGridScaling.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwoGridScaling05.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantFiftyGridScaling01.dcm") -ADD_TEST(RTDoseIndexTest ${CORE_TEST_EXAMPLES} RTDoseIndexTest +ADD_TEST(RTDoseIndexTest ${CORE_TEST_EXAMPLES} RTDoseIndexTest "${TEST_DATA_ROOT}/TestDVH/dvh_test_TV.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT1.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT2.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT3.txt") -ADD_TEST(RTDoseStatisticsTest ${CORE_TEST_EXAMPLES} RTDoseStatisticsTest -"${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo_withDoseGridScaling.dcm" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa101.dos.gz" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa000.vdx" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa101.pln") +ADD_TEST(RTDoseStatisticsTest ${CORE_TEST_EXAMPLES} RTDoseStatisticsTest +"${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo_withDoseGridScaling.dcm" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln") ADD_TEST(RTDVHTest ${CORE_TEST_EXAMPLES} RTDVHTest "${TEST_DATA_ROOT}/TestDVH/dvh_test.txt") -ADD_TEST(DVHCalculatorExampleTest ${CORE_TEST_EXAMPLES} DVHCalculatorExampleTest +ADD_TEST(DVHCalculatorExampleTest ${CORE_TEST_EXAMPLES} DVHCalculatorExampleTest "${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/ConstantTwo_withDoseGridScaling.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/LinearIncrease3D.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/LinearIncreaseX.dcm") ADD_TEST(RTBioModelScatterPlotExampleTest ${CORE_TEST_EXAMPLES} RTBioModelScatterPlotExampleTest "${TEST_DATA_ROOT}/TestDVH/dvh_PTV_HIT.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_HT1.txt" "${TEST_DATA_ROOT}/TestDVH/dvh_test_TV.txt") -ADD_TEST(VoxelizationValidationTest ${CORE_TEST_EXAMPLES} VoxelizationValidationTest -"${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm" +ADD_TEST(VoxelizationValidationTest ${CORE_TEST_EXAMPLES} VoxelizationValidationTest +"${TEST_DATA_ROOT}/DICOM/StructureSet/RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm" "${TEST_DATA_ROOT}/DICOM/TestDose/LinearIncrease3D.dcm" "${TEST_DATA_ROOT}/boostMask/" "${TEST_DATA_ROOT}/OTBMask/") -ADD_TEST(DoseStatisticsIOVirtuosTest ${CORE_TEST_EXAMPLES} DoseStatisticsIOVirtuosTest -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa000.vdx" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa000.ctx.gz" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa101.dos.gz" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_aa/MPM_LR_aa101.pln" "CTV") RTTB_CREATE_TEST_MODULE(rttbExamples DEPENDS RTTBCore RTTBAlgorithms RTTBMasks RTTBOTBMask RTTBBoostMask RTTBIndices RTTBDicomIO RTTBVirtuosIO RTTBITKIO RTTBOtherIO RTTBModels PACKAGE_DEPENDS Litmus) diff --git a/testing/examples/RTDoseStatisticsTest.cpp b/testing/examples/RTDoseStatisticsTest.cpp index 82d8ff6..b5ee743 100644 --- a/testing/examples/RTDoseStatisticsTest.cpp +++ b/testing/examples/RTDoseStatisticsTest.cpp @@ -1,204 +1,197 @@ // ----------------------------------------------------------------------- // 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 #include #include #include "litCheckMacros.h" #include "rttbDoseStatistics.h" #include "rttbDoseStatisticsCalculator.h" #include "rttbDicomDoseAccessor.h" #include "rttbDicomFileDoseAccessorGenerator.h" #include "rttbVirtuosPlanFileDoseAccessorGenerator.h" #include "rttbVirtuosFileStructureSetGenerator.h" -#include "rttbOTBMaskAccessor.h" +#include "rttbBoostMaskAccessor.h" #include "rttbGenericMaskedDoseIterator.h" #include "rttbGenericDoseIterator.h" #include "rttbBaseType.h" namespace rttb { namespace testing { PREPARE_DEFAULT_TEST_REPORTING; /*! @brief RTDoseStatisticsTest. Max, min, mean, standard deviation, variance, Vx, Dx, MOHx, MOCx, MaxOHx, MinOCx are tested. Test if calculation in new architecture returns similar results to the original implementation. WARNING: The values for comparison need to be adjusted if the input files are changed!*/ const double reducedErrorConstant = 0.0001; const double expectedVal = 5.64477e-005; const double volume = 24120.; void testWithDummyDoseData(const std::string& doseFilename); void testWithRealVirtuosDoseDataAndStructure(const std::string& doseFilename, const std::string& structFilename, const std::string& planFilename, unsigned int structureNr); int RTDoseStatisticsTest(int argc, char* argv[]) { - typedef core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; - typedef core::GenericDoseIterator::DoseIteratorPointer DoseIteratorPointer; - typedef algorithms::DoseStatistics::ResultListPointer ResultListPointer; - std::string RTDOSE_FILENAME; std::string RTDOSE2_FILENAME; std::string RTSTRUCT_FILENAME; std::string RTPLAN_FILENAME; if (argc > 4) { RTDOSE_FILENAME = argv[1]; RTDOSE2_FILENAME = argv[2]; RTSTRUCT_FILENAME = argv[3]; RTPLAN_FILENAME = argv[4]; } else { std::cout << "at least four arguments required for RTDoseStatisticsTest" << std::endl; return -1; } testWithDummyDoseData(RTDOSE_FILENAME); //Structure 2 is RUECKENMARK testWithRealVirtuosDoseDataAndStructure(RTDOSE2_FILENAME, RTSTRUCT_FILENAME, RTPLAN_FILENAME, 2); RETURN_AND_REPORT_TEST_SUCCESS; } void testWithDummyDoseData(const std::string& doseFilename) { typedef core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; typedef core::GenericDoseIterator::DoseIteratorPointer DoseIteratorPointer; - typedef ::boost::shared_ptr > > ResultsVectorPointer; - io::dicom::DicomFileDoseAccessorGenerator doseAccessorGenerator1(doseFilename.c_str()); DoseAccessorPointer doseAccessor1(doseAccessorGenerator1.generateDoseAccessor()); //create corresponding DoseIterator ::boost::shared_ptr spDoseIteratorTmp = ::boost::make_shared(doseAccessor1); DoseIteratorPointer spDoseIterator(spDoseIteratorTmp); rttb::algorithms::DoseStatisticsCalculator doseStatisticsCalculator(spDoseIterator); std::vector precomputedDoseValues; precomputedDoseValues.push_back(0); precomputedDoseValues.push_back(0.5); precomputedDoseValues.push_back(1); std::vector precomputedVolumeValues; precomputedVolumeValues.push_back(20000/volume); precomputedVolumeValues.push_back(1); rttb::algorithms::DoseStatistics::DoseStatisticsPointer doseStatistics = doseStatisticsCalculator.calculateDoseStatistics(precomputedDoseValues, precomputedVolumeValues); CHECK_CLOSE(doseStatistics->getMean(), expectedVal, errorConstant); CHECK_CLOSE(doseStatistics->getStdDeviation(), 0, errorConstant); CHECK_CLOSE(doseStatistics->getVariance(), 0, errorConstant); double dummy; DoseTypeGy vx = doseStatistics->getVx(expectedVal,true,dummy); CHECK_EQUAL(vx, doseStatistics->getVx(0)); CHECK_CLOSE(expectedVal, doseStatistics->getDx(vx), reducedErrorConstant); CHECK_CLOSE(doseStatistics->getMaximum(), expectedVal, errorConstant); CHECK_CLOSE(doseStatistics->getMinimum(), expectedVal, errorConstant); auto minListPtr = doseStatistics->getMinimumPositions(); auto maxListPtr = doseStatistics->getMaximumPositions(); CHECK_EQUAL(maxListPtr->size(), 10); CHECK_EQUAL(minListPtr->size(), 10); CHECK_CLOSE(doseStatistics->getDx(24120), doseStatistics->getMinimum(), 0.001); CHECK_CLOSE(doseStatistics->getMOHx(24120), doseStatistics->getMean(), reducedErrorConstant); CHECK_CLOSE(doseStatistics->getMOCx(20000), doseStatistics->getMean(), reducedErrorConstant); CHECK_CLOSE(doseStatistics->getMinOCx(20000), doseStatistics->getMean(), reducedErrorConstant); } void testWithRealVirtuosDoseDataAndStructure(const std::string& doseFilename, const std::string& structFilename, const std::string& planFilename, unsigned int structureNr) { typedef core::GenericDoseIterator::DoseIteratorPointer DoseIteratorPointer; - typedef core::GenericMaskedDoseIterator::MaskAccessorPointer MaskAccessorPointer; typedef rttb::algorithms::DoseStatistics::DoseStatisticsPointer DoseStatisticsPointer; auto virtuosDoseAccessor = io::virtuos::VirtuosPlanFileDoseAccessorGenerator(doseFilename.c_str(), planFilename.c_str()).generateDoseAccessor(); auto virtuosStructureSet = io::virtuos::VirtuosFileStructureSetGenerator( structFilename.c_str(), doseFilename.c_str()).generateStructureSet(); - boost::shared_ptr spOTBMaskAccessorVirtuos = - boost::make_shared(virtuosStructureSet->getStructure(structureNr), + boost::shared_ptr spOTBMaskAccessorVirtuos = + boost::make_shared(virtuosStructureSet->getStructure(structureNr), virtuosDoseAccessor->getGeometricInfo()); spOTBMaskAccessorVirtuos->updateMask(); MaskAccessorPointer spMaskAccessor(spOTBMaskAccessorVirtuos); //create corresponding MaskedDoseIterator boost::shared_ptr spMaskedDoseIteratorTmp = boost::make_shared(spMaskAccessor, virtuosDoseAccessor); DoseIteratorPointer spMaskedDoseIterator(spMaskedDoseIteratorTmp); rttb::algorithms::DoseStatisticsCalculator doseStatisticsCalculatorVirtuos(spMaskedDoseIterator); DoseStatisticsPointer doseStatisticsVirtuos = doseStatisticsCalculatorVirtuos.calculateDoseStatistics(true); //comparison values computed with "old" DoseStatistics implementation - CHECK_EQUAL(doseStatisticsVirtuos->getMinimum(), 0); - CHECK_CLOSE(doseStatisticsVirtuos->getMaximum(), 35.3075, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getMean(), 16.1803, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getStdDeviation(), 9.84436, reducedErrorConstant); + CHECK_CLOSE(doseStatisticsVirtuos->getMinimum(), 6.4089, reducedErrorConstant); + CHECK_CLOSE(doseStatisticsVirtuos->getMaximum(), 39.0734, reducedErrorConstant); + CHECK_CLOSE(doseStatisticsVirtuos->getMean(), 22.5779, reducedErrorConstant); + CHECK_CLOSE(doseStatisticsVirtuos->getStdDeviation(), 6.28857, reducedErrorConstant); auto maxPositions = doseStatisticsVirtuos->getMaximumPositions(); auto minPositions = doseStatisticsVirtuos->getMinimumPositions(); CHECK_EQUAL(maxPositions->size(), 1); - CHECK_EQUAL(minPositions->size(), 10); + CHECK_EQUAL(minPositions->size(), 1); CHECK_EQUAL(maxPositions->begin()->first, doseStatisticsVirtuos->getMaximum()); - CHECK_EQUAL(maxPositions->begin()->second, 2138227); + CHECK_EQUAL(maxPositions->begin()->second, 3570772); CHECK_EQUAL(minPositions->begin()->first, doseStatisticsVirtuos->getMinimum()); - CHECK_EQUAL(minPositions->begin()->second, 39026); + CHECK_EQUAL(minPositions->begin()->second, 3571264); - CHECK_CLOSE(doseStatisticsVirtuos->getDx(0.02 * doseStatisticsVirtuos->getVolume()), 30.1528, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getVx(0.9 * doseStatisticsVirtuos->getMaximum()), 0.483529, + CHECK_CLOSE(doseStatisticsVirtuos->getDx(0.02 * doseStatisticsVirtuos->getVolume()), 31.8358, reducedErrorConstant); + CHECK_CLOSE(doseStatisticsVirtuos->getVx(0.9 * doseStatisticsVirtuos->getMaximum()), 0.471747, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getMOHx(0.1 * doseStatisticsVirtuos->getVolume()), 28.7019, + CHECK_CLOSE(doseStatisticsVirtuos->getMOHx(0.1 * doseStatisticsVirtuos->getVolume()), 31.3266, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getMOCx(0.05 * doseStatisticsVirtuos->getVolume()), 0, + CHECK_CLOSE(doseStatisticsVirtuos->getMOCx(0.05 * doseStatisticsVirtuos->getVolume()), 9.01261, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getMaxOHx(0.95 * doseStatisticsVirtuos->getVolume()), 0, + CHECK_CLOSE(doseStatisticsVirtuos->getMaxOHx(0.95 * doseStatisticsVirtuos->getVolume()), 10.3764, reducedErrorConstant); - CHECK_CLOSE(doseStatisticsVirtuos->getMinOCx(0.98 * doseStatisticsVirtuos->getVolume()), 30.1756, + CHECK_CLOSE(doseStatisticsVirtuos->getMinOCx(0.98 * doseStatisticsVirtuos->getVolume()), 31.8373, reducedErrorConstant); } }//testing }//rttb \ No newline at end of file diff --git a/testing/examples/files.cmake b/testing/examples/files.cmake index b0d5568..58f3bf0 100644 --- a/testing/examples/files.cmake +++ b/testing/examples/files.cmake @@ -1,20 +1,17 @@ -SET(CPP_FILES +SET(CPP_FILES RTBioModelExampleTest.cpp RTBioModelScatterPlotExampleTest.cpp RTDoseIndexTest.cpp RTDoseStatisticsTest.cpp RTDVHTest.cpp DVHCalculatorExampleTest.cpp DVHCalculatorComparisonTest.cpp ../models/rttbScatterTester.cpp rttbTestExamples.cpp - ../masks/rttbMaskVoxelListTester.cpp VoxelizationValidationTest.cpp - DoseStatisticsIOVirtuosTest.cpp ) -SET(H_FILES +SET(H_FILES ../models/rttbScatterTester.h - ../masks/rttbMaskVoxelListTester.h ) diff --git a/testing/examples/rttbTestExamples.cpp b/testing/examples/rttbTestExamples.cpp index d29927c..abc8840 100644 --- a/testing/examples/rttbTestExamples.cpp +++ b/testing/examples/rttbTestExamples.cpp @@ -1,69 +1,68 @@ // ----------------------------------------------------------------------- // 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(RTBioModelExampleTest); LIT_REGISTER_TEST(DVHCalculatorExampleTest); LIT_REGISTER_TEST(RTDVHTest); LIT_REGISTER_TEST(RTDoseIndexTest); LIT_REGISTER_TEST(RTDoseStatisticsTest); LIT_REGISTER_TEST(RTBioModelScatterPlotExampleTest); LIT_REGISTER_TEST(VoxelizationValidationTest); - LIT_REGISTER_TEST(DoseStatisticsIOVirtuosTest); } } } int main(int argc, char* argv[]) { int result = 0; rttb::testing::registerTests(); try { result = lit::multiTestsMain(argc, argv); } catch (const std::exception& /*e*/) { result = -1; } catch (...) { result = -1; } return result; } diff --git a/testing/io/virtuos/CMakeLists.txt b/testing/io/virtuos/CMakeLists.txt index e1a6624..7b83b5f 100644 --- a/testing/io/virtuos/CMakeLists.txt +++ b/testing/io/virtuos/CMakeLists.txt @@ -1,52 +1,46 @@ #----------------------------------------------------------------------------- # Setup the system information test. Write out some basic failsafe # information in case the test doesn't run. #----------------------------------------------------------------------------- SET(VIRTUOSIO_TEST ${EXECUTABLE_OUTPUT_PATH}/rttbVirtuosIOTests) SET(TEST_DATA_ROOT ${RTTBTesting_SOURCE_DIR}/data) SET(TEMP ${RTTBTesting_BINARY_DIR}/temporary) #----------------------------------------------------------------------------- -ADD_TEST(VirtuosDoseAccessorGeneratorTest ${VIRTUOSIO_TEST} VirtuosDoseAccessorGeneratorTest -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz" -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos") +ADD_TEST(VirtuosDoseAccessorGeneratorTest ${VIRTUOSIO_TEST} VirtuosDoseAccessorGeneratorTest +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz") ADD_TEST(VirtuosDoseIOTest ${VIRTUOSIO_TEST} VirtuosDoseIOTest -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz" -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos") - -#ADD_TEST(VirtuosDoseIOTest ${VIRTUOSIO_TEST} VirtuosDoseIOTest -#"${TEST_DATA_ROOT}/Virtuos/0001220308_Loga_Ivonne/0001220308_Loga_Ivonne111.pln" "${TEST_DATA_ROOT}/Virtuos/0001220308_Loga_Ivonne/0001220308_Loga_Ivonne111.dos.gz" -#"${TEST_DATA_ROOT}/Virtuos/0001220308_Loga_Ivonne/0001220308_Loga_Ivonne112.dos.gz") +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz") ADD_TEST(VirtuosStructureIOTest ${VIRTUOSIO_TEST} VirtuosStructureIOTest -"${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.vdx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx.gz" -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.ctx.gz" +"${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.vdx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx.gz" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.ctx.gz" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz") ADD_TEST(VirtuosStructureSetGeneratorTest ${VIRTUOSIO_TEST} VirtuosStructureSetGeneratorTest -"${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.vdx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx.gz" -"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.ctx.gz" +"${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.vdx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx.gz" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" "${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.ctx.gz" ) #trip data ADD_TEST(TripStructureIOTest ${VIRTUOSIO_TEST} TripStructureIOTest "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.vdx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx.gz" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030000.ctx" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030101.dos.gz" "${TEST_DATA_ROOT}/Virtuos/NHHTrip/NHH030101.dos") ADD_TEST(TripDoseIOTest ${VIRTUOSIO_TEST} TripDoseIOTest "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030101.pln" "${TEST_DATA_ROOT}/Virtuos/NHH030/NHH030101.dos.gz" "${TEST_DATA_ROOT}/Virtuos/NHHTrip/NHH030101.dos") -ADD_TEST(VirtuosDVHCalculatorExampleTest ${VIRTUOSIO_TEST} VirtuosDVHCalculatorExampleTest -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/MPM_LR_ah101.dos.gz" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/MPM_LR_ah000.vdx" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/MPM_LR_ah101.pln" -"${TEST_DATA_ROOT}/Virtuos/MPM_LR_ah/MPM_LR_ah000.ctx.gz" ) +ADD_TEST(VirtuosDVHCalculatorExampleTest ${VIRTUOSIO_TEST} VirtuosDVHCalculatorExampleTest +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.dos.gz" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.vdx" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac101.pln" +"${TEST_DATA_ROOT}/Virtuos/prostate_ac/prostate_ac000.ctx.gz" ) -RTTB_CREATE_TEST_MODULE(rttbVirtuosIO DEPENDS RTTBVirtuosIO RTTBMasks RTTBOTBMask PACKAGE_DEPENDS Boost Litmus VirtuosIO) +RTTB_CREATE_TEST_MODULE(rttbVirtuosIO DEPENDS RTTBVirtuosIO RTTBMasks RTTBOTBMask RTTBBoostMask PACKAGE_DEPENDS Boost Litmus VirtuosIO) diff --git a/testing/io/virtuos/VirtuosDVHCalculatorExampleTest.cpp b/testing/io/virtuos/VirtuosDVHCalculatorExampleTest.cpp index 93d13dc..db9751f 100644 --- a/testing/io/virtuos/VirtuosDVHCalculatorExampleTest.cpp +++ b/testing/io/virtuos/VirtuosDVHCalculatorExampleTest.cpp @@ -1,183 +1,131 @@ // ----------------------------------------------------------------------- // 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 #include #include #include #include "litCheckMacros.h" - - - #include "rttbBaseType.h" #include "rttbDVHCalculator.h" #include "rttbGenericMaskedDoseIterator.h" #include "rttbGenericDoseIterator.h" -#include "rttbNullPointerException.h" -#include "rttbInvalidParameterException.h" -#include "rttbOTBMaskAccessor.h" +#include "rttbBoostMaskAccessor.h" #include "rttbVirtuosPlanFileDoseAccessorGenerator.h" #include "rttbVirtuosDoseAccessor.h" #include "rttbVirtuosFileStructureSetGenerator.h" namespace rttb { namespace testing { /*! @brief VirtuosDVHCalculatorExampleTest. Test if calculation in new architecture returns similar results to the original implementation. WARNING: The values for comparison need to be adjusted if the input files are changed! */ int VirtuosDVHCalculatorExampleTest(int argc, char* argv[]) { typedef core::GenericDoseIterator::DoseAccessorPointer DoseAccessorPointer; typedef core::GenericMaskedDoseIterator::MaskAccessorPointer MaskAccessorPointer; typedef core::DVHCalculator::DoseIteratorPointer DoseIteratorPointer; - typedef core::DVHCalculator::MaskedDoseIteratorPointer MaskedDoseIteratorPointer; - typedef masks::legacy::OTBMaskAccessor::StructTypePointer StructTypePointer; + typedef masks::boost::BoostMaskAccessor::StructTypePointer StructTypePointer; typedef core::DVH::DVHPointer DVHPointer; typedef core::StructureSetGeneratorInterface::StructureSetPointer StructureSetPointer; PREPARE_DEFAULT_TEST_REPORTING; //ARGUMENTS: 1: virtuos dose file name // 2: virtuos structure file name // 3: virtuos plan file name // 4: virtuos CT file name std::string Virtuos_Dose_File; std::string Virtuos_Structure_File; std::string Virtuos_Plan_File; std::string Virtuos_CT_File; - if (argc > 1) + if (argc > 4) { Virtuos_Dose_File = argv[1]; - } - - if (argc > 2) - { Virtuos_Structure_File = argv[2]; - } - - if (argc > 3) - { Virtuos_Plan_File = argv[3]; - } - - if (argc > 4) - { Virtuos_CT_File = argv[4]; } //Virtuos DVH Test io::virtuos::VirtuosPlanFileDoseAccessorGenerator doseAccessorGeneratorVirtuos(Virtuos_Dose_File, Virtuos_Plan_File); DoseAccessorPointer doseAccessorVirtuos(doseAccessorGeneratorVirtuos.generateDoseAccessor()); StructureSetPointer rtStructureSetVirtuos = io::virtuos::VirtuosFileStructureSetGenerator( Virtuos_Structure_File, Virtuos_CT_File).generateStructureSet(); - for (int i = 1; i < rtStructureSetVirtuos->getNumberOfStructures(); i++) - { - //if(i=6 || i==8){//todo: assertion bug! - if (i == 8) - { - - //create MaskAccessor for each structure - boost::shared_ptr spOTBMaskAccessorVirtuos = - boost::make_shared(rtStructureSetVirtuos->getStructure(i), - doseAccessorVirtuos->getGeometricInfo()); - - spOTBMaskAccessorVirtuos->updateMask(); - - MaskAccessorPointer spMaskAccessor(spOTBMaskAccessorVirtuos); - - //create corresponding MaskedDoseIterator - - boost::shared_ptr spMaskedDoseIteratorTmp = - boost::make_shared(spMaskAccessor, doseAccessorVirtuos); - - DoseIteratorPointer spMaskedDoseIterator(spMaskedDoseIteratorTmp); - - std::cout << "dvh calc" << std::endl; - rttb::core::DVHCalculator* calc; - - if (i == 6) - { - calc = new rttb::core::DVHCalculator(spMaskedDoseIterator, - (rtStructureSetVirtuos->getStructure(i))->getUID(), doseAccessorVirtuos->getUID(), 0.367944); - } - else - { - calc = new rttb::core::DVHCalculator(spMaskedDoseIterator, - (rtStructureSetVirtuos->getStructure(i))->getUID(), doseAccessorVirtuos->getUID(), 0.510107); - } - - - DVHPointer dvhPtr = calc->generateDVH(); - - if (i == 6) - { - CHECK_CLOSE(42.497532, dvhPtr->getMaximum(), errorConstant); - CHECK_CLOSE(2.7595800000000001, dvhPtr->getMinimum(), errorConstant); - CHECK_CLOSE(7.4752642058590695, dvhPtr->getMean(), errorConstant); - CHECK_CLOSE(6.4390200000000002, dvhPtr->getMedian(), errorConstant); - CHECK_CLOSE(5.7031320000000001, dvhPtr->getModal(), errorConstant); - CHECK_CLOSE(3.5065188466477824, dvhPtr->getStdDeviation(), errorConstant); - CHECK_CLOSE(12.295674421896095, dvhPtr->getVariance(), errorConstant); - CHECK_CLOSE(177218.04900734947, dvhPtr->getNumberOfVoxels(), 1e-2); - } - - if (i == 8) - { - CHECK_CLOSE(68.099284499999996, dvhPtr->getMaximum(), errorConstant); - CHECK_CLOSE(24.7401895, dvhPtr->getMinimum(), errorConstant); - CHECK_CLOSE(54.384709827101481, dvhPtr->getMean(), errorConstant); - CHECK_CLOSE(54.836502499999995, dvhPtr->getMedian(), errorConstant); - CHECK_CLOSE(54.836502499999995, dvhPtr->getModal(), errorConstant); - CHECK_CLOSE(3.3345924130915088, dvhPtr->getStdDeviation(), errorConstant); - CHECK_CLOSE(11.119506561447452, dvhPtr->getVariance(), errorConstant); - CHECK_CLOSE(338856.04793872859, dvhPtr->getNumberOfVoxels(), 1e-2); - } - - } - } + //create MaskAccessor for structure DARM + boost::shared_ptr spMaskAccessorVirtuos = + boost::make_shared(rtStructureSetVirtuos->getStructure(4), + doseAccessorVirtuos->getGeometricInfo()); + + spMaskAccessorVirtuos->updateMask(); + + MaskAccessorPointer spMaskAccessor(spMaskAccessorVirtuos); + + //create corresponding MaskedDoseIterator + + boost::shared_ptr spMaskedDoseIteratorTmp = + boost::make_shared(spMaskAccessor, doseAccessorVirtuos); + + DoseIteratorPointer spMaskedDoseIterator(spMaskedDoseIteratorTmp); + + rttb::core::DVHCalculator* calc; + CHECK_NO_THROW(calc = new rttb::core::DVHCalculator(spMaskedDoseIterator, + (rtStructureSetVirtuos->getStructure(4))->getUID(), doseAccessorVirtuos->getUID())); + + DVHPointer dvhPtr; + CHECK_NO_THROW(dvhPtr = calc->generateDVH()); + + CHECK_CLOSE(4.08178, dvhPtr->getMaximum(), errorConstant); + CHECK_CLOSE(0.0151739, dvhPtr->getMinimum(), errorConstant); + CHECK_CLOSE(0.755342, dvhPtr->getMean(), errorConstant); + CHECK_CLOSE(0.440044, dvhPtr->getMedian(), errorConstant); + CHECK_CLOSE(0.0151739, dvhPtr->getModal(), errorConstant); + CHECK_CLOSE(0.835792, dvhPtr->getStdDeviation(), errorConstant); + CHECK_CLOSE(0.698549, dvhPtr->getVariance(), errorConstant); + CHECK_CLOSE(46573.0193175, dvhPtr->getNumberOfVoxels(), errorConstant); RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/virtuos/VirtuosDoseAccessorGeneratorTest.cpp b/testing/io/virtuos/VirtuosDoseAccessorGeneratorTest.cpp index 134a54c..e96185c 100644 --- a/testing/io/virtuos/VirtuosDoseAccessorGeneratorTest.cpp +++ b/testing/io/virtuos/VirtuosDoseAccessorGeneratorTest.cpp @@ -1,149 +1,133 @@ // ----------------------------------------------------------------------- // 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 #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbVirtuosCubeinfoDoseAccessorGenerator.h" #include "rttbVirtuosDoseFileDoseAccessorGenerator.h" #include "rttbVirtuosPlanFileDoseAccessorGenerator.h" #include "rttbVirtuosDoseAccessor.h" #include "rttbInvalidDoseException.h" #include "rttbInvalidParameterException.h" #include "../rttbDoseAccessorTester.h" namespace rttb { namespace testing { /*! @brief VirtuosDoseAccessorGeneratorTest - test the accessor generator generateDoseAccessor() of virtuos data 1) test virtuos accessor generator with only dose file 2) test virtuos accessor generator with dose and plan file 3) test virtuos accessor generator with cubeinfo */ int VirtuosDoseAccessorGeneratorTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; // 1: plan file name (virtuos) .../testing/data/Virtuos/prostate_ac/prostate_ac101.pln // 2: dose1 file name (virtuos) .../testing/data/Virtuos/prostate_ac/prostate_ac101.dos.gz - // 3: dose2 file name (trip): .../testing/data/Virtuos/prostate_ac/prostate_ac101.dos - // WARNING: Test will fail if dose2 does not contain the same dose as dose1! std::string RTPLAN_FILENAME; std::string RTDOSE_FILENAME; - std::string RTDOSE2_FILENAME; - - if (argc > 1) - { - RTPLAN_FILENAME = argv[1]; - } if (argc > 2) { + RTPLAN_FILENAME = argv[1]; RTDOSE_FILENAME = argv[2]; } - if (argc > 3) - { - RTDOSE2_FILENAME = argv[3]; - } - //1) test virtuos accessor generator with only dose file CHECK_NO_THROW(io::virtuos::VirtuosDoseFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), 0, 0).generateDoseAccessor()); CHECK_THROW_EXPLICIT( io::virtuos::VirtuosDoseFileDoseAccessorGenerator("test.dos.gz", 0, 0).generateDoseAccessor(), core::InvalidParameterException); //2) test virtuos accessor generator with dose and plan file CHECK_NO_THROW(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), "")); CHECK_NO_THROW(io::virtuos::VirtuosPlanFileDoseAccessorGenerator("myDose.dos.gz", RTPLAN_FILENAME.c_str())); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), "").generateDoseAccessor(), core::InvalidParameterException); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator("", RTPLAN_FILENAME.c_str()).generateDoseAccessor(), core::InvalidParameterException); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), "myPlanfile.pln").generateDoseAccessor(), core::InvalidParameterException); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator("myDose.dos.gz", RTPLAN_FILENAME.c_str()).generateDoseAccessor(), core::InvalidParameterException); CHECK_NO_THROW(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), RTPLAN_FILENAME.c_str()).generateDoseAccessor()); std::string testFileName = RTPLAN_FILENAME; size_t gzPosition = testFileName.find(".pln"); if (gzPosition != std::string::npos) { testFileName.erase(gzPosition, testFileName.length()); } CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(RTDOSE_FILENAME.c_str(), testFileName).generateDoseAccessor(), core::InvalidParameterException); testFileName = RTDOSE_FILENAME; gzPosition = testFileName.find(".dos"); if (gzPosition != std::string::npos) { testFileName.erase(gzPosition, testFileName.length()); } CHECK_THROW_EXPLICIT(io::virtuos::VirtuosPlanFileDoseAccessorGenerator(testFileName, RTPLAN_FILENAME.c_str()).generateDoseAccessor(), core::InvalidParameterException); //3) test virtuos accessor generator with cubeinfo Cubeinfo** pPointerOnVirtuosCube = new Cubeinfo*; *pPointerOnVirtuosCube = create_cubeinfo(0); CHECK_NO_THROW(io::virtuos::VirtuosCubeinfoDoseAccessorGenerator(*pPointerOnVirtuosCube)); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosCubeinfoDoseAccessorGenerator( *pPointerOnVirtuosCube).generateDoseAccessor(), core::InvalidDoseException); nc_init_cubeinfo(*pPointerOnVirtuosCube); CHECK_THROW_EXPLICIT(io::virtuos::VirtuosCubeinfoDoseAccessorGenerator( *pPointerOnVirtuosCube).generateDoseAccessor(), core::InvalidDoseException); - opencube(RTDOSE2_FILENAME.c_str() , *pPointerOnVirtuosCube); - CHECK_NO_THROW(io::virtuos::VirtuosCubeinfoDoseAccessorGenerator( - *pPointerOnVirtuosCube).generateDoseAccessor()); - RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/virtuos/VirtuosDoseIOTest.cpp b/testing/io/virtuos/VirtuosDoseIOTest.cpp index cd52bd7..8e0be12 100644 --- a/testing/io/virtuos/VirtuosDoseIOTest.cpp +++ b/testing/io/virtuos/VirtuosDoseIOTest.cpp @@ -1,227 +1,180 @@ // ----------------------------------------------------------------------- // 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 #include #include #include "litCheckMacros.h" #include "rttbBaseType.h" #include "rttbGeometricInfo.h" #include "rttbDoseIteratorInterface.h" #include "rttbVirtuosCubeinfoDoseAccessorGenerator.h" #include "rttbVirtuosDoseFileDoseAccessorGenerator.h" #include "rttbVirtuosPlanFileDoseAccessorGenerator.h" #include "rttbVirtuosDoseAccessor.h" #include "rttbNullPointerException.h" #include "rttbInvalidDoseException.h" #include "rttbInvalidParameterException.h" #include "rttbIndexOutOfBoundsException.h" #include "../rttbDoseAccessorTester.h" namespace rttb { namespace testing { /*! @brief VirtuosDoseIOTest - test the IO for virtuos data 1) test getPrescribedDose() and getNormalizationDose() 2) test virtuos dose import if geometric info was set correctly 3) test virtuos dose import accessing dose data and converting WARNING: The values for comparison need to be adjusted if the input files are changed! */ int VirtuosDoseIOTest(int argc, char* argv[]) { typedef core::DoseIteratorInterface::DoseAccessorPointer DoseAccessorPointer; PREPARE_DEFAULT_TEST_REPORTING; // 1: plan file name (virtuos) .../testing/data/Virtuos/prostate_ac/prostate_ac101.pln // 2: dose1 file name (virtuos) .../testing/data/Virtuos/prostate_ac/prostate_ac101.dos.gz - // 3: dose2 file name (trip): .../testing/data/Virtuos/prostate_ac/prostate_ac101.dos - // WARNING: Test will fail if dose2 does not contain the same dose as dose1! std::string RTPLAN_FILENAME; std::string RTDOSE_FILENAME; - std::string RTDOSE2_FILENAME; - - if (argc > 1) - { - RTPLAN_FILENAME = argv[1]; - } if (argc > 2) { + RTPLAN_FILENAME = argv[1]; RTDOSE_FILENAME = argv[2]; } - if (argc > 3) - { - RTDOSE2_FILENAME = argv[3]; - } - //1) test getPrescribedDose() and getNormalizationDose() io::virtuos::VirtuosDoseFileDoseAccessorGenerator doseAccessorGeneratorTest3( RTDOSE_FILENAME.c_str(), 885.0, 76.0); boost::shared_ptr virtuosTest3 = boost::static_pointer_cast (doseAccessorGeneratorTest3.generateDoseAccessor()); CHECK_EQUAL(76.0, virtuosTest3->getPrescribedDose()); CHECK_EQUAL(885.0, virtuosTest3->getNormalizationDose()); io::virtuos::VirtuosDoseFileDoseAccessorGenerator doseAccessorGeneratorTest4( RTDOSE_FILENAME.c_str(), 0, 0); boost::shared_ptr virtuosTest4 = boost::static_pointer_cast (doseAccessorGeneratorTest4.generateDoseAccessor()); CHECK_EQUAL(1, virtuosTest4->getPrescribedDose()); CHECK_EQUAL(1, virtuosTest4->getNormalizationDose()); io::virtuos::VirtuosPlanFileDoseAccessorGenerator doseAccessorGenerator1(RTDOSE_FILENAME.c_str(), RTPLAN_FILENAME.c_str()); boost::shared_ptr doseAccessor1 = boost::static_pointer_cast (doseAccessorGenerator1.generateDoseAccessor()); CHECK_EQUAL(76.0, doseAccessor1->getPrescribedDose()); CHECK_EQUAL(885.0, doseAccessor1->getNormalizationDose()); //2) test dose import if geometric info was set correctly core::GeometricInfo geoInfo = doseAccessor1->getGeometricInfo(); CHECK_EQUAL(256, geoInfo.getNumRows()); CHECK_EQUAL(256, geoInfo.getNumColumns()); CHECK_EQUAL(144, geoInfo.getNumSlices()); CHECK_EQUAL(256 * 256 * 144, doseAccessor1->getGridSize()); CHECK_EQUAL(OrientationMatrix(), geoInfo.getOrientationMatrix()); const VoxelGridID start = 0; const VoxelGridIndex3D start3D(0); VoxelGridID end, inbetween; VoxelGridIndex3D end3D, inbetween3D; //3) test dose import accessing dose data and converting CHECK_EQUAL(0, doseAccessor1->getValueAt(start)); CHECK_EQUAL(0, doseAccessor1-> getValueAt(start3D)); inbetween = int(doseAccessor1->getGridSize() / 2.0); doseAccessor1->getGeometricInfo().convert(inbetween, inbetween3D); CHECK_EQUAL(0, doseAccessor1->getValueAt(inbetween)); CHECK_EQUAL(0, doseAccessor1-> getValueAt(inbetween3D)); end = doseAccessor1->getGridSize() - 1; doseAccessor1->getGeometricInfo().convert(end, end3D); CHECK_EQUAL(0, doseAccessor1->getValueAt(end)); CHECK_EQUAL(0, doseAccessor1-> getValueAt(end3D)); /* Dose without plan */ - io::virtuos::VirtuosDoseFileDoseAccessorGenerator doseAccessorGenerator2(RTDOSE2_FILENAME.c_str(), + io::virtuos::VirtuosDoseFileDoseAccessorGenerator doseAccessorGenerator2(RTDOSE_FILENAME.c_str(), doseAccessor1->getNormalizationDose(), doseAccessor1->getPrescribedDose()); boost::shared_ptr doseAccessor2 = boost::static_pointer_cast (doseAccessorGenerator2.generateDoseAccessor()); CHECK_EQUAL(doseAccessor1->getPrescribedDose(), doseAccessor2->getPrescribedDose()); CHECK_EQUAL(doseAccessor1->getNormalizationDose(), doseAccessor2->getNormalizationDose()); //2) test dose import if geometric info was set correctly core::GeometricInfo geoInfo2 = doseAccessor2->getGeometricInfo(); CHECK_EQUAL(geoInfo.getNumRows(), geoInfo2.getNumRows()); CHECK_EQUAL(geoInfo.getNumColumns(), geoInfo2.getNumColumns()); CHECK_EQUAL(geoInfo.getNumSlices(), geoInfo2.getNumSlices()); CHECK_EQUAL(doseAccessor1->getGridSize(), doseAccessor2->getGridSize()); CHECK_EQUAL(geoInfo.getOrientationMatrix(), geoInfo2.getOrientationMatrix()); //3) test dose import accessing dose data and converting CHECK_EQUAL(doseAccessor1->getValueAt(start), doseAccessor2->getValueAt(start)); CHECK_EQUAL(doseAccessor1-> getValueAt(start3D), doseAccessor2-> getValueAt(start3D)); CHECK_EQUAL(doseAccessor2->getValueAt(start), doseAccessor2-> getValueAt(start3D)); inbetween = int(doseAccessor2->getGridSize() / 2.0); doseAccessor2->getGeometricInfo().convert(inbetween, inbetween3D); CHECK_EQUAL(doseAccessor1->getValueAt(inbetween), doseAccessor2->getValueAt(inbetween)); CHECK_EQUAL(doseAccessor1-> getValueAt(inbetween3D), doseAccessor2-> getValueAt(inbetween3D)); CHECK_EQUAL(doseAccessor2->getValueAt(inbetween), doseAccessor2-> getValueAt(inbetween3D)); end = doseAccessor2->getGridSize() - 1; doseAccessor2->getGeometricInfo().convert(end, end3D); CHECK_EQUAL(doseAccessor1->getValueAt(end), doseAccessor2->getValueAt(end)); CHECK_EQUAL(doseAccessor1-> getValueAt(end3D), doseAccessor2-> getValueAt(end3D)); CHECK_EQUAL(doseAccessor2->getValueAt(end), doseAccessor2-> getValueAt(end3D)); - /* Import Trip dose */ - io::virtuos::VirtuosDoseFileDoseAccessorGenerator doseAccessorGenerator3(RTDOSE2_FILENAME.c_str(), - doseAccessor1->getNormalizationDose(), - doseAccessor1->getPrescribedDose()); - boost::shared_ptr doseAccessor3 = - boost::static_pointer_cast - (doseAccessorGenerator3.generateDoseAccessor()); - - - CHECK_EQUAL(doseAccessor1->getPrescribedDose(), doseAccessor3->getPrescribedDose()); - CHECK_EQUAL(doseAccessor1->getNormalizationDose(), doseAccessor3->getNormalizationDose()); - - - //2) test dose import if geometric info was set correctly - core::GeometricInfo geoInfo3 = doseAccessor3->getGeometricInfo(); - CHECK_EQUAL(geoInfo.getNumRows(), geoInfo3.getNumRows()); - CHECK_EQUAL(geoInfo.getNumColumns(), geoInfo3.getNumColumns()); - CHECK_EQUAL(geoInfo.getNumSlices(), geoInfo3.getNumSlices()); - CHECK_EQUAL(doseAccessor1->getGridSize(), doseAccessor3->getGridSize()); - CHECK_EQUAL(geoInfo.getOrientationMatrix(), geoInfo3.getOrientationMatrix()); - - //3) test dose import accessing dose data and converting - - CHECK_EQUAL(doseAccessor1->getValueAt(start), doseAccessor3->getValueAt(start)); - CHECK_EQUAL(doseAccessor1-> getValueAt(start3D), doseAccessor3-> getValueAt(start3D)); - CHECK_EQUAL(doseAccessor3->getValueAt(start), doseAccessor3-> getValueAt(start3D)); - - inbetween = int(doseAccessor3->getGridSize() / 2.0); - doseAccessor3->getGeometricInfo().convert(inbetween, inbetween3D); - - CHECK_EQUAL(doseAccessor1->getValueAt(inbetween), doseAccessor3->getValueAt(inbetween)); - CHECK_EQUAL(doseAccessor1-> getValueAt(inbetween3D), doseAccessor3-> getValueAt(inbetween3D)); - CHECK_EQUAL(doseAccessor3->getValueAt(inbetween), doseAccessor3-> getValueAt(inbetween3D)); - DoseAccessorTester doseCompare(doseAccessor1, doseAccessor3); - CHECK_TESTER(doseCompare); RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb diff --git a/testing/io/virtuos/files.cmake b/testing/io/virtuos/files.cmake index 0c57d7e..3787683 100644 --- a/testing/io/virtuos/files.cmake +++ b/testing/io/virtuos/files.cmake @@ -1,14 +1,14 @@ SET(CPP_FILES rttbVirtuosIOTests.cpp TripDoseIOTest.cpp TripStructureIOTest.cpp VirtuosDoseIOTest.cpp VirtuosDoseAccessorGeneratorTest.cpp VirtuosDVHCalculatorExampleTest.cpp VirtuosStructureIOTest.cpp VirtuosStructureSetGeneratorTest.cpp ../rttbDoseAccessorTester.cpp ) -SET(H_FILES +SET(H_FILES ../rttbDoseAccessorTester.h )