13#ifndef ML_KERNEL_MACROS_H
14#define ML_KERNEL_MACROS_H
36 virtual void _calcKernelPage(SubImage *outSubImg, \
38 SubImage *inSubImgs, \
40 MLsoffset *indexTab, \
41 size_t indexTabSize, \
42 MLsoffset srcVoxelOffset, \
45 const ImageVector &ov1, \
46 const ImageVector &ov2, \
47 const ImageVector &pOf, \
48 size_t numVox) override; \
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
174#define _KERNEL_STD_PARAMS indexTab, indexTabSize, srcVoxelOffset, numVox, \
175 rowTab[0], outRowStartPointer, rowStart
180#define _KERNEL_STD_PARAMS_SUBIMG indexTab, indexTabSize, srcVoxelOffset, numVox, \
181 typedInTSubImgs[0], typedOutSubImg, rowStart
186#define _KERNEL_EXT_PARAMS indexTab, indexTabSize, srcVoxelOffset, numVox, \
187 rowTab, outRowStartPointer, rowStart, \
188 outIndex, numInSubImgs, loopIdx, iteration
193#define _KERNEL_EXT_PARAMS_SUBIMG indexTab, indexTabSize, srcVoxelOffset, numVox, \
194 typedInTSubImgs, typedOutSubImg, rowStart, \
195 outIndex, numInSubImgs, loopIdx, iteration
212#define _CALC_ROW_CPP_ANY(CLASS_NAME, SUPER_CLASS, TYPE_IMPLEMENTER, CASE_CODE) \
214 void CLASS_NAME::_calcKernelPage(SubImage *outSubImg, \
216 SubImage *inSubImgs, \
218 MLsoffset *indexTab, \
219 size_t indexTabSize, \
220 MLsoffset srcVoxelOffset, \
223 const ImageVector &ov1, \
224 const ImageVector &ov2, \
225 const ImageVector &pOf, \
229 ImageVector p, rowStart; \
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") \
250template <
typename INDTYPE>
260 "Unknown exception or out of memory. Returning "
261 "without calculating output page.");
286#define __KERNEL_CASE_CODE(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
289 IN_DATA_TYPE** rowTab = NULL; \
292 TSubImageWithCursor<OUT_DATA_TYPE > typedOutSubImg(*outSubImg); \
293 TSubImageWithCursor<IN_DATA_TYPE > *typedInTSubImgs = NULL; \
295 typedInTSubImgs = new TSubImageWithCursor<IN_DATA_TYPE >[mlrange_cast<size_t>(numInSubImgs)]; \
298 for (int inIdx=0; inIdx < numInSubImgs; ++inIdx){ \
299 typedInTSubImgs[inIdx].setData(inSubImgs[inIdx].getData()); \
300 typedInTSubImgs[inIdx].setBox (inSubImgs[inIdx].getBox()); \
304 rowTab = static_cast<IN_DATA_TYPE**> \
305 (MLAlloc(mlrange_cast<size_t>(numInSubImgs)*sizeof(IN_DATA_TYPE*), ML_THROW_NO_MEMORY)); \
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++){ \
314 rowStart.set(ov1.x, p.y, p.z, p.c, p.t, p.u); \
318 for (int inIdx=0; inIdx < numInSubImgs; ++inIdx){ \
321 typedInTSubImgs[inIdx].setCursorImagePosition(rowStart-pOf); \
322 rowTab[inIdx] = typedInTSubImgs[inIdx].getCursorPointer(); \
326 typedOutSubImg.setCursorImagePosition(rowStart); \
327 OUT_DATA_TYPE *outRowStartPointer = typedOutSubImg.getCursorPointer(); \
330 outRowStartPointer += 0; \
333 calcRow(ADD_PARAMS); \
341 __ML_KERNEL_CASE_CODE_clearAndHandleError(typedInTSubImgs, rowTab, false, #CLASS_NAME); \
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) \
355#define __KERNEL_CASE_CODE_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
357 ML_IMPLEMENT_DIFFERENT_INOUT_DATATYPES_CASES("", \
358 __KERNEL_CASE_CODE_EXT_DD_HELPER, \
359 inSubImgs->getDataType(), \
360 "__KERNEL_CASE_CODE_DD", \
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) \
377#define __KERNEL_CASE_CODE_SUBIMG_EXT_DD(OUT_DATA_TYPE, IN_DATA_TYPE, CLASS_NAME, ADD_PARAMS) \
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", \
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)
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)
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)
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)
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)
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)
#define ML_UNKNOWN_EXCEPTION
An unknown exception was detected and caught; this usually means that something for an unknown reason...
#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.