1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
20 //--------------------------------------------------------------------
21 template<class ImageType>
22 typename ImageType::Pointer AnatomicalFeatureDatabase::
23 GetImage(std::string tag)
25 if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
26 clitkExceptionMacro("Could not find the tag <" << tag << "> of type 'Image' in the DB ('"
27 << GetFilename() << "')");
30 typename ImageType::Pointer image;
31 if (m_MapOfImage[tag]) {
32 image = static_cast<ImageType *>(m_MapOfImage[tag]);
35 std::string s = m_MapOfTag[tag];
37 image = readImage<ImageType>(s);
38 // I add a reference count because the cache is not a smartpointer
39 image->SetReferenceCount(image->GetReferenceCount()+1);
40 // Insert into the cache
41 m_MapOfImage[tag] = &(*image); // pointer
46 //--------------------------------------------------------------------
49 //--------------------------------------------------------------------
50 template<class ImageType>
51 void AnatomicalFeatureDatabase::
52 SetImage(TagType tag, std::string f, typename ImageType::Pointer image, bool write)
54 SetImageFilename(tag, f);
55 m_MapOfImage[tag] = &(*image);
57 writeImage<ImageType>(image, f);
60 //--------------------------------------------------------------------
63 //--------------------------------------------------------------------
64 template<class ImageType>
65 void AnatomicalFeatureDatabase::
66 ReleaseImage(std::string tag)
68 if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
69 clitkExceptionMacro("Could not find the tag <" << tag << "> of type Image Filename in the DB");
74 if (m_MapOfImage[tag]) {
75 DD(m_MapOfImage[tag]->GetReferenceCount());
76 ImageType * image = static_cast<ImageType*>(m_MapOfImage[tag]);
77 image->SetReferenceCount(image->GetReferenceCount()-1);
78 m_MapOfImage.erase(tag);
80 DD(image->GetReferenceCount());
83 // DD(image->GetReferenceCount());
86 // Do nothing in this case (image not loaded)
90 //--------------------------------------------------------------------