void Init() { im1 = mitk::ImageGenerator::GenerateRandomImage<double>(2,2,2,1,2,2,2,1,0); im2 = mitk::ImageGenerator::GenerateRandomImage<double>(3,3,3,1,3,3,3,3,2); im3 = mitk::ImageGenerator::GenerateRandomImage<double>(4,4,4,1,4,4,4,5,4); im4 = mitk::ImageGenerator::GenerateRandomImage<double>(5,5,5,1,5,5,5,7,6); dataCol1 = mitk::DataCollection::New(); dataCol2 = mitk::DataCollection::New(); dataCol1->AddData(im1.GetPointer(),"T1"); dataCol1->AddData(im2.GetPointer(),"T2"); dataCol2->AddData(im3.GetPointer(),"T1"); dataCol2->AddData(im4.GetPointer(),"T2"); col1 = mitk::DataCollection::New(); col1->SetName("GnaBla"); col1->AddData(dataCol1.GetPointer(), "0001"); col1->AddData(dataCol2.GetPointer(), "0002"); m_Collection = mitk::DataCollection::New(); m_Collection->SetName("DummyCollection"); m_Collection->AddData(col1.GetPointer(), "C1"); }
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); } } }
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)"); }
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); } } }