X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkAnatomicalFeatureDatabase.txx;h=72e9dcdd06b9293742aa70dac935eb9d58ff4421;hb=ee568ccc2ae2be4d9d60967e522e2d81cb148d95;hp=7ec7f971ac05143d9afdf69b441f1b510c860662;hpb=bf4928c59a1d39f53fe03deb4b73ecb7e1cf214b;p=clitk.git diff --git a/segmentation/clitkAnatomicalFeatureDatabase.txx b/segmentation/clitkAnatomicalFeatureDatabase.txx index 7ec7f97..72e9dcd 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,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ //-------------------------------------------------------------------- @@ -34,7 +34,7 @@ GetImage(std::string tag, bool reload) else { std::string s = m_MapOfTag[tag]; // Read the file - image = readImage(s); + image = readImage(GetPath()+"/"+s); // I add a reference count because the cache is not a smartpointer image->SetReferenceCount(image->GetReferenceCount()+1); // Insert into the cache @@ -47,6 +47,39 @@ GetImage(std::string tag, bool reload) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +bool AnatomicalFeatureDatabase:: +CheckImage(std::string tag) +{ + if (m_MapOfTag.find(tag) == m_MapOfTag.end()) { + return false; + } + else { + typename ImageType::Pointer image; + if (m_MapOfImage[tag]) { + image = static_cast(m_MapOfImage[tag]); + } + else { + std::string s = m_MapOfTag[tag]; + // Read the file + std::string n = GetPath()+"/"+s; + // image = readImage(); + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(n.c_str()); + try { + reader->Update(); + } catch(itk::ExceptionObject & err) { + return false; + } + } + } + return true; +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void AnatomicalFeatureDatabase:: @@ -54,6 +87,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(image, f); } @@ -71,7 +106,6 @@ ReleaseImage(std::string tag) } else { typename ImageType::Pointer image = GetImage(tag); - DD(image->GetReferenceCount()); image->SetReferenceCount(image->GetReferenceCount()-1); m_MapOfImage.erase(tag); }