VTK读取三维点云图并显示

用VTK读取三维点云图并显示的程序遇到问题,求帮助
该程序是读取txt里的三维点云数据然后显示出来
程序如下:

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPoints.h"
#include "vtkUnsignedCharArray.h"
#include "vtkCamera.h"
#include "vtkPolyVertex.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSetMapper.h"
#include "vtkCellLinks.h"
#include "vector"
#include "cstdlib"
#include "stdlib.h"
//#include "stdafx.h"
#include "string"   
#include "string.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "iostream"
#include "fstream"

using namespace std;

int main()
{
  vtkRenderer *ren = vtkRenderer::New();
    
  vtkPoints *points = vtkPoints::New();
    

  vtkUnsignedCharArray *Colors = vtkUnsignedCharArray :: New();
  unsigned char Color[] = { 0, 0, 0 };
    
  vector<unsigned char> *oColors = new vector<unsigned char>;
  string line;
  int iPts = 0;
  double x = 0, y = 0, z = 0;
  int iStart = 0, iEnd = 0;
    

  ifstream fin("D:\\VTKstudy\\vtkpoint1\\bin\\leaf2.txt");
  if(!fin){
  cout << "Unable to open myfile";
  exit(1); // terminate with error

}

  string str;
  while(getline(fin,str)){ //一行一行地读,直到失败为止
    
  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  x= atof(line.c_str());
  iStart = iEnd + 1;
  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  y= atof(line.c_str());//strncpy(char_num,str+2+k,3);
  iStart = iEnd + 1;

  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  z= atof(line.c_str());
  points->InsertNextPoint(x, y, z);

  iStart = iEnd + 1;
  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  Color[0]= reinterpret_cast<unsigned char>(line.c_str());
  oColors->push_back(Color[0]);

  iStart = iEnd + 1;
  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  Color[1]= reinterpret_cast<unsigned char>(line.c_str());
  oColors->push_back(Color[1]);
  iStart = iEnd + 1;
  iEnd = str.find_first_of(' ', iStart );
  line.assign(str,iStart, iEnd - iStart);
  Color[2]= reinterpret_cast<unsigned char>(line.c_str());
    
  oColors->push_back(Color[2]);
  iStart = 0;

  iPts++;   
  }
  return 0;



  vtkPolyVertex *polyvertex =vtkPolyVertex ::New();
  polyvertex->GetPointIds()->SetNumberOfIds(iPts);
    
    
  for(int i = 0; i < iPts; 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);

  map1->SetColorModeToDefault();
  map1->SetScalarModeToUsePointFieldData();
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值