如何使用openGL显示点云 [英] How to display a point cloud with openGL

查看:672
本文介绍了如何使用openGL显示点云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用 OpenGL 显示点云。

我已经遵循了一些教程管理显示一些几何图式,但是当我尝试显示从csv文件读取的点云,它不工作。
文件读取效果非常好。

I have followed some tutorials and I managed to display some geometric schema but when i try to display a point cloud read from a csv file, it does not work. The reading of file work very well.

包括

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <boost/tokenizer.hpp>
#include <sstream>
#include <vector>

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <algorithm>

#include "Point.cpp"
#include "drawing.cpp"

using namespace std;

声明

void draw(vector<Point> v);

int pointsNBR = 200;

char *theFileName;

主要方法

int main (int argc, char** argv) {

  if(argv[1]){
    theFileName = argv[1];
  }else{
    cout << "Please enter the file name !!\n";
    exit(0);
  }

  if(argv[2]){
    pointsNBR = atoi(argv[2]);
  }
  PCEngine(theFileName, pointsNBR);

    SDL_Init(SDL_INIT_VIDEO);
  atexit(SDL_Quit);
  SDL_WM_SetCaption("Point Cloud", NULL);
  SDL_SetVideoMode(720,640, 32, SDL_OPENGL);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70,(double)640/480,1,1000);

  bool continuer = true;
  SDL_Event event;

  vector<Point> v = getCloudPoint(theFileName);
    draw(v);

  for (;;)    {
    SDL_WaitEvent(&event);
    switch(event.type){
        case SDL_QUIT:
        exit(0);
        break;
    }
  }

}

draw method

draw method

void draw(vector<Point> v){

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushMatrix();

  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluLookAt(3,4,2,0,0,0,0,0,1);

  glPointSize(2.0);

  glBegin(GL_POINTS);
    for (size_t n = 0; n < v.size(); n++){
        glColor3ub(v[n].r, v[n].g, v[n].b);
        glVertex3d(v[n].x, v[n].y, v[n].z);
    }
  glEnd();

  glFlush();
  SDL_GL_SwapBuffers();

  glPopMatrix();
  glPopAttrib();
}

我的问题是我没有任何显示。

My problem is that I haven't any display.

有人可以帮我吗?

推荐答案

您应该使用

You should use the GL_MODELVIEW to position your cloud in the scene.

在绘制方法更改 glMatrixMode(GL_PROJECTION);

In the draw method change glMatrixMode(GL_PROJECTION); to glMatrixMode(GL_MODELVIEW);

这篇关于如何使用openGL显示点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