[vtkusers] Using intensity data from structured light scanner to shade triangles?

Øystein Skotheim oystein+vtk at edge.no
Fri Aug 31 12:19:11 EDT 2007


Hello. I am trying to visualize data from a 3D scanner based on 
structured light that gives me a matrix of (x,y,z,I) values where I is a 
recorded gray scale intensity in each data point.

It looks quite cool when I just draw all the points with the given 
intensity values (I do this by assigning a scalar value to each cell, as 
shown in the code below).

I have also been experimenting with constructing triangulated data by 
using vtkDelaunay2D. However when I render the triangulated data (by 
using vtkPolyDataMapper), the scalar data seems to be ignored. (I have 
managed to calculate normal vectors and do Gouraud shading, but this is 
not what I want).

Is it possible to use the scalar data (intensity data) to colour/shade 
the triangles? Can anyone advice me regarding how this can be done?

Below is the code I use to visualize the points with grayvalue intensities:

--cut--

// Initialize vtk variables
vtkPolyData *cloud = vtkPolyData::New();
vtkPoints *verts = vtkPoints::New();
vtkCellArray *cells = vtkCellArray::New();
vtkDoubleArray *colArray = vtkDoubleArray::New();
vtkLookupTable *lut = vtkLookupTable::New();
int PointIds[1];

FILE *fp = fopen(filename, "r");

while (!feof(fp) &&  (fscanf(fp, "%f %f %f %f %f",
   &x, &y, &z, &c, &i)==5)) {
     PointIds[0] = verts->InsertNextPoint(x, y, z);
     cells->InsertNextCell(1, PointIds);
     colArray->InsertNextValue(i);
}

fclose(fp);

cloud->SetPoints(verts);
cloud->SetVerts(cells);

verts->Delete();
cells->Delete();

// Create a gray lookup table
lut->SetNumberOfColors(255);
lut->SetSaturationRange(0,0);
lut->SetHueRange(0,0);
lut->SetValueRange(0,1);
lut->Build();

colArray->SetLookupTable(lut);
cloud->GetCellData()->SetScalars(colArray);

// No need for LUT anymore
lut->Delete();

// Now render
vtkPolyDataMapper *cloudMapper = vtkPolyDataMapper::New();
vtkActor *cloudActor = vtkActor::New();
vtkRenderer *cloudRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

cloudMapper->SetInput(cloud);
cloudMapper->ScalarVisibilityOff();

cloudMapper->ScalarVisibilityOn();
cloudMapper->SetScalarRange(cmin,cmax);

cloudActor->SetMapper(cloudMapper);
cloudActor->GetProperty()->SetRepresentationToPoints();
cloudActor->GetProperty()->SetColor(0.0,1.0,0.0);

cloudRenderer->AddActor(cloudActor);
cloudRenderer->SetBackground( 0.1f, 0.2f, 0.4f );

iren->SetRenderWindow(renWin);

renWin->AddRenderer(cloudRenderer);
renWin->SetSize(500,500);
renWin->Render();

vtkInteractorStyleTrackballCamera *style =
   vtkInteractorStyleTrackballCamera::New();

iren->SetInteractorStyle(style);

// Start interactive rendering
iren->Start();

// clean up
cloudMapper->Delete();
cloudActor->Delete();
cloud->Delete();
cloudRenderer->Delete();
renWin->Delete();
iren->Delete();
style->Delete();

--cut--

Thank you very much.

Best regards,
-- 

Øystein Skotheim
Scientist, Optical Measurement Systems and Data Analysis
SINTEF ICT [http://www.sintef.com/omd]



More information about the vtkusers mailing list