MeVisLab Toolbox Reference
mlKernelMacros.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_KERNEL_MACROS_H
14#define ML_KERNEL_MACROS_H
15
16
20//
21// For related code and more information see \c mlKernelExample.h,
22// \c mlKernel.h, \c mlKernelBaseModule.h, \c mlKernelModule.h,
23// \c mlKernelEditor.h, \c mlRankFilter.h, \c mlExtConvolutionFilter.h,
24// \c mlKernelMacros, \c mlKernelTools.h and \c mlConvolutionFilter.h.
25
26//----------------------------------------------------------------------------------------------------
33//----------------------------------------------------------------------------------------------------
34#define CALC_ROW_H() \
35 protected: \
36 virtual void _calcKernelPage(SubImage *outSubImg, \
37 int outIndex, \
38 SubImage *inSubImgs, \
39 int numInSubImgs, \
40 MLsoffset *indexTab, \
41 size_t indexTabSize, \
42 MLsoffset srcVoxelOffset, \
43 size_t loopIdx, \
44 size_t iteration, \
45 const ImageVector &ov1, \
46 const ImageVector &ov2, \
47 const ImageVector &pOf, \
48 size_t numVox) override; \
49
50
51//----------------------------------------------------------------------------------------------------
55//----------------------------------------------------------------------------------------------------
56#define CALC_ROW_CPP(CLASS_NAME, SUPER_CLASS) \
57 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE)
58
59//----------------------------------------------------------------------------------------------------
63//----------------------------------------------------------------------------------------------------
64#define CALC_ROW_DEFAULT_TYPES_CPP(CLASS_NAME, SUPER_CLASS) \
65 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_DEFAULT_CASES, _KERNEL_CASE_CODE)
66
67//----------------------------------------------------------------------------------------------------
73//----------------------------------------------------------------------------------------------------
74#define CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION) \
75 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION, _KERNEL_CASE_CODE)
76
77//----------------------------------------------------------------------------------------------------
81//----------------------------------------------------------------------------------------------------
82#define CALC_ROW_CPP_EXT(CLASS_NAME, SUPER_CLASS) \
83 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE_EXT)
84
85//----------------------------------------------------------------------------------------------------
89//----------------------------------------------------------------------------------------------------
90#define CALC_ROW_CPP_EXT_DD(CLASS_NAME, SUPER_CLASS) \
91 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE_EXT_DD)
92
93//----------------------------------------------------------------------------------------------------
100//----------------------------------------------------------------------------------------------------
101#define CALC_ROW_CPP_ANY_EXT(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION) \
102 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION, _KERNEL_CASE_CODE_EXT)
103
104
105
106//----------------------------------------------------------------------------------------------------
110//----------------------------------------------------------------------------------------------------
111#define CALC_ROW_CPP_SUBIMG(CLASS_NAME, SUPER_CLASS) \
112 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE_SUBIMG)
113
114//----------------------------------------------------------------------------------------------------
120//----------------------------------------------------------------------------------------------------
121#define CALC_ROW_CPP_ANY_SUBIMG(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION) \
122 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION, _KERNEL_CASE_CODE_SUBIMG)
123
124//----------------------------------------------------------------------------------------------------
128//----------------------------------------------------------------------------------------------------
129#define CALC_ROW_CPP_SUBIMG_EXT(CLASS_NAME, SUPER_CLASS) \
130 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE_SUBIMG_EXT)
131
132//----------------------------------------------------------------------------------------------------
137//----------------------------------------------------------------------------------------------------
138#define CALC_ROW_CPP_SUBIMG_EXT_DD(CLASS_NAME, SUPER_CLASS) \
139 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, ML_IMPLEMENT_SCALAR_CASES, _KERNEL_CASE_CODE_SUBIMG_EXT_DD)
140
141//----------------------------------------------------------------------------------------------------
147//----------------------------------------------------------------------------------------------------
148#define CALC_ROW_CPP_ANY_SUBIMG_EXT(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION) \
149 _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, SWITCH_SELECTION, _KERNEL_CASE_CODE_SUBIMG_EXT)
150
151
152
153
154
155
156
157
158//----------------------------------------------------------------------------------------------------
159//
160//
161//
162//
163// Now follows PRIVATE Stuff: Do not use! It is subject to change!
164//
165//
166//
167//
168//----------------------------------------------------------------------------------------------------
169
170
171//----------------------------------------------------------------------------------------------------
173//----------------------------------------------------------------------------------------------------
174#define _KERNEL_STD_PARAMS indexTab, indexTabSize, srcVoxelOffset, numVox, \
175 rowTab[0], outRowStartPointer, rowStart
176
177//----------------------------------------------------------------------------------------------------
179//----------------------------------------------------------------------------------------------------
180#define _KERNEL_STD_PARAMS_SUBIMG indexTab, indexTabSize, srcVoxelOffset, numVox, \
181 typedInTSubImgs[0], typedOutSubImg, rowStart
182
183//----------------------------------------------------------------------------------------------------
185//----------------------------------------------------------------------------------------------------
186#define _KERNEL_EXT_PARAMS indexTab, indexTabSize, srcVoxelOffset, numVox, \
187 rowTab, outRowStartPointer, rowStart, \
188 outIndex, numInSubImgs, loopIdx, iteration
189
190//----------------------------------------------------------------------------------------------------
192//----------------------------------------------------------------------------------------------------
193#define _KERNEL_EXT_PARAMS_SUBIMG indexTab, indexTabSize, srcVoxelOffset, numVox, \
194 typedInTSubImgs, typedOutSubImg, rowStart, \
195 outIndex, numInSubImgs, loopIdx, iteration
196
197
198//----------------------------------------------------------------------------------------------------
211//------------------------------------------------------------------------------------------------------
212#define _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, TYPE_IMPLEMENTER, CASE_CODE) \
213 \
214 void CLASS_NAME::_calcKernelPage(SubImage *outSubImg, \
215 int outIndex, \
216 SubImage *inSubImgs, \
217 int numInSubImgs, \
218 MLsoffset *indexTab, \
219 size_t indexTabSize, \
220 MLsoffset srcVoxelOffset, \
221 size_t loopIdx, \
222 size_t iteration, \
223 const ImageVector &ov1, \
224 const ImageVector &ov2, \
225 const ImageVector &pOf, \
226 size_t numVox) \
227 { \
228 /* Loop and position variables used in inner macros. */ \
229 ImageVector p, rowStart; \
230 \
231 /* Only to avoid warnings if not used by macro. */ \
232 loopIdx += 0u; \
233 iteration += 0u; \
234 outIndex += 0; \
235 \
236 switch(outSubImg->getDataType()){ \
237 TYPE_IMPLEMENTER(CLASS_NAME, CASE_CODE, OUT_SWITCH_TYPE, \
238 "_CALC_ROW_CPP_ANY", INTYPE_DUMMY) \
239 ML_IMPLEMENT_DEFAULT_HANDLING("_CALC_ROW_CPP_ANY") \
240 } \
241 } \
242
243
244
245//----------------------------------------------------------------------------------------------------
249//----------------------------------------------------------------------------------------------------
250template <typename INDTYPE>
251 void __ML_KERNEL_CASE_CODE_clearAndHandleError(ML_NAMESPACE::TSubImageWithCursor<INDTYPE> *&typedInTSubImgs,
252 INDTYPE **&rowTab,
253 bool err,
254 const char *className)
255 {
256 if (err){
257 // Print error only if requested.
258 ML_PRINT_ERROR(className ? className : "__KERNEL_CASE_CODE_SUBIMG",
260 "Unknown exception or out of memory. Returning "
261 "without calculating output page.");
262 }
263 /* Clean up. */
264 MLFree(rowTab);
265 rowTab = nullptr;
266 delete [] typedInTSubImgs;
267 typedInTSubImgs = nullptr;
268 }
269
270//----------------------------------------------------------------------------------------------------
285//----------------------------------------------------------------------------------------------------
286#define __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
287 { \
288 /* Pointer table to row starts in all input subimages. */ \
289 IN_DATA_TYPE** rowTab = NULL; \
290 \
291 /* Create typed versions of the subimages. */ \
292 TSubImageWithCursor<OUT_DATA_TYPE > typedOutSubImg(*outSubImg); \
293 TSubImageWithCursor<IN_DATA_TYPE > *typedInTSubImgs = NULL; \
294 /* Create a table of typed input subimages. */ \
295 typedInTSubImgs = new TSubImageWithCursor<IN_DATA_TYPE >[mlrange_cast<size_t>(numInSubImgs)]; \
296 \
297 /* Define contents of typed input subimages. */ \
298 for (int inIdx=0; inIdx < numInSubImgs; ++inIdx){ \
299 typedInTSubImgs[inIdx].setData(inSubImgs[inIdx].getData()); \
300 typedInTSubImgs[inIdx].setBox (inSubImgs[inIdx].getBox()); \
301 } \
302 \
303 /* Create a table of input pointers to rows. */ \
304 rowTab = static_cast<IN_DATA_TYPE**> \
305 (MLAlloc(mlrange_cast<size_t>(numInSubImgs)*sizeof(IN_DATA_TYPE*), ML_THROW_NO_MEMORY)); \
306 \
307 /* Loop over all rows of the subimages. */ \
308 for (p.u=ov1.u; p.u<=ov2.u; p.u++){ \
309 for (p.t=ov1.t; p.t<=ov2.t; p.t++){ \
310 for (p.c=ov1.c; p.c<=ov2.c; p.c++){ \
311 for (p.z=ov1.z; p.z<=ov2.z; p.z++){ \
312 for (p.y=ov1.y; p.y<=ov2.y; p.y++){ \
313 /* Set cursors to begin of rows in input and output subimage. */ \
314 rowStart.set(ov1.x, p.y, p.z, p.c, p.t, p.u); \
315 \
316 /* Call the calcRow() method of the module and pass all important information, */ \
317 /* especially the pointers to the rows starts in input and output subimages. */ \
318 for (int inIdx=0; inIdx < numInSubImgs; ++inIdx){ \
319 /* Set subimage cursor to row start and store it in rowStart. */ \
320 /* Note that pOf is the position offset passed to _calcKernelPage as argument. */ \
321 typedInTSubImgs[inIdx].setCursorImagePosition(rowStart-pOf); \
322 rowTab[inIdx] = typedInTSubImgs[inIdx].getCursorPointer(); \
323 } \
324 \
325 /* Set subimage cursor to row start and also set outRowStartPointer to it. */ \
326 typedOutSubImg.setCursorImagePosition(rowStart); \
327 OUT_DATA_TYPE *outRowStartPointer = typedOutSubImg.getCursorPointer(); \
328 \
329 /* Pointer table to row starts in all input subimages. */ \
330 outRowStartPointer += 0; /* To avoid compiler warnings. */ \
331 \
332 /* Call the user implemented calcRow function with the specified parameter set. */ \
333 calcRow(ADD_PARAMS); \
334 } /* y */ \
335 } \
336 } \
337 } \
338 } /* u */ \
339 \
340 /* Clean up without error. */ \
341 __ML_KERNEL_CASE_CODE_clearAndHandleError(typedInTSubImgs, rowTab, false, #CLASS_NAME); \
342 }
343
344
345//----------------------------------------------------------------------------------------------------
347//----------------------------------------------------------------------------------------------------
348#define __KERNEL_CASE_CODE_EXT_DD_HELPER(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
349 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, OPNAME, _KERNEL_EXT_PARAMS) \
350
351//----------------------------------------------------------------------------------------------------
354//----------------------------------------------------------------------------------------------------
355#define __KERNEL_CASE_CODE_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
356 { \
357 ML_IMPLEMENT_DIFFERENT_INOUT_DATATYPES_CASES("", \
358 __KERNEL_CASE_CODE_EXT_DD_HELPER, \
359 inSubImgs->getDataType(), \
360 "__KERNEL_CASE_CODE_DD", \
361 OUT_DATA_TYPE); \
362 \
363 } \
364
365//----------------------------------------------------------------------------------------------------
368//----------------------------------------------------------------------------------------------------
369#define __KERNEL_CASE_CODE_SUBIMG_EXT_DD_HELPER(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
370 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, OPNAME, _KERNEL_EXT_PARAMS_SUBIMG) \
371
372//----------------------------------------------------------------------------------------------------
376//----------------------------------------------------------------------------------------------------
377#define __KERNEL_CASE_CODE_SUBIMG_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
378 { \
379 ML_IMPLEMENT_DIFFERENT_SCALAR_INOUT_DATATYPES_CASES("", \
380 __KERNEL_CASE_CODE_SUBIMG_EXT_DD_HELPER, \
381 inSubImgs->getDataType(), \
382 "__KERNEL_CASE_SUBIMG_CODE_DD", \
383 OUT_DATA_TYPE); \
384 } \
385
386
387
388
389//----------------------------------------------------------------------------------------------------
391//----------------------------------------------------------------------------------------------------
392#define _KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
393 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_STD_PARAMS)
394
395//----------------------------------------------------------------------------------------------------
397//----------------------------------------------------------------------------------------------------
398#define _KERNEL_CASE_CODE_EXT(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
399 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_EXT_PARAMS)
400
401//----------------------------------------------------------------------------------------------------
404//----------------------------------------------------------------------------------------------------
405#define _KERNEL_CASE_CODE_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
406 __KERNEL_CASE_CODE_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_EXT_PARAMS)
407
408
409
410//----------------------------------------------------------------------------------------------------
412//----------------------------------------------------------------------------------------------------
413#define _KERNEL_CASE_CODE_SUBIMG(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
414 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_STD_PARAMS_SUBIMG)
415
416//----------------------------------------------------------------------------------------------------
418//----------------------------------------------------------------------------------------------------
419#define _KERNEL_CASE_CODE_SUBIMG_EXT(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
420 __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_EXT_PARAMS_SUBIMG)
421
422//----------------------------------------------------------------------------------------------------
425//----------------------------------------------------------------------------------------------------
426#define _KERNEL_CASE_CODE_SUBIMG_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME) \
427 __KERNEL_CASE_CODE_SUBIMG_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, _KERNEL_EXT_PARAMS_SUBIMG)
428
429
430
431#endif // __mlKernelMacros_H
432
433
434
435
#define ML_UNKNOWN_EXCEPTION
An unknown exception was detected and caught; this usually means that something for an unknown reason...
Definition mlTypeDefs.h:730
#define ML_PRINT_ERROR(FUNC_NAME, REASON, HANDLING)
Like ML_PRINT_ERROR_DUMP(FUNC_NAME, REASON, HANDLING, RT_OBJ) without a runtime object to be dumped.
void __ML_KERNEL_CASE_CODE_clearAndHandleError(ml::TSubImageWithCursor< INDTYPE > *&typedInTSubImgs, INDTYPE **&rowTab, bool err, const char *className)
Non-public template helper function to handle dynamic memory cleanup.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
ML_UTILS_EXPORT void MLFree(void *ptr)
Free function to be use instead of free if code is written which uses/bases on the ML.