InstantCameraArray.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //------------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains the instant camera array class which supports grabbing with multiple camera devices.
  10. */
  11. #ifndef INCLUDED_INSTANTCAMERAARRAY_H_3108332
  12. #define INCLUDED_INSTANTCAMERAARRAY_H_3108332
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <pylon/InstantCamera.h>
  18. namespace Pylon
  19. {
  20. /** \addtogroup Pylon_InstantCameraApiGeneric
  21. * @{
  22. */
  23. /*!
  24. \class CInstantCameraArray
  25. \brief Supports grabbing with multiple camera devices.
  26. \threading
  27. The CInstantCameraArray class is not thread-safe.
  28. */
  29. class PYLONBASE_API CInstantCameraArray
  30. {
  31. public:
  32. //Creation and life time------------------------------------------------
  33. /*!
  34. \brief Creates an Instant Camera Array of size 0.
  35. Initialize() can be used to adjust the size of the array.
  36. \error
  37. Does not throw C++ exceptions.
  38. */
  39. CInstantCameraArray();
  40. /*!
  41. \brief Creates an Instant Camera Array.
  42. Calls Initialize() to adjust the size of the array.
  43. \param[in] numberOfCameras The number of cameras the array shall hold. Can be 0.
  44. The index operator can be used to access the individual cameras
  45. for attaching a %Pylon Device or for configuration.
  46. Example:
  47. \code
  48. // Create an array of two devices.
  49. CInstantCamera array(2);
  50. // Attach Pylon Devices.
  51. array[0].Attach( pDevice1);
  52. array[1].Attach( pDevice2);
  53. \endcode
  54. \error
  55. Does not throw C++ exceptions, except when memory allocation fails.
  56. */
  57. CInstantCameraArray( size_t numberOfCameras );
  58. /*!
  59. \brief Destroys the Instant Camera Array.
  60. If a grab is in progress, it is stopped by calling StopGrabbing().
  61. \error
  62. Does not throw C++ exceptions.
  63. */
  64. virtual ~CInstantCameraArray();
  65. /*!
  66. \brief Initializes the array.
  67. <ul>
  68. <li> If a grab is in progress, it is stopped by calling StopGrabbing().
  69. <li> All cameras of the array are destroyed.
  70. <li> A new set of cameras is created. No %Pylon Devices are attached.
  71. <li> The camera context values are set to the index of the camera in the array using CInstantCamera::SetCameraContext.
  72. </ul>
  73. The index operator can be used to access the individual cameras
  74. for attaching a %Pylon Device or for configuration.
  75. \param[in] numberOfCameras The number of cameras the array shall hold.
  76. \error
  77. Does not throw C++ exceptions, except when memory allocation fails.
  78. */
  79. virtual void Initialize( size_t numberOfCameras );
  80. /*!
  81. \brief Returns the attachment state of cameras in the array.
  82. \return True if all cameras in the array have a %Pylon Device attached. False is returned if the size of the array is 0.
  83. \error
  84. Does not throw C++ exceptions.
  85. */
  86. virtual bool IsPylonDeviceAttached() const;
  87. /*!
  88. \brief Returns the connection state of the camera devices used by the Instant Cameras in the array.
  89. The device removal is only detected if the Instant Cameras and therefore the attached %Pylon Devices are open.
  90. The %Pylon Device is not operable after this event.
  91. After it is made sure that no access to the %Pylon Device or any of its node maps is made anymore
  92. the %Pylon Device should be destroyed using InstantCamera::DeviceDestroy().
  93. The access to the %Pylon Device can be protected using the lock provided by GetLock(), e.g. when accessing parameters.
  94. \return True if the camera device removal from the PC for any camera in the array has been detected.
  95. \error
  96. Does not throw C++ exceptions.
  97. */
  98. virtual bool IsCameraDeviceRemoved() const;
  99. /*!
  100. \brief Destroys the %Pylon Devices that are attached to the Instant Cameras in the array.
  101. \attention The node maps, e.g. the camera node map, of the attached %Pylon Device must not be accessed anymore while destroying the %Pylon Device.
  102. <ul>
  103. <li> If a grab is in progress, it is stopped by calling StopGrabbing().
  104. <li> DestroyDevice is called for all cameras. See CInstantCamera::DestroyDevice() for more information.
  105. </ul>
  106. \post
  107. No %Pylon Devices are attached to the cameras in the array.
  108. \error
  109. Does not throw C++ exceptions.
  110. */
  111. virtual void DestroyDevice();
  112. /*!
  113. \brief Detaches all %Pylon Devices that are attached to the Instant Cameras in the array.
  114. <ul>
  115. <li> If a grab is in progress, it is stopped by calling StopGrabbing().
  116. <li> DetachDevice is called for all cameras, see CInstantCamera::DetachDevice() for more information.
  117. </ul>
  118. \post
  119. <ul>
  120. <li> No %Pylon Devices are attached to the cameras in the array.
  121. <li> The ownership of the %Pylon Devices goes to the caller who is responsible for destroying the %Pylon Devices.
  122. </ul>
  123. \error
  124. Does not throw C++ exceptions.
  125. */
  126. virtual void DetachDevice();
  127. //Control opening and closing of the device-----------------------------
  128. /*!
  129. \brief Opens all cameras in the array.
  130. Open is called for all cameras. See CInstantCamera::Open() for more information.
  131. \pre
  132. <ul>
  133. <li> The size of the array is larger than 0.
  134. <li> All devices are attached.
  135. </ul>
  136. \post
  137. The cameras are open.
  138. \error
  139. If one camera throws an exception, all cameras are closed by calling Close().
  140. */
  141. virtual void Open();
  142. /*!
  143. \brief Returns the open state of the cameras in the array.
  144. \error Does not throw C++ exceptions.
  145. \return Returns true if all cameras in the array are open. False is returned if the size of the array is 0.
  146. */
  147. virtual bool IsOpen() const;
  148. /*!
  149. \brief Closes all cameras in the array.
  150. <ul>
  151. <li> If a grab is in progress, it is stopped by calling StopGrabbing().
  152. <li> Close is called for all cameras, see CInstantCamera::Close() for more information.
  153. </ul>
  154. \post
  155. All cameras in the array are closed.
  156. \error
  157. Does not throw C++ exceptions.
  158. */
  159. virtual void Close();
  160. /*!
  161. \brief Returns the size of the array.
  162. \error
  163. Does not throw C++ exceptions.
  164. */
  165. virtual size_t GetSize() const;
  166. /*!
  167. \brief Retrieve a camera by index
  168. \pre
  169. The index is smaller than GetSize();
  170. \error
  171. Throws an exception if the index is not valid.
  172. */
  173. virtual CInstantCamera& operator[]( size_t index );
  174. /*!
  175. \brief Retrieve a camera by index
  176. \pre
  177. The index is smaller than GetSize();
  178. \error
  179. Throws an exception if the index is not valid.
  180. */
  181. virtual const CInstantCamera& operator[]( size_t index ) const;
  182. //Grab -----------------------------------------------------------------
  183. /*!
  184. \brief Starts the grabbing of images for all cameras.
  185. <ul>
  186. <li> StartGrabbing is called for all cameras with the provided parameters, see CInstantCamera::StartGrabbing() for more information.
  187. <li> The grabbing is started.
  188. <li> The starting position for retrieving results is set to the first camera.
  189. </ul>
  190. \param[in] strategy The grab strategy, see Pylon::InstantCamera::EStrategy for more information.
  191. \param[in] grabLoopType Indicates using the internal grab thread of the camera.
  192. \pre
  193. <ul>
  194. <li> The size of the array is larger than 0.
  195. <li> All devices are attached.
  196. <li> The grabbing is stopped.
  197. <li> The preconditions for calling StartGrabbing() are met for every camera in the array.
  198. </ul>
  199. \post
  200. The grabbing is started.
  201. \error
  202. The camera objects may throw an exception. The grabbing is stopped calling StopGrabbing() in this case.
  203. */
  204. virtual void StartGrabbing( EGrabStrategy strategy = GrabStrategy_OneByOne, EGrabLoop grabLoopType = GrabLoop_ProvidedByUser );
  205. /*!
  206. \brief Retrieves a grab result according to the strategy, waits if it is not yet available
  207. <ul>
  208. <li> The content of the passed grab result is released.
  209. <li> If the grabbing is not started, the method returns immediately false.
  210. <li> If GrabStrategy_UpcomingImage strategy: RetrieveResult is called for a camera. Cameras are processed using a round-robin strategy.
  211. <li> If GrabStrategy_OneByOne, GrabStrategy_LatestImageOnly or GrabStrategy_LatestImages strategy: Pending images or camera events are retrieved. Cameras are processed using a round-robin strategy.
  212. <li> If GrabStrategy_OneByOne, GrabStrategy_LatestImageOnly or GrabStrategy_LatestImages strategy: Wait for a grab result if it is not yet available. Camera events are handled.
  213. </ul>
  214. The camera array index is assigned to the context value of the instant camera when Initialize() is called.
  215. This context value is attached to the result when the result is retrieved and can be obtained using the grab result method GrabResultData::GetCameraContext().
  216. The context value can be used to associate the result with the camera from where it originated.
  217. \param[in] timeoutMs A timeout value in ms for waiting for a grab result, or the INFINITE value.
  218. \param[out] grabResult Receives the grab result.
  219. \param[in] timeoutHandling If timeoutHandling equals TimeoutHandling_ThrowException, a timeout exception is thrown on timeout.
  220. \return True if the call successfully retrieved a grab result, false otherwise.
  221. \pre
  222. The preconditions for calling StartGrabbing() are met for every camera in the array.
  223. \post
  224. <ul>
  225. <li> If successful, one image is removed from the output queue of a camera and is returned in the grabResult parameter.
  226. <li> If not successful, an empty grab result is returned in the grabResult parameter.
  227. </ul>
  228. \error
  229. The Instant Camera Array object is still valid after error. The grabbing is stopped by calling StopGrabbing() if an exception is thrown.
  230. */
  231. virtual bool RetrieveResult( unsigned int timeoutMs, CGrabResultPtr& grabResult, ETimeoutHandling timeoutHandling = TimeoutHandling_ThrowException );
  232. /*!
  233. \brief Stops the grabbing of images.
  234. The grabbing is stopped.
  235. StopGrabbing is called for all cameras. See CInstantCamera::StopGrabbing() for more information.
  236. \post
  237. The grabbing is stopped.
  238. \error
  239. Does not throw C++ exceptions.
  240. \threading
  241. Can be called while one other thread is polling RetrieveResult() in a IsGrabbing()/RetrieveResult() loop
  242. to stop grabbing.
  243. */
  244. virtual void StopGrabbing();
  245. /*!
  246. \brief Returns state of grabbing.
  247. The camera array is grabbing after a successful call to StartGrabbing() until StopGrabbing() has been called.
  248. \return Returns true if still grabbing.
  249. \error
  250. Does not throw C++ exceptions.
  251. */
  252. virtual bool IsGrabbing() const;
  253. public:
  254. /// The type of the camera class in the array.
  255. typedef CInstantCamera InstantCamera_t;
  256. protected:
  257. //Functionality that can be provided by specializing class--------------
  258. /*
  259. \brief Creates an instance of an instant camera class.
  260. The method is called from Initialize() method.
  261. \return Returns pointer to the created class.
  262. \error
  263. Does not throw C++ exceptions, except when memory allocation fails.
  264. */
  265. virtual CInstantCamera* CreateInstantCamera();
  266. /*
  267. \brief Destroys an instance of an instant camera class.
  268. The method is called from Initialize() method.
  269. Cameras are destroyed in the reverse order they are created.
  270. \param[in] pCamera Camera instance to destroy.
  271. \error
  272. Does not throw C++ exceptions.
  273. */
  274. virtual void DestroyInstantCamera( CInstantCamera* pCamera );
  275. private:
  276. // The camera array object can not be copied.
  277. CInstantCameraArray( const CInstantCameraArray& );
  278. // The camera array object can not be copied.
  279. void operator = ( const CInstantCameraArray& );
  280. class CInstantCameraArrayImpl;
  281. CInstantCameraArrayImpl* m_pImpl;
  282. };
  283. /**
  284. * @}
  285. */
  286. }
  287. #ifdef _MSC_VER
  288. # pragma pack(pop)
  289. #endif /* _MSC_VER */
  290. #endif /* INCLUDED_INSTANTCAMERAARRAY_H_3108332 */