[vtkusers] issue aobut point cloud data visulization!

njuzg guangz at u.washington.edu
Wed Jun 10 02:24:01 EDT 2009


I have wrote a little c++ scripts to visulize the point cloud data(x,y,z,i)
using vtk. The following is the code, but i cannot see the visulized point
cloud data, could someone help me figure out what's the problem with this
code?

ifstream file_to_read("E:/a.txt");
const int max_num_of_char_in_a_line=512,
          num_of_header_lines=0;
		  
for (int i=0; i<num_of_header_lines; ++i)
  file_to_read.ignore(max_num_of_char_in_a_line,'\n');

  
vector<float> xcoord_array, ycoord_array, 
            zcoord_array,intensity_array;

if(!file_to_read)
    cerr<<"File could not be opened!"<<endl;

float x,y,z,t;
	
while(!file_to_read.eof())
{
file_to_read>>x;
file_to_read.ignore(1);
file_to_read>>y;
file_to_read.ignore(1);
file_to_read>>z;
file_to_read.ignore(1);
file_to_read>>t;
file_to_read.ignore(1);

xcoord_array.push_back(x);
ycoord_array.push_back(y);
zcoord_array.push_back(z);
intensity_array.push_back(t);

vtkFloatArray *scalars =vtkFloatArray::New();
for(int i=0; i<intensity_array.size(); ++i)
   scalars->InsertTuple1(i,intensity_array[i]);
   
vtkPoints *points=vtkPoints::New();

for(int i=0; i<xcoord_array.size(); ++i)
points->InsertPoint(i,xcoord_array[i],ycoord_array[i],zcoord_array[i]);




 vtkCellArray* pts = vtkCellArray::New();
// pts->InsertNextCell(1);
  for(int i=0; i<xcoord_array.size();++i)
	  pts->InsertCellPoint(i);
 


vtkPolyData *polydata=vtkPolyData::New();
   polydata->SetPoints(points);
   polydata->SetPolys(pts);
   polydata->GetPointData()->SetScalars(scalars);

vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
  mapper->SetInput(polydata);
  mapper->SetScalarRange(0, 40);

 vtkActor* actor = vtkActor::New();
  actor->SetMapper(mapper);

 vtkRenderer* ren = vtkRenderer::New();
  ren->AddActor(actor);
  ren->SetBackground(1,1,1);

  vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren);
  renWin->SetSize(1024,768);
  

  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  iren->Initialize();
  iren->Start();

  points->Delete();
  scalars->Delete();
  polydata->Delete();
  mapper->Delete();
  actor->Delete();
  ren->Delete();
  renWin->Delete();
  iren->Delete();

-- 
View this message in context: http://www.nabble.com/issue-aobut-point-cloud-data-visulization%21-tp23956438p23956438.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list