VS2005+VTK读入点云文件

使用VTK读入点云文件的基础代码:


头文件:

也许不是全部都用到,为了接下来得工程还是全部都包含进去了

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkShrinkFilter.h"
#include "vtkElevationFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"
#include "vtkCullerCollection.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkPolyVertex.h"
#include "vtkUnstructuredGrid.h"
#include <iostream>
#include "vtkPolyDataMapper.h"
#include "vtkScanPointReader.h"
#include "vtkProperty.h"



main部分:

//读取点云数据
void main()
{
	FILE *fp = NULL;
	fp = fopen( "C:\\test.sp", "r");
	if ( fp == NULL)
	{
		printf("Error in open file test.sp\n");
		getchar();
		exit(-1);
	}else
		printf("open scan point success\n");


	vtkRenderer *ren = vtkRenderer::New();
	double arr[3] = {0};

	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(1,0, 0);

    ren->AddActor(actor1);
    ren->SetBackground(1, 1, 1);

    vtkRenderWindow* win=vtkRenderWindow::New();
    win->AddRenderer(ren);
    win->SetSize(400,400);
    win->BordersOn();
	//On则运行起来将会是全屏显示
    //win->FullScreenOn();
    //win->HideCursor();

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

    iren->SetRenderWindow(win);
    vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
    iren->SetInteractorStyle(style);   

	iren->Initialize();
    iren->Start();
    ren->Delete();
    win->Delete();
    iren->Delete();

	
}

运行结果:



本文使用的是 vs2005+vtk5.10.1

使用的是vs里面的控制台程序编写。

这样读入点云的方式是最原始的方式。






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VS2017 中使用 VTK8.0.0 时遇到未加载符号文件的问题,主要是由于开发环境配置不正确或者版本不匹配所导致的。 首先,确保已经正确安装了VS2017和VTK8.0.0,并且版本是兼容的,可以在VTK官方网站上下载最新版本。 其次,检查项目的属性设置,确保已经正确添加了VTK的头文件路径和库文件路径。在项目的属性页中,找到“配置属性” -> “VC++目录” -> “包含目录”和“库目录”,添加正确的路径。 然后,还要确保已经正确配置了项目的链接器设置。在项目的属性页中,找到“配置属性” -> “链接器” -> “输入”,添加vtk的库文件名(如vtkCommonCore-8.0.lib)。 最后,重新编译项目,如果仍然出现未加载符号文件的问题,可以尝试以下几个解决方法: 1. 清理和重建项目:在VS的“生成”菜单中选择“清理解决方案”,然后选择“重建解决方案”。 2. 检查平台和配置设置:确保项目的平台和配置设置与安装的VTK版本相匹配。 3. 检查运行时库设置:在项目属性页的“C/C++” -> “代码生成”中,将“运行时库”设置为与VTK使用的运行时库相匹配的选项。 4. 检查依赖项:确保项目的所有依赖项(包括VTK的依赖项)已正确安装和配置。 如果以上方法仍然无法解决问题,可以尝试在VTK的官方论坛或者社区寻求帮助,或者查阅VTK的文档和资料寻找解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值