4
* Created on: Dec 29, 2008
8
#include "depthImageCamera.h"
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)
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;
23
if ((flareAngle>0) && (flareAngle != M_PI/4) ) {
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;
32
//this->init(attachedTo, pos, orient);
34
//this->type = "DepthImageCamera";
36
this->sensorReturnValueType = typeid(osg::Image**).name();
41
void DepthImageCamera::evaluate(ParameterReturnValue srv)
45
osg::Image* image = new osg::Image;
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());
52
printf("%s: Viewport x: %d Viewport y: %d Höhe: %d, Breite: %d \n", this->camera->GetName().c_str(), x, y, height, width);
54
image->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE);
55
image->readPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE);
58
//osg::ref_ptr<osg::Image> image = getRawData();
59
//srv = MAKE_SENSOR_VALUE(&image);
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());
65
// cast void* to Image**
66
osg::Image** data = reinterpret_cast<osg::Image**> (srv.pValue);
68
// create image consisting of the raw data values
69
value = new osg::Image(*getRawData());
71
// put back these values to the sensor return value