Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 (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 #ifndef mitkTimeHelper_h
14 #define mitkTimeHelper_h
15 
16 #include <mitkTimeGeometry.h>
17 
18 namespace mitk
19 {
20  //## @brief convert the start- and end-index-time of output-region in
21  //## start- and end-index-time of input-region via millisecond-time
22  template <class TOutputRegion, class TInputRegion>
23  void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry,
24  const TOutputRegion &outputRegion,
25  const mitk::TimeGeometry *inputTimeGeometry,
26  TInputRegion &inputRegion)
27  {
28  assert(outputTimeGeometry != nullptr);
29  assert(inputTimeGeometry != nullptr);
30 
31  // convert the start-index-time of output in start-index-time of input via millisecond-time
32  mitk::TimePointType timeInMS = outputTimeGeometry->TimeStepToTimePoint(outputRegion.GetIndex(3));
33  mitk::TimeStepType timestep = inputTimeGeometry->TimePointToTimeStep(timeInMS);
34  if ((timeInMS > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) &&
35  (inputTimeGeometry->IsValidTimeStep(timestep)))
36  inputRegion.SetIndex(3, timestep);
37  else
38  inputRegion.SetIndex(3, 0);
39  // convert the end-index-time of output in end-index-time of input via millisecond-time
40  timeInMS = outputTimeGeometry->TimeStepToTimePoint(outputRegion.GetIndex(3) + outputRegion.GetSize(3) - 1);
41  timestep = inputTimeGeometry->TimePointToTimeStep(timeInMS);
42  if ((timeInMS > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) &&
43  (outputTimeGeometry->IsValidTimeStep(timestep)))
44  inputRegion.SetSize(3, timestep - inputRegion.GetIndex(3) + 1);
45  else
46  inputRegion.SetSize(3, 1);
47  }
48 
49  //##Documentation
50  //## @brief convert the start- and end-index-time of output in
51  //## start- and end-index-time of input1 and input2 via millisecond-time
52  template <class TOutputData, class TInputData>
53  void GenerateTimeInInputRegion(const TOutputData *output, TInputData *input)
54  {
55  assert(output != nullptr);
56  assert(input != nullptr);
57 
58  const typename TOutputData::RegionType &outputRegion = output->GetRequestedRegion();
59  typename TInputData::RegionType inputRegion;
60 
61  if (outputRegion.GetSize(3) < 1)
62  {
63  typename TInputData::RegionType::SizeType inputsize;
64  inputsize.Fill(0);
65  inputRegion.SetSize(inputsize);
66  input->SetRequestedRegion(&inputRegion);
67  }
68 
69  // convert the start-index-time of output in start-index-time of input via millisecond-time
70  inputRegion = input->GetRequestedRegion();
71  GenerateTimeInInputRegion(output->GetTimeGeometry(), outputRegion, input->GetTimeGeometry(), inputRegion);
72  input->SetRequestedRegion(&inputRegion);
73  }
74 
75 } // end namespace mitk
76 
77 #endif
mitk::TimeGeometry
Definition: mitkTimeGeometry.h:43
mitk::GenerateTimeInInputRegion
void GenerateTimeInInputRegion(const mitk::TimeGeometry *outputTimeGeometry, const TOutputRegion &outputRegion, const mitk::TimeGeometry *inputTimeGeometry, TInputRegion &inputRegion)
Definition: mitkTimeHelper.h:23
mitk::TimeGeometry::TimeStepToTimePoint
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const =0
Converts a time step to a time point.
mitkTimeGeometry.h
mitk::TimeGeometry::TimePointToTimeStep
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::TimeGeometry::IsValidTimeStep
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is available.
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitk::TimePointType
mitk::ScalarType TimePointType
Definition: mitkTimeGeometry.h:26