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