⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lasview.cpp

📁 Lidar数据处理时
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }
    else
    {
      fprintf(stderr,"WARNING: out-of-core rendering from file not possible in pipe mode.\n");
    }
    break;
  case 'C':
  case 'c':
    STREAM_COLORING += 1;
    if (STREAM_COLORING > 4) STREAM_COLORING = 0;
    fprintf(stderr,"STREAM_COLORING %d\n",STREAM_COLORING);
    glutPostRedisplay();
    break;
  case 'T':
    if (DIRTY_POINTS)
    {
      // works only in replay mode
      fprintf(stderr,"tiny steps only work during second play (replay)\n");
    }
    else
    {
      REPLAY_COUNT -= 1;
      if (REPLAY_COUNT < 0)
      {
        REPLAY_COUNT = 0;
      }
    }
    glutPostRedisplay();
    break;
  case 't':
    if (DIRTY_POINTS)
    {
      NEXT_STEP = lasreader->p_count;
      WorkingOn = vizContinue();
    }
    else
    {
      if (REPLAY_COUNT >= p_count)
      {
        REPLAY_COUNT = 0;
      }
      REPLAY_COUNT += 1;
    }
    glutPostRedisplay();
    break;
  case 'S':
    if (DIRTY_POINTS)
    {
      // works only in replay mode
      fprintf(stderr,"back stepping only work during second play (replay)\n");
    }
    else
    {
      NEXT_STEP = p_count / EXACTLY_N_STEPS;
      if (NEXT_STEP == 0) NEXT_STEP = 1;
      REPLAY_COUNT -= NEXT_STEP;
      if (REPLAY_COUNT < 0)
      {
        REPLAY_COUNT = 0;
      }
    }
    glutPostRedisplay();
    break;
  case 'P':
    if (file_name)
    {
      DIRTY_POINTS = 1;
    }
    else
    {
      fprintf(stderr,"WARNING: cannot replay from file when operating in pipe mode.\n");
    }
  case 'p':
    if (DIRTY_POINTS)
    {
      AnimationOn = !AnimationOn;
    }
    else
    {
      if (REPLAY_IT == 0)
      {
        if (REPLAY_COUNT >= p_count)
        {
          REPLAY_COUNT = 0;
        }
        NEXT_STEP = p_count / EXACTLY_N_STEPS;
        if (NEXT_STEP == 0) NEXT_STEP = 1;
        REPLAY_IT = 1;
      }
      else
      {
        REPLAY_IT = 0;
      }
    }
  case 's':
    if (DIRTY_POINTS)
    {
      if (WorkingOn == 0)
      {
        vizBegin();
        WorkingOn = vizContinue();
      }
      else
      {
        WorkingOn = vizContinue();
      }
      if (WorkingOn == 0)
      {
        vizEnd();
        AnimationOn = 0;
      }
    }
    else
    {
      if (REPLAY_COUNT >= p_count)
      {
        REPLAY_COUNT = 0;
      }
      NEXT_STEP = p_count / EXACTLY_N_STEPS;
      if (NEXT_STEP == 0) NEXT_STEP = 1;
      REPLAY_COUNT += NEXT_STEP;
    }
    glutPostRedisplay();
    break;
  case 'K':
  case 'k':
    printf("-kamera %g %g %g %g %g\n", Azimuth, Elevation, DistX,DistY,DistZ);
    break;
  };
}

static void MyMenuFunc(int value)
{
  if (value >= 100)
  {
    if (value <= 102)
    {
      InteractionMode = value - 100;
      glutPostRedisplay();
    }
    else if (value == 103)
    {
      myKeyboard('s',0,0);
    }
    else if (value == 104)
    {
      myKeyboard('p',0,0);
    }
    else if (value == 105)
    {
      myKeyboard('o',0,0);
    }
    else if (value == 109)
    {
      myKeyboard('q',0,0);
    }
    else if (value == 150)
    {
      myKeyboard('c',0,0);
    }
    else if (value == 151)
    {
      myKeyboard('=',0,0);
    }
    else if (value == 152)
    {
      myKeyboard('-',0,0);
    }
    else if (value == 153)
    {
      myKeyboard(']',0,0);
    }
    else if (value == 154)
    {
      myKeyboard('[',0,0);
    }
  }
  else if (value == 40)
  {
    EXACTLY_N_STEPS = 5;
  }
  else if (value == 41)
  {
    EXACTLY_N_STEPS = 10;
  }
  else if (value == 42)
  {
    EXACTLY_N_STEPS = 25;
  }
  else if (value == 43)
  {
    EXACTLY_N_STEPS = 50;
  }
  else if (value == 44)
  {
    EXACTLY_N_STEPS = 100;
  }
  else if (value == 45)
  {
    EXACTLY_N_STEPS = 250;
  }
  else if (value == 46)
  {
    EXACTLY_N_STEPS = 500;
  }
  else if (value == 47)
  {
    EXACTLY_N_STEPS = 1000;
  }
  else if (value == 48)
  {
    EXACTLY_N_STEPS = 10000;
  }
}

