HBase.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 uint32_t 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. {
  78. eSignalNone = 0, /**< No signal */
  79. eSignalStartAbort, /**< Initiate abort: stop running, abort mutexes etc. */
  80. eSignalAbort, /**< Finalize abort, wait for resources to finish */
  81. eSignalRestore, /**< After abortion is complete, restore mutexes etc. */
  82. } HSignalTypeEnum;
  83. typedef Herror (*HHandleSerializeFunc)(Hproc_handle, struct HStreamBufferT*,
  84. void*);
  85. typedef Herror (*HHandleDeserializeFunc)(Hproc_handle, struct HStreamBufferT*,
  86. void**);
  87. typedef Herror (*HHandleDestructorFunc)(Hproc_handle, void*);
  88. typedef Herror (*HHandleSignalFunc)(HSignalTypeEnum signal, void*);
  89. /****************************************************************************/
  90. /** HHandleInfo holds handle type information.
  91. ****************************************************************************
  92. * This structure exists once per handle type (usually per sem_type).
  93. * It contains basic, static, constant information about that type.
  94. * Most notably, it contains pointers to the functions that operate on the
  95. * handles (clear, serialize, deserialize and signal).
  96. *
  97. * Handles (instances) of types where the cb_signal callback is not NULL are
  98. * stored in a list that allows calling the signal callback for each of them.
  99. *
  100. * All serialized items must have a unique header, usually a string, that
  101. * identifies them. 'header' contains a pointer to that header, allowing
  102. * other functions to identify a serialized item based on its header.
  103. * If no (de)serialization function is set, header must be NULL.
  104. *
  105. * \ingroup data_structures_handles
  106. ****************************************************************************/
  107. typedef struct H_HANDLE_TYPE
  108. {
  109. INT4_8 type_id; /**< Type ID */
  110. const char* sem_type; /**< sem_type of the handle */
  111. HHandleSerializeFunc cb_serialize; /**< Serialize this handle type */
  112. HHandleDeserializeFunc cb_deserialize; /**< Deserialize this handle type */
  113. const char* header; /**< Serialization header */
  114. HHandleDestructorFunc cb_clear; /**< Clear this handle type */
  115. HHandleSignalFunc cb_signal; /**< Signal (for semaphores etc.) */
  116. struct HhandleListT* list; /**< List of handles, or NULL */
  117. } HHandleInfo;
  118. /****************************************************************************/
  119. /** HANDLE_INFO_INITIALIZER: Convenience macro for initializing HHandleInfo
  120. ****************************************************************************/
  121. #define HANDLE_INFO_INITIALIZER(TYPE_ID, SEM_TYPE, FUN_SERIALIZE, \
  122. FUN_DESERIALIZE, HEADER_STRING, FUN_CLEAR, \
  123. FUN_SIGNAL, LIST) \
  124. { \
  125. (INT4_8)(TYPE_ID), (SEM_TYPE), (HHandleSerializeFunc)(FUN_SERIALIZE), \
  126. (HHandleDeserializeFunc)(FUN_DESERIALIZE), HEADER_STRING, \
  127. (HHandleDestructorFunc)(FUN_CLEAR), (HHandleSignalFunc)(FUN_SIGNAL), \
  128. (LIST) \
  129. }
  130. /****************************************************************************/
  131. /** HANDLE_INFO_INITIALIZER_NOSER: Convenience macro for init. HHandleInfo
  132. ****************************************************************************
  133. * Use this macro for handles that cannot be (de)serialized.
  134. ****************************************************************************/
  135. #define HANDLE_INFO_INITIALIZER_NOSER(TYPE_ID, SEM_TYPE, FUN_CLEAR, \
  136. FUN_SIGNAL, LIST) \
  137. { \
  138. (INT4_8)(TYPE_ID), (SEM_TYPE), (HHandleSerializeFunc)NULL, \
  139. (HHandleDeserializeFunc)NULL, (const char*)NULL, \
  140. (HHandleDestructorFunc)(FUN_CLEAR), (HHandleSignalFunc)(FUN_SIGNAL), \
  141. (LIST) \
  142. }
  143. typedef struct HhandleT* Hphandle;
  144. typedef union
  145. {
  146. INT4_8 l; /* 4/8 byte integer (input) */
  147. double d; /* 8 byte real (input) */
  148. char* s; /* pointer to strings (input) */
  149. double f; /* 8 byte real (legacy 11.0) (input) */
  150. Hphandle h; /* Pointer to handle (input) */
  151. } Hpar; /* parameter passing for the C interface */
  152. typedef union
  153. {
  154. INT4_8* l; /* 4/8 byte integer (output) */
  155. double* d; /* 8 byte real, (output) */
  156. char* s; /* pointer to strings (output) */
  157. void* p; /* pointer to var. of any type (e.g. tuple)(output)*/
  158. double* f; /* 8 byte real, (legacy 11.0) (output) */
  159. } Hvar; /* parameter passing for the C interface */
  160. typedef struct
  161. {
  162. Hpar par; /* values */
  163. int type; /* type flag */
  164. } Hcpar; /* parameter passing for the C interface */
  165. typedef struct
  166. {
  167. Hvar var; /* values */
  168. int type; /* type flag */
  169. } Hcvar; /* parameter passing for the C interface */
  170. typedef union
  171. {
  172. INT4_8* l;
  173. double* d;
  174. char** s;
  175. Hcpar* cpar;
  176. Hphandle* h;
  177. } Hcelem; /* pure type array */
  178. typedef struct HCTUPLE
  179. {
  180. Hpar val;
  181. int type;
  182. /*
  183. * Add manual padding here so that a Hcpar can be mapped to a Hctuple
  184. * exactly, including the padding compilers insert at the end of data
  185. * structures to align the entire structure to the largest alignment of any
  186. * structure member. Note that on 32 bit Linux for Intel, Hcpar is aligned to
  187. * 4 bytes, so no manual padding is necessary on that architecture (only).
  188. */
  189. #if !(defined(__linux__) && defined(__i386__))
  190. char pad[sizeof(Hcpar) - sizeof(Hpar) - sizeof(int)];
  191. #endif
  192. INT4_8 num; /* number of set array elements */
  193. INT4_8 capacity; /* allocated array length */
  194. int free; /* free array elem when destroying tuple? */
  195. Hcelem elem; /* the actual array */
  196. } Hctuple;
  197. #define HCTUPLE_INITIALIZER \
  198. { \
  199. {0}, UNDEF_PAR, {0}, 0, 0, 0, \
  200. { \
  201. NULL \
  202. } \
  203. }
  204. typedef struct
  205. {
  206. Hcvar* variables; /* variables (of application) to write back values */
  207. Hcpar* element; /* tuple element(s) */
  208. INT4_8 num_el; /* number of used elements */
  209. INT4_8 length; /* total length of array (incl. unused elements) */
  210. } Hcvtuple; /* for passing control parameter variables from */
  211. /* the language to the core interface */
  212. #ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
  213. # pragma pack(pop)
  214. #endif
  215. /*****************************************************************************/
  216. /* Bool constants (legacy) */
  217. /*****************************************************************************/
  218. #ifdef TRUE
  219. # undef TRUE
  220. #endif
  221. #define TRUE true
  222. #ifdef FALSE
  223. # undef FALSE
  224. #endif
  225. #define FALSE false
  226. /*****************************************************************************/
  227. /* Pixel types of HALCON images */
  228. /*****************************************************************************/
  229. #define UNDEF_IMAGE 0
  230. #define BYTE_IMAGE (1 << 0)
  231. #define INT4_IMAGE (1 << 1)
  232. #define LONG_IMAGE INT4_IMAGE
  233. #define FLOAT_IMAGE (1 << 2)
  234. #define DIR_IMAGE (1 << 3)
  235. #define CYCLIC_IMAGE (1 << 4)
  236. #define INT1_IMAGE (1 << 5)
  237. /* (1<<6) omitted so far -> use it for next new image type */
  238. #define COMPLEX_IMAGE (1 << 7)
  239. /* (1<<8) omitted so far -> use it for next new image type */
  240. #define INT2_IMAGE (1 << 9)
  241. #define UINT2_IMAGE (1 << 10)
  242. #define VF_IMAGE (1 << 11)
  243. #define INT8_IMAGE (1 << 12)
  244. /*****************************************************************************/
  245. /* Type of HALCON vector field images */
  246. /*****************************************************************************/
  247. #define VF_ABSOLUTE 0
  248. #define VF_RELATIVE (1 << 0)
  249. /*****************************************************************************/
  250. /* data types for handling pthreads (POSIX threads) and mutex variables */
  251. /*****************************************************************************/
  252. typedef void* H_pthread_t; /* pthread handle */
  253. typedef void* H_pthread_mutex_t; /* pthread mutex data type */
  254. typedef void* H_pthread_cond_t; /* pthread condition variable */
  255. typedef void* H_pthread_barrier_t; /* pthread barrier variable */
  256. /*****************************************************************************/
  257. /* signature of the callback functions for drawing objects */
  258. /*****************************************************************************/
  259. #ifndef _WIN32
  260. # define __stdcall
  261. #endif
  262. typedef Herror(__stdcall* HDrawObjectCallback)(Hphandle DrawHandle,
  263. Hphandle WindowHandle,
  264. char* type);
  265. /*****************************************************************************/
  266. /* signature of the callback functions for buffer window content updates */
  267. /*****************************************************************************/
  268. typedef Herror(__stdcall* HUpdateContentCallback)(void* context);
  269. /*****************************************************************************/
  270. /* signature of the callback function for license recheck failure callbacks */
  271. /*****************************************************************************/
  272. typedef void(__stdcall* HLicenseRecheckFailedCallback)(void* context,
  273. Herror error);
  274. /* A define for the restrict qualifier */
  275. #if !defined(H_RESTRICT)
  276. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  277. /* Compiler is in C99 mode and should know about the restrict qualifier */
  278. # define H_RESTRICT restrict
  279. # else
  280. # if (defined(_WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) || \
  281. defined(__INTEL_COMPILER)
  282. /* Intel Compilers and grown-up Microsoft Compilers always know a __restrict */
  283. # define H_RESTRICT __restrict
  284. # elif (defined(__linux) || defined(__APPLE__)) && defined(__GNUC__)
  285. /* Gcc knows about __restrict__ since at least gcc 3.0 */
  286. # define H_RESTRICT __restrict__
  287. # elif defined(__TI_COMPILER_VERSION__)
  288. /* TI's cgtools know about restrict. */
  289. # define H_RESTRICT restrict
  290. # else
  291. # define H_RESTRICT
  292. # endif
  293. # endif /* __STDC_VERSION__ */
  294. #endif /* H_RESTRICT */
  295. /* A define for the inline qualifier */
  296. #if !defined(H_INLINE)
  297. # ifdef __cplusplus
  298. # define H_INLINE inline
  299. # else
  300. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  301. /* compiler is in C99 mode and should know about the inline qualifier */
  302. # define H_INLINE inline
  303. # else
  304. # if defined(_WIN32) || defined(__alpha) || defined(__sgi)
  305. # define H_INLINE __inline
  306. # else
  307. # if defined(__linux) || defined(__APPLE__)
  308. # define H_INLINE __inline__
  309. # else
  310. # if defined(__sun)
  311. # define H_INLINE inline
  312. # else
  313. # define H_INLINE
  314. # endif
  315. # endif
  316. # endif
  317. # endif /* __STDC_VERSION__ */
  318. # endif /* #ifdef __cplusplus .. else */
  319. #endif /* H_INLINE */
  320. /* A define to force functions to be inlined */
  321. #if defined(_WIN32)
  322. # define H_FORCEINLINE __forceinline
  323. #elif (defined(__linux) || defined(__APPLE__)) && defined(__GNUC__)
  324. # define H_FORCEINLINE H_INLINE __attribute__((always_inline))
  325. #else
  326. # define H_FORCEINLINE H_INLINE
  327. #endif
  328. #endif /* ifndef HBASE_H */