Beispiel #1
0
// Render at (x,y) in window coordinates.
void GlText::DrawWindow(GLfloat x, GLfloat y, GLfloat z)
{
    // find object point (x,y,z)' in pixel coords
    GLdouble projection[16];
    GLdouble modelview[16];
    GLint    view[4];
    
    glGetDoublev(GL_PROJECTION_MATRIX, projection );
    glGetDoublev(GL_MODELVIEW_MATRIX, modelview );
    glGetIntegerv(GL_VIEWPORT, view );
        
    DisplayBase().Activate();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();    
    gluOrtho2D(0, DisplayBase().v.w, 0, DisplayBase().v.h);    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    
    glTranslatef((int)x,(int)y,z);
    Draw();

    // Restore viewport
    glViewport(view[0],view[1],view[2],view[3]);
    
    // Restore modelview / project matrices
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();    
}
Beispiel #2
0
OculusHud::OculusHud()
    : post_unwarp(true), handler(*this)
{
    InitialiseOculus();
    InitialiseFramebuffer();
    InitialiseShader();

    // Make this the default fullscreen view
    DisplayBase().AddDisplay(*this);
    SetBounds(Attach::Pix(0),Attach::Pix(HMD.VResolution),Attach::Pix(0),Attach::Pix(HMD.HResolution));
    handler.SetHandler(&pangolin::StaticHandler);
    View::SetHandler(&handler);

    // Initialise per-eye views / parameters
    for(int i=0; i<2; ++i) {
        int hw = HMD.HResolution/2;
        eyeview[i].SetBounds(Attach::Pix(0),Attach::Pix(HMD.VResolution),Attach::Pix(i*hw),Attach::Pix((1+i)*hw));
        this->AddDisplay(eyeview[i]);
    }

    // Setup default projection parameters
    const OVR::Util::Render::DistortionConfig& Distortion = stereo.GetDistortionConfig();
    const float ppos = HMD.HResolution * Distortion.XCenterOffset / 4.0f;
    SetParams(204.4, ppos, 0.177, -0.083);

    common.SetHandler(&pangolin::StaticHandler);
    this->AddDisplay(common);

    T_oc = IdentityMatrix();

    pangolin::SetFullscreen();
}
void CameraCalibration::InitPangolin(int PanelWidth)
{

	if(stereo_mode)
	{
		const int WindowWidth = (ImageSize.width)*2+PanelWidth-1;
		const int WindowHeight = ImageSize.height;

		// Create OpenGL window in single line thanks to GLUT
		CreateGlutWindowAndBind("Main", WindowWidth, WindowHeight, GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Issue specific OpenGl we might need
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		//GLenum err = glewInit();
		//if(GLEW_OK != err)
		//{
		//    cerr << "GLEW Error: " << glewGetErrorString(err) << endl;
		//    exit(0);
		//}

		panel = &CreatePanel("ui").SetBounds(1.0, 0.0, 0.0, (double)PanelWidth/DisplayBase().v.w);

		CamIntrins = new OpenGlMatrixSpec[2];

		CamIntrins[0] = ProjectionMatrixRDF_TopLeft(ImageSize.width,
													ImageSize.height,
													calib_params[0].CameraMatrix.at<double>(0, 0),
													calib_params[0].CameraMatrix.at<double>(1, 1),
													calib_params[0].CameraMatrix.at<double>(0, 2),
													calib_params[0].CameraMatrix.at<double>(1, 2),
													0.1,
													10000);

		CamIntrins[1] = ProjectionMatrixRDF_TopLeft(ImageSize.width,
													ImageSize.height,
													calib_params[1].CameraMatrix.at<double>(0, 0),
													calib_params[1].CameraMatrix.at<double>(1, 1),
													calib_params[1].CameraMatrix.at<double>(0, 2),
													calib_params[1].CameraMatrix.at<double>(1, 2),
													0.1,
													10000);

		const double panel = (double)(PanelWidth-1)/(double)(WindowWidth-1);
		const double middle_h = ((double)(WindowWidth-PanelWidth)/2.0)/(double)(WindowWidth) + (double)(PanelWidth)/(double)(WindowWidth);

		view[0] = &Display("ViewLeft").SetBounds(1.0, 0, panel, middle_h, -(double)ImageSize.width/(double)ImageSize.height);
		view[1] = &Display("ViewRight").SetBounds(1.0, 0, middle_h, 1.0, -(double)ImageSize.width/(double)ImageSize.height);
		
	}

	InitTexture();

	glutSpecialFunc(&SpecialKeyFunction);
}
Beispiel #4
0
PyObject * pangolin_record_window(PyObject* /*self*/, PyObject* args)
{
    Var<std::string> default_record_uri("pango.console.default_record_uri");
    const char *record_uri = default_record_uri.Get().c_str();

    if (!PyArg_ParseTuple(args, "|s", &record_uri)) {
        return NULL;
    }

    DisplayBase().RecordOnRender(record_uri);
    if(context->console_view) {
        context->console_view->ShowWithoutAnimation(false);
    }
    Py_RETURN_NONE;
}
Beispiel #5
0
void ToggleConsole()
{
#ifdef HAVE_PYTHON
    if( !context->console_view) {
        // Create console and let the pangolin context take ownership
        context->console_view = new ConsoleView(new PyInterpreter());
        context->named_managed_views["pangolin_console"] = context->console_view;
        context->console_view->SetFocus();
        context->console_view->zorder = std::numeric_limits<int>::max();
        DisplayBase().AddDisplay(*context->console_view);
    }else{
        context->console_view->ToggleShow();
        if(context->console_view->IsShown()) {
            context->console_view->SetFocus();
        }
    }
#endif
}
int main( int argc, char* argv[])
{

    if(argc < 3)
    {
		cerr << "Usage: [-mono, -stereo] [config.xml]" << endl;
        cerr << "A xml file containing iamge list is required." << endl;
        exit(EXIT_FAILURE);
    }

	string mode(argv[1]);
	CameraCalibration camera_calib;
	if(mode == "-stereo")
	{
		// Stereo camera calibration
		camera_calib.setStereoMode(true);

		string xml_input(argv[2]);
		camera_calib.ReadStereoCalibParams(xml_input);	

		num_frames = camera_calib.getNumFrames();

		camera_calib.StereoCalibration();
        camera_calib.InitPangolin(150);
    
		static Var<int> img_idx("ui.Image: ", 0, 0, camera_calib.getNumFrames()-1);
		static Var<bool> is_stereobind("ui.Stereo Bind", false, true);
		static Var<bool> is_undistorted("ui.Undistorted images", false, true);
		static Var<bool> is_rectified("ui.Rectified images", false, true);
		//static Var<bool> disp_button("ui.Show OpenCV SBM", false, false);
		static Var<bool> export_button("ui.Export Results", false, false);

        while( !Pangolin::ShouldQuit() )
		{
            if(Pangolin::HasResized())
				DisplayBase().ActivateScissorAndClear();

			show_idx = (int*)img_idx.var->val;
			if(is_rectified)
			{
				for(int c_idx=0; c_idx<2; c_idx++)					
					camera_calib.DrawRectifiedImage(c_idx, img_idx);	

			}
			else
			{
				for(int c_idx=0; c_idx<2; c_idx++)
					camera_calib.DrawChessboardAndImage(c_idx, img_idx, is_undistorted, is_stereobind);
			}

			camera_calib.panel->Render();

			if(Pushed(export_button))
				camera_calib.WriteCalibParams();

			//if(Pushed(disp_button))
			//	camera_calib.OpenCVSBM(camera_calib.calib_params[0].ImageList.at(img_idx), 
			//						   camera_calib.calib_params[1].ImageList.at(img_idx));

			camera_calib.panel->Render();			

			// Swap frames and Process Events
			glutSwapBuffers();
			glutMainLoopEvent();
		}
	}	
	else
	{	

		// Monocular camera calibration
		camera_calib.setStereoMode(false);

		string xml_input(argv[1]);
		camera_calib.ReadStereoCalibParams(xml_input);	

	}            	

    return 0;

}
Beispiel #7
0
void RenderViews()
{
    Viewport::DisableScissor();
    DisplayBase().Render();
}