[vtkusers] VTK Point Cloud
Luca Pallozzi Lavorante
lplavorante at gmail.com
Wed Jan 9 08:11:25 EST 2008
Valerie,
you have to create a vtkpolyData instance. I have a function that reads a
XYZ ASCII file (whose name you pass as argument) and creates the polydata
(actually, inside the polydata, instances od vtkPoints and vtkCellArray are
used). Once you have the polydata, you´ll proceed with visualization using
the vtkPolyData -> vtkPolyDataMapper -> vtkActor pipeline
Here is the function.
Luca
vtkPolyData *xyzreader (char *name) {
double x[3];
FILE *f;
char LINE[256];
if ( (f = fopen(name, "r")) == NULL ) {
fprintf (stderr, "Error while opening file %s!\n", name);
return NULL;
}
vtkPoints *points = vtkPoints::New();
vtkPolyData *poly = vtkPolyData::New();
vtkCellArray *conn = vtkCellArray::New();
// Create geometry of point cloud
while ( fgets(LINE, 256, f) != NULL ) {
if (sscanf(LINE, "%lf %lf %lf", &x[0], &x[1], &x[2]) != 3) {
fprintf (stderr, "I/O Error!\n");
fclose (f);
return NULL;
}
points->InsertNextPoint(x);
} // End of while loop
// Create topology of point cloud. This is necessary!
for (int i = 0; i < points->GetNumberOfPoints(); i++)
conn->InsertNextCell(1, &i);
poly->SetPoints(points);
poly->SetVerts(conn);
points->Delete();
conn->Delete();
fclose (f);
return poly;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080109/0be9e7e1/attachment.htm>
More information about the vtkusers
mailing list