Medical Imaging Interaction Toolkit  2024.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 {
26  // define custom command to accept std::functions as "filter" and as "action"
27  class MITKCORE_EXPORT StdFunctionCommand : public itk::Command
28  {
29  public:
32 
33  using FilterFunction = std::function<bool(const itk::EventObject&)>;
34  using ActionFunction = std::function<void(const itk::EventObject&)>;
35 
37  itkNewMacro(Self);
38 
40  itkTypeMacro(StdFunctionCommand, itk::Command);
41 
42  void SetCommandFilter(FilterFunction stdFunctionFilter)
43  {
44  m_StdFilterFunction = stdFunctionFilter;
45  }
46 
47  void SetCommandAction(ActionFunction stdFunctionAction)
48  {
49  m_StdActionFunction = stdFunctionAction;
50  }
51 
52  void Execute(Object*, const itk::EventObject& event) override
53  {
54  if (m_StdFilterFunction && m_StdActionFunction)
55  {
56  if (m_StdFilterFunction(event))
57  {
58  m_StdActionFunction(event);
59  }
60  }
61  }
62 
63  void Execute(const Object*, const itk::EventObject& event) override
64  {
65  if (m_StdFilterFunction && m_StdActionFunction)
66  {
67  if (m_StdFilterFunction(event))
68  {
69  m_StdActionFunction(event);
70  }
71  }
72  }
73 
74  protected:
77 
79  : m_StdFilterFunction(nullptr)
80  , m_StdActionFunction(nullptr)
81  {}
82 
83  ~StdFunctionCommand() override {}
84 
85  private:
86  ITK_DISALLOW_COPY_AND_ASSIGN(StdFunctionCommand);
87  };
88 
89 } // end namespace mitk
90 
91 #endif
mitk::StdFunctionCommand::ActionFunction
std::function< void(const itk::EventObject &)> ActionFunction
Definition: mitkStdFunctionCommand.h:34
mitk::StdFunctionCommand::m_StdFilterFunction
FilterFunction m_StdFilterFunction
Definition: mitkStdFunctionCommand.h:75
mitk::StdFunctionCommand
Definition: mitkStdFunctionCommand.h:27
mitk::StdFunctionCommand::SetCommandFilter
void SetCommandFilter(FilterFunction stdFunctionFilter)
Definition: mitkStdFunctionCommand.h:42
mitk::StdFunctionCommand::Execute
void Execute(Object *, const itk::EventObject &event) override
Definition: mitkStdFunctionCommand.h:52
itk::SmartPointer< Self >
mitk::StdFunctionCommand::Execute
void Execute(const Object *, const itk::EventObject &event) override
Definition: mitkStdFunctionCommand.h:63
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::StdFunctionCommand::StdFunctionCommand
StdFunctionCommand()
Definition: mitkStdFunctionCommand.h:78
mitk::StdFunctionCommand::FilterFunction
std::function< bool(const itk::EventObject &)> FilterFunction
Definition: mitkStdFunctionCommand.h:33
MitkCoreExports.h
mitk::StdFunctionCommand::m_StdActionFunction
ActionFunction m_StdActionFunction
Definition: mitkStdFunctionCommand.h:76
mitk::StdFunctionCommand::SetCommandAction
void SetCommandAction(ActionFunction stdFunctionAction)
Definition: mitkStdFunctionCommand.h:47
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::StdFunctionCommand::~StdFunctionCommand
~StdFunctionCommand() override
Definition: mitkStdFunctionCommand.h:83