[vtkusers] Shading vertices
Jan Fransens
jan.fransens at luc.ac.be
Mon Mar 29 06:25:40 EST 2004
Hi all,
I am trying to render a cloud of vertices with shading. In the code I have
included below, I generate a pointset representing two orthogonal planes.
Since there only are two planes, I constructed a vtkCellArray with two
cells, each cell containing the vertices of one plane, and then set one
normal per cell (during the polydata construction). However, this generates
two flat colored planes, one having the red color I assigned to the actor
while the other one is rendered black (see screenshot). Does anyone have an
idea how to solve this?
Many thanks,
Jan.
My Code:
int npixels=100;
vtkPoints* points = vtkPoints::New();
points->Allocate(2*npixels*npixels);
vtkCellArray* verts = vtkCellArray::New();
vtkFloatArray* normals = vtkFloatArray::New();
normals->SetNumberOfComponents(3);
normals->SetNumberOfTuples(2);
normals->InsertNextTuple3(0,0,1);
normals->InsertNextTuple3(1,0,0);
float x,y,z;
z = 0.0;
verts->InsertNextCell(npixels*npixels);
for(int i=0; i<npixels;i++)
{
x = -1.0 + i*2.0/npixels;
for(int j=0; j<npixels; j++)
{
y = -1.0+j*2.0/npixels;
int id = points->InsertNextPoint(x,y,z);
verts->InsertCellPoint(id);
}
}
x = 0.0;
verts->InsertNextCell(npixels*npixels);
for(i=0; i<npixels;i++)
{
y = -1.0 + i*2.0/npixels;
for(int j=0; j<npixels; j++)
{
z = -1.0+j*2.0/npixels;
int id = points->InsertNextPoint(x,y,z);
verts->InsertCellPoint(id);
}
}
vtkPolyData* pd = vtkPolyData::New();
pd->SetPoints(points);
pd->SetVerts(verts);
pd->GetCellData()->SetNormals(normals);
vtkPolyDataMapper* pdm = vtkPolyDataMapper::New();
pdm->SetInput(pd);
vtkActor* a = vtkActor::New();
a->SetMapper(pdm);
a->GetProperty()->SetPointSize(4.0);
a->GetProperty()->SetColor(1.0,0.0,0.0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040329/da86062e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intersecting planes.jpg
Type: image/jpeg
Size: 6368 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040329/da86062e/attachment.jpg>
More information about the vtkusers
mailing list