PylonDataContainer.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2020-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: DV, JS
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains a class to access multi-component grab results
  10. */
  11. #ifndef INCLUDED_PYLONDATACONTAINER_H
  12. #define INCLUDED_PYLONDATACONTAINER_H
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <pylon/PylonBase.h>
  18. #include <pylon/PixelType.h>
  19. #include <pylon/PayloadType.h>
  20. namespace Pylon
  21. {
  22. // Forward declaration
  23. class CGrabResultPtr;
  24. class GrabResult;
  25. class CPylonDataComponent;
  26. /**
  27. * \class CPylonDataContainer
  28. * \brief Provides methods for accessing grab results consisting of multiple components.
  29. *
  30. * Some cameras can return complex grab results consisting of multiple components.
  31. * For example, Basler blaze cameras return a data stream that is composed of range, intensity,
  32. * and confidence components.
  33. * To access the individual components, you can use the \c CPylonDataContainer class.
  34. *
  35. * A \c CPylonDataContainer can hold one or more components.
  36. * You can obtain a container by calling \c Pylon::CGrabResultData::GetDataContainer().
  37. * You can then use the container to query for the number of components by calling \c Pylon::CGrabResultData::GetDataComponentCount().
  38. * To retrieve a specific component, you can call \c Pylon::CGrabResultData::GetDataComponent().
  39. * Each component in the container can be used to access the actual data, e.g., the range values, and its metadata.
  40. *
  41. * \attention Any \c CPylonDataContainer or \c CPylonDataComponent will hold a reference to the \c CGrabResultData
  42. * from which it has been created. To allow the instant camera to reuse the \c CGrabResultData
  43. * and prevent buffer underruns, you must destroy the \c CPylonDataContainer and all its \c CPylonDataComponent objects.
  44. *
  45. * \threading
  46. * This class is not thread-safe.
  47. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  48. */
  49. class PYLONBASE_API CPylonDataContainer
  50. {
  51. public:
  52. /**
  53. * \brief Creates a \c CPylonDataContainer from a given \c CGrabResultPtr.
  54. * \param ptrGrabResult The grab result to create a container from.
  55. *
  56. * Creates a \c CPylonDataContainer from a given \c CGrabResultPtr.
  57. * The \c CPylonDataContainer instance created will hold a reference to the \c CGrabResultData from which it has been created.
  58. * To allow the instant camera to reuse the grab result and prevent buffer underruns,
  59. * you must destroy the \c CPylonDataContainer.
  60. *
  61. * \post
  62. * <ul>
  63. * <li> A new reference to the grab result passed in ptrGrabResult has been set.
  64. * </ul>
  65. *
  66. * \error
  67. * Does not throw an exception if the \c CGrabResultPtr was invalid or points to an invalid/unsuccessful result.
  68. * Instead, an empty container is returned.
  69. * Can throw exceptions if the data in the result is invalid or malformed.
  70. * Can throw exceptions in low-memory conditions.
  71. *
  72. * \threading
  73. * This class is not thread-safe.
  74. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  75. */
  76. explicit CPylonDataContainer( const CGrabResultPtr& ptrGrabResult );
  77. /**
  78. * \brief Creates a \c CPylonDataContainer from a given \c GrabResult.
  79. * \param grabResult The grab result to create a container from.
  80. *
  81. * Creates a \c CPylonDataContainer from a given \c GrabResult.
  82. * The \c CPylonDataContainer instance created is only valid as long as the associated buffer
  83. * is not queued or deregistered and deleted.
  84. *
  85. * \error
  86. * Does not throw an exception if the GrabResult contains an unsuccessful result.
  87. * Instead, an empty container is returned.
  88. * Can throw exceptions if the data in the buffer of the GrabResult is invalid or malformed.
  89. * Can throw exceptions in low-memory conditions.
  90. *
  91. * \threading
  92. * This class is not thread-safe.
  93. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  94. */
  95. explicit CPylonDataContainer( const GrabResult& grabResult );
  96. /**
  97. * \brief Creates a \c CPylonDataContainer by loading the data from the file passed.
  98. *
  99. * \copydetails Pylon::CPylonDataContainer::Load()
  100. *
  101. */
  102. explicit CPylonDataContainer( const Pylon::String_t& filename );
  103. /**
  104. * \brief Creates an empty \c CPylonDataContainer.
  105. *
  106. * Creates an empty \c CPylonDataContainer.
  107. * The \c CPylonDataContainer instance created will not be valid.
  108. *
  109. * \error
  110. * Can throw exceptions in low-memory conditions.
  111. *
  112. * \threading
  113. * This class is not thread-safe.
  114. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  115. */
  116. CPylonDataContainer();
  117. /**
  118. * \brief Creates a shallow copy of an existing \c CPylonDataContainer.
  119. * \param rhs Container to copy from.
  120. *
  121. * \post
  122. * <ul>
  123. * <li> A new reference to the grab result or buffer of the container passed in rhs has been set.
  124. * </ul>
  125. *
  126. * \error
  127. * Can throw exceptions in low-memory conditions.
  128. *
  129. * \threading
  130. * This class is not thread-safe.
  131. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  132. */
  133. CPylonDataContainer( const CPylonDataContainer& rhs );
  134. /**
  135. * \brief Destroys the \c CPylonDataContainer instance. If the instance has been created through a GrabResultPtr,
  136. * the reference to that \c CGrabResultData will be released.
  137. *
  138. * \post
  139. * <ul>
  140. * <li> The reference to a grab result or buffer has been released.
  141. * </ul>
  142. *
  143. * \error
  144. * Does not throw C++ exceptions.
  145. *
  146. * \threading
  147. * This class is not thread-safe.
  148. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  149. */
  150. ~CPylonDataContainer();
  151. /**
  152. * \brief Assigns a shallow copy of the \c CPylonDataContainer to this instance.
  153. * \param rhs CPylonDataContainer to copy data from.
  154. * \return Returns a reference to the current instance.
  155. *
  156. * \post
  157. * <ul>
  158. * <li> The reference to a previous grab result or buffer has been released.
  159. * <li> A new reference to the grab result or buffer of the container passed in rhs has been set.
  160. * </ul>
  161. *
  162. * \error
  163. * Can throw exceptions in low-memory conditions.
  164. *
  165. * \threading
  166. * This class is not thread-safe.
  167. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  168. */
  169. CPylonDataContainer& operator=( const CPylonDataContainer& rhs );
  170. /**
  171. * \brief Returns the number of components contained in the container.
  172. * \return Returns the number of components contained in the container.
  173. *
  174. * You can use the return value to iterate over the existing components by calling \c Pylon::CPylonDataContainer::GetDataComponent().
  175. *
  176. * \error
  177. * Does not throw C++ exceptions.
  178. *
  179. * \threading
  180. * This class is not thread-safe.
  181. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  182. */
  183. size_t GetDataComponentCount() const;
  184. /**
  185. * \brief Returns a specific component from the container.
  186. * \param index Index of the component to return. The index must be less than the value returned by \c Pylon::CPylonDataContainer::GetComponentCount().
  187. * \return Returns the component specified by the index parameter.
  188. *
  189. * \error
  190. * Throws an exception if the index parameter is out of range.
  191. * Can throw exceptions in low-memory conditions.
  192. *
  193. * \threading
  194. * This class is not thread-safe.
  195. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  196. */
  197. const CPylonDataComponent GetDataComponent( const size_t index ) const;
  198. /**
  199. * \brief Saves the container to disk.
  200. * \param filename Name and path of the file to save the container to.
  201. *
  202. * \pre
  203. * The container must contain at least one component.
  204. *
  205. * \error
  206. * Throws an exception if the container cannot be saved.
  207. *
  208. * \threading
  209. * This class is not thread-safe.
  210. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  211. */
  212. void Save( const Pylon::String_t& filename ) const;
  213. /**
  214. * \brief Loads a container from a file.
  215. * \param filename Name and path of the file to load.
  216. *
  217. * Loads a container and all its components from a file on disk.
  218. *
  219. * \post
  220. * <ul>
  221. * <li> The reference to a previous grab result or buffer has been released.
  222. * <li> A new buffer has been allocated to hold the data loaded.
  223. * </ul>
  224. *
  225. * \error
  226. * Throws an exception if the container cannot be read.
  227. * Throws an exception if the contents of the file does not contain a valid container.
  228. *
  229. * \threading
  230. * This class is not thread-safe.
  231. * If you access the same instance from multiple threads, you must make sure to synchronize the access accordingly.
  232. */
  233. void Load( const Pylon::String_t& filename );
  234. private:
  235. class CPylonDataContainerImpl;
  236. CPylonDataContainerImpl* m_pImpl;
  237. };
  238. }
  239. #endif // INCLUDED_PYLONDATACONTAINER_H