X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkAnatomicalFeatureDatabase.txx;h=dc7c39a6652d9672e44543e317ec22860e1afd3d;hb=bffde3a7ae834139793d8c00f73986879146b0e0;hp=c155d44084c2581a6940e03069fee49f7bc9de03;hpb=d9caeb637df099fbc667f2442728aae256df3236;p=clitk.git diff --git a/segmentation/clitkAnatomicalFeatureDatabase.txx b/segmentation/clitkAnatomicalFeatureDatabase.txx index c155d44..dc7c39a 100644 --- a/segmentation/clitkAnatomicalFeatureDatabase.txx +++ b/segmentation/clitkAnatomicalFeatureDatabase.txx @@ -34,7 +34,10 @@ GetImage(std::string tag, bool reload) else { std::string s = m_MapOfTag[tag]; // Read the file - image = readImage(GetPath()+"/"+s); + if (s[0] != '/') + image = readImage(GetPath() + "/" + s); + else + image = readImage(s); // I add a reference count because the cache is not a smartpointer image->SetReferenceCount(image->GetReferenceCount()+1); // Insert into the cache @@ -47,6 +50,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::