コード例 #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();
}
コード例 #2
0
mitk::ConnectomicsHistogramsContainer * mitk::ConnectomicsHistogramCache::operator[]( mitk::ConnectomicsNetwork::Pointer sp_NetworkData )
{
  BaseData *p_BaseData = dynamic_cast< BaseData* >( sp_NetworkData.GetPointer() );

  if(!p_BaseData)
  {
    MITK_WARN << "ConnectomicsHistogramCache::operator[] with null connectomics network data called";
    return nullptr;
  }

  ConnectomicsHistogramsCacheElement *elementToUpdate = nullptr;

  bool first( true );

  bool found( false );

  for(auto iter = cache.begin(); iter != cache.end(); iter++)
  {
    ConnectomicsHistogramsCacheElement *e = dynamic_cast<ConnectomicsHistogramsCacheElement *>(*iter);
    BaseData *p_tmp = e->baseData.Lock();

    if(p_tmp == p_BaseData)
    {
      if(!first)
      {
        cache.erase(iter);
        cache.push_front(e);
      }
      if( p_BaseData->GetMTime() > e->m_LastUpdateTime.GetMTime())
      {
        // found but needs an update
        found = true;
        elementToUpdate = e;
        break;
      }

      // found but no update needed
      return dynamic_cast<ConnectomicsHistogramsContainer*>( e->GetHistograms() );
    }

    first = false;
  }

  if( !found )
  {
    if (dynamic_cast<ConnectomicsNetwork*>(p_BaseData))
    {
      elementToUpdate = new ConnectomicsHistogramsCacheElement();
    }
    else
    {
      MITK_WARN << "not supported: " << p_BaseData->GetNameOfClass();
      return nullptr;
    }

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

  if(elementToUpdate)
  {
    elementToUpdate->ComputeFromBaseData(p_BaseData);
    elementToUpdate->m_LastUpdateTime.Modified();
    return dynamic_cast<ConnectomicsHistogramsContainer*>( elementToUpdate->GetHistograms() );
  }
  return nullptr;
}