Medical Imaging Interaction Toolkit  2026.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 
36 #define MITK_TOOL_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
37 class EXPORT_SPEC CLASS_NAME##Factory : public ::itk::ObjectFactoryBase \
38 { \
39  public: \
40  /* ITK typedefs */ \
41  typedef CLASS_NAME##Factory Self; \
42  typedef itk::ObjectFactoryBase Superclass; \
43  typedef itk::SmartPointer<Self> Pointer; \
44  typedef itk::SmartPointer<const Self> ConstPointer; \
45  \
46  /* Methods from ObjectFactoryBase */ \
47  virtual const char *GetITKSourceVersion() const override { return ITK_SOURCE_VERSION; } \
48  virtual const char *GetDescription() const override { return DESCRIPTION; } \
49  /* Method for class instantiation. */ \
50  itkFactorylessNewMacro(Self); \
51  \
52  /* Run-time type information (and related methods). */ \
53  itkTypeMacro(CLASS_NAME##Factory, itkObjectFactoryBase); \
54  \
55  protected: \
56  CLASS_NAME##Factory() \
57  { \
58  itk::ObjectFactoryBase::RegisterOverride( \
59  "mitkTool", #CLASS_NAME, DESCRIPTION, 1, itk::CreateObjectFunction<CLASS_NAME>::New()); \
60  } \
61  \
62  ~CLASS_NAME##Factory() \
63  { \
64  itk::ObjectFactoryBase::UnRegisterFactory(this); \
65  } \
66  private: \
67  CLASS_NAME##Factory(const Self &); /* purposely not implemented */ \
68  void operator=(const Self &); /* purposely not implemented */ \
69 }; \
70  \
71 class CLASS_NAME##RegistrationMethod \
72  { \
73  public: \
74  CLASS_NAME##RegistrationMethod() \
75  { \
76  /*MITK_INFO("tools") << "Registered " #CLASS_NAME; */ \
77  m_Factory = CLASS_NAME##Factory::New(); \
78  itk::ObjectFactoryBase::RegisterFactory(m_Factory); \
79  } \
80  \
81  ~CLASS_NAME##RegistrationMethod() \
82  { \
83  /*MITK_INFO("tools") << "UnRegistered " #CLASS_NAME; */ \
84  itk::ObjectFactoryBase::UnRegisterFactory(m_Factory); \
85  } \
86  \
87  private: \
88  CLASS_NAME##Factory::Pointer m_Factory; \
89  }; \
90  \
91 static CLASS_NAME##RegistrationMethod somestaticinitializer_##CLASS_NAME;
92 
104 #define MITK_DERIVED_SM_TOOL_MACRO(EXPORT_SPEC, BASE_CLASS, CLASS_NAME, DESCRIPTION) \
105 class EXPORT_SPEC CLASS_NAME##Tool : public BASE_CLASS \
106 { \
107  public: \
108  typedef CLASS_NAME##Tool Self; \
109  typedef BASE_CLASS Superclass; \
110  typedef itk::SmartPointer<Self> Pointer; \
111  typedef itk::SmartPointer<const Self> ConstPointer; \
112  \
113  itkFactorylessNewMacro(Self); \
114  itkCloneMacro(Self); \
115  \
116  protected: \
117  \
118  CLASS_NAME##Tool() \
119  { \
120  m_SegmentationGenerator = CLASS_NAME::New(); \
121  } \
122  \
123  void RegisterProgressObserver() \
124  { \
125  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::Pointer command = \
126  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::New(); \
127  command->SetCallbackFunction(this, &CLASS_NAME##Tool::OnProgressEvent); \
128  m_SegmentationGenerator->AddSegmentationProgressObserver<CLASS_NAME##Tool>(command); \
129  } \
130  \
131  void RegisterFinishedSegmentationObserver() \
132  { \
133  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::Pointer command = \
134  itk::ReceptorMemberCommand<CLASS_NAME##Tool>::New(); \
135  command->SetCallbackFunction(this, &CLASS_NAME##Tool::OnSegmentationFinished); \
136  m_SegmentationGenerator->AddSegmentationFinishedObserver<CLASS_NAME##Tool>(command); \
137  } \
138  \
139  ~CLASS_NAME##Tool() {} \
140 }; \
141  \
142 MITK_TOOL_MACRO(EXPORT_SPEC, CLASS_NAME##Tool, DESCRIPTION);
143 
144 /* GUI classes are _not_ exported! */
145 
156 #define MITK_TOOL_GUI_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
157 class EXPORT_SPEC CLASS_NAME##Factory : public ::itk::ObjectFactoryBase \
158 { \
159  public: \
160  /* ITK typedefs */ \
161  typedef CLASS_NAME##Factory Self; \
162  typedef itk::ObjectFactoryBase Superclass; \
163  typedef itk::SmartPointer<Self> Pointer; \
164  typedef itk::SmartPointer<const Self> ConstPointer; \
165  \
166  /* Methods from ObjectFactoryBase */ \
167  virtual const char *GetITKSourceVersion() const override { return ITK_SOURCE_VERSION; } \
168  virtual const char *GetDescription() const override { return DESCRIPTION; } \
169  /* Method for class instantiation. */ \
170  itkFactorylessNewMacro(Self); \
171  \
172  /* Run-time type information (and related methods). */ \
173  itkTypeMacro(CLASS_NAME##Factory, itkObjectFactoryBase); \
174  \
175  protected: \
176  CLASS_NAME##Factory() \
177  { \
178  itk::ObjectFactoryBase::RegisterOverride( \
179  #CLASS_NAME, #CLASS_NAME, DESCRIPTION, 1, itk::CreateObjectFunction<CLASS_NAME>::New()); \
180  } \
181  \
182  ~CLASS_NAME##Factory() \
183  { \
184  itk::ObjectFactoryBase::UnRegisterFactory(this); \
185  } \
186  private: \
187  CLASS_NAME##Factory(const Self &); /* purposely not implemented */ \
188  void operator=(const Self &); /* purposely not implemented */ \
189 }; \
190  \
191 class CLASS_NAME##RegistrationMethod \
192  { \
193  public: \
194  CLASS_NAME##RegistrationMethod() \
195  { \
196  /*MITK_INFO("tools") << "Registered " #CLASS_NAME; */ \
197  m_Factory = CLASS_NAME##Factory::New(); \
198  itk::ObjectFactoryBase::RegisterFactory(m_Factory); \
199  } \
200  \
201  ~CLASS_NAME##RegistrationMethod() \
202  { \
203  /*MITK_INFO("tools") << "UnRegistered " #CLASS_NAME; */ \
204  itk::ObjectFactoryBase::UnRegisterFactory(m_Factory); \
205  } \
206  \
207  private: \
208  CLASS_NAME##Factory::Pointer m_Factory; \
209  }; \
210  \
211 static CLASS_NAME##RegistrationMethod somestaticinitializer_##CLASS_NAME;
212 
223 #define MITK_EXTERNAL_TOOL_GUI_HEADER_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
224 extern "C" \
225 { \
226  EXPORT_SPEC itk::ObjectFactoryBase* itkLoad(); \
227 }
228 
239 #define MITK_EXTERNAL_TOOL_GUI_CPP_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
240 MITK_TOOL_GUI_MACRO(EXPORT_SPEC, CLASS_NAME, DESCRIPTION) \
241 extern "C" \
242 { \
243  EXPORT_SPEC itk::ObjectFactoryBase* itkLoad() \
244  { \
245  static CLASS_NAME##Factory::Pointer p = CLASS_NAME##Factory::New(); \
246  return p; \
247  } \
248 }
249 
250 #endif