static void displayMessage()
{
  glColor3f( 0.7f, 0.7f, 0.7f );  // Set colour to grey
  glMatrixMode( GL_PROJECTION );
  glPushMatrix();
  glLoadIdentity();
  gluOrtho2D( 0.0f, 1.0f, 0.0f, 1.0f );
  glMatrixMode( GL_MODELVIEW );
  glPushMatrix();
  glLoadIdentity();
  glRasterPos2f( 0.03f, 0.95f );
  
  if( InteractionMode == 0 )
  {
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'r');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'o');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 't');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'a');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 't');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'e');
  }
  else if( InteractionMode == 1 )
  {    
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 't');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'r');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'a');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'n');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 's');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'l');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'a');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 't');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'e');
  }
  else
  {
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'z');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'o');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'o');
    glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'm');
  }

  glPopMatrix();
  glMatrixMode( GL_PROJECTION );
  glPopMatrix();
}

static void myDisplay()
{
  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  glViewport(0,0,WindowW,WindowH);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(30.0f,(float)WindowW/WindowH,0.0625f,5.0f);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(DistX,DistY,DistZ, DistX,DistY,0, 0,1,0);

  glRotatef(Elevation,1,0,0);
  glRotatef(Azimuth,0,1,0);

  glTranslatef(boundingBoxTranslateX,boundingBoxTranslateY,boundingBoxTranslateZ*EXTRA_Z_SCALE);
  glScalef(boundingBoxScale,boundingBoxScale,boundingBoxScale*EXTRA_Z_SCALE);

  int rendered_points;

  if (DIRTY_POINTS)
  {
    rendered_points = p_count;
  }
  else
  {
    if (REPLAY_COUNT > p_count)
    {
      rendered_points = p_count;
      REPLAY_IT = 0;
    }
    else
    {
      rendered_points = REPLAY_COUNT;
    }
  }

  // draw points

  glEnable(GL_DEPTH_TEST);

  if (p_count && POINT_SIZE)
  {
    glPointSize(POINT_SIZE);
    glBegin(GL_POINTS);
    if (STREAM_COLORING == 0)
    {
      glColor3f(0,0,0);
      for (int i = 0; i < rendered_points; i++)
      {
        glVertex3fv(&(point_buffer[i*3]));
      }
    }
    else if (STREAM_COLORING == 1)
    {
      float color;
      for (int i = 0; i < rendered_points; i++)
      {
        color = 0.1f+0.7f*i/p_count;
        glColor3f(color,color,color);
        glVertex3fv(&(point_buffer[i*3]));
      }
    }
    else if (STREAM_COLORING == 2)
    {
      for (int i = 0; i < rendered_points; i++)
      {
        if (i < p_count/3)
        {
          glColor3f(0.1f+0.7f*i/(p_count/3),0.1f,0.1f);
        }
        else if (i < 2*(p_count/3))
        {
          glColor3f(0.8f,0.1f+0.7f*(i-(p_count/3))/(p_count/3),0.1f);
        }
        else
        {
          glColor3f(0.8f, 0.8f, 0.1f+0.7f*(i-2*(p_count/3))/(p_count/3));
        }
        glVertex3fv(&(point_buffer[i*3]));
      }
    }
    else if (STREAM_COLORING == 3)
    {
      for (int i = 0; i < rendered_points; i++)
      {
        float height = point_buffer[i*3+2] - boundingBoxMin[2];
        if (height < (boundingBoxHeight/3))
        {
          glColor3f(0.1f+0.7f*height/(boundingBoxHeight/3),0.1f,0.1f);
        }
        else if (height < 2*(boundingBoxHeight/3))
        {
          glColor3f(0.8f,0.1f+0.7f*(height-(boundingBoxHeight/3))/(boundingBoxHeight/3),0.1f);
        }
        else
        {
          glColor3f(0.8f, 0.8f, 0.1f+0.7f*(height-2*(boundingBoxHeight/3))/(boundingBoxHeight/3));
        }
        glVertex3fv(&(point_buffer[i*3]));
      }
    }
    else
    {
      for (int i = 0; i < rendered_points; i++)
      {
        float height = point_buffer[i*3+2] - boundingBoxMin[2];
        if (height < (boundingBoxHeight/2))
        {
          glColor3f(0.1f+0.7f*height/(boundingBoxHeight/2),0.1f,0.1f+0.8f-0.7f*height/(boundingBoxHeight/2));
        }
        else if (height < 2*(boundingBoxHeight/2))
        {
          glColor3f(0.8f, 0.1f + 0.7f*(height-(boundingBoxHeight/2))/(boundingBoxHeight/2), 0.1f + 0.7f*(height-(boundingBoxHeight/2))/(boundingBoxHeight/2));
        }
        glVertex3fv(&(point_buffer[i*3]));
      }
    }
    glEnd();
  }

  if (RENDER_BOUNDINGBOX)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glColor3f(0,1,0);
    glLineWidth(1.0f);
    glBegin(GL_QUADS);
    if (RENDER_BOUNDINGBOX == 1)
    {
      glVertex3f(boundingBoxMin[0], boundingBoxMin[1], boundingBoxMin[2]);
      glVertex3f(boundingBoxMin[0], boundingBoxMax[1], boundingBoxMin[2]);
      glVertex3f(boundingBoxMax[0], boundingBoxMax[1], boundingBoxMin[2]);
      glVertex3f(boundingBoxMax[0], boundingBoxMin[1], boundingBoxMin[2]);
      glVertex3f(boundingBoxMin[0], boundingBoxMin[1], boundingBoxMax[2]);
      glVertex3f(boundingBoxMin[0], boundingBoxMax[1], boundingBoxMax[2]);
      glVertex3f(boundingBoxMax[0], boundingBoxMax[1], boundingBoxMax[2]);
      glVertex3f(boundingBoxMax[0], boundingBoxMin[1], boundingBoxMax[2]);
    }
    glEnd();
    glLineWidth(1.0f);
  }

  glDisable(GL_DEPTH_TEST);

  displayMessage();
  glutSwapBuffers();
}

