Exemplo n.º 1
0
SimpleHistogram* SimpleHistogramCache::operator[](BaseData::Pointer sp_BaseData)
{
  BaseData *p_BaseData = sp_BaseData.GetPointer();

  if(!p_BaseData)
  {
    MITK_WARN << "SimpleHistogramCache::operator[] with null base data called";
    return 0;
  }

  Element *elementToUpdate = 0;

  bool first = true;

  for(CacheContainer::iterator iter = cache.begin(); iter != cache.end(); iter++)
  {
    Element *e = *iter;
    BaseData *p_tmp = e->baseData.GetPointer();

    if(p_tmp == p_BaseData)
    {
      if(!first)
      {
        cache.erase(iter);
        cache.push_front(e);
      }
      if( p_BaseData->GetMTime() > e->m_LastUpdateTime.GetMTime())
        goto recomputeElement;

      //MITK_INFO << "using a cached histogram";

      return e->GetHistogram();
    }

    first = false;
  }

  if (dynamic_cast<Image*>(p_BaseData))
  {
    elementToUpdate = new ImageHistogramCacheElement();
  }
  else if (dynamic_cast<UnstructuredGrid*>(p_BaseData))
  {
    elementToUpdate = new UnstructuredGridHistogramCacheElement();
  }
  else
  {
    MITK_WARN << "not supported: " << p_BaseData->GetNameOfClass();
  }

  elementToUpdate->baseData = p_BaseData;
  cache.push_front(elementToUpdate);
  TrimCache();

  recomputeElement:

  //MITK_INFO << "computing a new histogram";

  elementToUpdate->ComputeFromBaseData(p_BaseData);
  elementToUpdate->m_LastUpdateTime.Modified();
  return elementToUpdate->GetHistogram();
}