Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
mitkDataCollectionUtility.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 
14 #ifndef mitkDataCollectionUtility_h
15 #define mitkDataCollectionUtility_h
16 
17 
18 #include <mitkDataCollection.h>
19 
26 namespace mitk
27 {
28  class DataCollectionUtility
29  {
30  public:
31  template <class OriginImageType, class TargetImageType>
32  static void EnsureImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target);
33 
34  static void Compile()
35  {
37  std::string blub = "haha";
38  typedef itk::Image<double, 3> ImType;
39  EnsureImageInCollection<ImType, ImType>(col, blub, blub);
40  };
41 } // end namespace
42 
43 template <class OriginImageType, class TargetImageType>
44 void
45 mitk::DataCollectionUtility::EnsureDataImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target)
46 {
47  typedef typename TargetImageType FeatureImage;
48  typedef typename OriginImageType LabelImage;
49 
50  if (collection->HasElement(origin))
51  {
52  LabelImage::Pointer originImage = dynamic_cast<LabelImage*>(collection->GetData(origin).GetPointer());
53  if (!collection->HasElement(target) && originImage.IsNotNull())
54  {
55  FeatureImage::Pointer image = FeatureImage::New();
56  image->SetRegions(originImage->GetLargestPossibleRegion());
57  image->SetSpacing(originImage->GetSpacing());
58  image->SetOrigin(originImage->GetOrigin());
59  image->SetDirection(originImage->GetDirection());
60  image->Allocate();
61 
62  collection->AddData(dynamic_cast<itk::DataObject*>(image.GetPointer()),target,"");
63  }
64  }
65  for (std::size_t i = 0; i < collection->Size();++i)
66  {
67  mitk::DataCollection* newCol = dynamic_cast<mitk::DataCollection*>(collection->GetData(i).GetPointer());
68  if (newCol != 0)
69  {
70  EnsureDataImageInCollection(newCol, origin, target);
71  }
72  }
73 };
74 
75 #endif
mitk::DataCollection::New
static Pointer New()
itk::SmartPointer< Self >
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitkDataCollection.h
mitk::DataCollection
Definition: mitkDataCollection.h:54