From d24dbd466ba6aac0ed3e85f590ee1b933eb141d4 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 4 Nov 2011 10:24:20 +0100 Subject: [PATCH] Second version of databse of rel pos --- itk/clitkRelativePositionDataBase.cxx | 50 ++++----- itk/clitkRelativePositionDataBase.h | 156 ++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 26 deletions(-) create mode 100644 itk/clitkRelativePositionDataBase.h diff --git a/itk/clitkRelativePositionDataBase.cxx b/itk/clitkRelativePositionDataBase.cxx index 6679388..a9b7327 100644 --- a/itk/clitkRelativePositionDataBase.cxx +++ b/itk/clitkRelativePositionDataBase.cxx @@ -30,14 +30,14 @@ namespace clitk { is >> index.patient; is >> index.station; is >> index.object; - is >> index.orientation.angle1; - index.orientation.angle1 = clitk::deg2rad(index.orientation.angle1); - is >> index.orientation.angle2; - index.orientation.angle2 = clitk::deg2rad(index.orientation.angle2); + is >> index.direction.angle1; + index.direction.angle1 = clitk::deg2rad(index.direction.angle1); + is >> index.direction.angle2; + index.direction.angle2 = clitk::deg2rad(index.direction.angle2); std::string s; is >> s; - if (s=="true") index.orientation.notFlag = true; - else index.orientation.notFlag = false; + if (s=="true") index.direction.notFlag = true; + else index.direction.notFlag = false; } //-------------------------------------------------------------------- @@ -55,7 +55,6 @@ namespace clitk { //-------------------------------------------------------------------- void RelativePositionDataBase::Read(const std::string & filename) { - DD(filename); std::ifstream is; openFileForReading(is, filename); @@ -75,19 +74,19 @@ namespace clitk { } MapByObjectType & s = m_DB[index.station]; - // Get Orientation map from Object + // Get Direction map from Object if (s.find(index.object) == s.end()) { - MapByOrientationType r; + MapByDirectionType r; s[index.object] = r; } - MapByOrientationType & r = s[index.object]; + MapByDirectionType & r = s[index.object]; - // Get Patient map from Orientation - if (r.find(index.orientation) == r.end()) { + // Get Patient map from Direction + if (r.find(index.direction) == r.end()) { MapByPatientType q; - r[index.orientation] = q; + r[index.direction] = q; } - MapByPatientType & q = r[index.orientation]; + MapByPatientType & q = r[index.direction]; // Set value by patient q[index.patient] = v; @@ -98,14 +97,13 @@ namespace clitk { } // End insertion } // end loop reading - DD("end read"); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- - const RelativePositionDataBase::MapByOrientationType & - RelativePositionDataBase::GetMapByOrientation(const IndexType & index) const + const RelativePositionDataBase::MapByDirectionType & + RelativePositionDataBase::GetMapByDirection(const IndexType & index) const { const MapByObjectType & a = GetMapByObject(index.station); if (a.find(index.object) == a.end()) { @@ -132,13 +130,13 @@ namespace clitk { const RelativePositionDataBase::MapByPatientType & RelativePositionDataBase::GetMapByPatient(const IndexType & index) const { - const MapByOrientationType & a = GetMapByOrientation(index); - if (a.find(index.orientation) == a.end()) { + const MapByDirectionType & a = GetMapByDirection(index); + if (a.find(index.direction) == a.end()) { std::ostringstream s; - index.orientation.Print(s); - clitkExceptionMacro("Could not find index in DB (orientation= '" << s.str() << "' not found)."); + index.direction.Print(s); + clitkExceptionMacro("Could not find index in DB (direction= '" << s.str() << "' not found)."); } - return a.find(index.orientation)->second; + return a.find(index.direction)->second; } //-------------------------------------------------------------------- @@ -208,15 +206,15 @@ namespace clitk { //-------------------------------------------------------------------- void - RelativePositionDataBase::GetListOfOrientations(const std::string & station, + RelativePositionDataBase::GetListOfDirections(const std::string & station, const std::string & object, - std::vector & orientations) const + std::vector & directions) const { IndexType i; i.station = station; i.object = object; - const MapByOrientationType & n = GetMapByOrientation(i); - MapToVecFirst(n, orientations); + const MapByDirectionType & n = GetMapByDirection(i); + MapToVecFirst(n, directions); } //-------------------------------------------------------------------- diff --git a/itk/clitkRelativePositionDataBase.h b/itk/clitkRelativePositionDataBase.h new file mode 100644 index 0000000..57cdcec --- /dev/null +++ b/itk/clitkRelativePositionDataBase.h @@ -0,0 +1,156 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ===========================================================================**/ + +#ifndef CLITKRELATIVEPOSITIONDATABASE_H +#define CLITKRELATIVEPOSITIONDATABASE_H + +// clitk +#include "clitkCommon.h" + +namespace clitk { + + //-------------------------------------------------------------------- + /* + FIXME + */ + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + class RelativePositionDirectionType { + public: + double angle1; + double angle2; + bool notFlag; + + void Print(std::ostream & os = std::cout) const { + os << clitk::rad2deg(angle1) << " " << clitk::rad2deg(angle2) << " "; + if (notFlag) os << "true"; + else os << "false"; + os << " "; + } + + void PrintOptions(std::ostream & os = std::cout) const { + os << "angle1 = " << clitk::rad2deg(angle1) << std::endl + << "angle2 = " << clitk::rad2deg(angle2) << std::endl; + if (notFlag) os << "inverse" << std::endl; + } + + void Println(std::ostream & os = std::cout) const { + Print(os); + os << std::endl; + } + + bool operator< (const RelativePositionDirectionType &compare) const + { + if (angle1 < compare.angle1) return true; + if (angle1 > compare.angle1) return false; + + if (angle2 < compare.angle2) return true; + if (angle2 > compare.angle2) return false; + + if (notFlag == true) { + if (compare.notFlag == false) return true; + else return false; + } + return false; + } + }; + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + class RelativePositionDataBaseIndexType { + public: + std::string patient; + std::string station; + std::string object; + RelativePositionDirectionType direction; + void Print(std::ostream & os = std::cout) const { + os << patient << " " << station << " " << object << " "; + direction.Print(os); + } + void Println(std::ostream & os = std::cout) const { + Print(os); + os << std::endl; + } + }; + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + class RelativePositionInformationType { + public: + double threshold; + int sizeBeforeThreshold; + int sizeAfterThreshold; + int sizeReference; + void Print(std::ostream & os = std::cout) const { + os << threshold << " " << sizeBeforeThreshold << " " + << sizeAfterThreshold << " " << sizeReference; + } + void Println(std::ostream & os = std::cout) const { + Print(os); + os << std::endl; + } + }; + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + class RelativePositionDataBase { + + public: + RelativePositionDataBase() {} + ~RelativePositionDataBase() {} + + typedef RelativePositionDataBaseIndexType IndexType; + + void Read(const std::string & filename); + double GetAreaGain(const IndexType & index) const; + double GetThreshold(const IndexType & index) const; + int GetNumberOfPatient(const IndexType & index) const; + std::vector & GetListOfPatients(const IndexType & index) const; + void GetListOfObjects(const std::string & station, std::vector & objects) const; + void GetListOfDirections(const std::string & station, + const std::string & object, + std::vector & directions) const; + bool CheckIndex(const IndexType & index) const; + + protected: + typedef std::map MapByPatientType; + typedef std::map MapByDirectionType; + typedef std::map MapByObjectType; + typedef std::map MapByStationType; + MapByStationType m_DB; + + void ReadIndex(std::istream & is, IndexType & index); + void ReadInformation(std::istream & is, RelativePositionInformationType & v); + + const MapByDirectionType & GetMapByDirection(const IndexType & index) const; + const MapByPatientType & GetMapByPatient(const IndexType & index) const; + const RelativePositionInformationType & GetInformation(const IndexType & index) const; + const MapByObjectType & GetMapByObject(const std::string & station) const; + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#endif -- 2.45.1