1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
20 #include "clitkAnatomicalFeatureDatabase.h"
26 //--------------------------------------------------------------------
27 clitk::AnatomicalFeatureDatabase::AnatomicalFeatureDatabase()
29 SetFilename("noname.afdb");
31 //--------------------------------------------------------------------
34 //--------------------------------------------------------------------
35 void clitk::AnatomicalFeatureDatabase::Write()
39 openFileForWriting(os, GetFilename());
40 MapTagType::const_iterator iter = m_MapOfTag.begin();
41 while (iter != m_MapOfTag.end()) {
42 os << iter->first << " " << iter->second << std::endl;
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 void clitk::AnatomicalFeatureDatabase::Load()
55 openFileForReading(is, GetFilename());
56 // load line by line string/string
61 std::getline(is,value,'\n');
62 m_MapOfTag[tag] = value;
65 //--------------------------------------------------------------------
68 //--------------------------------------------------------------------
69 void clitk::AnatomicalFeatureDatabase::SetPoint3D(std::string tag, PointType3D & p)
71 ::itk::OStringStream value;
72 value << p[0] << " " << p[1] << " " << p[2];
73 m_MapOfTag[tag] = value.str();
75 //--------------------------------------------------------------------
78 //--------------------------------------------------------------------
79 void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D & p)
81 if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
82 clitkExceptionMacro("Could not find the tag <" << tag << "> of type Point3D in the DB");
85 std::string s = m_MapOfTag[tag];
87 // construct a stream from the string
88 std::stringstream strstr(s);
90 // use stream iterators to copy the stream to the vector as
91 // whitespace separated strings
92 std::istream_iterator<std::string> it(strstr);
93 std::istream_iterator<std::string> end;
94 std::vector<std::string> results(it, end);
96 // parse the string into 3 doubles
97 for(int i=0; i<3; i++) {
99 p[i] = atof(results[i].c_str());
105 #include <boost/foreach.hpp>
106 #include <boost/tokenizer.hpp>
107 // parse the string into 3 doubles
108 boost::char_separator<char> sep(", ");
109 boost::tokenizer<boost::char_separator<char> > tokens(s, sep);
111 BOOST_FOREACH(std::string t, tokens) {
112 std::cout << t << "." << std::endl;
113 p[i] = atof(t.c_str());
119 //--------------------------------------------------------------------