6 #include <OpenGL/glu.h> 11 #include <hrpModel/Sensor.h> 22 double i_near,
double i_far,
double i_fovy,
23 GLlink *i_link,
int i_id) :
25 m_near(i_near), m_far(i_far),
26 m_fovy(i_fovy), m_width(i_width), m_height(i_height),
27 m_frameBuffer(0), m_renderBuffer(0), m_texture(0),
28 m_sensor(NULL), m_colorBuffer(NULL)
69 memcpy(o_trans,
m_trans,
sizeof(
double)*16);
79 glMatrixMode(GL_PROJECTION);
82 (
double)w / (
double)h,
138 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
139 glMatrixMode(GL_MODELVIEW);
148 glBindTexture( GL_TEXTURE_2D,
m_texture );
159 std::cerr <<
"invalid image length" << std::endl;
173 std::cerr <<
"invalid image length" << std::endl;
178 for (
unsigned int j=0; j<
m_width; j++){
179 *dst = 0.299*src[0] + 0.587*src[1] + 0.114*src[2];
202 double zs = w/(2*tan(fovx/2));
203 unsigned int npoints=0;
209 for (
int j=0; j<w; j+=step){
210 float d = depth[
i*w+j];
214 ptr[2] = far*near/(d*(far-
near)-far);
215 ptr[0] = -(j-w/2)*ptr[2]/zs;
216 ptr[1] = -(
i-h/2)*ptr[2]/zs;
218 unsigned char *
c = (
unsigned char *)(ptr + 3);
219 int offset = ((h-1-
i)*w+j)*3;
221 c[1] = rgb[offset+1];
222 c[2] = rgb[offset+2];
233 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
238 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
240 glBindTexture( GL_TEXTURE_2D,
m_texture );
241 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
242 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
243 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
244 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
245 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
247 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
255 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
257 glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
260 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
267 glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
hrp::VisionSensor * sensor()
double * getAbsTransform()
std::vector< unsigned char > image
void addShape(GLshape *i_shape)
std::vector< GLshape * > m_shapes
const std::string & name() const
void setViewTarget(double x, double y, double z)
png_infop png_bytep * trans
size_t drawObjects(bool showSensors=true)
void setViewPoint(double x, double y, double z)
void render(GLsceneBase *i_scene)
Sensor * sensor(int sensorType, int sensorId) const
void initRenderbuffer(void)
void initFramebuffer(void)
GLcamera(int i_width, int i_height, double i_near, double i_far, double i_fovy, GLlink *i_link=NULL, int i_id=-1)
void mulTrans(const double i_m1[16], const double i_m2[16], double o_m[16])
std::vector< unsigned char > depth
hrp::VisionSensor * m_sensor
void computeAbsTransform()
void computeAbsTransform(double o_trans[16])
void highlight(bool flag)
unsigned char * m_colorBuffer