Visual Servoing Platform  version 3.0.0
vpDiskGrabber.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Disk framegrabber.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
39 #include <visp3/io/vpDiskGrabber.h>
40 
41 
46  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
47 {
48  setDirectory("/tmp");
49  setBaseName("I");
50  setExtension("pgm");
51 
52  init = false;
53 }
54 
55 
56 vpDiskGrabber::vpDiskGrabber(const char *generic_name)
57  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
58 {
59  setDirectory("/tmp");
60  setBaseName("I");
61  setExtension("pgm");
62 
63  init = false;
64  if (strlen( generic_name ) >= FILENAME_MAX) {
66  "Not enough memory to intialize the generic name"));
67  }
68 
69  strcpy(this->genericName, generic_name);
70  useGenericName = true;
71 }
72 
73 
85 vpDiskGrabber::vpDiskGrabber(const char *dir, const char *basename,
86  long number,
87  int step, unsigned int noz,
88  const char *ext)
89  : image_number(number), image_step(step), number_of_zero(noz), useGenericName(false)
90 {
91  setDirectory(dir);
92  setBaseName(basename);
93  setExtension(ext);
94 
95  init = false;
96 }
97 
98 void
100 {
101  long first_number = getImageNumber();
102 
103  vpDEBUG_TRACE(2, "first %ld", first_number);
104 
105  acquire(I);
106 
107  setImageNumber(first_number);
108 
109  width = I.getWidth();
110  height = I.getHeight();
111 
112  init = true;
113 }
114 
120 void
122 {
123  // First we save the image number, so that it can be reaffected after the
124  // acquisition. That means that the first image is readed twice
125  long first_number = getImageNumber();
126  vpDEBUG_TRACE(2, "first %ld", first_number);
127 
128  acquire(I);
129 
130  setImageNumber(first_number);
131 
132  width = I.getWidth();
133  height = I.getHeight();
134 
135  init = true;
136 }
137 
143 void
145 {
146  // First we save the image number, so that it can be reaffected after the
147  // acquisition. That means that the first image is readed twice
148  long first_number = getImageNumber();
149  vpDEBUG_TRACE(2, "first %ld", first_number);
150 
151  acquire(I);
152 
153  setImageNumber(first_number);
154 
155  width = I.getWidth();
156  height = I.getHeight();
157 
158  init = true;
159 }
160 
167 void
169 {
170 
171  char name[FILENAME_MAX] ;
172 
173  if(useGenericName)
174  sprintf(name,genericName,image_number) ;
175  else
176  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
177 
178  image_number += image_step ;
179 
180  vpDEBUG_TRACE(2, "load: %s\n", name);
181 
182  vpImageIo::read(I, name) ;
183 
184  width = I.getWidth();
185  height = I.getHeight();
186 }
187 
194 void
196 {
197 
198  char name[FILENAME_MAX] ;
199 
200  if(useGenericName)
201  sprintf(name,genericName,image_number) ;
202  else
203  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
204 
205  image_number += image_step ;
206 
207  vpDEBUG_TRACE(2, "load: %s\n", name);
208 
209  vpImageIo::read(I, name) ;
210 
211  width = I.getWidth();
212  height = I.getHeight();
213 
214 }
215 
222 void
224 {
225 
226  char name[FILENAME_MAX] ;
227 
228  if(useGenericName)
229  sprintf(name,genericName,image_number) ;
230  else
231  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
232 
233  image_number += image_step ;
234 
235  vpDEBUG_TRACE(2, "load: %s\n", name);
236 
237  vpImageIo::readPFM(I, name) ;
238 
239  width = I.getWidth();
240  height = I.getHeight();
241 
242 }
243 
251 void
253 {
254 
255  char name[FILENAME_MAX] ;
256 
257  if(useGenericName)
258  sprintf(name,genericName,img_number) ;
259  else
260  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
261 
262  vpDEBUG_TRACE(2, "load: %s\n", name);
263 
264  vpImageIo::read(I, name) ;
265 
266  width = I.getWidth();
267  height = I.getHeight();
268 }
269 
277 void
279 {
280 
281  char name[FILENAME_MAX] ;
282 
283  if(useGenericName)
284  sprintf(name,genericName,img_number) ;
285  else
286  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
287 
288  vpDEBUG_TRACE(2, "load: %s\n", name);
289 
290  vpImageIo::read(I, name) ;
291 
292  width = I.getWidth();
293  height = I.getHeight();
294 
295 }
296 
297 
305 void
307 {
308 
309  char name[FILENAME_MAX] ;
310 
311  if(useGenericName)
312  sprintf(name,genericName,img_number) ;
313  else
314  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,img_number,extension) ;
315 
316  vpDEBUG_TRACE(2, "load: %s\n", name);
317 
318  vpImageIo::readPFM(I, name) ;
319 
320  width = I.getWidth();
321  height = I.getHeight();
322 
323 }
324 
330 void
332 {
333  // Nothing do do here...
334 }
335 
336 
343 {
344 }
345 
346 
350 void
352 {
353  sprintf(directory, "%s", dir) ;
354 }
355 
359 void
360 vpDiskGrabber::setBaseName(const char *name)
361 {
362  sprintf(base_name, "%s", name) ;
363 }
364 
368 void
370 {
371  sprintf(extension, "%s", ext) ;
372 }
373 
377 void
379 {
380  image_number = number ;
381  vpDEBUG_TRACE(2, "image number %ld", image_number);
382 
383 }
384 
388 void
390 {
391  image_step = step;
392 }
396 void
398 {
399  number_of_zero = noz ;
400 }
401 
402 void
403 vpDiskGrabber::setGenericName(const char *generic_name)
404 {
405  if (strlen( generic_name ) >= FILENAME_MAX) {
407  "Not enough memory to intialize the generic name"));
408  }
409 
410  strcpy(this->genericName, generic_name) ;
411  useGenericName = true;
412 }
unsigned int getWidth() const
Definition: vpImage.h:161
void setBaseName(const char *name)
error that can be emited by ViSP classes.
Definition: vpException.h:73
void setDirectory(const char *dir)
static void readPFM(vpImage< float > &I, const char *filename)
Definition: vpImageIo.cpp:823
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()
#define vpDEBUG_TRACE
Definition: vpDebug.h:478
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:274
unsigned int width
Number of columns in the image.
void setGenericName(const char *genericName)