How to display a point cloud with openGL

…衆ロ難τιáo~ 提交于 2019-12-20 14:08:44

问题


I'm trying to display a point cloud with OpenGL.

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.

the includes

#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;

declarations

void draw(vector<Point> v);

int pointsNBR = 200;

char *theFileName;

main method

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

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.

Can someone help me please?


回答1:


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

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



来源:https://stackoverflow.com/questions/22264400/how-to-display-a-point-cloud-with-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!