21 void mitk::CropTimestepsImageFilter::VerifyInputImage(
const mitk::Image* inputImage)
const 24 mitkThrow() <<
"Input image is not initialized.";
27 mitkThrow() <<
"Input image volume is not set.";
31 if (
nullptr == geometry || !geometry->IsValid())
32 mitkThrow() <<
"Input image has invalid geometry.";
35 mitkThrow() <<
"CropTimestepsImageFilter only works with 2D+t and 3D+t images.";
39 mitkThrow() <<
"Input image has only one timestep.";
42 if (!geometry->GetImageGeometry())
43 mitkThrow() <<
"Geometry of input image is not an image geometry.";
46 void mitk::CropTimestepsImageFilter::GenerateOutputInformation()
50 if (m_LowerBoundaryTimestep > m_UpperBoundaryTimestep) {
51 mitkThrow() <<
"lower timestep is larger than upper timestep.";
54 m_UpperBoundaryTimestep = input->GetTimeSteps();
56 else if (m_UpperBoundaryTimestep > input->GetTimeSteps()) {
57 m_UpperBoundaryTimestep = input->GetTimeSteps();
58 MITK_WARN <<
"upper boundary timestep set to " << m_UpperBoundaryTimestep;
60 m_DesiredRegion = ComputeDesiredRegion();
61 unsigned int dimension = input->GetDimension();
62 auto dimensions =
new unsigned int[dimension];
63 itk2vtk(m_DesiredRegion.GetSize(), dimensions);
65 memcpy(dimensions + 3, input->GetDimensions() + 3, (dimension - 3) *
sizeof(
unsigned int));
67 dimensions[3] = m_UpperBoundaryTimestep - m_LowerBoundaryTimestep;
70 output->Initialize(
mitk::PixelType(input->GetPixelType()), dimension, dimensions);
72 auto newTimeGeometry = AdaptTimeGeometry(input->GetTimeGeometry(), m_LowerBoundaryTimestep, m_UpperBoundaryTimestep);
73 output->SetTimeGeometry(newTimeGeometry);
74 output->SetPropertyList(input->GetPropertyList());
80 auto index = desiredRegion.GetIndex();
81 auto size = desiredRegion.GetSize();
82 unsigned int timeDimension = 3;
83 index[timeDimension] = m_LowerBoundaryTimestep;
84 size[timeDimension] = m_UpperBoundaryTimestep - m_LowerBoundaryTimestep;
85 desiredRegion.SetIndex(index);
86 desiredRegion.SetSize(size);
93 newTimeGeometry->ClearAllGeometries();
94 for (
unsigned int timestep = startTimestep; timestep < endTimestep; timestep++) {
95 auto geometryForTimePoint = sourceGeometry->GetGeometryForTimeStep(timestep);
96 newTimeGeometry->AppendNewTimeStep(geometryForTimePoint,
97 sourceGeometry->GetMinimumTimePoint(timestep),
98 sourceGeometry->GetMaximumTimePoint(timestep));
100 return newTimeGeometry.GetPointer();
103 void mitk::CropTimestepsImageFilter::GenerateData()
105 const auto* inputImage = this->
GetInput();
108 if ((output->IsInitialized() ==
false))
113 timeSelector->SetInput(inputImage);
115 unsigned int timeStart = m_DesiredRegion.GetIndex(3);
116 unsigned int timeEnd = timeStart + m_DesiredRegion.GetSize(3);
117 for (
unsigned int timestep = timeStart; timestep < timeEnd; ++timestep)
119 timeSelector->SetTimeNr(timestep);
120 timeSelector->UpdateLargestPossibleRegion();
122 output->SetVolume(imageAccessorWithOneTimestep.GetData(), timestep-
timeStart);
131 Superclass::SetInput(image);
137 mitkThrow() <<
"Input index " << index <<
" is invalid.";
142 void mitk::CropTimestepsImageFilter::VerifyInputInformation()
144 Superclass::VerifyInputInformation();
bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
itk::SmartPointer< Self > Pointer
unsigned int GetDimension() const
Get dimension of the image.
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
mitk::Image::Pointer image
void itk2vtk(const Tin &in, Tout &out)
InputImageType * GetInput(void)
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
const RegionType & GetLargestPossibleRegion() const
unsigned int GetTimeSteps() const
Get the number of time steps from the TimeGeometry As the base data has not a data vector given by it...
OutputType * GetOutput()
Get the output data of this image source object.
ImageReadAccessor class to get locked read access for a particular image part.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
itk::SmartPointer< const Self > ConstPointer
void SetInput(const InputImageType *image) override
Sets the input image.
Class for defining the data type of pixels.