RTK  1.4.0
Reconstruction Toolkit
rtkMacro.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright RTK Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef rtkMacro_h
20 #define rtkMacro_h
21 
22 #include <iostream>
23 #include <itkMacro.h>
24 #include <itkImageBase.h>
25 #include "rtkGgoArgsInfoManager.h"
26 
27 //--------------------------------------------------------------------
28 #ifndef CLANG_PRAGMA_PUSH
29 #define ITK_PRAGMA(x) _Pragma (#x)
30 #if defined(__clang__) && defined(__has_warning)
31 #define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
32 #define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
33 # if __has_warning("-Wfloat-equal")
34 #define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA( clang diagnostic ignored "-Wfloat-equal" )
35 # endif
36 #else
37 #define CLANG_PRAGMA_PUSH
38 #define CLANG_PRAGMA_POP
39 #define CLANG_SUPPRESS_Wfloat_equal
40 #endif
41 #endif
42 //--------------------------------------------------------------------
43 
44 //--------------------------------------------------------------------
45 #ifndef ITK_NULLPTR
46 # define ITK_NULLPTR NULL
47 #endif
48 //--------------------------------------------------------------------
49 
50 //--------------------------------------------------------------------
51 #ifndef ITK_OVERRIDE
52 # define ITK_OVERRIDE
53 #endif
54 //--------------------------------------------------------------------
55 
56 //--------------------------------------------------------------------
63 #ifndef DD
64 # define DD(a) std::cout << #a " = [ " << a << " ]" << std::endl;
65 #endif
66 //--------------------------------------------------------------------
67 
68 //--------------------------------------------------------------------
75 #define GGO(ggo_filename, args_info) \
76  args_info_##ggo_filename args_info; \
77  cmdline_parser_##ggo_filename##_params args_params; \
78  cmdline_parser_##ggo_filename##_params_init(&args_params); \
79  args_params.print_errors = 1; \
80  args_params.check_required = 0; \
81  args_params.override = 1; \
82  args_params.initialize = 1; \
83  if(0 != cmdline_parser_##ggo_filename##_ext(argc, argv, &args_info, &args_params) ) \
84  { \
85  std::cerr << "Error in cmdline_parser_" #ggo_filename "_ext" << std::endl; \
86  exit(1); \
87  } \
88  std::string configFile; \
89  if(args_info.config_given) \
90  configFile = args_info.config_arg; \
91  cmdline_parser_##ggo_filename##_free(&args_info); \
92  if (configFile != "") \
93  { \
94  if(0 != cmdline_parser_##ggo_filename##_config_file (configFile.c_str(), &args_info, &args_params) ) \
95  { \
96  std::cerr << "Error in cmdline_parser_" #ggo_filename "_config_file" << std::endl; \
97  exit(1); \
98  } \
99  args_params.initialize = 0; \
100  } \
101  args_params.check_required = 1; \
102  if(0 != cmdline_parser_##ggo_filename##_ext(argc, argv, &args_info, &args_params) ) \
103  { \
104  std::cerr << "Error in cmdline_parser_" #ggo_filename "_ext" << std::endl; \
105  exit(1); \
106  } \
107  rtk::args_info_manager< args_info_##ggo_filename > \
108  manager_object( args_info, cmdline_parser_##ggo_filename##_free );
109 //--------------------------------------------------------------------
110 
111 //--------------------------------------------------------------------
118 #define TRY_AND_EXIT_ON_ITK_EXCEPTION(execFunc) \
119  try \
120  { \
121  execFunc; \
122  } \
123  catch( itk::ExceptionObject & err ) \
124  { \
125  std::cerr << "ExceptionObject caught with " #execFunc \
126  << " in file " << __FILE__ \
127  << " line " << __LINE__ \
128  << std::endl; \
129  std::cerr << err << std::endl; \
130  itk::InvalidRequestedRegionError* r; \
131  r = dynamic_cast<itk::InvalidRequestedRegionError*>(&err); \
132  if(r) \
133  { \
134  if( r->GetDataObject()->GetSource() ) \
135  { \
136  std::cerr << "Invalid requested region error triggered by " \
137  << r->GetDataObject()->GetSource()->GetNameOfClass() \
138  << std::endl; \
139  } \
140  itk::ImageBase<3> *img; \
141  img = dynamic_cast<itk::ImageBase<3>*>(r->GetDataObject()); \
142  if(img) \
143  { \
144  DD(img->GetRequestedRegion()) \
145  DD(img->GetLargestPossibleRegion()) \
146  } \
147  } \
148  exit(EXIT_FAILURE); \
149  }
150 //--------------------------------------------------------------------
151 
152 //--------------------------------------------------------------------
161 #ifdef RTK_TIME_EACH_FILTER
162 #undef itkSimpleNewMacro
163 #define itkSimpleNewMacro(x) \
164  static Pointer New(void) \
165  { \
166  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
167  if ( smartPtr.GetPointer() == ITK_NULLPTR ) \
168  { \
169  smartPtr = new x; \
170  } \
171  smartPtr->UnRegister(); \
172  /* If smartPtr is a ProcessObject, watch it */ \
173  itk::ProcessObject* processObjectPointer = ITK_NULLPTR; \
174  processObjectPointer = dynamic_cast<itk::ProcessObject*>(smartPtr.GetPointer()); \
175  if (processObjectPointer != ITK_NULLPTR) \
176  { \
177  rtk::GlobalTimer::GetInstance()->Watch(processObjectPointer); \
178  } \
179  return smartPtr; \
180  }
181 
182 #undef itkCreateAnotherMacro
183 #define itkCreateAnotherMacro(x) \
184  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
185  { \
186  ::itk::LightObject::Pointer smartPtr; \
187  smartPtr = x::New().GetPointer(); \
188  return smartPtr; \
189  }
190 
191 #undef itkFactorylessNewMacro
192 #define itkFactorylessNewMacro(x) \
193  static Pointer New(void) \
194  { \
195  Pointer smartPtr; \
196  x * rawPtr = new x; \
197  smartPtr = rawPtr; \
198  rawPtr->UnRegister(); \
199  /* If smartPtr is a ProcessObject, watch it */ \
200  itk::ProcessObject* processObjectPointer = ITK_NULLPTR; \
201  processObjectPointer = dynamic_cast<itk::ProcessObject*>(smartPtr.GetPointer()); \
202  if (processObjectPointer != ITK_NULLPTR) \
203  { \
204  rtk::GlobalTimer::GetInstance()->Watch(processObjectPointer); \
205  } \
206  return smartPtr; \
207  } \
208  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
209  { \
210  ::itk::LightObject::Pointer smartPtr; \
211  smartPtr = x::New().GetPointer(); \
212  return smartPtr; \
213  }
214 #endif //RTK_TIME_EACH_FILTER
215 
216 
217 #endif