ViSP  2.6.2
vpDiskGrabber.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDiskGrabber.cpp 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 {
51  setDirectory("/tmp");
52  setBaseName("I");
53  setImageNumber(0);
54  setStep(1);
55  setNumberOfZero(0);
56  setExtension("pgm");
57 
58  init = false;
59  useGenericName = false;
60 }
61 
62 
63 vpDiskGrabber::vpDiskGrabber(const char *genericName)
64 {
65  strcpy(this->genericName, genericName);
66  useGenericName = true;
67 }
68 
69 
81 vpDiskGrabber::vpDiskGrabber(const char *dir, const char *basename,
82  long number,
83  int step, unsigned int noz,
84  const char *ext)
85 {
86  setDirectory(dir);
87  setBaseName(basename);
88  setImageNumber(number);
89  setStep(step);
90  setNumberOfZero(noz);
91  setExtension(ext);
92 
93  init = false;
94  useGenericName = false;
95 }
96 
97 void
99 {
100  long first_number = getImageNumber();
101 
102  vpDEBUG_TRACE(2, "first %ld", first_number);
103 
104  acquire(I);
105 
106  setImageNumber(first_number);
107 
108  width = I.getWidth();
109  height = I.getHeight();
110 
111  init = true;
112 }
113 
119 void
121 {
122  // Fisrt we save the image number, so that it can be reaffected after the
123  // acquisition. That means that the first image is readed twice
124  long first_number = getImageNumber();
125  vpDEBUG_TRACE(2, "first %ld", first_number);
126 
127  acquire(I);
128 
129  setImageNumber(first_number);
130 
131  width = I.getWidth();
132  height = I.getHeight();
133 
134  init = true;
135 }
136 
137 
144 void
146 {
147 
148  char name[FILENAME_MAX] ;
149 
150  if(useGenericName)
151  sprintf(name,genericName,image_number) ;
152  else
153  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
154 
155  image_number += image_step ;
156 
157  vpDEBUG_TRACE(2, "load: %s\n", name);
158 
159  vpImageIo::read(I, name) ;
160 
161  width = I.getWidth();
162  height = I.getHeight();
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 }
192 
200 void
202 {
203 
204  char name[FILENAME_MAX] ;
205 
206  if(useGenericName)
207  sprintf(name,genericName,image_number) ;
208  else
209  sprintf(name,"%s/%s%0*ld.%s",directory,base_name,number_of_zero,image_number,extension) ;
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 
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  vpDEBUG_TRACE(2, "load: %s\n", name);
238 
239  vpImageIo::read(I, name) ;
240 
241  width = I.getWidth();
242  height = I.getHeight();
243 
244 }
245 
251 void
253 {
254  // Nothing do do here...
255 }
256 
257 
264 {
265 }
266 
267 
271 void
273 {
274  sprintf(directory, "%s", dir) ;
275 }
276 
280 void
281 vpDiskGrabber::setBaseName(const char *name)
282 {
283  sprintf(base_name, "%s", name) ;
284 }
285 
289 void
291 {
292  sprintf(extension, "%s", ext) ;
293 }
294 
298 void
300 {
301  image_number = number ;
302  vpDEBUG_TRACE(2, "image number %ld", image_number);
303 
304 }
305 
309 void
311 {
312  image_step = step;
313 }
317 void
319 {
320  number_of_zero = noz ;
321 }
322 
323 void
324 vpDiskGrabber::setGenericName(const char *genericName)
325 {
326  strcpy(this->genericName, genericName) ;
327  useGenericName = true;
328 }
#define vpDEBUG_TRACE
Definition: vpDebug.h:454
unsigned int getWidth() const
Definition: vpImage.h:154
void setBaseName(const char *name)
void setDirectory(const char *dir)
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:145
void acquire(vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:239
unsigned int width
Number of columns in the image.
void setGenericName(const char *genericName)