Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkSliceNavigationController.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 mitkSliceNavigationController_h
14 #define mitkSliceNavigationController_h
15 
16 #include <MitkCoreExports.h>
17 
18 #include <mitkBaseController.h>
19 #include <mitkMessage.h>
20 #include <mitkAnatomicalPlanes.h>
21 #include <mitkRenderingManager.h>
22 #include <mitkTimeGeometry.h>
23 
24 #ifdef __GNUC__
25 #pragma GCC visibility push(default)
26 #endif
27 #include <itkEventObject.h>
28 #ifdef __GNUC__
29 #pragma GCC visibility pop
30 #endif
31 
32 #include <itkCommand.h>
33 
34 namespace mitk
35 {
36 #define mitkTimeGeometryEventMacro(classname, super) \
37  class MITKCORE_EXPORT classname : public super \
38  { \
39  public: \
40  typedef classname Self; \
41  typedef super Superclass; \
42  classname(TimeGeometry *aTimeGeometry, unsigned int aPos) : Superclass(aTimeGeometry, aPos) {} \
43  virtual ~classname() {} \
44  virtual const char *GetEventName() const { return #classname; } \
45  virtual bool CheckEvent(const ::itk::EventObject *e) const { return dynamic_cast<const Self *>(e); } \
46  virtual ::itk::EventObject *MakeObject() const { return new Self(GetTimeGeometry(), GetPos()); } \
47  private: \
48  void operator=(const Self &); \
49  }
50 
51  class PlaneGeometry;
52  class BaseGeometry;
53  class BaseRenderer;
54 
135  {
136  public:
137 
139  itkNewMacro(Self);
140 
149  itkGetConstObjectMacro(InputWorldTimeGeometry, TimeGeometry);
150 
154  itkGetConstObjectMacro(CreatedWorldGeometry, TimeGeometry);
155  itkGetObjectMacro(CreatedWorldGeometry, TimeGeometry);
156 
166 
177  itkSetEnumMacro(DefaultViewDirection, AnatomicalPlane);
178  itkGetEnumMacro(DefaultViewDirection, AnatomicalPlane);
179 
184  const char *GetViewDirectionAsString() const;
185 
191 
197  virtual void Update();
198 
208  virtual void Update(AnatomicalPlane viewDirection, bool top = true, bool frontside = true, bool rotated = false);
209 
216  virtual void SendCreatedWorldGeometry();
217 
223 
230  virtual void SendSlice();
231 
232  class MITKCORE_EXPORT TimeGeometryEvent : public itk::AnyEvent
233  {
234  public:
236  typedef itk::AnyEvent Superclass;
237 
238  TimeGeometryEvent(TimeGeometry* aTimeGeometry, unsigned int aPos) : m_TimeGeometry(aTimeGeometry), m_Pos(aPos) {}
239  ~TimeGeometryEvent() override {}
240  const char* GetEventName() const override { return "TimeGeometryEvent"; }
241  bool CheckEvent(const ::itk::EventObject* e) const override { return dynamic_cast<const Self*>(e); }
242  ::itk::EventObject* MakeObject() const override { return new Self(m_TimeGeometry, m_Pos); }
243  TimeGeometry* GetTimeGeometry() const { return m_TimeGeometry; }
244  unsigned int GetPos() const { return m_Pos; }
245 
246  private:
247  TimeGeometry::Pointer m_TimeGeometry;
248  unsigned int m_Pos;
249  // TimeGeometryEvent(const Self&);
250  void operator=(const Self&); // just hide
251  };
252 
253 
257 
258  template <typename T>
259  void ConnectGeometrySendEvent(T* receiver)
260  {
261  auto eventReceptorCommand = itk::ReceptorMemberCommand<T>::New();
262  eventReceptorCommand->SetCallbackFunction(receiver, &T::SetGeometry);
263  unsigned long tag = AddObserver(GeometrySendEvent(nullptr, 0), eventReceptorCommand);
264  m_ReceiverToObserverTagsMap[static_cast<void*>(receiver)].push_back(tag);
265  }
266 
267  template <typename T>
268  void ConnectGeometryUpdateEvent(T* receiver)
269  {
270  auto eventReceptorCommand = itk::ReceptorMemberCommand<T>::New();
271  eventReceptorCommand->SetCallbackFunction(receiver, &T::UpdateGeometry);
272  unsigned long tag = AddObserver(GeometryUpdateEvent(nullptr, 0), eventReceptorCommand);
273  m_ReceiverToObserverTagsMap[static_cast<void*>(receiver)].push_back(tag);
274  }
275 
276  template <typename T>
277  void ConnectGeometrySliceEvent(T* receiver)
278  {
279  auto eventReceptorCommand = itk::ReceptorMemberCommand<T>::New();
280  eventReceptorCommand->SetCallbackFunction(receiver, &T::SetGeometrySlice);
281  unsigned long tag = AddObserver(GeometrySliceEvent(nullptr, 0), eventReceptorCommand);
282  m_ReceiverToObserverTagsMap[static_cast<void*>(receiver)].push_back(tag);
283  }
284 
285  // use a templated method to get the right offset when casting to void*
286  template <typename T>
287  void Disconnect(T* receiver)
288  {
289  auto i = m_ReceiverToObserverTagsMap.find(static_cast<void*>(receiver));
290  if (i == m_ReceiverToObserverTagsMap.end())
291  return;
292  const std::list<unsigned long>& tags = i->second;
293  for (auto tagIter = tags.begin(); tagIter != tags.end(); ++tagIter)
294  {
295  RemoveObserver(*tagIter);
296  }
297  m_ReceiverToObserverTagsMap.erase(i);
298  }
299 
302 
311  void SelectSliceByPoint(const Point3D& point);
312 
315 
320 
325  itkSetObjectMacro(Renderer, BaseRenderer);
326  itkGetMacro(Renderer, BaseRenderer*);
327 
340  void ReorientSlices(const Point3D& point, const Vector3D& normal);
341 
352  void ReorientSlices(const Point3D& point, const Vector3D& axisVec0, const Vector3D& axisVec1);
353 
358  void ExecuteOperation(Operation* operation) override;
359 
365  itkSetMacro(SliceLocked, bool);
366  itkGetMacro(SliceLocked, bool);
367  itkBooleanMacro(SliceLocked);
368 
375  itkSetMacro(SliceRotationLocked, bool);
376  itkGetMacro(SliceRotationLocked, bool);
377  itkBooleanMacro(SliceRotationLocked);
378 
384 
385  protected:
386 
389 
390  void CreateWorldGeometry(bool top, bool frontside, bool rotated);
391 
392  TimeGeometry::ConstPointer m_InputWorldTimeGeometry;
393  TimeGeometry::Pointer m_CreatedWorldGeometry;
394 
397 
398  RenderingManager::Pointer m_RenderingManager;
399 
401 
403 
406 
407  typedef std::map<void*, std::list<unsigned long>> ObserverTagsMapType;
409  };
410 
411 } // namespace mitk
412 
413 #endif
#define MITKCORE_EXPORT
Base class for renderer slice, camera, and time control.
Abstract base class describing the geometry of a data object.
Organizes the rendering process.
Event/message class with one parameter.
Definition: mitkMessage.h:552
Base class for all operations in the undo/redo framework.
Definition: mitkOperation.h:38
Describes the geometry of a plane object.
TimeGeometryEvent(TimeGeometry *aTimeGeometry, unsigned int aPos)
bool CheckEvent(const ::itk::EventObject *e) const override
Controls the selection of the slice the associated BaseRenderer will display.
void CreateWorldGeometry(bool top, bool frontside, bool rotated)
mitkClassMacro(SliceNavigationController, BaseController)
const BaseGeometry * GetCurrentGeometry3D()
Returns the BaseGeometry of the currently selected time step.
std::map< void *, std::list< unsigned long > > ObserverTagsMapType
void SetInputWorldTimeGeometry(const TimeGeometry *geometry)
Set the input world time geometry out of which the geometries for slicing will be created.
void AdjustSliceStepperRange()
Adjusts the numerical range of the slice stepper according to the current geometry orientation of thi...
itkSetEnumMacro(ViewDirection, AnatomicalPlane)
Set the desired view directions.
itkGetEnumMacro(DefaultViewDirection, AnatomicalPlane)
virtual void SendCreatedWorldGeometryUpdate()
Tell observers to re-read the currently selected 2D geometry.
virtual void SendCreatedWorldGeometry()
Send the created geometry to the connected observers (renderers)
virtual void SetViewDirectionToDefault()
Reset the view direction to the default view direction.
itkGetEnumMacro(ViewDirection, AnatomicalPlane)
virtual void Update()
Do the actual creation and send it to the connected observers (renderers)
Message1< const Point3D & > SetCrosshairEvent
Signal emitted when the crosshair position changes. The parameter is the new position in world coordi...
const char * GetViewDirectionAsString() const
Get the current view direction as a human-readable string.
void ReorientSlices(const Point3D &point, const Vector3D &normal)
Re-orient the slice stack using a normal vector.
virtual void SendSlice()
Send the currently selected slice to the connected observers (renderers)
void ExecuteOperation(Operation *operation) override
Execute an operation (e.g. OpMOVE, OpRESTOREPLANEPOSITION, OpAPPLYTRANSFORMMATRIX).
const PlaneGeometry * GetCurrentPlaneGeometry()
Returns the currently selected Plane in the current BaseGeometry (if existent).
itkSetEnumMacro(DefaultViewDirection, AnatomicalPlane)
Set the default view direction.
void SelectSliceByPoint(const Point3D &point)
Select the slice closest to the given 3D point.
TimeGeometry::ConstPointer m_InputWorldTimeGeometry
virtual void Update(AnatomicalPlane viewDirection, bool top=true, bool frontside=true, bool rotated=false)
Extended version of Update, additionally allowing to specify the direction/orientation of the created...
void ReorientSlices(const Point3D &point, const Vector3D &axisVec0, const Vector3D &axisVec1)
Re-orient the slice stack using two explicit axis vectors.
#define mitkTimeGeometryEventMacro(classname, super)
Find image slices visible on a given plane.
AnatomicalPlane
Enumeration of standard anatomical image planes.