RTK  2.0.1
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 //--------------------------------------------------------------------
51 #ifndef DD
52 # define DD(a) std::cout << #a " = [ " << a << " ]" << std::endl;
53 #endif
54 //--------------------------------------------------------------------
55 
56 //--------------------------------------------------------------------
63 #define GGO(ggo_filename, args_info) \
64  args_info_##ggo_filename args_info; \
65  cmdline_parser_##ggo_filename##_params args_params; \
66  cmdline_parser_##ggo_filename##_params_init(&args_params); \
67  args_params.print_errors = 1; \
68  args_params.check_required = 0; \
69  args_params.override = 1; \
70  args_params.initialize = 1; \
71  if(0 != cmdline_parser_##ggo_filename##_ext(argc, argv, &args_info, &args_params) ) \
72  { \
73  std::cerr << "Error in cmdline_parser_" #ggo_filename "_ext" << std::endl; \
74  exit(1); \
75  } \
76  std::string configFile; \
77  if(args_info.config_given) \
78  configFile = args_info.config_arg; \
79  cmdline_parser_##ggo_filename##_free(&args_info); \
80  if (configFile != "") \
81  { \
82  if(0 != cmdline_parser_##ggo_filename##_config_file (configFile.c_str(), &args_info, &args_params) ) \
83  { \
84  std::cerr << "Error in cmdline_parser_" #ggo_filename "_config_file" << std::endl; \
85  exit(1); \
86  } \
87  args_params.initialize = 0; \
88  } \
89  args_params.check_required = 1; \
90  if(0 != cmdline_parser_##ggo_filename##_ext(argc, argv, &args_info, &args_params) ) \
91  { \
92  std::cerr << "Error in cmdline_parser_" #ggo_filename "_ext" << std::endl; \
93  exit(1); \
94  } \
95  rtk::args_info_manager< args_info_##ggo_filename > \
96  manager_object( args_info, cmdline_parser_##ggo_filename##_free );
97 //--------------------------------------------------------------------
98 
99 //--------------------------------------------------------------------
106 #define TRY_AND_EXIT_ON_ITK_EXCEPTION(execFunc) \
107  try \
108  { \
109  execFunc; \
110  } \
111  catch( itk::ExceptionObject & err ) \
112  { \
113  std::cerr << "ExceptionObject caught with " #execFunc \
114  << " in file " << __FILE__ \
115  << " line " << __LINE__ \
116  << std::endl; \
117  std::cerr << err << std::endl; \
118  itk::InvalidRequestedRegionError* rInv; \
119  rInv = dynamic_cast<itk::InvalidRequestedRegionError*>(&err); \
120  if(rInv) \
121  { \
122  if( rInv->GetDataObject()->GetSource() ) \
123  { \
124  std::cerr << "Invalid requested region error triggered by " \
125  << rInv->GetDataObject()->GetSource()->GetNameOfClass() \
126  << std::endl; \
127  } \
128  itk::ImageBase<3> *img; \
129  img = dynamic_cast<itk::ImageBase<3>*>(rInv->GetDataObject()); \
130  if(img) \
131  { \
132  DD(img->GetRequestedRegion()) \
133  DD(img->GetLargestPossibleRegion()) \
134  } \
135  } \
136  exit(EXIT_FAILURE); \
137  }
138 //--------------------------------------------------------------------
139 
140 //--------------------------------------------------------------------
149 #ifdef RTK_TIME_EACH_FILTER
150 #undef itkSimpleNewMacro
151 #define itkSimpleNewMacro(x) \
152  static Pointer New(void) \
153  { \
154  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
155  if ( smartPtr.GetPointer() == nullptr ) \
156  { \
157  smartPtr = new x; \
158  } \
159  smartPtr->UnRegister(); \
160  /* If smartPtr is a ProcessObject, watch it */ \
161  itk::ProcessObject* processObjectPointer = nullptr; \
162  processObjectPointer = dynamic_cast<itk::ProcessObject*>(smartPtr.GetPointer()); \
163  if (processObjectPointer != nullptr) \
164  { \
165  rtk::GlobalTimer::GetInstance()->Watch(processObjectPointer); \
166  } \
167  return smartPtr; \
168  }
169 
170 #undef itkCreateAnotherMacro
171 #define itkCreateAnotherMacro(x) \
172  virtual::itk::LightObject::Pointer CreateAnother(void) const override \
173  { \
174  ::itk::LightObject::Pointer smartPtr; \
175  smartPtr = x::New().GetPointer(); \
176  return smartPtr; \
177  }
178 
179 #undef itkFactorylessNewMacro
180 #define itkFactorylessNewMacro(x) \
181  static Pointer New(void) \
182  { \
183  Pointer smartPtr; \
184  x * rawPtr = new x; \
185  smartPtr = rawPtr; \
186  rawPtr->UnRegister(); \
187  /* If smartPtr is a ProcessObject, watch it */ \
188  itk::ProcessObject* processObjectPointer = nullptr; \
189  processObjectPointer = dynamic_cast<itk::ProcessObject*>(smartPtr.GetPointer()); \
190  if (processObjectPointer != nullptr) \
191  { \
192  rtk::GlobalTimer::GetInstance()->Watch(processObjectPointer); \
193  } \
194  return smartPtr; \
195  } \
196  virtual::itk::LightObject::Pointer CreateAnother(void) const override \
197  { \
198  ::itk::LightObject::Pointer smartPtr; \
199  smartPtr = x::New().GetPointer(); \
200  return smartPtr; \
201  }
202 #endif //RTK_TIME_EACH_FILTER
203 
204 
205 #endif