Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkTimeNavigationController.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 TimeNavigationController_h
14 #define TimeNavigationController_h
15 
16 #include <MitkCoreExports.h>
17 
18 #include <mitkBaseController.h>
19 #include <mitkTimeGeometry.h>
20 
21 #include <itkCommand.h>
22 
23 namespace mitk
24 {
70  {
71  public:
72 
74  itkNewMacro(Self);
75 
83  void SetInputWorldTimeGeometry(const TimeGeometry* geometry);
84  itkGetConstObjectMacro(InputWorldTimeGeometry, mitk::TimeGeometry);
85 
91  virtual void Update();
92 
99  virtual void SendTime();
100 
101  class MITKCORE_EXPORT TimeEvent : public itk::AnyEvent
102  {
103  public:
104 
105  typedef TimeEvent Self;
106  typedef itk::AnyEvent Superclass;
107 
108  TimeEvent(TimeStepType timeStep) : m_TimeStep(timeStep) {}
109  ~TimeEvent() override {}
110  const char *GetEventName() const override { return "TimeEvent"; }
111  bool CheckEvent(const ::itk::EventObject *e) const override { return dynamic_cast<const Self *>(e); }
112  ::itk::EventObject *MakeObject() const override { return new Self(m_TimeStep); }
113  TimeStepType GetTimeStep() const { return m_TimeStep; }
114  private:
115 
116  TimeStepType m_TimeStep;
117  void operator=(const Self &);
118  };
119 
120  template <typename T>
121  void ConnectTimeEvent(T* receiver)
122  {
123  typedef typename itk::ReceptorMemberCommand<T>::Pointer ReceptorMemberCommandPointer;
124  ReceptorMemberCommandPointer eventReceptorCommand = itk::ReceptorMemberCommand<T>::New();
125  eventReceptorCommand->SetCallbackFunction(receiver, &T::SetGeometryTime);
126  unsigned long tag = AddObserver(TimeEvent(0), eventReceptorCommand);
127  m_ReceiverToObserverTagsMap[static_cast<void *>(receiver)].push_back(tag);
128  }
129 
130  // use a templated method to get the right offset when casting to void*
131  template <typename T>
132  void Disconnect(T* receiver)
133  {
134  auto i = m_ReceiverToObserverTagsMap.find(static_cast<void*>(receiver));
135  if (i == m_ReceiverToObserverTagsMap.end())
136  return;
137  const std::list<unsigned long>& tags = i->second;
138  for (auto tagIter = tags.begin(); tagIter != tags.end(); ++tagIter)
139  {
140  RemoveObserver(*tagIter);
141  }
142  m_ReceiverToObserverTagsMap.erase(i);
143  }
144 
149 
156 
157  protected:
158 
161 
162  TimeGeometry::ConstPointer m_InputWorldTimeGeometry;
163 
165 
166  typedef std::map<void*, std::list<unsigned long>> ObserverTagsMapType;
168  };
169 
170 } // namespace mitk
171 
172 #endif
#define MITKCORE_EXPORT
Baseclass for renderer slice-/camera-/time-control.
bool CheckEvent(const ::itk::EventObject *e) const override
::itk::EventObject * MakeObject() const override
Controls the time-related properties of the time stepper, according to the given input world time geo...
TimePointType GetSelectedTimePoint() const
Convenience method that returns the time point that corresponds to the selected time step....
virtual void Update()
Do the actual time-related properties extraction and send the currently selected time step to the con...
virtual void SendTime()
Send the currently selected time step to the connected observers (renderers).
TimeGeometry::ConstPointer m_InputWorldTimeGeometry
TimeStepType GetSelectedTimeStep() const
Convenience method that returns the time step currently selected by the controller.
mitkClassMacro(TimeNavigationController, BaseController)
std::map< void *, std::list< unsigned long > > ObserverTagsMapType
void SetInputWorldTimeGeometry(const TimeGeometry *geometry)
Set the input time geometry out of which the time-related properties will be generated.
Find image slices visible on a given plane.
std::size_t TimeStepType
mitk::ScalarType TimePointType