[vtkusers] coloring a surface based on surface normals

Steffen Oeltze stoeltze at isg.cs.uni-magdeburg.de
Fri Feb 1 03:32:15 EST 2008


Dear VTK-users,

I would like to colorize a surface according to its surface (cell)
normals (which I compute using vtkPolyDataNormals) applying the
RGB-color channels: x->R, y->G, z->B. Below you find my source code
which unfortunately does not work properly. The image I receive shows
nasty stripes all over the surface as if there was something wrong with
the normal ordering or the ordering of its components. I applied the
example dataset "fran_cut.vtk".

Any help from you is deeply appreciated.

Steffen

-------------------------------------------------------------------------

vtkPolyDataReader *reader = vtkPolyDataReader::New();
    reader->SetFileName(".../fran_cut.vtk");
    reader->Update();

vtkPolyData *data = vtkPolyData::New();
    data = reader->GetOutput();

vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInput(data);
    normals->SetFeatureAngle(60.0);
    normals->ComputePointNormalsOff();
normals->ComputeCellNormalsOn();
    normals->AutoOrientNormalsOn();
    normals->SplittingOn();
    normals->Update();

vtkIdType numCells    = data->GetNumberOfCells();

vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
    colors->SetName("colors2");
    colors->SetNumberOfTuples(numCells);
    colors->SetNumberOfComponents(3);

double *tempTuple = NULL;

for (vtkIdType cellID=0; cellID<numCells; cellID++) {

tempTuple= 
normals->GetOutput()->GetCellData()->GetNormals()->GetTuple3(cellID);
// transform normal components from [-1,+1] to [0,255]
        colors->InsertTuple3(cellID,(tempTuple[0]+1.0)*0.5*255.0,
(tempTuple[1]+1.0)*0.5*255.0, (tempTuple[2]+1.0)*0.5*255.0);
}

(data->GetPointData())->AddArray(colors);

vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
    mapper->SetInput(data);
    mapper->SelectColorArray("colors2");
    mapper->SetScalarMode(3);
    mapper->SetScalarRange(mapper->GetInput()->GetScalarRange());

........








More information about the vtkusers mailing list