HBase.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*****************************************************************************
  2. * HBase.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/libhalcon
  6. * Description: Basic definitions for HALCON, HALCON/C, HALCON/C++
  7. * and other language interfaces
  8. *
  9. * (c) 1996-2020 by MVTec Software GmbH
  10. * www.mvtec.com
  11. *
  12. *****************************************************************************/
  13. #ifndef HBASE_H
  14. #define HBASE_H
  15. #include <stdlib.h> /* NULL */
  16. #include "HIntDef.h"
  17. typedef void* VOIDP;
  18. /*****************************************************************************/
  19. /* Parameter passing (Control parameters) */
  20. /*****************************************************************************/
  21. #define UNDEF_PAR 0 /* Parameter type: no defined type */
  22. #define LONG_PAR 1 /* Parameter type: long */
  23. #define FLOAT_PAR 2 /* Parameter type: float */
  24. #define STRING_PAR 4 /* Parameter type: string */
  25. #define HANDLE_PAR 16 /* Parameter type: handle (arbitrary data) */
  26. #define INT_PAR LONG_PAR /* Parameter type: int */
  27. #define DOUBLE_PAR FLOAT_PAR /* Parameter type: double */
  28. #define MIXED_PAR 8 /* Parameter type: Hcpar */
  29. #define MAX_TUPLE_TYPE HANDLE_PAR /* maximum type number */
  30. /* Possible parameter types for a single element: */
  31. #define ANY_ELEM (LONG_PAR|FLOAT_PAR|STRING_PAR|HANDLE_PAR)
  32. /* Possible parameter types for a tuple: */
  33. #define ANY_TUPLE (ANY_ELEM|MIXED_PAR)
  34. /* 32 reserved */
  35. #define POINTER_PAR 64 /* Parameter type: pointer to any type */
  36. #define TUPLE_PAR 128 /* Parameter type: pointer to tuple */
  37. #define MAX_PAR HANDLE_PAR
  38. /*****************************************************************************/
  39. /* Constants and basic types */
  40. /*****************************************************************************/
  41. #define MAX_TUPLE_LENGTH 1000000 /* max. length of a tuple */
  42. #define MAX_STRING 1024 /* max. length of a string */
  43. typedef UINT4 Herror; /* Type function values (error messages) */
  44. typedef long *Hkey; /* primary key in DB (for iconic objects) */
  45. #define UNDEF_KEY (Hkey)(0) /* Undefined iconic object */
  46. /*****************************************************************************/
  47. /* Structures for passing parameters between language interface and core */
  48. /*****************************************************************************/
  49. #ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
  50. /* sets the struct member alignment to avoid problems if
  51. * the settings of the user differ to those of the HALCON
  52. * version. (8 is the default alignment, generally) */
  53. # pragma pack(push,8)
  54. #endif
  55. /*****************************************************************************/
  56. /* HALCON procedure (operator) handle */
  57. /*****************************************************************************/
  58. /* This data structure contains all informations about an instance of an */
  59. /* HALCON operator or an HALCON thread derived from an HALCON operator */
  60. /* instance. The contained information describes the processing context of */
  61. /* HALCON operators (e.g. parameter values, debugging information, etc.). */
  62. /*****************************************************************************/
  63. typedef void *Hproc_handle;
  64. /*****************************************************************************/
  65. /* Structures, Functions and Defines for Handles */
  66. /*****************************************************************************/
  67. struct HStreamBufferT;
  68. struct HhandleListT;
  69. /****************************************************************************/
  70. /** HSignalTypeEnum: List of signals that can be sent to handles
  71. ****************************************************************************
  72. * This enum defines a set of signals that can be sent to the
  73. * signalling callback of handles. Note that the callback functions must
  74. * ignore any signal that they do not understand.
  75. ****************************************************************************/
  76. typedef enum {
  77. eSignalNone = 0, /**< No signal */
  78. eSignalStartAbort, /**< Initiate abort: stop running, abort mutexes etc. */
  79. eSignalAbort, /**< Finalize abort, wait for resources to finish */
  80. eSignalRestore, /**< After abortion is complete, restore mutexes etc. */
  81. } HSignalTypeEnum;
  82. typedef Herror (*HHandleSerializeFunc)(Hproc_handle, struct HStreamBufferT *,
  83. void *);
  84. typedef Herror (*HHandleDeserializeFunc)(Hproc_handle, struct HStreamBufferT *,
  85. void **);
  86. typedef Herror (*HHandleDestructorFunc)(Hproc_handle, void *);
  87. typedef Herror (*HHandleSignalFunc)(HSignalTypeEnum signal, void *);
  88. /****************************************************************************/
  89. /** HHandleInfo holds handle type information.
  90. ****************************************************************************
  91. * This structure exists once per handle type (usually per sem_type).
  92. * It contains basic, static, constant information about that type.
  93. * Most notably, it contains pointers to the functions that operate on the
  94. * handles (clear, serialize, deserialize and signal).
  95. *
  96. * Handles (instances) of types where the cb_signal callback is not NULL are
  97. * stored in a list that allows calling the signal callback for each of them.
  98. *
  99. * All serialized items must have a unique header, usually a string, that
  100. * identifies them. 'header' contains a pointer to that header, allowing
  101. * other functions to identify a serialized item based on its header.
  102. * If no (de)serialization function is set, header must be NULL.
  103. *
  104. * \ingroup data_structures_handles
  105. ****************************************************************************/
  106. typedef struct H_HANDLE_TYPE {
  107. INT4_8 type_id; /**< Type ID */
  108. const char * sem_type; /**< sem_type of the handle */
  109. HHandleSerializeFunc cb_serialize; /**< Serialize this handle type */
  110. HHandleDeserializeFunc cb_deserialize; /**< Deserialize this handle type */
  111. const char * header; /**< Serialization header */
  112. HHandleDestructorFunc cb_clear; /**< Clear this handle type */
  113. HHandleSignalFunc cb_signal; /**< Signal (for semaphores etc.) */
  114. struct HhandleListT * list; /**< List of handles, or NULL */
  115. } HHandleInfo;
  116. /****************************************************************************/
  117. /** HANDLE_INFO_INITIALIZER: Convenience macro for initializing HHandleInfo
  118. ****************************************************************************/
  119. # define HANDLE_INFO_INITIALIZER(TYPE_ID, SEM_TYPE, FUN_SERIALIZE, \
  120. FUN_DESERIALIZE, HEADER_STRING, FUN_CLEAR, \
  121. FUN_SIGNAL, LIST) \
  122. { \
  123. (INT4_8)(TYPE_ID), (SEM_TYPE), (HHandleSerializeFunc)(FUN_SERIALIZE), \
  124. (HHandleDeserializeFunc)(FUN_DESERIALIZE), HEADER_STRING, \
  125. (HHandleDestructorFunc)(FUN_CLEAR), \
  126. (HHandleSignalFunc)(FUN_SIGNAL), (LIST) \
  127. }
  128. /****************************************************************************/
  129. /** HANDLE_INFO_INITIALIZER_NOSER: Convenience macro for init. HHandleInfo
  130. ****************************************************************************
  131. * Use this macro for handles that cannot be (de)serialized.
  132. ****************************************************************************/
  133. # define HANDLE_INFO_INITIALIZER_NOSER(TYPE_ID, SEM_TYPE, FUN_CLEAR, \
  134. FUN_SIGNAL, LIST) \
  135. { \
  136. (INT4_8)(TYPE_ID), (SEM_TYPE), (HHandleSerializeFunc)NULL, \
  137. (HHandleDeserializeFunc)NULL, (const char *)NULL, \
  138. (HHandleDestructorFunc)(FUN_CLEAR), \
  139. (HHandleSignalFunc)(FUN_SIGNAL), (LIST) \
  140. }
  141. typedef struct HhandleT *Hphandle;
  142. typedef union
  143. {
  144. INT4_8 l; /* 4/8 byte integer (input) */
  145. double d; /* 8 byte real (input) */
  146. char *s; /* pointer to strings (input) */
  147. double f; /* 8 byte real (legacy 11.0) (input) */
  148. Hphandle h; /* Pointer to handle (input) */
  149. } Hpar; /* parameter passing for the C interface */
  150. typedef union
  151. {
  152. INT4_8 *l; /* 4/8 byte integer (output) */
  153. double *d; /* 8 byte real, (output) */
  154. char *s; /* pointer to strings (output) */
  155. void *p; /* pointer to var. of any type (e.g. tuple)(output)*/
  156. double *f; /* 8 byte real, (legacy 11.0) (output) */
  157. } Hvar; /* parameter passing for the C interface */
  158. typedef struct
  159. {
  160. Hpar par; /* values */
  161. HINT type; /* type flag */
  162. } Hcpar; /* parameter passing for the C interface */
  163. typedef struct
  164. {
  165. Hvar var; /* values */
  166. HINT type; /* type flag */
  167. } Hcvar; /* parameter passing for the C interface */
  168. typedef union {
  169. INT4_8 *l;
  170. double *d;
  171. char **s;
  172. Hcpar *cpar;
  173. Hphandle *h;
  174. } Hcelem; /* pure type array */
  175. typedef struct HCTUPLE
  176. {
  177. Hpar val;
  178. HINT type;
  179. /*
  180. * Add manual padding here so that a Hcpar can be mapped to a Hctuple exactly,
  181. * including the padding compilers insert at the end of data structures to
  182. * align the entire structure to the largest alignment of any structure
  183. * member. Note that on 32 bit Linux for Intel, Hcpar is aligned to 4 bytes,
  184. * so no manual padding is necessary on that architecture (only).
  185. */
  186. #if !(defined(__linux__) && defined(__i386__))
  187. char pad[sizeof(Hcpar)-sizeof(Hpar)-sizeof(HINT)];
  188. #endif
  189. INT4_8 num; /* number of set array elements */
  190. INT4_8 capacity; /* allocated array length */
  191. HINT free; /* free array elem when destroying tuple? */
  192. Hcelem elem; /* the actual array */
  193. } Hctuple;
  194. #define HCTUPLE_INITIALIZER {{0},UNDEF_PAR,{0},0,0,0,{NULL}}
  195. typedef struct
  196. {
  197. Hcvar *variables; /* variables (of application) to write back values */
  198. Hcpar *element; /* tuple element(s) */
  199. INT4_8 num_el; /* number of used elements */
  200. INT4_8 length; /* total length of array (incl. unused elements) */
  201. } Hcvtuple; /* for passing control parameter variables from */
  202. /* the language to the core interface */
  203. #ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
  204. # pragma pack(pop)
  205. #endif
  206. /*****************************************************************************/
  207. /* Bool constants */
  208. /*****************************************************************************/
  209. #ifdef TRUE
  210. #undef TRUE
  211. #endif
  212. #define TRUE true
  213. #ifdef FALSE
  214. #undef FALSE
  215. #endif
  216. #define FALSE false
  217. /*****************************************************************************/
  218. /* Pixel types of HALCON images */
  219. /*****************************************************************************/
  220. #define UNDEF_IMAGE (HINT)0
  221. #define BYTE_IMAGE (HINT)(1<<0)
  222. #define INT4_IMAGE (HINT)(1<<1)
  223. #define LONG_IMAGE INT4_IMAGE
  224. #define FLOAT_IMAGE (HINT)(1<<2)
  225. #define DIR_IMAGE (HINT)(1<<3)
  226. #define CYCLIC_IMAGE (HINT)(1<<4)
  227. #define INT1_IMAGE (HINT)(1<<5)
  228. /* (1<<6) omitted so far -> use it for next new image type */
  229. #define COMPLEX_IMAGE (HINT)(1<<7)
  230. /* (1<<8) omitted so far -> use it for next new image type */
  231. #define INT2_IMAGE (HINT)(1<<9)
  232. #define UINT2_IMAGE (HINT)(1<<10)
  233. #define VF_IMAGE (HINT)(1<<11)
  234. #define INT8_IMAGE (HINT)(1<<12)
  235. /*****************************************************************************/
  236. /* Type of HALCON vector field images */
  237. /*****************************************************************************/
  238. #define VF_ABSOLUTE (INT4)0
  239. #define VF_RELATIVE (INT4)(1<<0)
  240. /*****************************************************************************/
  241. /* data types for handling pthreads (POSIX threads) and mutex variables */
  242. /*****************************************************************************/
  243. typedef void* H_pthread_t; /* pthread handle */
  244. typedef void* H_pthread_mutex_t; /* pthread mutex data type */
  245. typedef void* H_pthread_cond_t; /* pthread condition variable */
  246. typedef void* H_pthread_barrier_t; /* pthread barrier variable */
  247. /*****************************************************************************/
  248. /* signature of the callback functions for drawing objects */
  249. /*****************************************************************************/
  250. #ifndef _WIN32
  251. #define __stdcall
  252. #endif
  253. typedef Herror (__stdcall *HDrawObjectCallback)(Hphandle DrawHandle,
  254. Hphandle WindowHandle,
  255. char* type);
  256. /*****************************************************************************/
  257. /* signature of the callback functions for buffer window content updates */
  258. /*****************************************************************************/
  259. typedef Herror (__stdcall *HUpdateContentCallback)(void *context);
  260. /*****************************************************************************/
  261. /* signature of the callback function for license recheck failure callbacks */
  262. /*****************************************************************************/
  263. typedef void (__stdcall *HLicenseRecheckFailedCallback)(void *context,
  264. Herror error);
  265. /* A define for the restrict qualifier */
  266. #if !defined(H_RESTRICT)
  267. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  268. /* Compiler is in C99 mode and should know about the restrict qualifier */
  269. # define H_RESTRICT restrict
  270. # else
  271. # if (defined(_WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) || defined(__INTEL_COMPILER)
  272. /* Intel Compilers and grown-up Microsoft Compilers always know a __restrict */
  273. # define H_RESTRICT __restrict
  274. # elif (defined(__linux) || defined(__APPLE__)) && defined(__GNUC__)
  275. /* Gcc knows about __restrict__ since at least gcc 3.0 */
  276. # define H_RESTRICT __restrict__
  277. # elif defined(__TI_COMPILER_VERSION__)
  278. /* TI's cgtools know about restrict. */
  279. # define H_RESTRICT restrict
  280. # else
  281. # define H_RESTRICT
  282. # endif
  283. # endif /* __STDC_VERSION__ */
  284. #endif /* H_RESTRICT */
  285. /* A define for the inline qualifier */
  286. #if !defined(H_INLINE)
  287. #ifdef __cplusplus
  288. #define H_INLINE inline
  289. #else
  290. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  291. /* compiler is in C99 mode and should know about the inline qualifier */
  292. # define H_INLINE inline
  293. #else
  294. #if defined(_WIN32) || defined(__alpha) || defined(__sgi)
  295. # define H_INLINE __inline
  296. #else
  297. #if defined(__linux) || defined(__APPLE__)
  298. # define H_INLINE __inline__
  299. #else
  300. #if defined(__sun)
  301. # define H_INLINE inline
  302. #else
  303. # define H_INLINE
  304. #endif
  305. #endif
  306. #endif
  307. #endif /* __STDC_VERSION__ */
  308. #endif /* #ifdef __cplusplus .. else */
  309. #endif /* H_INLINE */
  310. /* A define to force functions to be inlined */
  311. #if defined(_WIN32)
  312. #define H_FORCEINLINE __forceinline
  313. #elif (defined(__linux) || defined(__APPLE__)) && defined(__GNUC__)
  314. #define H_FORCEINLINE H_INLINE __attribute__((always_inline))
  315. #else
  316. #define H_FORCEINLINE H_INLINE
  317. #endif
  318. #endif /* ifndef HBASE_H */