HVector.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*****************************************************************************
  2. * HVector.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/C++
  6. * Description: Vector class for engine and HDevelop export
  7. *
  8. * (c) 2014-2020 by MVTec Software GmbH
  9. * www.mvtec.com
  10. *
  11. *****************************************************************************
  12. *
  13. *
  14. *****************************************************************************/
  15. #ifndef HCPP_VECTOR_H
  16. #define HCPP_VECTOR_H
  17. #include "halconcpp/HTuple.h"
  18. #include "halconcpp/HObjectBase.h"
  19. #include "halconcpp/HObject.h"
  20. namespace HalconCpp
  21. {
  22. class Hvector;
  23. class LIntExport HVector
  24. {
  25. protected:
  26. // No public constructors, create HTupleVector or HObjectVector instead
  27. // Create an empty vector
  28. HVector(Hlong dimension);
  29. // Copy constructor
  30. HVector(const HVector& vector);
  31. public:
  32. // Destroy vector
  33. virtual ~HVector();
  34. /* Operator overloads */
  35. // Assignment operator
  36. HVector& operator=(const HVector& vector);
  37. // Comparison operators
  38. bool operator==(const HVector& vector) const;
  39. bool operator!=(const HVector& vector) const;
  40. // Non-const indexing operator. If necessary, the vector
  41. // will be enlarged to accomodate the index
  42. HVector& operator[](Hlong index);
  43. // Const indexing operator. An exception will be raised if the
  44. // index is out of range.
  45. const HVector& operator[](Hlong index) const;
  46. /* Methods */
  47. // Dimension of vector;
  48. Hlong Dimension() const
  49. {
  50. return mDimension;
  51. }
  52. // Length of vector
  53. Hlong Length() const;
  54. // Clear contents of vector
  55. HVector& Clear();
  56. // Remove element from vector
  57. HVector& Remove(Hlong index);
  58. // Insert element into vector
  59. HVector& Insert(Hlong index, const HVector& vector);
  60. // Return a simple string representation of the vector contents,
  61. // mainly for logging and debugging purposes. The result should not
  62. // be parsed and text format may change in the future.
  63. virtual HString ToString() const;
  64. // Assistive functionality for engine and code export
  65. // Raise exception on dimension mismatch
  66. void AssertDimension(Hlong dimension) const;
  67. // Assistive functionality for internal vector use
  68. protected:
  69. // FOR INTERNAL IMPLEMENTATION ONLY. NOT INTENDED
  70. // TO BE USED IN USER-DERIVED CLASSES
  71. // Increase length of vector (with dimension > 0) to ensure index is valid
  72. void AssertSize(Hlong index);
  73. // Test for equality
  74. virtual bool EqualImpl(const HVector& vector) const;
  75. // Create empty element to initialize gaps in vector
  76. virtual void ClearImpl();
  77. // Create concatenation of two vectors on the heap.
  78. HVector* ConcatImpl(const HVector& vector) const;
  79. // Create deep copy of all subvectors and elements
  80. virtual HVector* CloneImpl() const = 0;
  81. // Create empty element to initialize gaps in vector
  82. virtual HVector* GetDefaultElement() const = 0;
  83. // Returns new copy of this instance on the heap
  84. HVector* Clone() const;
  85. // Member variables
  86. protected:
  87. Hlong mDimension;
  88. // Data container
  89. Hvector* mVector;
  90. };
  91. class LIntExport HTupleVector : public HVector
  92. {
  93. public:
  94. // Create empty vector of specified dimension. In case of dimension
  95. // 0 a leaf vector for an empty tuple is created
  96. explicit HTupleVector(Hlong dimension)
  97. : HVector(dimension)
  98. {
  99. }
  100. // Create leaf vector of dimension 0 for the specified tuple
  101. explicit HTupleVector(const HTuple& tuple)
  102. : HVector(0),
  103. mTuple(tuple)
  104. {
  105. }
  106. // Create 1-dimensional vector by splitting input tuple into
  107. // blocks of fixed size (except possibly for the last block)
  108. // This corresponds to convert_tuple_to_vector_1d in HDevelop.
  109. explicit HTupleVector(const HTuple& tuple, Hlong block_size);
  110. // Copy constructor
  111. HTupleVector(const HTupleVector& vector);
  112. /* Operator overloads */
  113. // Assignment operator
  114. HTupleVector& operator=(const HTupleVector& vector);
  115. // Comparison operator
  116. bool operator==(const HTupleVector& vector) const;
  117. bool operator!=(const HTupleVector& vector) const;
  118. // Non-const indexing operator. If necessary, the vector
  119. // will be enlarged to accomodate the index
  120. HTupleVector& operator[](Hlong index);
  121. // Const indexing operator. An exception will be raised if the
  122. // index is out of range.
  123. const HTupleVector& operator[](Hlong index) const;
  124. /* Methods */
  125. // Clear contents of vector
  126. HTupleVector& Clear();
  127. // Remove element from vector
  128. HTupleVector& Remove(Hlong index);
  129. // Insert element into vector
  130. HTupleVector& Insert(Hlong index, const HTupleVector& vector);
  131. // Concatenate two vectors (creating new vector)
  132. HTupleVector Concat(const HTupleVector& vector);
  133. /* Value access (for leaf vectors of dimension 0) */
  134. const HTuple& T() const;
  135. HTuple& T();
  136. // Concatenates all tuples stored in the vector
  137. HTuple ConvertVectorToTuple() const;
  138. // Return a simple string representation of the vector contents,
  139. // mainly for logging and debugging purposes. The result should not
  140. // be parsed and text format may change in the future.
  141. virtual HString ToString() const;
  142. // Assistive functionality for internal vector use
  143. protected:
  144. // Test for equality
  145. virtual bool EqualImpl(const HVector& vector) const;
  146. // Create deep copy of all subvectors and elements
  147. virtual HVector* CloneImpl() const;
  148. // Create empty element to initialize gaps in vector
  149. virtual HVector* GetDefaultElement() const;
  150. protected:
  151. HTuple mTuple;
  152. };
  153. class LIntExport HObjectVector : public HVector
  154. {
  155. public:
  156. // Create empty vector of specified dimension. In case of dimension
  157. // 0 a leaf vector for an empty object is created
  158. explicit HObjectVector(Hlong dimension);
  159. // Create leaf vector of dimension 0 for the specified object
  160. explicit HObjectVector(const HObject& obj)
  161. : HVector(0),
  162. mObject(obj)
  163. {
  164. }
  165. // Copy constructor
  166. HObjectVector(const HObjectVector& vector);
  167. /* Operator overloads */
  168. // Assignment operator
  169. HObjectVector& operator=(const HObjectVector& vector);
  170. // Comparison operator
  171. bool operator==(const HObjectVector& vector) const;
  172. bool operator!=(const HObjectVector& vector) const;
  173. // Non-const indexing operator. If necessary, the vector
  174. // will be enlarged to accomodate the index
  175. HObjectVector& operator[](Hlong index);
  176. // Const indexing operator. An exception will be raised if the
  177. // index is out of range.
  178. const HObjectVector& operator[](Hlong index) const;
  179. /* Methods */
  180. // Clear contents of vector
  181. HObjectVector& Clear();
  182. // Remove element from vector
  183. HObjectVector& Remove(Hlong index);
  184. // Insert element into vector
  185. HObjectVector& Insert(Hlong index, const HObjectVector& vector);
  186. // Concatenate two vectors (creating new vector)
  187. HObjectVector Concat(const HObjectVector& vector);
  188. /* Value access (for leaf vectors of dimension 0) */
  189. const HObject& O() const;
  190. HObject& O();
  191. // Return a simple string representation of the vector contents,
  192. // mainly for logging and debugging purposes. The result should not
  193. // be parsed and text format may change in the future.
  194. virtual HString ToString() const;
  195. // Assistive functionality for internal vector use
  196. protected:
  197. // Test for equality
  198. virtual bool EqualImpl(const HVector& vector) const;
  199. // Create deep copy of all subvectors and elements
  200. virtual HVector* CloneImpl() const;
  201. // Create empty element to initialize gaps in vector
  202. virtual HVector* GetDefaultElement() const;
  203. protected:
  204. HObject mObject;
  205. };
  206. }
  207. #endif