int main(int argc, char *argv[])
{
  if (argc == 1 || strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"-help") == 0) 
  {
    usage();
    exit(0);
  }
  else
  {
    glutInit(&argc, argv);

    for (int i = 1; i < argc; i++)
    {
      if (strcmp(argv[i],"-win") == 0)
      {
        i++;
        WindowW = atoi(argv[i]);
        i++;
        WindowH = atoi(argv[i]);
      }
      else if (strcmp(argv[i],"-steps") == 0)
      {
        i++;
        EXACTLY_N_STEPS = atoi(argv[i]);
      }
      else if (strcmp(argv[i],"-every") == 0)
      {
        i++;
        EVERY_NTH_STEP = atoi(argv[i]);
      }
      else if (strcmp(argv[i],"-points") == 0)
      {
        i++;
        EXACTLY_N_POINTS = atoi(argv[i]);
      }
      else if (strcmp(argv[i],"-kamera") == 0)
      {
        i++;
        sscanf(argv[i], "%f", &Azimuth);
        i++;
        sscanf(argv[i], "%f", &Elevation);
        i++;
        sscanf(argv[i], "%f", &DistX);
        i++;
        sscanf(argv[i], "%f", &DistY);
        i++;
        sscanf(argv[i], "%f", &DistZ);
      }
      else if (strcmp(argv[i],"-only_first") == 0)
      {
        only_first = true;
      }
      else if (strcmp(argv[i],"-only_last") == 0)
      {
        only_last = true;
      }
      else if (strcmp(argv[i],"-i") == 0)
      {
        i++;
        file_name = argv[i];
      }
      else if (i == argc-1)
      {
        file_name = argv[argc-1];
      }
      else
      {
        usage();
      }
    }
  }

  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(WindowW,WindowH);
  glutInitWindowPosition(180,100);
  glutCreateWindow("just a little LAS viewer");
  
  glShadeModel(GL_FLAT);
  
  InitColors();
  InitLight();
  
  glutDisplayFunc(myDisplay);
  glutReshapeFunc(myReshape);
  glutIdleFunc(myIdle);
  
  glutMouseFunc(myMouseFunc);
  glutMotionFunc(myMotionFunc);
  glutKeyboardFunc(myKeyboard);

  // steps sub menu
  int menuSteps = glutCreateMenu(MyMenuFunc);
  glutAddMenuEntry("in 5 steps", 40);
  glutAddMenuEntry("in 10 steps", 41);
  glutAddMenuEntry("in 25 steps", 42);
  glutAddMenuEntry("in 50 steps", 43);
  glutAddMenuEntry("in 100 steps", 44);
  glutAddMenuEntry("in 250 steps", 45);
  glutAddMenuEntry("in 500 steps", 46);
  glutAddMenuEntry("in 1000 steps", 47);
  glutAddMenuEntry("in 10000 steps", 48);

  // main menu
  glutCreateMenu(MyMenuFunc);
  glutAddSubMenu("steps ...", menuSteps);
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("rotate <SPACE>", 100);
  glutAddMenuEntry("translate <SPACE>", 101);
  glutAddMenuEntry("zoom <SPACE>", 102);
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("<s>tep", 103);
  glutAddMenuEntry("<p>lay", 104);
  glutAddMenuEntry("st<o>p", 105);
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("<c>oloring mode", 150);
  glutAddMenuEntry("points large <=>", 151);
  glutAddMenuEntry("points small <->", 152);
  glutAddMenuEntry("height more <]>", 153);
  glutAddMenuEntry("height less <[>", 154);
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("<Q>UIT", 109);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  myKeyboard('p',0,0);

  glutMainLoop();

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -