]> Creatis software - clitk.git/blobdiff - segmentation/clitkAnatomicalFeatureDatabase.txx
Romulo:
[clitk.git] / segmentation / clitkAnatomicalFeatureDatabase.txx
index f1ee25ebc8b863d855e4ecb052aaa77e02a1ef27..1aad4f6eec882f08f2ee2964feb095b75b4258f6 100644 (file)
@@ -20,7 +20,7 @@
 //--------------------------------------------------------------------
 template<class ImageType>
 typename ImageType::Pointer AnatomicalFeatureDatabase::
-GetImage(std::string tag)
+GetImage(std::string tag, bool reload)
 {
   if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
     clitkExceptionMacro("Could not find the tag <" << tag << "> of type 'Image' in the DB ('"
@@ -28,7 +28,7 @@ GetImage(std::string tag)
   }
   else {
     typename ImageType::Pointer image;
-    if (m_MapOfImage[tag]) {
+    if ((!reload) && (m_MapOfImage[tag])) {
       image = static_cast<ImageType *>(m_MapOfImage[tag]);
     }
     else {
@@ -37,7 +37,8 @@ GetImage(std::string tag)
       image = readImage<ImageType>(s);
       // I add a reference count because the cache is not a smartpointer
       image->SetReferenceCount(image->GetReferenceCount()+1);
-      // Insert into the cache 
+      // Insert into the cache
+      m_MapOfImage.erase(tag); 
       m_MapOfImage[tag] = &(*image); // pointer
     }
     return image;
@@ -53,6 +54,8 @@ SetImage(TagType tag, std::string f, typename ImageType::Pointer image, bool wri
 {
   SetImageFilename(tag, f);
   m_MapOfImage[tag] = &(*image);
+  // I add a reference count because the cache is not a smartpointer
+  image->SetReferenceCount(image->GetReferenceCount()+1);
   if (write) {
     writeImage<ImageType>(image, f);
   }
@@ -69,22 +72,9 @@ ReleaseImage(std::string tag)
     clitkExceptionMacro("Could not find the tag <" << tag << "> of type Image Filename in the DB");
   }
   else {
-    DD("TODO");
-    exit(0);
-     if (m_MapOfImage[tag]) {
-      DD(m_MapOfImage[tag]->GetReferenceCount());
-      ImageType * image = static_cast<ImageType*>(m_MapOfImage[tag]);
-      image->SetReferenceCount(image->GetReferenceCount()-1);
-      m_MapOfImage.erase(tag);
-      /*
-      DD(image->GetReferenceCount());
-      image->Delete();
-      */
-      //      DD(image->GetReferenceCount());
-    }
-    else {
-      // Do nothing in this case (image not loaded)
-    }
+    typename ImageType::Pointer image = GetImage<ImageType>(tag);
+    image->SetReferenceCount(image->GetReferenceCount()-1);
+    m_MapOfImage.erase(tag);
   }
 }
 //--------------------------------------------------------------------