Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTimeHelper.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 #ifndef MITKTIMEHELPER_H_HEADER_INCLUDED_C1C2FCD2
18 #define MITKTIMEHELPER_H_HEADER_INCLUDED_C1C2FCD2
19 
20 #include <mitkTimeGeometry.h>
21 
22 namespace mitk
23 {
24  //## @brief convert the start- and end-index-time of output-region in
25  //## start- and end-index-time of input-region via millisecond-time
26  template <class TOutputRegion, class TInputRegion>
27  void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry,
28  const TOutputRegion &outputRegion,
29  const mitk::TimeGeometry *inputTimeGeometry,
30  TInputRegion &inputRegion)
31  {
32  assert(outputTimeGeometry != nullptr);
33  assert(inputTimeGeometry != nullptr);
34 
35  // convert the start-index-time of output in start-index-time of input via millisecond-time
36  mitk::TimePointType timeInMS = outputTimeGeometry->TimeStepToTimePoint(outputRegion.GetIndex(3));
37  mitk::TimeStepType timestep = inputTimeGeometry->TimePointToTimeStep(timeInMS);
38  if ((timeInMS > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) &&
39  (inputTimeGeometry->IsValidTimeStep(timestep)))
40  inputRegion.SetIndex(3, timestep);
41  else
42  inputRegion.SetIndex(3, 0);
43  // convert the end-index-time of output in end-index-time of input via millisecond-time
44  timeInMS = outputTimeGeometry->TimeStepToTimePoint(outputRegion.GetIndex(3) + outputRegion.GetSize(3) - 1);
45  timestep = inputTimeGeometry->TimePointToTimeStep(timeInMS);
46  if ((timeInMS > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) &&
47  (outputTimeGeometry->IsValidTimeStep(timestep)))
48  inputRegion.SetSize(3, timestep - inputRegion.GetIndex(3) + 1);
49  else
50  inputRegion.SetSize(3, 1);
51  }
52 
53  //##Documentation
54  //## @brief convert the start- and end-index-time of output in
55  //## start- and end-index-time of input1 and input2 via millisecond-time
56  template <class TOutputData, class TInputData>
57  void GenerateTimeInInputRegion(const TOutputData *output, TInputData *input)
58  {
59  assert(output != nullptr);
60  assert(input != nullptr);
61 
62  const typename TOutputData::RegionType &outputRegion = output->GetRequestedRegion();
63  typename TInputData::RegionType inputRegion;
64 
65  if (outputRegion.GetSize(3) < 1)
66  {
67  typename TInputData::RegionType::SizeType inputsize;
68  inputsize.Fill(0);
69  inputRegion.SetSize(inputsize);
70  input->SetRequestedRegion(&inputRegion);
71  }
72 
73  // convert the start-index-time of output in start-index-time of input via millisecond-time
74  inputRegion = input->GetRequestedRegion();
75  GenerateTimeInInputRegion(output->GetTimeGeometry(), outputRegion, input->GetTimeGeometry(), inputRegion);
76  input->SetRequestedRegion(&inputRegion);
77  }
78 
79 } // end namespace mitk
80 
81 #endif // MITKTIMEHELPER_H_HEADER_INCLUDED_C1C2FCD2
DataCollection - Class to facilitate loading/accessing structured data.
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.