]> Creatis software - clitk.git/blobdiff - segmentation/clitkAnatomicalFeatureDatabase.cxx
morpho math filter
[clitk.git] / segmentation / clitkAnatomicalFeatureDatabase.cxx
index dbd05c61a30fcb8a628fef0150a7b6de8dfd3f37..8bf17fbb57873f6f37150363512a7675ad9b7455 100644 (file)
 // std
 #include <iterator>
 #include <sstream>
+#include <cctype>
+#include <functional>
 
 //--------------------------------------------------------------------
 clitk::AnatomicalFeatureDatabase::AnatomicalFeatureDatabase() 
 { 
-  SetFilename("noname.afdb"); 
+  SetFilename("default.afdb"); 
 }
 //--------------------------------------------------------------------
 
@@ -69,6 +71,7 @@ static inline std::string &trim(std::string &s) {
 //--------------------------------------------------------------------
 void clitk::AnatomicalFeatureDatabase::Load() 
 {
+  m_MapOfTag.clear();
   // open file
   std::ifstream is;
   openFileForReading(is, GetFilename());
@@ -76,11 +79,14 @@ void clitk::AnatomicalFeatureDatabase::Load()
   while (!is.fail()) {
     std::string tag;
     is >> tag; 
-    std::string value;
-    std::getline(is,value,'\n');
-    ltrim(value); // remove leading space
-    m_MapOfTag[tag] = value;
+    if (tag != "") {
+      std::string value;
+      std::getline(is,value,'\n');
+      ltrim(value); // remove leading space
+      m_MapOfTag[tag] = value;
+    }
   }
+  is.close();
 }
 //--------------------------------------------------------------------
 
@@ -95,6 +101,16 @@ void clitk::AnatomicalFeatureDatabase::SetPoint3D(std::string tag, PointType3D &
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+double clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, int dim)
+{
+  PointType3D p;
+  GetPoint3D(tag, p);
+  return p[dim];
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D & p)
 {
@@ -115,7 +131,13 @@ void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D &
 
     // parse the string into 3 doubles
     for(int i=0; i<3; i++) {
-      p[i] = atof(results[i].c_str());
+
+      if (!clitk::fromString<double>(p[i], results[i].c_str())) {
+        clitkExceptionMacro("Error while reading Point3D, could not convert '" 
+                            << results[i].c_str() << "' into double.");
+      }
+
+        //      p[i] = atof(results[i].c_str());
     }
 
     /*
@@ -144,3 +166,5 @@ void clitk::AnatomicalFeatureDatabase::SetImageFilename(std::string tag, std::st
 }
 //--------------------------------------------------------------------
 
+
+