2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbitkImage.h,v $
32 Date: $Date: 2012/11/16 08:50:39 $
33 Version: $Revision: 1.9 $
34 =========================================================================*/
41 #ifndef __BBITKIMAGE_H_INCLUDED__
42 #define __BBITKIMAGE_H_INCLUDED__
46 #include "bbtkSystem.h"
51 // bbtk typedefs for itk images
52 #define BBTK_TYPEDEF_ITK_IMAGE(TYPE,DIM) \
53 typedef itk::Image<TYPE,DIM> Image_##TYPE##_##DIM; \
54 typedef const Image_##TYPE##_##DIM Image_##TYPE##_##DIM##_c; \
55 typedef Image_##TYPE##_##DIM * Image_##TYPE##_##DIM##_ptr; \
56 typedef Image_##TYPE##_##DIM##_c * Image_##TYPE##_##DIM##_cptr;
59 #define BBTK_TYPEDEF_ITK_IMAGES_DIM(DIM) \
60 BBTK_TYPEDEF_ITK_IMAGE(int8_t,DIM); \
61 BBTK_TYPEDEF_ITK_IMAGE(uint8_t,DIM); \
62 BBTK_TYPEDEF_ITK_IMAGE(int16_t,DIM); \
63 BBTK_TYPEDEF_ITK_IMAGE(uint16_t,DIM); \
64 BBTK_TYPEDEF_ITK_IMAGE(int32_t,DIM); \
65 BBTK_TYPEDEF_ITK_IMAGE(uint32_t,DIM); \
66 BBTK_TYPEDEF_ITK_IMAGE(float,DIM); \
67 BBTK_TYPEDEF_ITK_IMAGE(double,DIM)
69 BBTK_TYPEDEF_ITK_IMAGES_DIM(2);
70 BBTK_TYPEDEF_ITK_IMAGES_DIM(3);
71 BBTK_TYPEDEF_ITK_IMAGES_DIM(4);
72 //BBTK_TYPEDEF_ITK_IMAGES_DIM(5)
76 #define BBTK_BEGIN_TEMPLATE_SWITCH(TYPE_INFO) if (false) {}
78 #define BBTK_END_TEMPLATE_SWITCH(TYPE_INFO) else { bbtkError("bbtk was not built for itk images of type <"<< bbtk::demangle_type_name(TYPE_INFO.name())<<">"); }
80 #define BBTK_END_TEMPLATE_SWITCH_MESSAGE(TYPE_INFO,MESSAGE) else { bbtkError(MESSAGE); }
82 /// Generic macro which calls a TEMPLATE_FUNCTION instanciated
83 /// on TEMPLATE_TYPE iff TYPE_INFO == typeid(TEST_TYPE).
84 /// This macro must be used (maybe several times) between a pair of BEGIN_TEMPLATE_SWITCH and END_TEMPLATE_SWITCH macros
85 #define TEMPLATE_SWITCH(TYPE_INFO,TEST_TYPE,TEMPLATE_FUNCTION,TEMPLATE_TYPE) \
86 else if (TYPE_INFO == typeid(bbitk::TEST_TYPE)) \
87 { TEMPLATE_FUNCTION<bbitk::TEMPLATE_TYPE>(); }
91 #ifdef BBTK_ITK_IMAGE_DIM_2
92 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
93 # define BBTK_SWITCH_ITK_IMAGE_int8_t_2(TYPE_INFO,FUN,CONST) \
94 TEMPLATE_SWITCH(TYPE_INFO,Image_int8_t_2_##CONST##ptr,FUN,Image_int8_t_2)
96 # define BBTK_SWITCH_ITK_IMAGE_int8_t_2(TYPE_INFO,FUN,CONST)
98 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
99 # define BBTK_SWITCH_ITK_IMAGE_int16_t_2(TYPE_INFO,FUN,CONST) \
100 TEMPLATE_SWITCH(TYPE_INFO,Image_int16_t_2_##CONST##ptr,FUN,Image_int16_t_2)
102 # define BBTK_SWITCH_ITK_IMAGE_int16_t_2(TYPE_INFO,FUN,CONST)
104 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
105 # define BBTK_SWITCH_ITK_IMAGE_int32_t_2(TYPE_INFO,FUN,CONST) \
106 TEMPLATE_SWITCH(TYPE_INFO,Image_int32_t_2_##CONST##ptr,FUN,Image_int32_t_2)
108 # define BBTK_SWITCH_ITK_IMAGE_int32_t_2(TYPE_INFO,FUN,CONST)
110 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
111 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_2(TYPE_INFO,FUN,CONST) \
112 TEMPLATE_SWITCH(TYPE_INFO,Image_uint8_t_2_##CONST##ptr,FUN,Image_uint8_t_2)
114 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_2(TYPE_INFO,FUN,CONST)
116 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
117 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_2(TYPE_INFO,FUN,CONST) \
118 TEMPLATE_SWITCH(TYPE_INFO,Image_uint16_t_2_##CONST##ptr,FUN,Image_uint16_t_2)
120 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_2(TYPE_INFO,FUN,CONST)
122 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
123 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_2(TYPE_INFO,FUN,CONST) \
124 TEMPLATE_SWITCH(TYPE_INFO,Image_uint32_t_2_##CONST##ptr,FUN,Image_uint32_t_2)
126 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_2(TYPE_INFO,FUN,CONST)
128 # ifdef BBTK_ITK_IMAGE_TYPE_float
129 # define BBTK_SWITCH_ITK_IMAGE_float_2(TYPE_INFO,FUN,CONST) \
130 TEMPLATE_SWITCH(TYPE_INFO,Image_float_2_##CONST##ptr,FUN,Image_float_2)
132 # define BBTK_SWITCH_ITK_IMAGE_float_2(TYPE_INFO,FUN,CONST)
134 # ifdef BBTK_ITK_IMAGE_TYPE_double
135 # define BBTK_SWITCH_ITK_IMAGE_double_2(TYPE_INFO,FUN,CONST) \
136 TEMPLATE_SWITCH(TYPE_INFO,Image_double_2_##CONST##ptr,FUN,Image_double_2)
138 # define BBTK_SWITCH_ITK_IMAGE_double_2(TYPE_INFO,FUN,CONST)
141 # define BBTK_SWITCH_ITK_IMAGE_int8_t_2(TYPE_INFO,FUN,CONST)
142 # define BBTK_SWITCH_ITK_IMAGE_int16_t_2(TYPE_INFO,FUN,CONST)
143 # define BBTK_SWITCH_ITK_IMAGE_int32_t_2(TYPE_INFO,FUN,CONST)
144 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_2(TYPE_INFO,FUN,CONST)
145 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_2(TYPE_INFO,FUN,CONST)
146 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_2(TYPE_INFO,FUN,CONST)
147 # define BBTK_SWITCH_ITK_IMAGE_float_2(TYPE_INFO,FUN,CONST)
148 # define BBTK_SWITCH_ITK_IMAGE_double_2(TYPE_INFO,FUN,CONST)
153 #ifdef BBTK_ITK_IMAGE_DIM_3
154 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
155 # define BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,CONST) \
156 TEMPLATE_SWITCH(TYPE_INFO,Image_int8_t_3_##CONST##ptr,FUN,Image_int8_t_3)
158 # define BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,CONST)
160 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
161 # define BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,CONST) \
162 TEMPLATE_SWITCH(TYPE_INFO,Image_int16_t_3_##CONST##ptr,FUN,Image_int16_t_3)
164 # define BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,CONST)
166 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
167 # define BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,CONST) \
168 TEMPLATE_SWITCH(TYPE_INFO,Image_int32_t_3_##CONST##ptr,FUN,Image_int32_t_3)
170 # define BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,CONST)
172 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
173 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,CONST) \
174 TEMPLATE_SWITCH(TYPE_INFO,Image_uint8_t_3_##CONST##ptr,FUN,Image_uint8_t_3)
176 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,CONST)
178 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
179 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,CONST) \
180 TEMPLATE_SWITCH(TYPE_INFO,Image_uint16_t_3_##CONST##ptr,FUN,Image_uint16_t_3)
182 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,CONST)
184 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
185 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,CONST) \
186 TEMPLATE_SWITCH(TYPE_INFO,Image_uint32_t_3_##CONST##ptr,FUN,Image_uint32_t_3)
188 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,CONST)
190 # ifdef BBTK_ITK_IMAGE_TYPE_float
191 # define BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,CONST) \
192 TEMPLATE_SWITCH(TYPE_INFO,Image_float_3_##CONST##ptr,FUN,Image_float_3)
194 # define BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,CONST)
196 # ifdef BBTK_ITK_IMAGE_TYPE_double
197 # define BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,CONST) \
198 TEMPLATE_SWITCH(TYPE_INFO,Image_double_3_##CONST##ptr,FUN,Image_double_3)
200 # define BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,CONST)
203 # define BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,CONST)
204 # define BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,CONST)
205 # define BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,CONST)
206 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,CONST)
207 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,CONST)
208 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,CONST)
209 # define BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,CONST)
210 # define BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,CONST)
215 #ifdef BBTK_ITK_IMAGE_DIM_4
216 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
217 # define BBTK_SWITCH_ITK_IMAGE_int8_t_4(TYPE_INFO,FUN,CONST) \
218 TEMPLATE_SWITCH(TYPE_INFO,Image_int8_t_4_##CONST##ptr,FUN,Image_int8_t_4)
220 # define BBTK_SWITCH_ITK_IMAGE_int8_t_4(TYPE_INFO,FUN,CONST)
222 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
223 # define BBTK_SWITCH_ITK_IMAGE_int16_t_4(TYPE_INFO,FUN,CONST) \
224 TEMPLATE_SWITCH(TYPE_INFO,Image_int16_t_4_##CONST##ptr,FUN,Image_int16_t_4)
226 # define BBTK_SWITCH_ITK_IMAGE_int16_t_4(TYPE_INFO,FUN,CONST)
228 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
229 # define BBTK_SWITCH_ITK_IMAGE_int32_t_4(TYPE_INFO,FUN,CONST) \
230 TEMPLATE_SWITCH(TYPE_INFO,Image_int32_t_4_##CONST##ptr,FUN,Image_int32_t_4)
232 # define BBTK_SWITCH_ITK_IMAGE_int32_t_4(TYPE_INFO,FUN,CONST)
234 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
235 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_4(TYPE_INFO,FUN,CONST) \
236 TEMPLATE_SWITCH(TYPE_INFO,Image_uint8_t_4_##CONST##ptr,FUN,Image_uint8_t_4)
238 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_4(TYPE_INFO,FUN,CONST)
240 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
241 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_4(TYPE_INFO,FUN,CONST) \
242 TEMPLATE_SWITCH(TYPE_INFO,Image_uint16_t_4_##CONST##ptr,FUN,Image_uint16_t_4)
244 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_4(TYPE_INFO,FUN,CONST)
246 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
247 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_4(TYPE_INFO,FUN,CONST) \
248 TEMPLATE_SWITCH(TYPE_INFO,Image_uint32_t_4_##CONST##ptr,FUN,Image_uint32_t_4)
250 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_4(TYPE_INFO,FUN,CONST)
252 # ifdef BBTK_ITK_IMAGE_TYPE_float
253 # define BBTK_SWITCH_ITK_IMAGE_float_4(TYPE_INFO,FUN,CONST) \
254 TEMPLATE_SWITCH(TYPE_INFO,Image_float_4_##CONST##ptr,FUN,Image_float_4)
256 # define BBTK_SWITCH_ITK_IMAGE_float_4(TYPE_INFO,FUN,CONST)
258 # ifdef BBTK_ITK_IMAGE_TYPE_double
259 # define BBTK_SWITCH_ITK_IMAGE_double_4(TYPE_INFO,FUN,CONST) \
260 TEMPLATE_SWITCH(TYPE_INFO,Image_double_4_##CONST##ptr,FUN,Image_double_4)
262 # define BBTK_SWITCH_ITK_IMAGE_double_4(TYPE_INFO,FUN,CONST)
265 # define BBTK_SWITCH_ITK_IMAGE_int8_t_4(TYPE_INFO,FUN,CONST)
266 # define BBTK_SWITCH_ITK_IMAGE_int16_t_4(TYPE_INFO,FUN,CONST)
267 # define BBTK_SWITCH_ITK_IMAGE_int32_t_4(TYPE_INFO,FUN,CONST)
268 # define BBTK_SWITCH_ITK_IMAGE_uint8_t_4(TYPE_INFO,FUN,CONST)
269 # define BBTK_SWITCH_ITK_IMAGE_uint16_t_4(TYPE_INFO,FUN,CONST)
270 # define BBTK_SWITCH_ITK_IMAGE_uint32_t_4(TYPE_INFO,FUN,CONST)
271 # define BBTK_SWITCH_ITK_IMAGE_float_4(TYPE_INFO,FUN,CONST)
272 # define BBTK_SWITCH_ITK_IMAGE_double_4(TYPE_INFO,FUN,CONST)
276 /// General macro which calls the template function FUN instanciated
277 /// on the right type of itk image depending on the value of TYPE_INFO (which must be of type type_info).
278 #define BBTK_TEMPLATE_ITK_IMAGE_SWITCH(TYPE_INFO,FUN) \
279 BBTK_BEGIN_TEMPLATE_SWITCH(TYPE_INFO) \
280 BBTK_SWITCH_ITK_IMAGE_int8_t_2(TYPE_INFO,FUN,) \
281 BBTK_SWITCH_ITK_IMAGE_int16_t_2(TYPE_INFO,FUN,) \
282 BBTK_SWITCH_ITK_IMAGE_int32_t_2(TYPE_INFO,FUN,) \
283 BBTK_SWITCH_ITK_IMAGE_uint8_t_2(TYPE_INFO,FUN,) \
284 BBTK_SWITCH_ITK_IMAGE_uint16_t_2(TYPE_INFO,FUN,) \
285 BBTK_SWITCH_ITK_IMAGE_uint32_t_2(TYPE_INFO,FUN,) \
286 BBTK_SWITCH_ITK_IMAGE_float_2(TYPE_INFO,FUN,) \
287 BBTK_SWITCH_ITK_IMAGE_double_2(TYPE_INFO,FUN,) \
288 BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,) \
289 BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,) \
290 BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,) \
291 BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,) \
292 BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,) \
293 BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,) \
294 BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,) \
295 BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,) \
296 BBTK_SWITCH_ITK_IMAGE_int8_t_4(TYPE_INFO,FUN,) \
297 BBTK_SWITCH_ITK_IMAGE_int16_t_4(TYPE_INFO,FUN,) \
298 BBTK_SWITCH_ITK_IMAGE_int32_t_4(TYPE_INFO,FUN,) \
299 BBTK_SWITCH_ITK_IMAGE_uint8_t_4(TYPE_INFO,FUN,) \
300 BBTK_SWITCH_ITK_IMAGE_uint16_t_4(TYPE_INFO,FUN,) \
301 BBTK_SWITCH_ITK_IMAGE_uint32_t_4(TYPE_INFO,FUN,) \
302 BBTK_SWITCH_ITK_IMAGE_float_4(TYPE_INFO,FUN,) \
303 BBTK_SWITCH_ITK_IMAGE_double_4(TYPE_INFO,FUN,) \
304 BBTK_END_TEMPLATE_SWITCH(TYPE_INFO)
308 /// General macro which calls the template function FUN instanciated
309 /// on the right type of itk image depending on the value of TYPE_INFO (which must be of type type_info).
310 #define BBTK_TEMPLATE_ITK_IMAGE_DIM_3_SWITCH(TYPE_INFO,FUN,ERROR_MESSAGE) \
311 BBTK_BEGIN_TEMPLATE_SWITCH(TYPE_INFO) \
312 BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,) \
313 BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,) \
314 BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,) \
315 BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,) \
316 BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,) \
317 BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,) \
318 BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,) \
319 BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,) \
320 BBTK_END_TEMPLATE_SWITCH_MESSAGE(TYPE_INFO,ERROR_MESSAGE)
323 /// General macro which calls the template function FUN instanciated
324 /// on the right type of itk image depending on the value of TYPE_INFO (which must be of type type_info).
326 #define BBTK_TEMPLATE_CONST_ITK_IMAGE_SWITCH(TYPE_INFO,FUN) \
327 BBTK_BEGIN_TEMPLATE_SWITCH(TYPE_INFO) \
328 BBTK_SWITCH_ITK_IMAGE_int8_t_2(TYPE_INFO,FUN,c) \
329 BBTK_SWITCH_ITK_IMAGE_int16_t_2(TYPE_INFO,FUN,c) \
330 BBTK_SWITCH_ITK_IMAGE_int32_t_2(TYPE_INFO,FUN,c) \
331 BBTK_SWITCH_ITK_IMAGE_uint8_t_2(TYPE_INFO,FUN,c) \
332 BBTK_SWITCH_ITK_IMAGE_uint16_t_2(TYPE_INFO,FUN,c) \
333 BBTK_SWITCH_ITK_IMAGE_uint32_t_2(TYPE_INFO,FUN,c) \
334 BBTK_SWITCH_ITK_IMAGE_float_2(TYPE_INFO,FUN,c) \
335 BBTK_SWITCH_ITK_IMAGE_double_2(TYPE_INFO,FUN,c) \
336 BBTK_SWITCH_ITK_IMAGE_int8_t_3(TYPE_INFO,FUN,c) \
337 BBTK_SWITCH_ITK_IMAGE_int16_t_3(TYPE_INFO,FUN,c) \
338 BBTK_SWITCH_ITK_IMAGE_int32_t_3(TYPE_INFO,FUN,c) \
339 BBTK_SWITCH_ITK_IMAGE_uint8_t_3(TYPE_INFO,FUN,c) \
340 BBTK_SWITCH_ITK_IMAGE_uint16_t_3(TYPE_INFO,FUN,c) \
341 BBTK_SWITCH_ITK_IMAGE_uint32_t_3(TYPE_INFO,FUN,c) \
342 BBTK_SWITCH_ITK_IMAGE_float_3(TYPE_INFO,FUN,c) \
343 BBTK_SWITCH_ITK_IMAGE_double_3(TYPE_INFO,FUN,c) \
344 BBTK_SWITCH_ITK_IMAGE_int8_t_4(TYPE_INFO,FUN,c) \
345 BBTK_SWITCH_ITK_IMAGE_int16_t_4(TYPE_INFO,FUN,c) \
346 BBTK_SWITCH_ITK_IMAGE_int32_t_4(TYPE_INFO,FUN,c) \
347 BBTK_SWITCH_ITK_IMAGE_uint8_t_4(TYPE_INFO,FUN,c) \
348 BBTK_SWITCH_ITK_IMAGE_uint16_t_4(TYPE_INFO,FUN,c) \
349 BBTK_SWITCH_ITK_IMAGE_uint32_t_4(TYPE_INFO,FUN,c) \
350 BBTK_SWITCH_ITK_IMAGE_float_4(TYPE_INFO,FUN,c) \
351 BBTK_SWITCH_ITK_IMAGE_double_4(TYPE_INFO,FUN,c) \
352 BBTK_END_TEMPLATE_SWITCH(TYPE_INFO)
354 #define BBTK_GITIFPTI_DIM(DIM) \
355 if (pti == typeid(unsigned char)) \
356 return typeid(itk::Image<unsigned char,DIM>*); \
357 if (pti == typeid(unsigned short)) \
358 return typeid(itk::Image<unsigned short,DIM>*); \
359 if (pti == typeid(unsigned int)) \
360 return typeid(itk::Image<unsigned int,DIM>*); \
361 if (pti == typeid(unsigned long)) \
362 return typeid(itk::Image<unsigned long,DIM>*); \
363 if (pti == typeid(signed char)) \
364 return typeid(itk::Image<signed char,DIM>*); \
365 if (pti == typeid(signed short)) \
366 return typeid(itk::Image<signed short,DIM>*); \
367 if (pti == typeid(signed int)) \
368 return typeid(itk::Image<signed int,DIM>*); \
369 if (pti == typeid(signed long)) \
370 return typeid(itk::Image<signed long,DIM>*); \
371 if (pti == typeid(float)) \
372 return typeid(itk::Image<float,DIM>*); \
373 if (pti == typeid(double)) \
374 return typeid(itk::Image<double,DIM>*);
377 inline bbtk::TypeInfo GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(
381 if (dim==2) { BBTK_GITIFPTI_DIM(2); }
382 else if (dim==3) { BBTK_GITIFPTI_DIM(3); }
383 else if (dim==4) { BBTK_GITIFPTI_DIM(4); }
386 //bbtkGlobalError("GetImageTypeInfoFromPixelTypeInfo : itk::Images not compiled for dim "<<dim);
393 #undef BBTK_GITIFPTI_DIM
397 template <typename ValueType>
403 template <typename T>
406 return m_map[ (void*)typeid(T).name() ];
408 template <typename T>
409 ValueType& operator[]( const T& )
411 return m_map[ (void*)typeid(T).name() ];
414 ValueType& operator[]( const std::type_info& t)
416 return m_map[ (void*)t.name() ];
419 unsigned int size() const { return m_map.size(); }
421 typedef typename std::map<void*, ValueType>::const_iterator const_iterator;
423 const_iterator begin() const { return m_map.begin(); }
424 const_iterator end() const { return m_map.end(); }
427 std::map<void*, ValueType> m_map;
430 #define BBTK_BUILD_ITK_IMAGE_FUNCTION_MAPPING(MAP,FUN) \
431 MAP.value<bbtk::Image_int8_t_2_ptr>() = FUN<bbtk::Image_int8_t_2_ptr>; \
432 MAP.value<bbtk::Image_int16_t_2_ptr>() = FUN<bbtk::Image_int16_t_2_ptr>; \
433 MAP.value<bbtk::Image_int32_t_2_ptr>() = FUN<bbtk::Image_int32_t_2_ptr>; \
434 MAP.value<bbtk::Image_uint8_t_2_ptr>() = FUN<bbtk::Image_uint8_t_2_ptr>; \
435 MAP.value<bbtk::Image_uint16_t_2_ptr>() = FUN<bbtk::Image_uint16_t_2_ptr>; \
436 MAP.value<bbtk::Image_uint32_t_2_ptr>() = FUN<bbtk::Image_uint32_t_2_ptr>; \
437 MAP.value<bbtk::Image_float_2_ptr>() = FUN<bbtk::Image_float_2_ptr>; \
438 MAP.value<bbtk::Image_double_2_ptr>() = FUN<bbtk::Image_double_2_ptr>; \
439 MAP.value<bbtk::Image_int8_t_3_ptr>() = FUN<bbtk::Image_int8_t_3_ptr>; \
440 MAP.value<bbtk::Image_int16_t_3_ptr>() = FUN<bbtk::Image_int16_t_3_ptr>; \
441 MAP.value<bbtk::Image_int32_t_3_ptr>() = FUN<bbtk::Image_int32_t_3_ptr>; \
442 MAP.value<bbtk::Image_uint8_t_3_ptr>() = FUN<bbtk::Image_uint8_t_3_ptr>; \
443 MAP.value<bbtk::Image_uint16_t_3_ptr>() = FUN<bbtk::Image_uint16_t_3_ptr>; \
444 MAP.value<bbtk::Image_uint32_t_3_ptr>() = FUN<bbtk::Image_uint32_t_3_ptr>; \
445 MAP.value<bbtk::Image_float_3_ptr>() = FUN<bbtk::Image_float_3_ptr>; \
446 MAP.value<bbtk::Image_double_3_ptr>() = FUN<bbtk::Image_double_3_ptr>; \
447 MAP.value<bbtk::Image_int8_t_4_ptr>() = FUN<bbtk::Image_int8_t_4_ptr>; \
448 MAP.value<bbtk::Image_int16_t_4_ptr>() = FUN<bbtk::Image_int16_t_4_ptr>; \
449 MAP.value<bbtk::Image_int32_t_4_ptr>() = FUN<bbtk::Image_int32_t_4_ptr>; \
450 MAP.value<bbtk::Image_uint8_t_4_ptr>() = FUN<bbtk::Image_uint8_t_4_ptr>; \
451 MAP.value<bbtk::Image_uint16_t_4_ptr>() = FUN<bbtk::Image_uint16_t_4_ptr>; \
452 MAP.value<bbtk::Image_uint32_t_4_ptr>() = FUN<bbtk::Image_uint32_t_4_ptr>; \
453 MAP.value<bbtk::Image_float_4_ptr>() = FUN<bbtk::Image_float_4_ptr>; \
454 MAP.value<bbtk::Image_double_4_ptr>() = FUN<bbtk::Image_double_4_ptr>;
456 //=======================================================================
459 //=======================================================================
460 // Type traits ImagePointer to define bbtk::any<ImagePointer>
461 /// The TypeTraits for all itk::Image pointer types
462 template <typename T> struct ImagePointer { static const bool value = false; };
464 typedef bbtk::any<ImagePointer> anyImagePointer;
466 // Specialisations for instantiated image types
468 #ifdef BBTK_ITK_IMAGE_DIM_2
469 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
470 template <> struct ImagePointer<Image_int8_t_2_ptr> { static const bool value = true; };
472 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
473 template <> struct ImagePointer<Image_int16_t_2_ptr> { static const bool value = true; };
475 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
476 template <> struct ImagePointer<Image_int32_t_2_ptr> { static const bool value = true; };
478 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
479 template <> struct ImagePointer<Image_uint8_t_2_ptr> { static const bool value = true; };
481 # ifdef BBTK_ITK_IMAGE_TYPE_uint16_t
482 template <> struct ImagePointer<Image_uint16_t_2_ptr> { static const bool value = true; };
484 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
485 template <> struct ImagePointer<Image_uint32_t_2_ptr> { static const bool value = true; };
487 # ifdef BBTK_ITK_IMAGE_TYPE_float
488 template <> struct ImagePointer<Image_float_2_ptr> { static const bool value = true; };
490 # ifdef BBTK_ITK_IMAGE_TYPE_double
491 template <> struct ImagePointer<Image_double_2_ptr> { static const bool value = true; };
497 #ifdef BBTK_ITK_IMAGE_DIM_3
498 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
499 template <> struct ImagePointer<Image_int8_t_3_ptr> { static const bool value = true; };
501 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
502 template <> struct ImagePointer<Image_int16_t_3_ptr> { static const bool value = true; };
504 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
505 template <> struct ImagePointer<Image_int32_t_3_ptr> { static const bool value = true; };
507 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
508 template <> struct ImagePointer<Image_uint8_t_3_ptr> { static const bool value = true; };
510 # ifdef BBTK_ITK_IMAGE_TYPE_uint16_t
511 template <> struct ImagePointer<Image_uint16_t_3_ptr> { static const bool value = true; };
513 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
514 template <> struct ImagePointer<Image_uint32_t_3_ptr> { static const bool value = true; };
516 # ifdef BBTK_ITK_IMAGE_TYPE_float
517 template <> struct ImagePointer<Image_float_3_ptr> { static const bool value = true; };
519 # ifdef BBTK_ITK_IMAGE_TYPE_double
520 template <> struct ImagePointer<Image_double_3_ptr> { static const bool value = true; };
526 #ifdef BBTK_ITK_IMAGE_DIM_4
527 # ifdef BBTK_ITK_IMAGE_TYPE_int8_t
528 template <> struct ImagePointer<Image_int8_t_4_ptr> { static const bool value = true; };
530 # ifdef BBTK_ITK_IMAGE_TYPE_int16_t
531 template <> struct ImagePointer<Image_int16_t_4_ptr> { static const bool value = true; };
533 # ifdef BBTK_ITK_IMAGE_TYPE_int32_t
534 template <> struct ImagePointer<Image_int32_t_4_ptr> { static const bool value = true; };
536 # ifdef BBTK_ITK_IMAGE_TYPE_uint8_t
537 template <> struct ImagePointer<Image_uint8_t_4_ptr> { static const bool value = true; };
539 # ifdef BBTK_ITK_IMAGE_TYPE_uint16_t
540 template <> struct ImagePointer<Image_uint16_t_4_ptr> { static const bool value = true; };
542 # ifdef BBTK_ITK_IMAGE_TYPE_uint32_t
543 template <> struct ImagePointer<Image_uint32_t_4_ptr> { static const bool value = true; };
545 # ifdef BBTK_ITK_IMAGE_TYPE_float
546 template <> struct ImagePointer<Image_float_4_ptr> { static const bool value = true; };
548 # ifdef BBTK_ITK_IMAGE_TYPE_double
549 template <> struct ImagePointer<Image_double_4_ptr> { static const bool value = true; };
558 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(bbitk::anyImagePointer,"anyItkImagePointer");
559 // BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(bbitk::Image_double_2_ptr,"itkImageDouble3ptr");
560 // BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(bbitk::Image_double_3_ptr,"itkImageDouble3ptr");
562 // Human readable names for itk images
563 // #define BBTK_HUMAN_READABLE_ITK_IMAGE_NAME(TYPE,DIM) std::string("itkImage")+HumanTypeName<TYPE>()+std::string(#DIM)+std::string("ptr")
565 #define BBTK_HUMAN_READABLE_ITK_IMAGE(TYPE,DIM) \
566 template <> inline std::string HumanTypeName< bbitk::Image_##TYPE##_##DIM##_ptr >() \
567 { std::string n("itkImage"); \
568 n+= HumanTypeName<TYPE>(); \
569 n += std::string(#DIM); \
570 n += std::string("ptr"); \
572 template <> inline std::string HumanTypeName< bbitk::Image_##TYPE##_##DIM##_ptr >(const bbitk::Image_##TYPE##_##DIM##_ptr &) \
573 { std::string n("itkImage");\
574 n+= HumanTypeName<TYPE>(); \
575 n += std::string(#DIM); \
576 n+= std::string("ptr"); \
578 template <> inline std::string HumanTypeName< bbitk::Image_##TYPE##_##DIM##_cptr >() \
579 { std::string n("itkImage"); \
580 n+= HumanTypeName<TYPE>();\
581 n += std::string(#DIM);\
582 n += std::string("cptr"); \
584 template <> inline std::string HumanTypeName< bbitk::Image_##TYPE##_##DIM##_cptr >(const bbitk::Image_##TYPE##_##DIM##_cptr &) \
585 { std::string n("itkImage");\
586 n+= HumanTypeName<TYPE>(); \
587 n += std::string(#DIM); \
588 n+= std::string("cptr"); \
591 //BBTK_HUMAN_READABLE_ITK_IMAGE(int8_t,2);
593 // BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(bbitk::Image_##TYPE##_##DIM##_ptr,BBTK_HUMAN_READABLE_ITK_IMAGE_NAME(TYPE,DIM) )
596 #define BBTK_HUMAN_READABLE_ITK_IMAGES_DIM(DIM) \
597 BBTK_HUMAN_READABLE_ITK_IMAGE(int8_t,DIM); \
598 BBTK_HUMAN_READABLE_ITK_IMAGE(uint8_t,DIM); \
599 BBTK_HUMAN_READABLE_ITK_IMAGE(int16_t,DIM); \
600 BBTK_HUMAN_READABLE_ITK_IMAGE(uint16_t,DIM);\
601 BBTK_HUMAN_READABLE_ITK_IMAGE(int32_t,DIM); \
602 BBTK_HUMAN_READABLE_ITK_IMAGE(uint32_t,DIM);\
603 BBTK_HUMAN_READABLE_ITK_IMAGE(float,DIM); \
604 BBTK_HUMAN_READABLE_ITK_IMAGE(double,DIM)
606 BBTK_HUMAN_READABLE_ITK_IMAGES_DIM(2);
607 BBTK_HUMAN_READABLE_ITK_IMAGES_DIM(3);
608 BBTK_HUMAN_READABLE_ITK_IMAGES_DIM(4);
609 //BBTK_HUMAN_READABLE_ITK_IMAGES_DIM(5)