From: dsarrut Date: Mon, 4 Oct 2010 08:05:25 +0000 (+0000) Subject: manage anatomical features DB X-Git-Tag: v1.2.0~365 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7afed19d109924974c9467e17be57d04b3d95f91;p=clitk.git manage anatomical features DB --- diff --git a/segmentation/clitkAnatomicalFeatureDatabase.cxx b/segmentation/clitkAnatomicalFeatureDatabase.cxx new file mode 100644 index 0000000..a132f58 --- /dev/null +++ b/segmentation/clitkAnatomicalFeatureDatabase.cxx @@ -0,0 +1,120 @@ +/*========================================================================= + 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://oncora1.lyon.fnclcc.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 + ======================================================================-====*/ + +// clitk +#include "clitkAnatomicalFeatureDatabase.h" + +// std +#include +#include + +//-------------------------------------------------------------------- +clitk::AnatomicalFeatureDatabase::AnatomicalFeatureDatabase() +{ + SetFilename("noname.afdb"); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::AnatomicalFeatureDatabase::Write() +{ + // open file + std::ofstream os; + openFileForWriting(os, GetFilename()); + MapTagType::const_iterator iter = m_MapOfTag.begin(); + while (iter != m_MapOfTag.end()) { + os << iter->first << " " << iter->second << std::endl; + iter++; + } + os.close(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::AnatomicalFeatureDatabase::Load() +{ + // open file + std::ifstream is; + openFileForReading(is, GetFilename()); + // load line by line string/string + while (!is.fail()) { + std::string tag; + is >> tag; DD(tag); + std::string value; + std::getline(is,value,'\n'); + m_MapOfTag[tag] = value; + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::AnatomicalFeatureDatabase::SetPoint3D(std::string tag, PointType3D & p) +{ + ::itk::OStringStream value; + value << p[0] << " " << p[1] << " " << p[2]; + m_MapOfTag[tag] = value.str(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D & p) +{ + if (m_MapOfTag.find(tag) == m_MapOfTag.end()) { + clitkExceptionMacro("Could not find the tag <" << tag << "> of type Point3D in the DB"); + } + else { + std::string s = m_MapOfTag[tag]; + + // construct a stream from the string + std::stringstream strstr(s); + + // use stream iterators to copy the stream to the vector as + // whitespace separated strings + std::istream_iterator it(strstr); + std::istream_iterator end; + std::vector results(it, end); + + // parse the string into 3 doubles + for(int i=0; i<3; i++) { + DD(results[i]); + p[i] = atof(results[i].c_str()); + DD(p[i]); + } + + /* + // boost + #include + #include + // parse the string into 3 doubles + boost::char_separator sep(", "); + boost::tokenizer > tokens(s, sep); + int i=0; + BOOST_FOREACH(std::string t, tokens) { + std::cout << t << "." << std::endl; + p[i] = atof(t.c_str()); + i++; + } + */ + } +} +//-------------------------------------------------------------------- + diff --git a/segmentation/clitkAnatomicalFeatureDatabase.h b/segmentation/clitkAnatomicalFeatureDatabase.h new file mode 100644 index 0000000..78f04e3 --- /dev/null +++ b/segmentation/clitkAnatomicalFeatureDatabase.h @@ -0,0 +1,61 @@ +/*========================================================================= + 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://oncora1.lyon.fnclcc.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 CLITKANATOMICALFEATUREDATABASE_H +#define CLITKANATOMICALFEATUREDATABASE_H + +// clitk +#include "clitkCommon.h" + +namespace clitk { + + //-------------------------------------------------------------------- + /* + Class to store and retreive anatomical feature such as 3D + named landmarks points. + */ + class AnatomicalFeatureDatabase: public itk::Object + { + public: + AnatomicalFeatureDatabase(); + + // Set/Get filename + itkSetMacro(Filename, std::string); + itkGetConstMacro(Filename, std::string); + + // Read and write DB + void Write(); + void Load(); + + // Get landmarks + typedef itk::Point PointType3D; + void SetPoint3D(std::string tag, PointType3D & p); + void GetPoint3D(std::string tag, PointType3D & p); + + protected: + std::string m_Filename; + typedef std::map MapTagType; + MapTagType m_MapOfTag; + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#endif // CLITKANATOMICALFEATUREDATABASE_H