X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkAnatomicalFeatureDatabase.txx;h=02907716c64c198674b95699cc15b481a657a201;hb=e3dfdd2305abb337638468aaca3d9b20718b5026;hp=ae4567bab60b1c9a1dbc701ea59fce1e131fdc4e;hpb=756f7290b30fcc91e2a52efdb233716f43c04c92;p=clitk.git diff --git a/segmentation/clitkAnatomicalFeatureDatabase.txx b/segmentation/clitkAnatomicalFeatureDatabase.txx index ae4567b..0290771 100644 --- a/segmentation/clitkAnatomicalFeatureDatabase.txx +++ b/segmentation/clitkAnatomicalFeatureDatabase.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,22 +14,67 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ //-------------------------------------------------------------------- template 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 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 ((!reload) && (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.erase(tag); + 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); + // I add a reference count because the cache is not a smartpointer + image->SetReferenceCount(image->GetReferenceCount()+1); + 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 { + typename ImageType::Pointer image = GetImage(tag); + image->SetReferenceCount(image->GetReferenceCount()-1); + m_MapOfImage.erase(tag); + } +} +//--------------------------------------------------------------------