ViSP  2.10.0
vpDiskGrabber.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDiskGrabber.cpp 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Disk framegrabber.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp/vpDiskGrabber.h>
44 
45 
50  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
51 {
52  setDirectory("/tmp");
53  setBaseName("I");
54  setExtension("pgm");
55 
56  init = false;
57 }
58 
59 
60 vpDiskGrabber::vpDiskGrabber(const char *generic_name)
61  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
62 {
63  setDirectory("/tmp");
64  setBaseName("I");
65  setExtension("pgm");
66 
67  init = false;
68  if (strlen( generic_name ) >= FILENAME_MAX) {
70  "Not enough memory to intialize the generic name"));
71  }
72 
73  strcpy(this->genericName, generic_name);
74  useGenericName = true;
75 }
76 
77 
89 vpDiskGrabber::vpDiskGrabber(const char *dir, const char *basename,
90  long number,
91  int step, unsigned int noz,
92  const char *ext)
93  : image_number(number), image_step(step), number_of_zero(noz), useGenericName(false)
94 {
95  setDirectory(dir);
96  setBaseName(basename);
97  setExtension(ext);
98 
99  init = false;
100 }
101 
102 void
104 {
105  long first_number = getImageNumber();
106 
107  vpDEBUG_TRACE(2, "first %ld", first_number);
108 
109  acquire(I);
110 
111  setImageNumber(first_number);
112 
113  width = I.getWidth();
114  height = I.getHeight();
115 
116  init = true;
117 }
118 
124 void
126 {
127  // First we save the image number, so that it can be reaffected after the
128  // acquisition. That means that the first image is readed twice
129  long first_number = getImageNumber();
130  vpDEBUG_TRACE(2, "first %ld", first_number);
131 
132  acquire(I);
133 
134  setImageNumber(first_number);
135 
136  width = I.getWidth();
137  height = I.getHeight();
138 
139  init = true;
140 }
141 
147 void
149 {
150  // First we save the image number, so that it can be reaffected after the
151  // acquisition. That means that the first image is readed twice
152  long first_number = getImageNumber();
153  vpDEBUG_TRACE(2, "first %ld", first_number);
154 
155  acquire(I);
156 
157  setImageNumber(first_number);
158 
159  width = I.getWidth();
160  height = I.getHeight();
161 
162  init = true;
163 }
164 
171 void
173 {
174 
175  char name[FILENAME_MAX] ;
176 
177  if(useGenericName)
178  sprintf(name,genericName,image_number) ;
179  else
180  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
181 
182  image_number += image_step ;
183 
184  vpDEBUG_TRACE(2, "load: %s\n", name);
185 
186  vpImageIo::read(I, name) ;
187 
188  width = I.getWidth();
189  height = I.getHeight();
190 }
191 
198 void
200 {
201 
202  char name[FILENAME_MAX] ;
203 
204  if(useGenericName)
205  sprintf(name,genericName,image_number) ;
206  else
207  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
208 
209  image_number += image_step ;
210 
211  vpDEBUG_TRACE(2, "load: %s\n", name);
212 
213  vpImageIo::read(I, name) ;
214 
215  width = I.getWidth();
216  height = I.getHeight();
217 
218 }
219 
226 void
228 {
229 
230  char name[FILENAME_MAX] ;
231 
232  if(useGenericName)
233  sprintf(name,genericName,image_number) ;
234  else
235  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
236 
237  image_number += image_step ;
238 
239  vpDEBUG_TRACE(2, "load: %s\n", name);
240 
241  vpImageIo::readPFM(I, name) ;
242 
243  width = I.getWidth();
244  height = I.getHeight();
245 
246 }
247 
255 void
257 {
258 
259  char name[FILENAME_MAX] ;
260 
261  if(useGenericName)
262  sprintf(name,genericName,img_number) ;
263  else
264  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
265 
266  vpDEBUG_TRACE(2, "load: %s\n", name);
267 
268  vpImageIo::read(I, name) ;
269 
270  width = I.getWidth();
271  height = I.getHeight();
272 }
273 
281 void
283 {
284 
285  char name[FILENAME_MAX] ;
286 
287  if(useGenericName)
288  sprintf(name,genericName,img_number) ;
289  else
290  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
291 
292  vpDEBUG_TRACE(2, "load: %s\n", name);
293 
294  vpImageIo::read(I, name) ;
295 
296  width = I.getWidth();
297  height = I.getHeight();
298 
299 }
300 
301 
309 void
311 {
312 
313  char name[FILENAME_MAX] ;
314 
315  if(useGenericName)
316  sprintf(name,genericName,img_number) ;
317  else
318  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
319 
320  vpDEBUG_TRACE(2, "load: %s\n", name);
321 
322  vpImageIo::readPFM(I, name) ;
323 
324  width = I.getWidth();
325  height = I.getHeight();
326 
327 }
328 
334 void
336 {
337  // Nothing do do here...
338 }
339 
340 
347 {
348 }
349 
350 
354 void
356 {
357  sprintf(directory, "%s", dir) ;
358 }
359 
363 void
364 vpDiskGrabber::setBaseName(const char *name)
365 {
366  sprintf(base_name, "%s", name) ;
367 }
368 
372 void
374 {
375  sprintf(extension, "%s", ext) ;
376 }
377 
381 void
383 {
384  image_number = number ;
385  vpDEBUG_TRACE(2, "image number %ld", image_number);
386 
387 }
388 
392 void
394 {
395  image_step = step;
396 }
400 void
402 {
403  number_of_zero = noz ;
404 }
405 
406 void
407 vpDiskGrabber::setGenericName(const char *generic_name)
408 {
409  if (strlen( generic_name ) >= FILENAME_MAX) {
411  "Not enough memory to intialize the generic name"));
412  }
413 
414  strcpy(this->genericName, generic_name) ;
415  useGenericName = true;
416 }
#define vpDEBUG_TRACE
Definition: vpDebug.h:482
unsigned int getWidth() const
Definition: vpImage.h:161
void setBaseName(const char *name)
error that can be emited by ViSP classes.
Definition: vpException.h:76
void setDirectory(const char *dir)
static void readPFM(vpImage< float > &I, const char *filename)
Definition: vpImageIo.cpp:827
virtual ~vpDiskGrabber()
void setNumberOfZero(unsigned int noz)
void setStep(int a)
unsigned int height
Number of rows in the image.
void setImageNumber(long number)
void open(vpImage< unsigned char > &I)
void setExtension(const char *ext)
bool init
Set to true if the frame grabber has been initialized.
long getImageNumber()
unsigned int getHeight() const
Definition: vpImage.h:152
void acquire(vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:278
unsigned int width
Number of columns in the image.
void setGenericName(const char *genericName)