X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkAnatomicalFeatureDatabase.txx;h=f1ee25ebc8b863d855e4ecb052aaa77e02a1ef27;hb=1fea92ac237c16c1f027ffabdb42066f6f4f6114;hp=ae4567bab60b1c9a1dbc701ea59fce1e131fdc4e;hpb=756f7290b30fcc91e2a52efdb233716f43c04c92;p=clitk.git diff --git a/segmentation/clitkAnatomicalFeatureDatabase.txx b/segmentation/clitkAnatomicalFeatureDatabase.txx index ae4567b..f1ee25e 100644 --- a/segmentation/clitkAnatomicalFeatureDatabase.txx +++ b/segmentation/clitkAnatomicalFeatureDatabase.txx @@ -23,13 +23,68 @@ typename ImageType::Pointer AnatomicalFeatureDatabase:: GetImage(std::string tag) { if (m_MapOfTag.find(tag) == m_MapOfTag.end()) { - clitkExceptionMacro("Could not find the tag <" << tag << "> of type Image Filename in the DB"); + clitkExceptionMacro("Could not find the tag <" << tag << "> of type 'Image' in the DB ('" + << GetFilename() << "')"); } else { - std::string s = m_MapOfTag[tag]; - // Read the file - typename ImageType::Pointer image = readImage(s); + typename ImageType::Pointer image; + if (m_MapOfImage[tag]) { + image = static_cast(m_MapOfImage[tag]); + } + else { + std::string s = m_MapOfTag[tag]; + // Read the file + image = readImage(s); + // I add a reference count because the cache is not a smartpointer + image->SetReferenceCount(image->GetReferenceCount()+1); + // Insert into the cache + m_MapOfImage[tag] = &(*image); // pointer + } return image; } } //-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void AnatomicalFeatureDatabase:: +SetImage(TagType tag, std::string f, typename ImageType::Pointer image, bool write) +{ + SetImageFilename(tag, f); + m_MapOfImage[tag] = &(*image); + if (write) { + writeImage(image, f); + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void AnatomicalFeatureDatabase:: +ReleaseImage(std::string tag) +{ + if (m_MapOfTag.find(tag) == m_MapOfTag.end()) { + 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(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) + } + } +} +//--------------------------------------------------------------------