Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkConnectomicsHistogramCache.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  BaseData *p_BaseData = dynamic_cast< BaseData* >( sp_NetworkData.GetPointer() );
30 
31  if(!p_BaseData)
32  {
33  MITK_WARN << "ConnectomicsHistogramCache::operator[] with null connectomics network data called";
34  return nullptr;
35  }
36 
37  ConnectomicsHistogramsCacheElement *elementToUpdate = nullptr;
38 
39  bool first( true );
40 
41  bool found( false );
42 
43  for(auto iter = cache.begin(); iter != cache.end(); iter++)
44  {
46  BaseData *p_tmp = e->baseData.GetPointer();
47 
48  if(p_tmp == p_BaseData)
49  {
50  if(!first)
51  {
52  cache.erase(iter);
53  cache.push_front(e);
54  }
55  if( p_BaseData->GetMTime() > e->m_LastUpdateTime.GetMTime())
56  {
57  // found but needs an update
58  found = true;
59  elementToUpdate = e;
60  break;
61  }
62 
63  // found but no update needed
64  return dynamic_cast<ConnectomicsHistogramsContainer*>( e->GetHistograms() );
65  }
66 
67  first = false;
68  }
69 
70  if( !found )
71  {
72  if (dynamic_cast<ConnectomicsNetwork*>(p_BaseData))
73  {
74  elementToUpdate = new ConnectomicsHistogramsCacheElement();
75  }
76  else
77  {
78  MITK_WARN << "not supported: " << p_BaseData->GetNameOfClass();
79  return nullptr;
80  }
81 
82  elementToUpdate->baseData = p_BaseData;
83  cache.push_front(elementToUpdate);
84  TrimCache();
85  }
86 
87  if(elementToUpdate)
88  {
89  elementToUpdate->ComputeFromBaseData(p_BaseData);
90  elementToUpdate->m_LastUpdateTime.Modified();
91  return dynamic_cast<ConnectomicsHistogramsContainer*>( elementToUpdate->GetHistograms() );
92  }
93  return nullptr;
94 }
95 
ConnectomicsHistogramsContainer * GetHistograms()
Base of all data objects.
Definition: mitkBaseData.h:39
void ComputeFromBaseData(BaseData *baseData) override
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
Provides a method to cache network histograms.
ConnectomicsHistogramsContainer * operator[](ConnectomicsNetwork::Pointer sp_NetworkData)