Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ShowCamWxThreads.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __ShowCamWxThreads_hh__
26 #define __ShowCamWxThreads_hh__
27 
28 #include <bias_config.h>
29 #include <wx/wx.h>
30 
31 #include <Gui/StringConv.hh>
32 #include <Image/Camera.hh>
33 #include <Image/ImagePackage.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Debug/TimeMeasure.hh>
36 
37 #include <VideoSource/VideoSource_Base.hh>
38 
39 #include <Base/Common/TimeStamp.hh>
40 
41 
42 namespace BIAS {
43 
44  /**
45  @class ImageSaveThread
46  @brief This class creates a thread which stores an image in a file
47  if rescale is not zero then the stored image is downsampled
48  by this factor.
49  @author Christoffer Menk
50  */
51  class ImageSaveThread : public wxThread
52  {
53  public:
54  // Constructor for single images
55  ImageSaveThread(std::string cameraName,
56  const int& downsample,
57  wxMutex* BufferAccessMutex,
58  bool& writeToBuffer,
59  unsigned int& readIndex,
60  unsigned int& writeIndex,
62  BIAS::Camera<unsigned char>* imgCenter,
64  BIAS::Camera<float>* imgDepth,
65  BIAS::Camera<float>* imgAmp,
66  BIAS::Camera<float>* imgInt,
67  std::vector<Camera<unsigned char>* >* imageBuffer,
68  std::vector<Camera<unsigned char>* >* imageBufferCenter,
69  std::vector<Camera<unsigned char>* >* imageBufferRight,
70  std::vector<Camera<float>* >* imageBufferPmdDepth,
71  std::vector<Camera<float>* >* imageBufferPmdAmp,
72  std::vector<Camera<float>* >* imageBufferPmdInt,
73  bool saveToStream = false);
74 
76 
77  virtual ExitCode Entry();
78 
79  void SetSaveDirectory(std::string &path){saveDirectory_ = path;};
80  void ResetCounter(){ImageCounter_=0;};
81  void FinishSaving();
82 
83  private:
84  void SaveImage_(Camera <unsigned char>* im, std::string name);
85  void SaveImage_(Camera <float>* imF, std::string name);
86 
87  int mapNameToStreamIdx_(std::string name);
88 
89  private:
90  std::string saveDirectory_;
91  std::string cameraName_;
92 
93  int DownSample_;
94  unsigned int ImageCounter_;
95 
97  BIAS::Camera<unsigned char> *ImgCenter_;
98  BIAS::Camera<unsigned char> *ImgRight_;
100 
101  BIAS::Camera<float> *ImgDepth_;
102  BIAS::Camera<float> *ImgAmp_;
103  BIAS::Camera<float> *ImgInt_;
104 
105  std::vector<Camera<unsigned char>* > *ImageBuffer_;
106  std::vector<Camera<unsigned char>* > *ImageBufferCenter_;
107  std::vector<Camera<unsigned char>* > *ImageBufferRight_;
108  std::vector<Camera<float>* > *ImageBufferPMDDepth_;
109  std::vector<Camera<float>* > *ImageBufferPMDAmp_;
110  std::vector<Camera<float>* > *ImageBufferPMDInt_;
111  std::vector<Camera<float>* > *ImageBufferFloat_;
112 
113  wxMutex* BufferAccess_;
114  bool* WriteToBuffer_;
115  unsigned int* WriteIndex_;
116  unsigned int* ReadIndex_;
117 
118  std::vector<ImagePackage*> ips_;
119  std::vector<bool> bStreamOpen_;
120  bool stream_;
121  };
122 
123 
124  /** ***************************************************************
125  @class GrabSingleThread
126  @brief This class creates a thread which grabs a single image
127  @author Christoffer Menk
128  */
129  class GrabSingleThread : public wxThread
130  {
131  public:
132 
133  enum {
134  DCAM = 0,
136  SR,
145  };
146 
148  wxCondition *ClientCondition,
149  wxCondition *ServerCondition,
150  wxMutex *mutexClientCondition,
151  wxMutex *mutexServerCondition,
152  unsigned int threadNumber,
153  wxMutex *BufferAccessMutex,
154  bool& writeToBuffer,
155  unsigned int& readIndex,
156  unsigned int& writeIndex,
157 
159  BIAS::Camera<unsigned char> *imgCenter,
160  BIAS::Camera<unsigned char> *imgRight,
161  BIAS::Camera<float> *imgDepth,
162  BIAS::Camera<float> *imgAmp,
163  BIAS::Camera<float> *imgInt,
165 
166  std::vector<Camera<unsigned char>* > *imageBuffer,
167  std::vector<Camera<unsigned char>* > *imageBufferCenter,
168  std::vector<Camera<unsigned char>* > *imageBufferRight,
169  std::vector<Camera<float>* >* imageBufferPMDDepth,
170  std::vector<Camera<float>* >* imageBufferPMDAmp,
171  std::vector<Camera<float>* >* imageBufferPMDInt);
172 
173  virtual ~GrabSingleThread(){};
174  void SetWriteToBuffer(bool buffer){*WriteToBuffer_ = buffer;};
175  ExitCode Entry();
176  void OnExit() {};
177 
178  private:
179  BIAS::VideoSource *Cam_;
180  bool *WriteToBuffer_;
181  wxMutex *mutexClientCondition_;
182  wxMutex *mutexServerCondition_;
183  wxCondition *ClientCondition_;
184  wxCondition *ServerCondition_;
185  unsigned int threadNumber_;
186  wxMutex *BufferAccess_;
187  unsigned int *WriteIndex_;
188  unsigned int *ReadIndex_;
189  unsigned int BufferSize_;
191  BIAS::Camera<unsigned char>* ImgCenter_;
192  BIAS::Camera<unsigned char>* ImgRight_;
193  BIAS::Camera<unsigned char>* AllImages_;
194  BIAS::Camera<float>* ImgDepth_;
195  BIAS::Camera<float>* ImgAmp_;
196  BIAS::Camera<float>* ImgInt_;
197 
198  std::vector<Camera<unsigned char>* >* ImageBuffer_;
199  std::vector<Camera<unsigned char>* >* ImageBufferCenter_;
200  std::vector<Camera<unsigned char>* >* ImageBufferRight_;
201 
202  std::vector<Camera<float>* >* ImageBufferPMDDepth_;
203  std::vector<Camera<float>* >* ImageBufferPMDAmp_;
204  std::vector<Camera<float>* >* ImageBufferPMDInt_;
205  unsigned int camtype_;
206  };
207 
208 
209  /** ***************************************************************
210  @class GrabMasterThread
211  @brief Thread for synchronizing grabbing from multiple threads
212  @author Falko Kellner
213  */
214  class GrabMasterThread : public wxThread
215  {
216  public:
217 
218  GrabMasterThread(std::vector<BIAS::VideoSource*> *Cameras,
219  std::vector<wxCondition*> *ClientCondition,
220  std::vector<wxCondition*> *ServerCondition,
221  std::vector<wxMutex*> *mutexClientCondition,
222  std::vector<wxMutex*> *mutexServerCondition
223  );
224 
225  virtual ~GrabMasterThread(){};
226  ExitCode Entry();
227  void OnExit() {};
228  double fps_;
229  unsigned int FrameCounter_;
230 
231  private:
232  std::vector<wxMutex*> *mutexClientCondition_;
233  std::vector<wxMutex*> *mutexServerCondition_;
234  std::vector<wxCondition*> *ClientCondition_;
235  std::vector<wxCondition*> *ServerCondition_;
236  std::vector<BIAS::VideoSource*> *Cameras_;
237 
238  TimeMeasure StopWatch_;
239  };
240 
241 
242 } // end of namespace BIAS
243 
244 #endif // __ShowCamWxThreads_hh__
GrabSingleThread(BIAS::VideoSource *cam, wxCondition *ClientCondition, wxCondition *ServerCondition, wxMutex *mutexClientCondition, wxMutex *mutexServerCondition, unsigned int threadNumber, wxMutex *BufferAccessMutex, bool &writeToBuffer, unsigned int &readIndex, unsigned int &writeIndex, BIAS::Camera< unsigned char > *img, BIAS::Camera< unsigned char > *imgCenter, BIAS::Camera< unsigned char > *imgRight, BIAS::Camera< float > *imgDepth, BIAS::Camera< float > *imgAmp, BIAS::Camera< float > *imgInt, BIAS::Camera< unsigned char > *imgAll, std::vector< Camera< unsigned char > * > *imageBuffer, std::vector< Camera< unsigned char > * > *imageBufferCenter, std::vector< Camera< unsigned char > * > *imageBufferRight, std::vector< Camera< float > * > *imageBufferPMDDepth, std::vector< Camera< float > * > *imageBufferPMDAmp, std::vector< Camera< float > * > *imageBufferPMDInt)
Defines a common interface to different devices.
void SetSaveDirectory(std::string &path)
This class creates a thread which stores an image in a file if rescale is not zero then the stored im...
virtual ExitCode Entry()
void SetWriteToBuffer(bool buffer)
GrabMasterThread(std::vector< BIAS::VideoSource * > *Cameras, std::vector< wxCondition * > *ClientCondition, std::vector< wxCondition * > *ServerCondition, std::vector< wxMutex * > *mutexClientCondition, std::vector< wxMutex * > *mutexServerCondition)
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
ImageSaveThread(std::string cameraName, const int &downsample, wxMutex *BufferAccessMutex, bool &writeToBuffer, unsigned int &readIndex, unsigned int &writeIndex, BIAS::Camera< unsigned char > *img, BIAS::Camera< unsigned char > *imgCenter, BIAS::Camera< unsigned char > *imgRight, BIAS::Camera< float > *imgDepth, BIAS::Camera< float > *imgAmp, BIAS::Camera< float > *imgInt, std::vector< Camera< unsigned char > * > *imageBuffer, std::vector< Camera< unsigned char > * > *imageBufferCenter, std::vector< Camera< unsigned char > * > *imageBufferRight, std::vector< Camera< float > * > *imageBufferPmdDepth, std::vector< Camera< float > * > *imageBufferPmdAmp, std::vector< Camera< float > * > *imageBufferPmdInt, bool saveToStream=false)