Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkStdFunctionCommand.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 mitkStdFunctionCommand_h
14 #define mitkStdFunctionCommand_h
15 
16 #include <MitkCoreExports.h>
17 
18 // itk
19 #include <itkCommand.h>
20 
21 // c++
22 #include <functional>
23 
24 namespace mitk
25 {
33  class MITKCORE_EXPORT StdFunctionCommand : public itk::Command
34  {
35  public:
38 
40  using FilterFunction = std::function<bool(const itk::EventObject&)>;
41 
43  using ActionFunction = std::function<void(const itk::EventObject&)>;
44 
46  itkNewMacro(Self);
47 
49  itkTypeMacro(StdFunctionCommand, itk::Command);
50 
56  void SetCommandFilter(FilterFunction stdFunctionFilter)
57  {
58  m_StdFilterFunction = stdFunctionFilter;
59  }
60 
66  void SetCommandAction(ActionFunction stdFunctionAction)
67  {
68  m_StdActionFunction = stdFunctionAction;
69  }
70 
77  void Execute(Object*, const itk::EventObject& event) override
78  {
79  if (m_StdFilterFunction && m_StdActionFunction)
80  {
81  if (m_StdFilterFunction(event))
82  {
83  m_StdActionFunction(event);
84  }
85  }
86  }
87 
94  void Execute(const Object*, const itk::EventObject& event) override
95  {
96  if (m_StdFilterFunction && m_StdActionFunction)
97  {
98  if (m_StdFilterFunction(event))
99  {
100  m_StdActionFunction(event);
101  }
102  }
103  }
104 
105  protected:
108 
110  : m_StdFilterFunction(nullptr)
111  , m_StdActionFunction(nullptr)
112  {}
113 
114  ~StdFunctionCommand() override {}
115 
116  private:
117  ITK_DISALLOW_COPY_AND_ASSIGN(StdFunctionCommand);
118  };
119 
120 } // end namespace mitk
121 
122 #endif
#define MITKCORE_EXPORT
ITK command that uses std::function objects as filter and action callbacks.
void Execute(const Object *, const itk::EventObject &event) override
Execute the command for a const caller.
void SetCommandFilter(FilterFunction stdFunctionFilter)
Set the filter function that decides whether to handle an event.
std::function< void(const itk::EventObject &)> ActionFunction
Function type for the action to execute when the filter passes.
void Execute(Object *, const itk::EventObject &event) override
Execute the command for a non-const caller.
std::function< bool(const itk::EventObject &)> FilterFunction
Function type for filtering events. Returns true if the event should be handled.
void SetCommandAction(ActionFunction stdFunctionAction)
Set the action function to execute when the filter passes.
Find image slices visible on a given plane.