Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 
18 #ifndef mitkDataCollectionUtilit_h
19 #define mitkDataCollectionUtilit_h
20 
21 
22 #include <mitkDataCollection.h>
23 
30 namespace mitk
31 {
32  class DataCollectionUtility
33  {
34  public:
35  template <class OriginImageType, class TargetImageType>
36  static void EnsureImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target);
37 
38  static void Compile()
39  {
41  std::string blub = "haha";
42  typedef itk::Image<double, 3> ImType;
43  EnsureImageInCollection<ImType, ImType>(col, blub, blub);
44  };
45 } // end namespace
46 
47 template <class OriginImageType, class TargetImageType>
48 void
49 mitk::DataCollectionUtility::EnsureDataImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target)
50 {
51  typedef typename TargetImageType FeatureImage;
52  typedef typename OriginImageType LabelImage;
53 
54  if (collection->HasElement(origin))
55  {
56  LabelImage::Pointer originImage = dynamic_cast<LabelImage*>(collection->GetData(origin).GetPointer());
57  if (!collection->HasElement(target) && originImage.IsNotNull())
58  {
60  image->SetRegions(originImage->GetLargestPossibleRegion());
61  image->SetSpacing(originImage->GetSpacing());
62  image->SetOrigin(originImage->GetOrigin());
63  image->SetDirection(originImage->GetDirection());
64  image->Allocate();
65 
66  collection->AddData(dynamic_cast<itk::DataObject*>(image.GetPointer()),target,"");
67  }
68  }
69  for (std::size_t i = 0; i < collection->Size();++i)
70  {
71  mitk::DataCollection* newCol = dynamic_cast<mitk::DataCollection*>(collection->GetData(i).GetPointer());
72  if (newCol != 0)
73  {
74  EnsureDataImageInCollection(newCol, origin, target);
75  }
76  }
77 };
78 
79 
81 #endif //mitkDataCollectionUtilit_h
itk::Image< mitk::ScalarType, 3 > FeatureImage
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
static void EnsureDataImageInCollection(mitk::DataCollection::Pointer collection, std::string origin, std::string target)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.