zoukankan      html  css  js  c++  java
  • vtk点云数据的显示

     
    #include "vtkActor.h"
    #include "vtkRenderer.h"
    #include "vtkRenderWindow.h"
    #include "vtkRenderWindowInteractor.h"
    #include "vtkProperty.h"
    #include "vtkInteractorStyleTrackballCamera.h"
    #include "vtkPoints.h"
    #include "vtkPolyVertex.h"
    #include "vtkUnstructuredGrid.h"
    #include "vtkDataSetMapper.h"
    
    int main(int argc, char* argv[])
    {
        FILE *fp = NULL;
        if (argc==1)
        {
            if ((fp=fopen("venus.asc","r"))== NULL)
            {
                printf("Error in open file mbr.asc\n");
                return 1;
            }
        }
        else
        {
            if ((fp=fopen(argv[1],"r"))== NULL)
            {
                printf("Error in open file %s\n", argv[1]);
                return 1;
            }
        }
    
        vtkRenderer *ren=vtkRenderer::New();
        double arr[3];
    
        vtkPoints * points = vtkPoints::New();
        int n=0;
        while(!feof(fp))//首先读取点云数据到点表points同时指定点对应的id:
        {
            int ret=fscanf(fp,"%lf %lf %lf",&arr[0],&arr[1],&arr[2]);
            if(ret!=3)
                break;     
            points->InsertPoint(n,arr[0],arr[1],arr[2]);
            n++;
        }
        printf("%d\n", n);
        fclose(fp);
    
        vtkPolyVertex * polyvertex = vtkPolyVertex::New();
        polyvertex->GetPointIds()->SetNumberOfIds(n);
        int i=0;
        for(i=0;i<n;i++)//建立拓扑关系
        {
            polyvertex->GetPointIds()->SetId(i,i);
        }
    
        vtkUnstructuredGrid * grid=vtkUnstructuredGrid::New();
        grid->SetPoints(points);
        grid->InsertNextCell(polyvertex->GetCellType(),
                polyvertex->GetPointIds());
    
        vtkDataSetMapper *map1 = vtkDataSetMapper::New();
        map1->SetInput(grid);
    
        vtkActor *actor1 = vtkActor::New();
        actor1->SetMapper(map1);
        actor1->GetProperty()->SetColor(0.194,0.562, 0.75);
    
        ren->AddActor(actor1);
        ren->SetBackground(1, 1, 1);
    
        vtkRenderWindow* win=vtkRenderWindow::New();
        win->AddRenderer(ren);
        win->SetSize(400,400);
        win->BordersOn();
        //win->FullScreenOn();
        //win->HideCursor();
    
        vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    
        iren->SetRenderWindow(win);
        vtkInteractorStyleTrackballCamera *style =
            vtkInteractorStyleTrackballCamera::New();
        iren->SetInteractorStyle(style);   
    
        iren->Start();
        ren->Delete();
        win->Delete();
        iren->Delete();
    
        return 0;
    }
    编译命令为
    
            gcc -o 可执行文件名 源文件名 -I 头文件目录 需要的库文件 -Wno-dprecated:
    
                           
            gcc -o cloud cloud.cxx -I /usr/include/vtk-5.0 /usr/lib/libvtkRendering.so -Wno-deprecated
                           
                   
    
    运行:
    
            ./cloud venus.asc//数据文件
  • 相关阅读:
    Sql Server 查询一段日期内的全部礼拜天
    struts-config message-resources配置问题总结
    ImageTag小案例
    Struts1小案例问题教训总结(含中文乱码问题及解决)
    资源文件properties的存放路径
    BodyTagSupport小案例1
    客户端跳转与服务器跳转的区别
    href中使用相对路径访问上级目录的方法
    Tomcat下配置多个Project的虚拟主机
    win7 telnet命令无法开启的解决方案(不是内部命令或外部命令)
  • 原文地址:https://www.cnblogs.com/lilun/p/3131240.html
Copyright © 2011-2022 走看看