~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srCore/sensor/depthImageCamera.cpp

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * depthImageCamera.cpp
 
3
 *
 
4
 *  Created on: Dec 29, 2008
 
5
 *      Author: winkler
 
6
 */
 
7
 
 
8
#include "depthImageCamera.h"
 
9
 
 
10
namespace srCore {
 
11
 
 
12
DepthImageCamera::DepthImageCamera(dtCore::RefPtr<BodyBase> attachedTo, osg::Vec3 pos, osg::Vec3 orient, float flareAngle, osg::Vec2 resolution, const std::string &name):
 
13
        CameraSensorBase(attachedTo, pos, orient, name, "DepthImageCamera", DEPTH_CAMERA, true)
 
14
{
 
15
 
 
16
        // set up camera properties
 
17
        this->minDistance = 0.3;
 
18
        this->maxDistance = 256;
 
19
        this->resolution = resolution;
 
20
        this->flareAngle = flareAngle;
 
21
        this->cameraType = DEPTH_CAMERA;
 
22
 
 
23
        if ((flareAngle>0) && (flareAngle != M_PI/4) ) {
 
24
 
 
25
                this->frustumDown = tan(flareAngle/2) * this->minDistance;
 
26
                this->frustumUp = tan(flareAngle/2) * this->minDistance;
 
27
                this->frustumRight = tan(flareAngle/2) * this->minDistance;
 
28
                this->frustumLeft = tan(flareAngle/2) * this->minDistance;
 
29
 
 
30
        }
 
31
 
 
32
        //this->init(attachedTo, pos, orient);
 
33
        this->setup();
 
34
        //this->type = "DepthImageCamera";
 
35
 
 
36
        this->sensorReturnValueType = typeid(osg::Image**).name();
 
37
 
 
38
}
 
39
 
 
40
 
 
41
void DepthImageCamera::evaluate(ParameterReturnValue srv)
 
42
{
 
43
 
 
44
        /*
 
45
        osg::Image* image = new osg::Image;
 
46
 
 
47
        int x = static_cast<int>(this->camera->GetOSGCamera()->getViewport()->x());
 
48
        int y = static_cast<int>(this->camera->GetOSGCamera()->getViewport()->y());
 
49
        unsigned int width = static_cast<unsigned int>(this->camera->GetOSGCamera()->getViewport()->width());
 
50
        unsigned int height = static_cast<unsigned int>(this->camera->GetOSGCamera()->getViewport()->height());
 
51
 
 
52
        printf("%s: Viewport x: %d Viewport y: %d Höhe: %d, Breite: %d \n", this->camera->GetName().c_str(), x, y, height, width);
 
53
 
 
54
        image->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE);
 
55
        image->readPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE);
 
56
        */
 
57
 
 
58
        //osg::ref_ptr<osg::Image> image = getRawData();
 
59
        //srv = MAKE_SENSOR_VALUE(&image);
 
60
 
 
61
        // sensor value type check
 
62
        if (srv.type!=typeid(osg::Image**).name()) printf("Parameter type needs to be osg::Image**. Casting could lead to errors.  \n "
 
63
                        "Parameter given: %s \n", srv.type.data());
 
64
 
 
65
        // cast void* to Image**
 
66
        osg::Image** data = reinterpret_cast<osg::Image**> (srv.pValue);
 
67
 
 
68
        // create image consisting of the raw data values
 
69
        value = new osg::Image(*getRawData());
 
70
 
 
71
        // put back these values to the sensor return value
 
72
        *data = value;
 
73
        srv.pValue = data;
 
74
 
 
75
        //value->unref();
 
76
}
 
77
 
 
78
}