Image Component Library (ICL)
PylonUtils.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/PylonUtils.h **
10 ** Module : ICLIO **
11 ** Authors: Viktor Richter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLIO/PylonIncludes.h>
35 #include <ICLUtils/Mutex.h>
36 #include <ICLUtils/Exception.h>
37 #include <ICLCore/CoreFunctions.h>
38 #include <ICLCore/ImgBase.h>
39 #include <ICLCore/Img.h>
40 
41 namespace icl {
42  namespace io{
43  namespace pylon {
44 
46  template <typename T>
48  private:
50  Pylon::StreamBufferHandle m_hBuffer;
51 
52  public:
53  PylonGrabberBuffer(size_t size) : m_pBuffer(NULL) {
54  m_pBuffer = new T[size];
55  if (!m_pBuffer)
56  throw utils::ICLException("Not enough memory to allocate image buffer");
57  }
59  if (m_pBuffer)
60  delete[] m_pBuffer;
61  }
62  T* getBufferPointer(void) {
63  return m_pBuffer;
64  }
65  Pylon::StreamBufferHandle getBufferHandle(void) {
66  return m_hBuffer;
67  }
68  void setBufferHandle(Pylon::StreamBufferHandle hBuffer) {
69  m_hBuffer = hBuffer;
70  }
71  };
72 
74  template <typename T>
75  class TsBuffer {
76  public:
80  uint64_t m_Timestamp;
82  size_t m_Size;
83 
85  TsBuffer(size_t size) : m_Timestamp(0), m_Size(size){
86  m_Buffer = new T[m_Size];
87  if (!m_Buffer)
88  throw utils::ICLException("Not enough memory to allocate image buffer");
89  }
92  if (m_Buffer){
93  delete[] m_Buffer;
94  }
95  }
97 
101  void copy(void* buffer){
102  T* tmp = (T*) buffer;
103  core::copy(tmp, tmp + m_Size, m_Buffer);
104  }
105  };
106 
108  class ConvBuffers {
109  public:
115  ICLIO_API void free();
125  std::vector<icl8u*>* m_Channels;
127  std::vector<icl16s*>* m_Channels16;
129  bool m_Reset;
130  };
131 
133 
138  public:
143 
145 
151 
157  ICLIO_API void setReset();
159  ICLIO_API bool newAvailable();
160 
161  private:
167  int m_Write;
169  int m_Next;
171  int m_Read;
173  bool m_Avail;
174  };
175 
177 
183  struct PylonAutoEnv{
184  public:
190 
191  ICLIO_API static bool initPylonEnv();
193 
194  ICLIO_API static bool termPylonEnv();
195  };
196 
198 
204  virtual ~Interruptable() {}
206  virtual void acquisitionStart() = 0;
208  virtual void acquisitionStop() = 0;
210  virtual void grabbingStart() = 0;
212  virtual void grabbingStop() = 0;
213  };
214 
216 
222  private:
225 
226  public:
228 
233  ICLIO_API AcquisitionInterruptor(Interruptable* i, bool mock = false);
236  };
237 
239 
244  private:
247 
248  public:
250 
255  ICLIO_API GrabbingInterruptor(Interruptable* i, bool mock = false);
258  };
259 
261  ICLIO_API void printHelp();
263  ICLIO_API Pylon::CDeviceInfo getDeviceFromArgs(std::string args);
265  ICLIO_API int channelFromArgs(std::string args);
267 
268  ICLIO_API Pylon::DeviceInfoList_t
269  getPylonDeviceList(Pylon::DeviceInfoList_t* filter=NULL);
270 
271  } //namespace pylon
272  } // namespace io
273 } //namespace icl
274 
TsBuffer(size_t size)
Constructor allocates required memory.
Definition: PylonUtils.h:85
static ICLIO_API bool initPylonEnv()
Initializes the Pylon environment.
void setBufferHandle(Pylon::StreamBufferHandle hBuffer)
Definition: PylonUtils.h:68
int m_Read
The object currently read from.
Definition: PylonUtils.h:171
size_t m_Size
holdss the size of m_Buffer
Definition: PylonUtils.h:82
icl::core::ImgBase * m_Image
To this ImageBase the converted image is written.
Definition: PylonUtils.h:117
undocument this line if you encounter any issues!
Definition: Any.h:37
ICLIO_API ~AcquisitionInterruptor()
Starts acquisition if stopped before.
bool m_Avail
tells whether an actualized object was written.
Definition: PylonUtils.h:173
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
ICLIO_API int channelFromArgs(std::string args)
Uses args to find out which BufferChannel to use.
icl8u * m_ImageBuff
Buffer für color conversion.
Definition: PylonUtils.h:119
ICLIO_API PylonAutoEnv()
Initializes Pylon environment if not already done.
ICLIO_API ConvBuffers()
Constructor sets all pointers to NULL.
utils::Mutex m_Mutex
the Mutex is used for concurrent reading and writing.
Definition: PylonUtils.h:165
T * m_Buffer
Buffer for image information.
Definition: PylonUtils.h:78
ICLIO_API void printHelp()
Prints help-information to std::cout.
virtual void acquisitionStop()=0
stops the acquisition
Buffer, registered to the Pylon-drivers StreamGrabber.
Definition: PylonUtils.h:47
ICLIO_API ConcGrabberBuffer()
Constructor creates and initializes resources.
~TsBuffer()
Frees allocated memory.
Definition: PylonUtils.h:91
ICLIO_API AcquisitionInterruptor(Interruptable *i, bool mock=false)
stops the acquisiton
virtual void grabbingStart()=0
starts grabbing
PylonGrabberBuffer(size_t size)
Definition: PylonUtils.h:53
A buffer holding image information and timestamp.
Definition: PylonUtils.h:75
uint64_t m_Timestamp
Buffer for image-timestamp.
Definition: PylonUtils.h:80
ICLIO_API ~GrabbingInterruptor()
Destructor calls grabbingStart().
ICLIO_API GrabbingInterruptor(Interruptable *i, bool mock=false)
Constructor calls grabbingStop().
ICLIO_API ConvBuffers * getNextWriteBuffer()
returns a pointer to the next write ConvBuffers.
ICLIO_API ~ConcGrabberBuffer()
Destructor frees allocated memory.
ICLIO_API Pylon::CDeviceInfo getDeviceFromArgs(std::string args)
Uses args to find demanded device.
icl16s * m_ImageBuff16
Buffer für 16 bit mono copy.
Definition: PylonUtils.h:121
ICLIO_API bool newAvailable()
tells whether a new ConvBuffers is available
Utility Structure.
Definition: PylonUtils.h:221
int m_Write
The object currently written to.
Definition: PylonUtils.h:167
T * m_pBuffer
Definition: PylonUtils.h:49
int m_Next
The write object currently not written to.
Definition: PylonUtils.h:169
This class holds all buffers needed for ColorConversion.
Definition: PylonUtils.h:108
#define ICLIO_API
Definition: CompatMacros.h:176
virtual void acquisitionStart()=0
starts the acquisition
virtual ~Interruptable()
Virtual destructor.
Definition: PylonUtils.h:204
Interruptable * m_Interu
A pointer to the PylonGrabberImpl that is to be stopped.
Definition: PylonUtils.h:224
ICLQt_API core::Img< T > filter(const core::Img< T > &image, const std::string &filter)
applies a filter operation on the source image (affinity for float)
Utility Structure.
Definition: PylonUtils.h:202
T * getBufferPointer(void)
Definition: PylonUtils.h:62
ICLIO_API void free()
deletes Objects pointed at, when pointer != NULL
ICLIO_API ~PylonAutoEnv()
Terminates Pylon environment when (calls to term) == (calls to init).
std::vector< icl16s * > * m_Channels16
Vector for 16bit mono-channel.
Definition: PylonUtils.h:127
ICLIO_API void setReset()
mark ConvBuffers to be reset on next write-access.
ICLIO_API ConvBuffers * getNextReadBuffer()
returns a pointer to the most recent actualized ConvBuffers.
Pylon::StreamBufferHandle m_hBuffer
Definition: PylonUtils.h:50
This is used for concurrent writing and reading of ConvBuffers.
Definition: PylonUtils.h:137
Interruptable * m_Interu
A pointer to the Interruptable that needs to be stopped.
Definition: PylonUtils.h:246
bool m_Reset
boolean showing whether this buffers need a reset
Definition: PylonUtils.h:129
ConvBuffers * m_Buffers[3]
current objects which alternately are read and written.
Definition: PylonUtils.h:163
~PylonGrabberBuffer()
Definition: PylonUtils.h:58
Base class for Exception handling in the ICL.
Definition: Exception.h:42
Pylon::StreamBufferHandle getBufferHandle(void)
Definition: PylonUtils.h:65
std::vector< icl8u * > * m_Channels
Vector for channels.
Definition: PylonUtils.h:125
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
Ipp16s icl16s
16bit signed integer type for the ICL (range [-32767, 32768 ])
Definition: BasicTypes.h:61
static ICLIO_API bool termPylonEnv()
terminates the Pylon environment.
ICLIO_API ~ConvBuffers()
calls free
Utility Structure.
Definition: PylonUtils.h:183
Mutex class of the ICL.
Definition: Mutex.h:54
icl::core::Img8u * m_ImageRGBA
Buffer for interlieved-to-planar conversion.
Definition: PylonUtils.h:123
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
ICLIO_API Pylon::DeviceInfoList_t getPylonDeviceList(Pylon::DeviceInfoList_t *filter=NULL)
Returns a list of available Pylon devices.
virtual void grabbingStop()=0
stops grabbing
void copy(void *buffer)
uses icl::io::pylon::TsBuffer::copy to write buffer-data to m_Buffer
Definition: PylonUtils.h:101
Utility Structure.
Definition: PylonUtils.h:243