X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkAnatomicalFeatureDatabase.cxx;h=a23deb40e86924f05451f0f478cf4f47704fec3d;hb=bf4928c59a1d39f53fe03deb4b73ecb7e1cf214b;hp=8bf17fbb57873f6f37150363512a7675ad9b7455;hpb=72375037f90c596a034b2ebe5e54e209e7b45511;p=clitk.git diff --git a/segmentation/clitkAnatomicalFeatureDatabase.cxx b/segmentation/clitkAnatomicalFeatureDatabase.cxx index 8bf17fb..a23deb4 100644 --- a/segmentation/clitkAnatomicalFeatureDatabase.cxx +++ b/segmentation/clitkAnatomicalFeatureDatabase.cxx @@ -114,46 +114,29 @@ double clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, int dim) //-------------------------------------------------------------------- void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D & p) { - if (m_MapOfTag.find(tag) == m_MapOfTag.end()) { + if (!TagExist(tag)) { clitkExceptionMacro("Could not find the tag <" << tag << "> of type Point3D in the DB"); + return; } - 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++) { + std::string s = m_MapOfTag[tag]; + + // construct a stream from the string + std::stringstream strstr(s); - if (!clitk::fromString(p[i], results[i].c_str())) { - clitkExceptionMacro("Error while reading Point3D, could not convert '" - << results[i].c_str() << "' into double."); - } + // 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); - // p[i] = atof(results[i].c_str()); - } + // parse the string into 3 doubles + for(int i=0; i<3; 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++; + if (!clitk::fromString(p[i], results[i].c_str())) { + clitkExceptionMacro("Error while reading Point3D, could not convert '" + << results[i].c_str() << "' into double."); } - */ } } //-------------------------------------------------------------------- @@ -167,4 +150,33 @@ void clitk::AnatomicalFeatureDatabase::SetImageFilename(std::string tag, std::st //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +bool clitk::AnatomicalFeatureDatabase::TagExist(std::string tag) +{ + return (m_MapOfTag.find(tag) != m_MapOfTag.end()); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +void clitk::AnatomicalFeatureDatabase::SetDouble(std::string tag, double value) +{ + m_MapOfTag[tag] = clitk::toString(value); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +double clitk::AnatomicalFeatureDatabase::GetDouble(std::string tag) +{ + if (!TagExist(tag)) { + clitkExceptionMacro("Could not find the tag <" << tag << "> of type Double in the DB"); + return -1; + } + double a; + if (!clitk::fromString(a, m_MapOfTag[tag])) { + clitkExceptionMacro("Error while reading Double (tag='" << tag << "'), could not convert '" + << m_MapOfTag[tag] << "' into double."); + } + return a; +} +//--------------------------------------------------------------------