static void EnsureDataImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target)
{
  typedef itk::Image<double, 3> FeatureImage;

  if (collection->HasElement(origin))
  {
    mitk::Image::Pointer originImage = dynamic_cast<mitk::Image*>(collection->GetMitkImage(origin).GetPointer());
    FeatureImage::Pointer itkOriginImage = FeatureImage::New();
    mitk::CastToItkImage(originImage,itkOriginImage);

    if (!collection->HasElement(target) && itkOriginImage.IsNotNull())
    {
      FeatureImage::Pointer image = FeatureImage::New();
      image->SetRegions(itkOriginImage->GetLargestPossibleRegion());
      image->SetSpacing(itkOriginImage->GetSpacing());
      image->SetOrigin(itkOriginImage->GetOrigin());
      image->SetDirection(itkOriginImage->GetDirection());
      image->Allocate();

      collection->AddData(dynamic_cast<itk::DataObject*>(image.GetPointer()),target,"");
    }
  }
  for (std::size_t i = 0; i < collection->Size();++i)
  {
    mitk::DataCollection* newCol = dynamic_cast<mitk::DataCollection*>(collection->GetData(i).GetPointer());
    if (newCol != 0)
    {
      EnsureDataImageInCollection(newCol, origin, target);
    }
  }
}
Exemplo n.º 2
0
void mitk::DCUtilities::EnsureUCharImageInDC(mitk::DataCollection::Pointer dc, std::string name, std::string origin)
{
  typedef itk::Image<unsigned char, 3> FeatureImage;
  typedef itk::Image<unsigned char, 3> LabelImage;

  mitk::DataCollectionImageIterator<unsigned char , 3> iter( dc, origin);
  while (!iter.IsAtEnd())
  {
    ++iter;
  }

  if (dc->HasElement(origin))
  {
    LabelImage::Pointer originImage = dynamic_cast<LabelImage*>(dc->GetData(origin).GetPointer());
    //    = dynamic_cast<LabelImage*>(dc->GetItkImage<LabelImage>(origin).GetPointer());
    if (!dc->HasElement(name) && originImage.IsNotNull())
    {
      MITK_INFO << "New unsigned char image necessary";
      FeatureImage::Pointer image = FeatureImage::New();
      image->SetRegions(originImage->GetLargestPossibleRegion());
      image->SetSpacing(originImage->GetSpacing());
      image->SetOrigin(originImage->GetOrigin());
      image->SetDirection(originImage->GetDirection());
      image->Allocate();
      image->FillBuffer(0);

      dc->AddData(dynamic_cast<itk::DataObject*>(image.GetPointer()),name,"");
    }
  }
  for (std::size_t i = 0; i < dc->Size();++i)
  {
    mitk::DataCollection* newCol = dynamic_cast<mitk::DataCollection*>(dc->GetData(i).GetPointer());
    if (newCol != 0)
    {
      EnsureUCharImageInDC(newCol, name, origin);
    }
  }
}