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