Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageTimeSelector.cpp
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 #include "mitkImageTimeSelector.h"
18 
19 mitk::ImageTimeSelector::ImageTimeSelector() : m_TimeNr(0), m_ChannelNr(0)
20 {
21 }
22 
24 {
25 }
26 
28 {
29  Image::ConstPointer input = this->GetInput();
30  Image::Pointer output = this->GetOutput();
31 
32  itkDebugMacro(<< "GenerateOutputInformation()");
33 
34  int dim = (input->GetDimension() < 3 ? input->GetDimension() : 3);
35  output->Initialize(input->GetPixelType(), dim, input->GetDimensions());
36 
37  if ((unsigned int)m_TimeNr >= input->GetDimension(3))
38  {
39  m_TimeNr = input->GetDimension(3) - 1;
40  }
41 
42  // initialize geometry
43  mitk::SlicedGeometry3D::Pointer sliced_geo = input->GetSlicedGeometry(m_TimeNr);
44  if (sliced_geo.IsNull())
45  {
46  mitkThrow() << "Failed to retrieve SlicedGeometry from input at timestep " << m_TimeNr;
47  }
48 
49  mitk::SlicedGeometry3D::Pointer sliced_geo_clone = sliced_geo->Clone();
50  if (sliced_geo_clone.IsNull())
51  {
52  mitkThrow() << "Failed to clone the retrieved sliced geometry.";
53  }
54 
55  mitk::BaseGeometry::Pointer geom_3d = dynamic_cast<BaseGeometry *>(sliced_geo_clone.GetPointer());
56  if (geom_3d.IsNotNull())
57  {
58  output->SetGeometry(geom_3d.GetPointer());
59  }
60  else
61  {
62  mitkThrow() << "Failed to cast the retrieved SlicedGeometry to a Geometry3D object.";
63  }
64 
65  output->SetPropertyList(input->GetPropertyList()->Clone());
66 }
67 
69 {
70  const Image::RegionType &requestedRegion = this->GetOutput()->GetRequestedRegion();
71 
72  // do we really need a complete volume at a time?
73  if (requestedRegion.GetSize(2) > 1)
74  {
75  mitk::ImageDataItem::Pointer im = this->GetVolumeData(m_TimeNr, m_ChannelNr)->Clone();
76  im->SetTimestep(0);
77  im->SetManageMemory(0);
78  this->SetVolumeItem(im, 0);
79  }
80  else
81  // no, so take just a slice!
82  this->SetSliceItem(
83  this->GetSliceData(requestedRegion.GetIndex(2), m_TimeNr, m_ChannelNr), requestedRegion.GetIndex(2), 0);
84 }
85 
87 {
88  Superclass::GenerateInputRequestedRegion();
89 
91  const_cast<mitk::ImageToImageFilter::InputImageType *>(this->GetInput());
92  Image::Pointer output = this->GetOutput();
93 
94  Image::RegionType requestedRegion;
95  requestedRegion = output->GetRequestedRegion();
96  requestedRegion.SetIndex(3, m_TimeNr);
97  requestedRegion.SetIndex(4, m_ChannelNr);
98  requestedRegion.SetSize(3, 1);
99  requestedRegion.SetSize(4, 1);
100 
101  input->SetRequestedRegion(&requestedRegion);
102 }
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
virtual void GenerateOutputInformation() override
virtual void GenerateInputRequestedRegion() override
itk::ImageRegion< RegionDimension > RegionType
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:76
BaseGeometry Describes the geometry of a data object.