vtk点云数据的显示

摘要:
Feof)//首先将点云数据读取到点表点,并指定点的对应id:{interrt=fscanf;if(ret!
 
#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//数据文件

免责声明:文章转载自《vtk点云数据的显示》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇springboot使用xml配置dubbo读取yml占位符webpack4.x的css单独打包、合并、自动添加前缀、压缩下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Datax3.0使用说明

任务是DataX作业的最小单位。每个任务负责一些数据的同步。DataX的调度决策思想是:-DataXJob根据数据库和表划分为100个任务。...

windows命令行下批量拷贝同一后缀的文件到另外一个目录

一个目录下有许多文件夹,您希望将每个文件夹下的wmv文件复制到另一个目录。如果用鼠标打开一个文件,复制一个,然后打开另一个,一个一个操作起来非常麻烦。一段时间后,可以实现xcopy命令:例如,复制中的所有文件。Cdisk x1目录下的wmv格式到Ddisk x2:xcopyc:x1目录。wmv/sd:x2命令将x1下的子目录复制到x2。如果只想复制文件,则不...

boost的下载和安装(windows版)

1 Introduction boost是一个准C++标准库,相当于STL的延续和扩展。它的设计理念类似于STL,它使用泛型来最大化重用。对于2boost的下载和安装,我们可以在官方boost网站上下载最新的boost版本。因为boost库可以像标准库一样在多个平台上运行,所以它只以源代码的形式正式提供。这是因为boost windows的安装版本不仅与处理...

华为交换机堆叠配置

请参考华为交换机的配置堆栈。[Leaf1-stack-port0/1]portinterfaceg0/0/12启用物理接口12加入堆栈组[Leaf1]stackslot0priority255修改优先级255,默认值为100警告:不要频繁修改优先级,因为它会使堆栈分裂。持续...

Spring Boot 核心配置文件 bootstrap &amp;amp; application

boostrap由父ApplicationContext加载,比applicaton优先加载boostrap里面的属性不能被覆盖3、bootstrap/application的应用场景application配置文件这个容易理解,主要用于SpringBoot项目的自动化配置。这个父级的SpringApplicationContext是先加载的,在加载appli...

IOS崩溃日志解析(crash log)

IOS的应用程序少不了crash,互联网统计分析工具友盟有一项目错误分析的功能,专门用于应用程序崩溃日志统计,最近研究友盟上统计到的崩溃日志,在此对崩溃日志做一个简单的总结。否则,应用将被iOS终止,并产生低内存崩溃报告。这样,我们去我们的dSYM文件看看我们的UUID是否和崩溃日志上的UUID一致,只有dSYM文件的UUID和崩溃日志上的UUID一致,我们...