Go to the documentation of this file.00001
00002
00003
00004 #include <GL/glut.h>
00005 #include <stdlib.h>
00006 #include <math.h>
00007 #include "tensor_field_nav_core/TfCore.h"
00008 #include <opencv2/core/core.hpp>
00009 #include <opencv2/highgui/highgui.hpp>
00010 #include <opencv2/imgproc/imgproc.hpp>
00011 #include <ros/ros.h>
00012 #include <image_transport/image_transport.h>
00013 #include <cv_bridge/cv_bridge.h>
00014 #include <sensor_msgs/image_encodings.h>
00015 #include <geometry_msgs/Pose.h>
00016 #include <tf/transform_listener.h>
00017 #include <X11/X.h>
00018 #include <X11/Xlib.h>
00019 #include <GL/gl.h>
00020 #include <GL/glx.h>
00021 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
00022 typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
00023 static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
00024 static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = 0;
00025 TfCore *tfCore;
00026
00027
00028 int main(int argc, char** argv)
00029 {
00030 static int visual_attribs[] = {
00031 None
00032 };
00033 int context_attribs[] = {
00034 GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
00035 GLX_CONTEXT_MINOR_VERSION_ARB, 0,
00036 None
00037 };
00038
00039 Display* dpy = XOpenDisplay(0);
00040 int fbcount = 0;
00041 GLXFBConfig* fbc = NULL;
00042 GLXContext ctx;
00043 GLXPbuffer pbuf;
00044
00045
00046 if ( ! (dpy = XOpenDisplay(0)) ){
00047 fprintf(stderr, "Failed to open display\n");
00048 exit(1);
00049 }
00050
00051
00052 if ( !(fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), visual_attribs, &fbcount) ) ){
00053 fprintf(stderr, "Failed to get FBConfig\n");
00054 exit(1);
00055 }
00056
00057
00058 glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB");
00059 glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc)glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent");
00060 if ( !(glXCreateContextAttribsARB && glXMakeContextCurrentARB) ){
00061 fprintf(stderr, "missing support for GLX_ARB_create_context\n");
00062 XFree(fbc);
00063 exit(1);
00064 }
00065
00066
00067 if ( !( ctx = glXCreateContextAttribsARB(dpy, fbc[0], 0, True, context_attribs)) ){
00068 fprintf(stderr, "Failed to create opengl context\n");
00069 XFree(fbc);
00070 exit(1);
00071 }
00072
00073
00074 int pbuffer_attribs[] = {
00075 GLX_PBUFFER_WIDTH, NPIX,
00076 GLX_PBUFFER_HEIGHT, NPIX,
00077 None
00078 };
00079 pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs);
00080
00081 XFree(fbc);
00082 XSync(dpy, False);
00083
00084
00085 if ( !glXMakeContextCurrent(dpy, pbuf, pbuf, ctx) ){
00086
00087
00088
00089 if ( !glXMakeContextCurrent(dpy, DefaultRootWindow(dpy), DefaultRootWindow(dpy), ctx) ){
00090 fprintf(stderr, "failed to make current\n");
00091 exit(1);
00092 }
00093 }
00094
00095 ros::init(argc, argv, "main");
00096 ros::NodeHandle nh;
00097 tfCore=new TfCore();
00098 tfCore->TfCoreInit();
00099 tfCore->makePatterns();
00100 tfCore->set_cur_as_keyframe(tfCore->curSliceID);
00101 tfCore->curSliceID++;
00102
00103 while(nh.ok()){
00104 ros::spinOnce();
00105 if(tfCore->isReceiveNewMap)
00106 tfCore->set_obstacles();
00107 tfCore->DrawGLScene(GL_RENDER);
00108 }
00109 return 0;
00110 }