Hvector.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*****************************************************************************
  2. * Hvector.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/C
  6. * Description: HALCON/C implementation of HDevelop vectors
  7. *
  8. * (c) 2014-2020 by MVTec Software GmbH
  9. * www.mvtec.com
  10. *
  11. ****************************************************************************/
  12. #ifndef HVECTOR_H
  13. #define HVECTOR_H
  14. #if defined(__cplusplus)
  15. extern "C" {
  16. #endif
  17. /*
  18. * The data structure Hvector is used to the vector functionality of the
  19. * hdevelop language. Creating, access and deletion must only be done with the
  20. * supplied procedures.
  21. */
  22. typedef Hlong Hvector; /* Handle implementation of vector */
  23. typedef enum {
  24. eVector=0x05EC0000,eTupleVector,eTupleLeaf,eObjectVector,eObjectLeaf
  25. } Hvectype;
  26. #define HVECTOR_UNDEF 0
  27. /**************************************************************************
  28. * Hvector functionality
  29. *************************************************************************/
  30. /* create_obj_vector creates an empty vector of dimension dim. The vector is
  31. * returned in vec and can contain objects only.*/
  32. LIntExport Herror V_create_obj_vector(Hlong dim, Hvector *H_RESTRICT vec);
  33. /* create_tuple_vector creates an empty vector of dimension dim. The vector is
  34. * returned in vec and can contain tuples only.*/
  35. LIntExport Herror V_create_tuple_vector(Hlong dim, Hvector *H_RESTRICT vec);
  36. /* destroy_vector frees the vector, its subvectors and leafs of any type and
  37. * dimension. */
  38. LIntExport Herror V_destroy_vector(Hvector vec);
  39. /* copy_vector returns a copy of src in dest. Deep copy is performed. */
  40. LIntExport Herror V_copy_vector(Hvector const src, Hvector *H_RESTRICT dest);
  41. /* set_vector_elem sets a sub vector subvec in vector vec. Therefore,
  42. * index addresses a sub vector that gets replaced by subvec. The old sub
  43. * vector is freed if existing. Otherwise, vec is extended accordingly (and
  44. * initialized with empty elements) to fulfill index.(self modifying)
  45. * Precondition: type(subvec) == type(vec) && dim(vec) == dim(subvec)+|index|
  46. */
  47. LIntExport Herror V_set_vector_elem(Hvector vec, Htuple const vec_idx,
  48. Hvector const subvec);
  49. /* set_vector_obj sets a iconic object obj in vector vec. Therefore,
  50. * vec_idx addresses an object in vec that gets replaced by obj. The old
  51. * iconic object in vec is freed if existing. Otherwise, vec is extended
  52. * accordingly (and initialized with empty elements) to fulfill vec_idx.(self
  53. * modifying)
  54. * Precondition: type(vec) == eObjectVector && dim(vec) == dim(subvec)+|index|
  55. */
  56. LIntExport Herror V_set_vector_obj(Hobject const obj, Hvector vec,
  57. Htuple const vec_idx);
  58. /* set_vector_tuple sets a tuple tpl in vector vec. Therefore,
  59. * vec_idx addresses a tuple in vec that gets replaced by obj. The old tuple
  60. * in vec is freed if existing. Otherwise, vec is extended accordingly (and
  61. * initialized with empty elements) to fulfill vec_idx.(self modifying)
  62. * Precondition: type(vec) == eTupleVector && dim(vec) == |index|
  63. */
  64. LIntExport Herror V_set_vector_tuple(Hvector vec, Htuple const vec_idx,
  65. Htuple const tpl);
  66. /* set_vector_tuple_elem executes a self modifying tuple_replace in the indexed
  67. * tuple in vec. vec_idx is a tuple of n=dim elements and indexes the tuple
  68. * in vec. tpl_idx contains the tuple indices to be replaced. val contains
  69. * the values to set.
  70. * If the length of any sub vector indexed by vec_idx is not sufficient,
  71. * set_vector_tuple_elem extends it automatically (initialized with empty
  72. * elements).
  73. * Precondition: type(vec) == eTupleVector && dim(vec) == |vec_idx|. */
  74. LIntExport Herror V_set_vector_tuple_elem(Hvector vec, Htuple const vec_idx,
  75. Htuple const tpl_idx,
  76. Htuple const val);
  77. /* get_vector_elem returns a copy of the sub vector of vec at index. The
  78. * error H_ERR_WIPV2 is returned if any value of index addresses an element
  79. * of a sub vector of vec beyond its length.
  80. * Remark: dim(subvec) = dim(vec)-|index|
  81. * type(subvec) = type(vec) */
  82. LIntExport Herror V_get_vector_elem(Hvector const vec, Htuple const index,
  83. Hvector *H_RESTRICT subvec);
  84. /* get_vector_obj returns a copy of an iconic object of vec at index. The
  85. * error H_ERR_WIPV2 is returned if any value of index addresses an element of a
  86. * sub vector of vec beyond its length.
  87. * Precondition: dim(vec) == |index| && type(vec) == eObjectVector */
  88. LIntExport Herror V_get_vector_obj(Hobject *H_RESTRICT obj, Hvector const vec,
  89. Htuple const index);
  90. /* get_vector_tuple returns a copy of a tuple of vector vec at index. The
  91. * error H_ERR_WIPV2 is returned if any value of index addresses an element of
  92. * a sub vector of vec beyond its length.
  93. * Precondition: dim(vec) == |index| && type(vec) == eTupleVector */
  94. LIntExport Herror V_get_vector_tuple( Hvector const vec, Htuple const index,
  95. Htuple *H_RESTRICT tpl);
  96. /* concat_vector appends vec2 at vec1 and returns the concatenated vector in
  97. * concat. vec1 and vec2 have to be of same dimension and type. */
  98. LIntExport Herror V_concat_vector(Hvector const vec1, Hvector const vec2,
  99. Hvector *H_RESTRICT vec_concat);
  100. /* insert_vector_elem inserts a vector ins at position ins_idx into a
  101. * sub vector of vec, indexed by vec_idx.
  102. * Different to set_vector_elem, the length of the sub vector indexed by
  103. * vec_idx gets increased by one. (self modifying)
  104. * Precondition: dim(vec) == dim(ins)+|vec_ins|
  105. * type(ins) == type(vec)
  106. * |ins_idx| == 1 */
  107. LIntExport Herror V_insert_vector_elem(Hvector vec, Htuple const vec_idx,
  108. Htuple const ins_idx,
  109. Hvector const ins);
  110. /* remove_vector_elem is the counterpart of insert_vector_elem. It frees all
  111. * contents at position rmv_idx of a sub vector indexed by vec_idx.
  112. * If the sub vector indexed by vec_idx does not exist, it gets created.
  113. * The length of the sub vector indexed by vec_idx gets decreased by one,
  114. * when rmv_idx is smaller than the length of the sub vector. (self modifying)
  115. * Precondition: dim(vec)>=|vec_idx| */
  116. LIntExport Herror V_remove_vector_elem(Hvector vec, Htuple const vec_idx,
  117. Htuple const rmv_idx);
  118. /* clear_vector frees all contents of a sub vector of vec and makes it empty.
  119. * The sub vector is indexed by 'index'. Type and dimension of the sub
  120. * vector remain. (self modifying)
  121. * Precondition: dim(vec)>=|index| */
  122. LIntExport Herror V_clear_vector(Hvector vec, Htuple const index);
  123. /* insert_vector_obj inserts an iconic object obj at position ins_idx into a
  124. * sub vector of vec, indexed by vec_idx.
  125. * Different to set_vector_obj, the length of the sub vector indexed by
  126. * vec_idx gets increased by one. (self modifying)
  127. * Precondition: dim(vec) == |vec_ins|
  128. * type(vec) == eObjectVector
  129. * |ins_idx| == 1 */
  130. LIntExport Herror V_insert_vector_obj(Hobject const obj, Hvector vec,
  131. Htuple const vec_idx,Htuple const ins_idx);
  132. /* insert_vector_tupel inserts a tuple tpl at position ins_idx into a
  133. * sub vector of vec, indexed by vec_idx.
  134. * Different to set_vector_tuple, the length of the sub vector indexed by
  135. * vec_idx gets increased by one. (self modifying)
  136. * Precondition: dim(vec) == |vec_ins|
  137. * type(vec) == eTupleVector
  138. * |ins_idx| == 1 */
  139. LIntExport Herror V_insert_vector_tuple(Hvector vec, Htuple const vec_idx,
  140. Htuple const ins_idx, Htuple const tpl);
  141. /* convert_vector_to_tuple concatenates the tuple leafs of a tuple vector
  142. * vec into one tuple tpl.
  143. * Precondition: type(vec) == eTupleVector */
  144. LIntExport Herror V_convert_vector_to_tuple( Hvector const vec,
  145. Htuple *H_RESTRICT tpl);
  146. /* convert_tuple_to_vector_1d separates the tuple elements of tpl according
  147. * to the length values in lengths into new sub tuples and generates a new
  148. * tuple vector vec with all these tuples as leafs. If lengths contains only
  149. * one value, tpl is separated into tuples of the same length (with the last
  150. * tuple containing the residuum).
  151. * Precondition: |lengths|==1 || sum(lengths)==|tpl|
  152. * dim(vec)=1, type(vec)=eTupleVector */
  153. LIntExport Herror V_convert_tuple_to_vector_1d( Htuple const tpl,
  154. Htuple const lengths,
  155. Hvector *H_RESTRICT vec);
  156. /* vector_equal returns TRUE if both vectors are identic. I.e.
  157. * both vectors have the same 'tree', the same type, and test_equal_obj
  158. * (tuple_equal, respectively) is true for all leafs. Else, equal is set
  159. * to FALSE.*/
  160. LIntExport Herror V_vector_equal(Hvector const vec1, Hvector const vec2,
  161. HBOOL *H_RESTRICT equal);
  162. /* vector_dim returns the dimensionality of the vector vec */
  163. LIntExport Herror V_vector_dim(Hvector const vec, Hlong *H_RESTRICT dim);
  164. /* vector type returns the type of the vector. eTupleVector, eObjectVector
  165. * are possible values */
  166. LIntExport Herror V_vector_type(Hvector const vec, Hvectype *H_RESTRICT type);
  167. /* vector_length returns the number of elements in vec */
  168. LIntExport Herror V_vector_length(Hvector const vec,
  169. Hlong *H_RESTRICT length);
  170. /* V_sub_vector_length returns the number of elements of a sub vector of vec,
  171. * indexed by vec_idx. Passing an empty tuple for vec_idx receives the same
  172. * result as V_vector_length. */
  173. LIntExport Herror V_sub_vector_length(Hvector const vec, Htuple const vec_idx,
  174. Hlong *H_RESTRICT length);
  175. /* Some printf auxiliary functions for debug support. They allow to transform
  176. * the basic HALCON/C data types into readable strings.
  177. * str points to a pre-allocated buffer of size bytes.
  178. * Upon successful completion, the Hsnprintf_* functions shall return the
  179. * number of bytes that would be written to str had size been sufficiently
  180. * large excluding the terminating null byte. If an output error was
  181. * encountered, these functions shall return a negative value.*/
  182. LIntExport int Hsnprintf_Hvector( char *H_RESTRICT str, Hlong size,
  183. Hvector const vec);
  184. LIntExport int Hsnprintf_Htuple( char *H_RESTRICT str, Hlong size,
  185. Htuple const tpl);
  186. LIntExport int Hsnprintf_Hobject( char *H_RESTRICT str, Hlong size,
  187. Hobject const obj);
  188. #if defined(__cplusplus)
  189. }
  190. #endif
  191. #endif