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);
    }
  }
}
예제 #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);
    }
  }
}
  void AddingImageAtFirstPositionIsPossible()
  {
    Init();
    mitk::DataCollectionSingleImageIterator<double, 3> iter(m_Collection, "T1");

    mitk::Image::Pointer im = mitk::ImageGenerator::GenerateRandomImage<double>(6,6,6,1,6,6,6,9,8);
    itk::Image<double, 3>::Pointer itkImage;
    mitk::CastToItkImage(im,itkImage);
    iter.AddImage(itkImage,"T3");

    itk::DataObject::Pointer obj = (dynamic_cast<mitk::DataCollection*> (col1->GetData("0001").GetPointer()))->GetData("T3");
    int spacing = dynamic_cast<itk::Image<double, 3> *> (obj.GetPointer())->GetSpacing()[0];
//    MITK_INFO << "Spacing: " << spacing;
    MITK_TEST_CONDITION_REQUIRED(spacing == 6, "Image is the first image (Checked by Spacing)");
  }