[vtkusers] issue aobut point cloud data visulization!

John Biddiscombe biddisco at cscs.ch
Wed Jun 10 03:08:56 EDT 2009


I suspect you're cell array is wrong. Here's an extract from one of mine 
which does work.

    vtkSmartPointer<vtkCellArray> vertices = 
vtkSmartPointer<vtkCellArray>::New();
    vtkIdType *cells = vertices->WritePointer(Nt, Nt*2);
    for (vtkIdType i=0; i<Nt; ++i) {
      cells[i*2]   = 1;
      cells[i*2+1] = i;
    }
    output->SetVerts(vertices);

The cell array would look like this...(one point per cell, and then the Id)
1,0, 1,1, 1,2, 1,3, 1,4, 1,5, 1,6, 1,7

and by using WritePointer(Nt, Nt*2) and accessing the array directly we 
do not lose on performance.

JB


> 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();
>
>   


-- 
John Biddiscombe,                            email:biddisco @ cscs.ch
http://www.cscs.ch/
CSCS, Swiss National Supercomputing Centre  | Tel:  +41 (91) 610.82.07
Via Cantonale, 6928 Manno, Switzerland      | Fax:  +41 (91) 610.82.82





More information about the vtkusers mailing list