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.GPL ** 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 <ICLIO/PylonIncludes.h> 00034 #include <ICLUtils/Mutex.h> 00035 #include <ICLUtils/Exception.h> 00036 #include <ICLCore/CoreFunctions.h> 00037 #include <ICLCore/ImgBase.h> 00038 #include <ICLCore/Img.h> 00039 00040 namespace icl { 00041 namespace io{ 00042 namespace pylon { 00043 00045 template <typename T> 00046 class PylonGrabberBuffer { 00047 private: 00048 T *m_pBuffer; 00049 Pylon::StreamBufferHandle m_hBuffer; 00050 00051 public: 00052 PylonGrabberBuffer(size_t size) : m_pBuffer(NULL) { 00053 m_pBuffer = new T[size]; 00054 if (!m_pBuffer) 00055 throw utils::ICLException("Not enough memory to allocate image buffer"); 00056 } 00057 ~PylonGrabberBuffer(){ 00058 if (m_pBuffer) 00059 delete[] m_pBuffer; 00060 } 00061 T* getBufferPointer(void) { 00062 return m_pBuffer; 00063 } 00064 Pylon::StreamBufferHandle getBufferHandle(void) { 00065 return m_hBuffer; 00066 } 00067 void setBufferHandle(Pylon::StreamBufferHandle hBuffer) { 00068 m_hBuffer = hBuffer; 00069 } 00070 }; 00071 00073 template <typename T> 00074 class TsBuffer { 00075 public: 00077 T* m_Buffer; 00079 uint64_t m_Timestamp; 00081 size_t m_Size; 00082 00084 TsBuffer(size_t size) : m_Timestamp(0), m_Size(size){ 00085 m_Buffer = new T[m_Size]; 00086 if (!m_Buffer) 00087 throw utils::ICLException("Not enough memory to allocate image buffer"); 00088 } 00090 ~TsBuffer(){ 00091 if (m_Buffer){ 00092 delete[] m_Buffer; 00093 } 00094 } 00096 00100 void copy(void* buffer){ 00101 T* tmp = (T*) buffer; 00102 core::copy(tmp, tmp + m_Size, m_Buffer); 00103 } 00104 }; 00105 00107 class ConvBuffers { 00108 public: 00110 ConvBuffers(); 00112 ~ConvBuffers(); 00114 void free(); 00116 icl::core::ImgBase* m_Image; 00118 icl8u* m_ImageBuff; 00120 icl16s* m_ImageBuff16; 00122 icl::core::Img8u* m_ImageRGBA; 00124 std::vector<icl8u*>* m_Channels; 00126 std::vector<icl16s*>* m_Channels16; 00128 bool m_Reset; 00129 }; 00130 00132 00136 class ConcGrabberBuffer { 00137 public: 00139 ConcGrabberBuffer(); 00141 ~ConcGrabberBuffer(); 00142 00144 00148 ConvBuffers* getNextReadBuffer(); 00150 00154 ConvBuffers* getNextWriteBuffer(); 00156 void setReset(); 00158 bool newAvailable(); 00159 00160 private: 00162 ConvBuffers* m_Buffers[3]; 00164 utils::Mutex m_Mutex; 00166 int m_Write; 00168 int m_Next; 00170 int m_Read; 00172 bool m_Avail; 00173 }; 00174 00176 00182 struct PylonAutoEnv{ 00183 public: 00185 PylonAutoEnv(); 00187 ~PylonAutoEnv(); 00189 00190 static bool initPylonEnv(); 00192 00193 static bool termPylonEnv(); 00194 }; 00195 00197 00201 struct Interruptable{ 00203 virtual ~Interruptable() {} 00205 virtual void acquisitionStart() = 0; 00207 virtual void acquisitionStop() = 0; 00209 virtual void grabbingStart() = 0; 00211 virtual void grabbingStop() = 0; 00212 }; 00213 00215 00220 struct AcquisitionInterruptor{ 00221 private: 00223 Interruptable* m_Interu; 00224 00225 public: 00227 00232 AcquisitionInterruptor(Interruptable* i, bool mock=false); 00234 ~AcquisitionInterruptor(); 00235 }; 00236 00238 00242 struct GrabbingInterruptor{ 00243 private: 00245 Interruptable* m_Interu; 00246 00247 public: 00249 00254 GrabbingInterruptor(Interruptable* i, bool mock=false); 00256 ~GrabbingInterruptor(); 00257 }; 00258 00260 void printHelp(); 00262 Pylon::CDeviceInfo getDeviceFromArgs(std::string args) throw(utils::ICLException); 00264 int channelFromArgs(std::string args); 00266 00267 Pylon::DeviceInfoList_t 00268 getPylonDeviceList(Pylon::DeviceInfoList_t* filter=NULL); 00269 00270 } //namespace pylon 00271 } // namespace io 00272 } //namespace icl 00273