Fawkes API  Fawkes Development Version
image_drawer.cpp
1 
2 /***************************************************************************
3  * image_drawer.cpp - Skeleton Visualization GUI: image drawer
4  *
5  * Created: Sat Mar 19 00:08:37 2011
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program 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 Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "image_drawer.h"
24 
25 #include <fvcams/camera.h>
26 #include <fvutils/color/colorspaces.h>
27 #include <fvutils/color/conversions.h>
28 
29 #include <cstdlib>
30 #include <cstdio>
31 #include <algorithm>
32 #include <GL/glut.h>
33 
34 using namespace fawkes;
35 using namespace firevision;
36 
37 /** @class SkelGuiImageDrawer "image_drawer.h"
38  * Draw images from camera in texture.
39  * Uses texture mapping to show an image acquired from a camera in the
40  * background.
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor.
45  * @param cam camera to capture image with
46  */
48  : SkelGuiTextureDrawer(cam->pixel_width(), cam->pixel_height())
49 {
50  __cam = cam;
51  __rgb_buf = malloc_buffer(RGB, __width, __height);
52 
53 }
54 
55 /** Destructor. */
57 {
58  free(__rgb_buf);
59 }
60 
61 /** Fill texture. */
62 void
64 {
65  __cam->capture();
66  convert(__cam->colorspace(), RGB, __cam->buffer(), __rgb_buf, __width, __height);
67  copy_rgb_to_texture(__rgb_buf);
68  __cam->dispose_buffer();
69 }
70 
SkelGuiImageDrawer(firevision::Camera *cam)
Constructor.
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:35
Fawkes library namespace.
const unsigned int __width
Width of visible area from texture.
virtual colorspace_t colorspace()=0
Colorspace of returned image.
virtual void capture()=0
Capture an image.
void copy_rgb_to_texture(const unsigned char *rgb_buf)
Copy an RGB buffer to texture.
virtual unsigned char * buffer()=0
Get access to current image buffer.
Draw images from camera in texture.
void fill_texture()
Fill texture.
const unsigned int __height
Height of visible area from texture.
~SkelGuiImageDrawer()
Destructor.
virtual void dispose_buffer()=0
Dispose current buffer.