VTK读取三维点云图并显示
2013-12-31 10:30
330 查看
用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();
该程序是读取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();
相关文章推荐
- VTK读取一个TXT文档中的三维点坐标显示三维点云
- VTK读取一个TXT文档中的三维点坐标显示三维点云
- ITK读取图片, 并重新写入图片文件, VTK显示
- 利用VTK显示文件读取进度模态对话框
- VTK图像读取与显示实例
- VTK中各种图像格式的读取与显示
- Vtk读取并显示保存图像
- ITK、VTK、Qt读取与显示DICOM文件------代码部分
- 利用VTK显示文件读取进度模态对话框
- VTK读取TIFF格式图片,获取像素值,显示图片
- {学海无涯}【基于VTK的三维建模】——1.Dicom文件的读取与显示
- 3 vtk读取并显示dicom文件
- ITK读取,转VTK,QT显示
- VTK 读取STL文件并且显示
- VTK 点云重建和读取.txt文档显示三维点云
- OpenGL将二维图形显示为三维点云图
- vtk实战(七)—读取三维点坐标
- VTK实现Dicom文件的读取及显示
- vtk读取文件并显示的几种方法
- vtk实战(九)—读取三维点坐标2