Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
mitkToolFactoryMacro.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 mitkToolFactoryMacro_h
14 #define mitkToolFactoryMacro_h
15 
16 #define MITK_TOOL_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
17 class EXPORT_SPEC CLASS_NAME##Factory : public ::itk::ObjectFactoryBase \
18 { \
19  public: \
20  /* ITK typedefs */ \
21  typedef CLASS_NAME##Factory Self; \
22  typedef itk::ObjectFactoryBase Superclass; \
23  typedef itk::SmartPointer<Self> Pointer; \
24  typedef itk::SmartPointer<const Self> ConstPointer; \
25  \
26  /* Methods from ObjectFactoryBase */ \
27  virtual const char *GetITKSourceVersion() const override { return ITK_SOURCE_VERSION; } \
28  virtual const char *GetDescription() const override { return DESCRIPTION; } \
29  /* Method for class instantiation. */ \
30  itkFactorylessNewMacro(Self); \
31  \
32  /* Run-time type information (and related methods). */ \
33  itkTypeMacro(CLASS_NAME##Factory, itkObjectFactoryBase); \
34  \
35  protected: \
36  CLASS_NAME##Factory() \
37  { \
38  itk::ObjectFactoryBase::RegisterOverride( \
39  "mitkTool", #CLASS_NAME, DESCRIPTION, 1, itk::CreateObjectFunction<CLASS_NAME>::New()); \
40  } \
41  \
42  ~CLASS_NAME##Factory() \
43  { \
44  itk::ObjectFactoryBase::UnRegisterFactory(this); \
45  } \
46  private: \
47  CLASS_NAME##Factory(const Self &); /* purposely not implemented */ \
48  void operator=(const Self &); /* purposely not implemented */ \
49 }; \
50  \
51 class CLASS_NAME##RegistrationMethod \
52  { \
53  public: \
54  CLASS_NAME##RegistrationMethod() \
55  { \
56  /*MITK_INFO("tools") << "Registered " #CLASS_NAME; */ \
57  m_Factory = CLASS_NAME##Factory::New(); \
58  itk::ObjectFactoryBase::RegisterFactory(m_Factory); \
59  } \
60  \
61  ~CLASS_NAME##RegistrationMethod() \
62  { \
63  /*MITK_INFO("tools") << "UnRegistered " #CLASS_NAME; */ \
64  itk::ObjectFactoryBase::UnRegisterFactory(m_Factory); \
65  } \
66  \
67  private: \
68  CLASS_NAME##Factory::Pointer m_Factory; \
69  }; \
70  \
71 static CLASS_NAME##RegistrationMethod somestaticinitializer_##CLASS_NAME;
72 
73 #define MITK_DERIVED_SM_TOOL_MACRO(EXPORT_SPEC, BASE_CLASS, CLASS_NAME, DESCRIPTION) \
74 class EXPORT_SPEC CLASS_NAME##Tool : public BASE_CLASS \
75 { \
76  public: \
77  typedef CLASS_NAME##Tool Self; \
78  typedef BASE_CLASS Superclass; \
79  typedef itk::SmartPointer<Self> Pointer; \
80  typedef itk::SmartPointer<const Self> ConstPointer; \
81  \
82  itkFactorylessNewMacro(Self); \
83  itkCloneMacro(Self); \
84  \
85  protected: \
86  \
87  CLASS_NAME##Tool() \
88  { \
89  m_SegmentationGenerator = CLASS_NAME::New(); \
90  } \
91  \
92  void RegisterProgressObserver() \
93  { \
94  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::Pointer command = \
95  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::New(); \
96  command->SetCallbackFunction(this, &CLASS_NAME##Tool::OnProgressEvent); \
97  m_SegmentationGenerator->AddSegmentationProgressObserver<CLASS_NAME##Tool>(command); \
98  } \
99  \
100  void RegisterFinishedSegmentationObserver() \
101  { \
102  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::Pointer command = \
103  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::New(); \
104  command->SetCallbackFunction(this, &CLASS_NAME##Tool::OnSegmentationFinished); \
105  m_SegmentationGenerator->AddSegmentationFinishedObserver<CLASS_NAME##Tool>(command); \
106  } \
107  \
108  ~CLASS_NAME##Tool() {} \
109 }; \
110  \
111 MITK_TOOL_MACRO(EXPORT_SPEC, CLASS_NAME##Tool, DESCRIPTION);
112 
113 /* GUI classes are _not_ exported! */
114 
115 #define MITK_TOOL_GUI_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
116 class EXPORT_SPEC CLASS_NAME##Factory : public ::itk::ObjectFactoryBase \
117 { \
118  public: \
119  /* ITK typedefs */ \
120  typedef CLASS_NAME##Factory Self; \
121  typedef itk::ObjectFactoryBase Superclass; \
122  typedef itk::SmartPointer<Self> Pointer; \
123  typedef itk::SmartPointer<const Self> ConstPointer; \
124  \
125  /* Methods from ObjectFactoryBase */ \
126  virtual const char *GetITKSourceVersion() const override { return ITK_SOURCE_VERSION; } \
127  virtual const char *GetDescription() const override { return DESCRIPTION; } \
128  /* Method for class instantiation. */ \
129  itkFactorylessNewMacro(Self); \
130  \
131  /* Run-time type information (and related methods). */ \
132  itkTypeMacro(CLASS_NAME##Factory, itkObjectFactoryBase); \
133  \
134  protected: \
135  CLASS_NAME##Factory() \
136  { \
137  itk::ObjectFactoryBase::RegisterOverride( \
138  #CLASS_NAME, #CLASS_NAME, DESCRIPTION, 1, itk::CreateObjectFunction<CLASS_NAME>::New()); \
139  } \
140  \
141  ~CLASS_NAME##Factory() \
142  { \
143  itk::ObjectFactoryBase::UnRegisterFactory(this); \
144  } \
145  private: \
146  CLASS_NAME##Factory(const Self &); /* purposely not implemented */ \
147  void operator=(const Self &); /* purposely not implemented */ \
148 }; \
149  \
150 class CLASS_NAME##RegistrationMethod \
151  { \
152  public: \
153  CLASS_NAME##RegistrationMethod() \
154  { \
155  /*MITK_INFO("tools") << "Registered " #CLASS_NAME; */ \
156  m_Factory = CLASS_NAME##Factory::New(); \
157  itk::ObjectFactoryBase::RegisterFactory(m_Factory); \
158  } \
159  \
160  ~CLASS_NAME##RegistrationMethod() \
161  { \
162  /*MITK_INFO("tools") << "UnRegistered " #CLASS_NAME; */ \
163  itk::ObjectFactoryBase::UnRegisterFactory(m_Factory); \
164  } \
165  \
166  private: \
167  CLASS_NAME##Factory::Pointer m_Factory; \
168  }; \
169  \
170 static CLASS_NAME##RegistrationMethod somestaticinitializer_##CLASS_NAME;
171 
172 #define MITK_EXTERNAL_TOOL_GUI_HEADER_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
173 extern "C" \
174 { \
175  EXPORT_SPEC itk::ObjectFactoryBase* itkLoad(); \
176 }
177 
178 #define MITK_EXTERNAL_TOOL_GUI_CPP_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
179 MITK_TOOL_GUI_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
180 extern "C" \
181 { \
182  EXPORT_SPEC itk::ObjectFactoryBase* itkLoad() \
183  { \
184  static CLASS_NAME##Factory::Pointer p = CLASS_NAME##Factory::New(); \
185  return p; \
186  } \
187 }
188 
189 #endif