diff --git a/code/masks/rttbVOIindexIdentifier.cpp b/code/masks/rttbVOIindexIdentifier.cpp index 06f6e50..cb98659 100644 --- a/code/masks/rttbVOIindexIdentifier.cpp +++ b/code/masks/rttbVOIindexIdentifier.cpp @@ -1,126 +1,147 @@ // ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library // -// (c) Copyright 2008 company=DKFZ"; location="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. -// ----------------------------------------------------------------------- -// @file VOIindexIdentifier.cpp -// @version -// @date -// @author $Author$ -// @author $Author$ -// @author -// Subversion HeadURL: $HeadURL$ - - -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- -// !!!EXPERIMENTAL CODE!!! +// 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. // -// This code may not be used for release. -// Add #define SIDT_ENFORCE_MATURE_CODE to any release module -// to ensure this policy. -// ----------------------------------------------------------------------- +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: +// @date $Date: +// @author $Author: +*/ #include "rttbVOIindexIdentifier.h" #include "rttbStructureSet.h" #include "rttbStructure.h" #include "rttbExceptionMacros.h" #include #include namespace rttb { - namespace masks + namespace masks + { + + const unsigned int VOIindexIdentifier::getIndexByVoiName(StructSetTypePointer spStructSet, + const std::string& name) { + if (!spStructSet) + { + std::ostringstream message; + message << "Exception: "<< "invalid method call spStructSet invalid"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } + VoiLabelList voiLabelList; - void VOIindexIdentifier::init(StructSetTypePointer spInStructSet) - { - this->_spStructSet.reset(); - this->_voiLabelList.clear(); - this->_spStructSet = spInStructSet; - - for (int i = 0; i < this->_spStructSet->getNumberOfStructures(); i++) - { - this->_voiLabelList.push_back(this->_spStructSet->getStructure(i)->getLabel()); - } - } + for (int i = 0; i < spStructSet->getNumberOfStructures(); i++) + { + voiLabelList.push_back(spStructSet->getStructure(i)->getLabel()); + } - const unsigned int VOIindexIdentifier::getIndexByVoiName(StructSetTypePointer spStructSet, - std::string name) - { - if (!spStructSet) - { - rttbDefaultExceptionMacro("invalid method call spStructSet invalid"); - } - this->init(spStructSet); - int returnValue = -1; - if (this->_voiLabelList.empty()) - { - rttbDefaultExceptionMacro("invalid method call, object state invalid, voiLabelList empty"); - } + int returnValue = -1; + if (voiLabelList.empty()) + { + std::ostringstream message; + message << "Exception: "<< "invalid method call, object state invalid, voiLabelList empty"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } - ::boost::regex optionalNamesREG("([^\|]*)([\|\|][^\|]*)+"); - ::boost::smatch what; - typedef std::vector< std::string > OptionalVectorType; - OptionalVectorType optionalVois; - ::boost::split(optionalVois, name, ::boost::is_any_of("||")); + ::boost::regex optionalNamesREG("([^\|]*)([\|\|][^\|]*)+"); + ::boost::smatch what; - for (OptionalVectorType::iterator i = optionalVois.begin(); i != optionalVois.end(); i++) - { - int counter = 0; + typedef std::vector< std::string > OptionalVectorType; + OptionalVectorType optionalVois; + ::boost::split(optionalVois, name, ::boost::is_any_of("||")); - for (VoiLabelList::const_iterator iter = this->_voiLabelList.begin(); - iter != this->_voiLabelList.end(); iter++) - { - if ((*iter).compare(*i) == 0) - { - returnValue = counter; - } + for (OptionalVectorType::iterator i = optionalVois.begin(); i != optionalVois.end(); i++) + { + int counter = 0; - counter++; - } - - } + /* + Searches for valid entries in the voi list. + Takes the first matching entry! + */ + for (VoiLabelList::const_iterator iter = voiLabelList.begin(); + iter != voiLabelList.end(); iter++) + { + if ((*iter).compare(*i) == 0) + { + returnValue = counter; + } - return returnValue; + counter++; } - const std::string VOIindexIdentifier::getVoiNameByIndex(StructSetTypePointer spStructSet, - const unsigned int index) - { - if (!spStructSet) - { - rttbDefaultExceptionMacro("invalid method call spStructSet invalid"); - } - this->init(spStructSet); - - if (this->_voiLabelList.empty()) - { - rttbDefaultExceptionMacro("invalid method call, object state invalid, voiLabelList empty"); - } - - if (index >= this->_voiLabelList.size()) - { - rttbDefaultExceptionMacro("invalid index, index out of range"); - } - - return this->_voiLabelList[index]; - } + } + + if (returnValue == -1) + { + std::ostringstream message; + message << "Exception: "<< "specified voi name not found!"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } + + return returnValue; + } + + const std::string VOIindexIdentifier::getVoiNameByIndex(StructSetTypePointer spStructSet, + const unsigned int& index) + { + if (!spStructSet) + { + std::ostringstream message; + message << "Exception: "<< "invalid method call spStructSet invalid"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } + + VoiLabelList voiLabelList; + + for (int i = 0; i < spStructSet->getNumberOfStructures(); i++) + { + voiLabelList.push_back(spStructSet->getStructure(i)->getLabel()); + } + + if (voiLabelList.empty()) + { + std::ostringstream message; + message << "Exception: "<< "invalid method call, object state invalid, voiLabelList empty"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } + + if (index >= voiLabelList.size()) + { + std::ostringstream message; + message << "Exception: "<< "invalid index, index out of range"; + ::rttb::core::Exception e_(message.str().c_str()); + throw e_; + } + + return voiLabelList[index]; } + } } diff --git a/code/masks/rttbVOIindexIdentifier.h b/code/masks/rttbVOIindexIdentifier.h index 804b1fb..13875bf 100644 --- a/code/masks/rttbVOIindexIdentifier.h +++ b/code/masks/rttbVOIindexIdentifier.h @@ -1,88 +1,86 @@ // ----------------------------------------------------------------------- +// RTToolbox - DKFZ radiotherapy quantitative evaluation library // -// (c) Copyright 2008 company=DKFZ"; location="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. -// ----------------------------------------------------------------------- -// @file VOIindexIdentifier.h -// @version -// @date -// @author $Author$ -// @author $Author$ -// @author -// Subversion HeadURL: $HeadURL$ - - -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- -// !!!EXPERIMENTAL CODE!!! +// 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. // -// This code may not be used for release. -// Add #define SIDT_ENFORCE_MATURE_CODE to any release module -// to ensure this policy. -// ----------------------------------------------------------------------- +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision: +// @date $Date: +// @author $Author: +*/ + -#ifndef __RTTB_MASKS_VOIINDEXIDENTIFIER_H -#define __RTTB_MASKS_VOIINDEXIDENTIFIER_H +#ifndef __VOI_INDEX_IDENTIFIER_H +#define __VOI_INDEX_IDENTIFIER_H #include "rttbStructureSet.h" #include "rttbStructure.h" #include namespace rttb { namespace masks { class VOIindexIdentifier { public: typedef ::boost::shared_ptr Pointer; typedef ::rttb::core::StructureSet StructSetType; typedef ::boost::shared_ptr StructSetTypePointer; typedef ::rttb::core::Structure StructType; typedef StructType::StructTypePointer StructTypePointer; typedef std::vector VoiLabelList; public: VOIindexIdentifier(){} virtual ~VOIindexIdentifier() {} /*!@brief get the index of the corresponding VOI - * @param valid struct must be loaded - * @param std::string filename + * @pre name must contain a valid voi name + * @pre spStructSet must point to a valid structure set. + * @param spStructSet Pointer to the structur set that should be checked for the named VOI. + * @param name Name of the VOI + * @exception ::rttb::core::Exception on invalid spStructSet + ::rttb::core::Exception on invalid spStructSet * @return the index */ - const unsigned int getIndexByVoiName(StructSetTypePointer spStructSet, - const std::string name); + static const unsigned int getIndexByVoiName(StructSetTypePointer spStructSet, + const std::string& name); /*!@brief get the VOI of the corresponding index - * @param valid struct must be loaded - * @param std::string filename + * @pre index must specify a valid index value + * @pre spStructSet must point to a valid structure set. + * @param spStructSet Pointer to the structur set that should be checked for the named VOI. + * @param name Index of the VOI + * @exception ::rttb::core::Exception on invalid spStructSet + ::rttb::core::Exception on invalid spStructSet * @return voi name */ - const std::string getVoiNameByIndex(StructSetTypePointer spStructSet, - const unsigned int index); + static const std::string getVoiNameByIndex(StructSetTypePointer spStructSet, + const unsigned int& index); - private: - void init(StructSetTypePointer spStructSet); - StructSetTypePointer _spStructSet; - VoiLabelList _voiLabelList; }; } } -#endif __RTTB_MASKS_VOIINDEXIDENTIFIER_H +#endif __VOI_INDEX_IDENTIFIER_H diff --git a/testing/masks/VOIindexIdentifierTest.cpp b/testing/masks/VOIindexIdentifierTest.cpp index a5e5817..21fb0b1 100644 --- a/testing/masks/VOIindexIdentifierTest.cpp +++ b/testing/masks/VOIindexIdentifierTest.cpp @@ -1,104 +1,100 @@ // ----------------------------------------------------------------------- // RTToolbox - DKFZ radiotherapy quantitative evaluation library // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See rttbCopyright.txt or // http://www.dkfz.de/en/sidt/projects/rttb/copyright.html [^] // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: // @date $Date: // @author $Author: */ // 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 "rttbDicomFileStructureSetGenerator.h" #include "rttbDicomIODStructureSetGenerator.h" #include "rttbDcmrtException.h" #include "rttbInvalidParameterException.h" #include "rttbVOIindexIdentifier.h" namespace rttb { namespace testing { - /*!@brief DicomIOTest - test structure set generator for dicom data - 1) test dicom file structure set generator - 2) test dicom IOD structure set generator - */ - int VOIindexIdentifierTest(int argc, char* argv[]) { typedef core::StructureSetGeneratorInterface::StructureSetPointer StructureSetPointer; //typedef boost::shared_ptr DRTStrSetIODPtr; PREPARE_DEFAULT_TEST_REPORTING; //ARGUMENTS: 1: structure file name std::string RTSTRUCT_FILENAME; if (argc > 1) { RTSTRUCT_FILENAME = argv[1]; } - - RTSTRUCT_FILENAME = "D:\\ajaeger\\Packages\\NotMeVisLab\\SBR\\RTToolbox\\AVIDIntegration\\testing\\data\\DICOM\\StructureSet\\RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm"; + else + { + RTSTRUCT_FILENAME = "D:\\ajaeger\\Packages\\NotMeVisLab\\SBR\\RTToolbox\\AVIDIntegration\\testing\\data\\DICOM\\StructureSet\\RS1.3.6.1.4.1.2452.6.841242143.1311652612.1170940299.4217870819.dcm"; + } StructureSetPointer rtStructureSet = io::dicom::DicomFileStructureSetGenerator( RTSTRUCT_FILENAME.c_str()).generateStructureSet(); StructureSetPointer emptyPointer = StructureSetPointer(); /* getIndexByVoiName */ CHECK_NO_THROW(::rttb::masks::VOIindexIdentifier testVOIindexId = ::rttb::masks::VOIindexIdentifier()); ::rttb::masks::VOIindexIdentifier testVOIindexId = ::rttb::masks::VOIindexIdentifier(); CHECK_THROW_EXPLICIT(testVOIindexId.getIndexByVoiName(emptyPointer,"Leber"), ::rttb::core::Exception); CHECK_NO_THROW(testVOIindexId.getIndexByVoiName(rtStructureSet,"Leber")); int intVoi = 5; CHECK_EQUAL(testVOIindexId.getIndexByVoiName(rtStructureSet,"Leber"),intVoi); CHECK_NO_THROW(testVOIindexId.getIndexByVoiName(rtStructureSet,"Leber||Leb")); CHECK_EQUAL(testVOIindexId.getIndexByVoiName(rtStructureSet,"Leber"),intVoi); CHECK_EQUAL(testVOIindexId.getIndexByVoiName(rtStructureSet,"Leber||Leb"),intVoi); - int intInvalidVoi = -1; - CHECK_EQUAL(testVOIindexId.getIndexByVoiName(rtStructureSet,"Herz"),intInvalidVoi); + CHECK_THROW_EXPLICIT(testVOIindexId.getIndexByVoiName(rtStructureSet,"Herz"),::rttb::core::Exception); /* getVoiNameByIndex */ CHECK_THROW_EXPLICIT(testVOIindexId.getVoiNameByIndex(emptyPointer, 5), ::rttb::core::Exception); CHECK_EQUAL(testVOIindexId.getVoiNameByIndex(rtStructureSet,5), "Leber"); std::string voiName = "Herz"; CHECK_THROW_EXPLICIT(testVOIindexId.getVoiNameByIndex(rtStructureSet,20), ::rttb::core::Exception); RETURN_AND_REPORT_TEST_SUCCESS; } }//testing }//rttb