Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLIO/src/ICLIO/PylonUtils.h ** 00010 ** Module : ICLIO ** 00011 ** Authors: Viktor Richter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLIO/PylonIncludes.h> 00035 #include <ICLUtils/Mutex.h> 00036 #include <ICLUtils/Exception.h> 00037 #include <ICLCore/CoreFunctions.h> 00038 #include <ICLCore/ImgBase.h> 00039 #include <ICLCore/Img.h> 00040 00041 namespace icl { 00042 namespace io{ 00043 namespace pylon { 00044 00046 template <typename T> 00047 class PylonGrabberBuffer { 00048 private: 00049 T *m_pBuffer; 00050 Pylon::StreamBufferHandle m_hBuffer; 00051 00052 public: 00053 PylonGrabberBuffer(size_t size) : m_pBuffer(NULL) { 00054 m_pBuffer = new T[size]; 00055 if (!m_pBuffer) 00056 throw utils::ICLException("Not enough memory to allocate image buffer"); 00057 } 00058 ~PylonGrabberBuffer(){ 00059 if (m_pBuffer) 00060 delete[] m_pBuffer; 00061 } 00062 T* getBufferPointer(void) { 00063 return m_pBuffer; 00064 } 00065 Pylon::StreamBufferHandle getBufferHandle(void) { 00066 return m_hBuffer; 00067 } 00068 void setBufferHandle(Pylon::StreamBufferHandle hBuffer) { 00069 m_hBuffer = hBuffer; 00070 } 00071 }; 00072 00074 template <typename T> 00075 class TsBuffer { 00076 public: 00078 T* m_Buffer; 00080 uint64_t m_Timestamp; 00082 size_t m_Size; 00083 00085 TsBuffer(size_t size) : m_Timestamp(0), m_Size(size){ 00086 m_Buffer = new T[m_Size]; 00087 if (!m_Buffer) 00088 throw utils::ICLException("Not enough memory to allocate image buffer"); 00089 } 00091 ~TsBuffer(){ 00092 if (m_Buffer){ 00093 delete[] m_Buffer; 00094 } 00095 } 00097 00101 void copy(void* buffer){ 00102 T* tmp = (T*) buffer; 00103 core::copy(tmp, tmp + m_Size, m_Buffer); 00104 } 00105 }; 00106 00108 class ConvBuffers { 00109 public: 00111 ICLIO_API ConvBuffers(); 00113 ICLIO_API ~ConvBuffers(); 00115 ICLIO_API void free(); 00117 icl::core::ImgBase* m_Image; 00119 icl8u* m_ImageBuff; 00121 icl16s* m_ImageBuff16; 00123 icl::core::Img8u* m_ImageRGBA; 00125 std::vector<icl8u*>* m_Channels; 00127 std::vector<icl16s*>* m_Channels16; 00129 bool m_Reset; 00130 }; 00131 00133 00137 class ConcGrabberBuffer { 00138 public: 00140 ICLIO_API ConcGrabberBuffer(); 00142 ICLIO_API ~ConcGrabberBuffer(); 00143 00145 00149 ICLIO_API ConvBuffers* getNextReadBuffer(); 00151 00155 ICLIO_API ConvBuffers* getNextWriteBuffer(); 00157 ICLIO_API void setReset(); 00159 ICLIO_API bool newAvailable(); 00160 00161 private: 00163 ConvBuffers* m_Buffers[3]; 00165 utils::Mutex m_Mutex; 00167 int m_Write; 00169 int m_Next; 00171 int m_Read; 00173 bool m_Avail; 00174 }; 00175 00177 00183 struct PylonAutoEnv{ 00184 public: 00186 ICLIO_API PylonAutoEnv(); 00188 ICLIO_API ~PylonAutoEnv(); 00190 00191 ICLIO_API static bool initPylonEnv(); 00193 00194 ICLIO_API static bool termPylonEnv(); 00195 }; 00196 00198 00202 struct Interruptable{ 00204 virtual ~Interruptable() {} 00206 virtual void acquisitionStart() = 0; 00208 virtual void acquisitionStop() = 0; 00210 virtual void grabbingStart() = 0; 00212 virtual void grabbingStop() = 0; 00213 }; 00214 00216 00221 struct AcquisitionInterruptor{ 00222 private: 00224 Interruptable* m_Interu; 00225 00226 public: 00228 00233 ICLIO_API AcquisitionInterruptor(Interruptable* i, bool mock = false); 00235 ICLIO_API ~AcquisitionInterruptor(); 00236 }; 00237 00239 00243 struct GrabbingInterruptor{ 00244 private: 00246 Interruptable* m_Interu; 00247 00248 public: 00250 00255 ICLIO_API GrabbingInterruptor(Interruptable* i, bool mock = false); 00257 ICLIO_API ~GrabbingInterruptor(); 00258 }; 00259 00261 ICLIO_API void printHelp(); 00263 ICLIO_API Pylon::CDeviceInfo getDeviceFromArgs(std::string args) throw(utils::ICLException); 00265 ICLIO_API int channelFromArgs(std::string args); 00267 00268 ICLIO_API Pylon::DeviceInfoList_t 00269 getPylonDeviceList(Pylon::DeviceInfoList_t* filter=NULL); 00270 00271 } //namespace pylon 00272 } // namespace io 00273 } //namespace icl 00274