]> Creatis software - clitk.git/commitdiff
Add New(), GetValueTag and Path (to search for image)
authorDavid Sarrut <david.sarrut@gmail.com>
Thu, 27 Oct 2011 13:51:52 +0000 (15:51 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Thu, 27 Oct 2011 13:51:52 +0000 (15:51 +0200)
segmentation/clitkAnatomicalFeatureDatabase.cxx
segmentation/clitkAnatomicalFeatureDatabase.h

index c86b2df07f7e4d056463861196589b9c7364ece0..0f5bfdd64a549714aef543b9ddc60801e0cc95bd 100644 (file)
 //--------------------------------------------------------------------
 clitk::AnatomicalFeatureDatabase::AnatomicalFeatureDatabase() 
 { 
-  SetFilename("default.afdb"); 
+  SetFilename("default.afdb");
+  SetPath("./");
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+clitk::AnatomicalFeatureDatabase::Pointer clitk::AnatomicalFeatureDatabase::New(std::string filename) 
+{ 
+  Pointer a = AnatomicalFeatureDatabase::New();
+  a->SetFilename(filename);
+  a->Load();
+  return a;
 }
 //--------------------------------------------------------------------
 
@@ -115,6 +127,19 @@ double clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, int dim)
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+std::string clitk::AnatomicalFeatureDatabase::GetTagValue(std::string tag)
+{
+  if (!TagExist(tag)) {
+    clitkExceptionMacro("Could not find the tag <" << tag << "> in the DB");
+    return "";
+  }
+  std::string s = m_MapOfTag[tag];
+  return s;
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void clitk::AnatomicalFeatureDatabase::GetPoint3D(std::string tag, PointType3D & p)
 {
index bd574d384fa3107f7bc5aea8628c65bc893574fd..59e8decc07e2008c71996d3f7d3c237495035518 100644 (file)
@@ -34,10 +34,17 @@ namespace clitk {
   class AnatomicalFeatureDatabase: public itk::Object
   {
   public:
-    AnatomicalFeatureDatabase();
-
+    // typedef
     typedef std::string TagType;
 
+    // New macro
+    typedef itk::Object                    Superclass;
+    typedef AnatomicalFeatureDatabase      Self;
+    typedef itk::SmartPointer<Self>        Pointer;
+    typedef itk::SmartPointer<const Self>  ConstPointer;
+    itkNewMacro(Self);
+    static Pointer New(std::string filename);
+
     // Set/Get filename 
     itkSetMacro(Filename, std::string);
     itkGetConstMacro(Filename, std::string);
@@ -45,6 +52,8 @@ namespace clitk {
     // Read and write DB
     void Write();
     void Load();
+    itkGetConstMacro(Path, std::string);
+    itkSetMacro(Path, std::string);
     
     // Set Get landmarks
     typedef itk::Point<double,3> PointType3D;
@@ -52,7 +61,8 @@ namespace clitk {
     void GetPoint3D(TagType tag, PointType3D & p);
     double GetPoint3D(std::string tag, int dim);
     bool TagExist(std::string tag);
-    
+    std::string GetTagValue(std::string tag);
+
     // Set Get image
     void SetImageFilename(TagType tag, std::string f);
     template<class ImageType>
@@ -70,16 +80,23 @@ namespace clitk {
     void RemoveTag(TagType tag);
 
   protected:
+    AnatomicalFeatureDatabase();
+    ~AnatomicalFeatureDatabase() {}
+
     std::string m_Filename;
+    std::string m_Path;
     typedef itk::ImageBase<3> ImageBaseType;
     typedef std::map<TagType, std::string> MapTagType;
-        typedef std::map<TagType, ImageBaseType*> MapTagImageType; 
+    typedef std::map<TagType, ImageBaseType*> MapTagImageType; 
     MapTagType m_MapOfTag;
     MapTagImageType m_MapOfImage;
 
   }; // end class
   //--------------------------------------------------------------------
 
+#define NewAFDB(NAME, FILE)                                             \
+  clitk::AnatomicalFeatureDatabase::Pointer NAME = clitk::AnatomicalFeatureDatabase::New(FILE);
+
   #include "clitkAnatomicalFeatureDatabase.txx" 
 
 } // end namespace clitk