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 <GL/glut.h>
26 #include <fvcams/camera.h>
27 #include <fvutils/color/colorspaces.h>
28 #include <fvutils/color/conversions.h>
29 
30 #include <algorithm>
31 #include <cstdio>
32 #include <cstdlib>
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 /** Destructor. */
56 {
57  free(rgb_buf_);
58 }
59 
60 /** Fill texture. */
61 void
63 {
64  cam_->capture();
65  convert(cam_->colorspace(), RGB, cam_->buffer(), rgb_buf_, width_, height_);
66  copy_rgb_to_texture(rgb_buf_);
67  cam_->dispose_buffer();
68 }
SkelGuiImageDrawer(firevision::Camera *cam)
Constructor.
const unsigned int height_
Height of visible area from texture.
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:32
const unsigned int width_
Width of visible area from texture.
Fawkes library namespace.
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.
~SkelGuiImageDrawer()
Destructor.
virtual void dispose_buffer()=0
Dispose current buffer.