[vtkusers] Coloring polydata with Scalars

sha1 at doc.ic.ac.uk sha1 at doc.ic.ac.uk
Thu Oct 20 17:51:50 EDT 2005


Hi,
  I am trying to color individual points of polydata surface. I tried following
code posted by bryan cole in vtk 4.4 on vs .net (win 2k and xp) , but it seems
to be doing nothing . Now , is there a problem with vtk 4.4 , because some
emails on archive suggest that this thing did work on vtk 3.2 , but does not
work on vtk 4x . Can any body suggest how to make this work.

Thanks in advance,

Hassan Amin
Code :-
  vtkSphereSource *cone = vtkSphereSource::New();
  cone->SetPhiResolution(20);
cone->SetThetaResolution(20);
  cone->Update();
  vtkFloatArray *fa=vtkFloatArray::New();
  fa->SetNumberOfValues(362);
for (int i=0;i<362;i++)
		{
			fa->SetValue(i,float(i));
		}
	cone->GetOutput()->GetPointData()->SetScalars(fa);
	cone->Modified();
	cone->Update();
	
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput( cone->GetOutput() );
  coneMapper->SetScalarRange(0,400);
  coneMapper->ScalarVisibilityOn();
  coneMapper->Modified();
  coneMapper->Update();
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );

  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );

  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );

  for (int i = 0; i < 360; ++i)
    {
    // render the image
    renWin->Render();
    // rotate the active camera by one degree
    ren1->GetActiveCamera()->Azimuth( 1 );
    }
  
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();





More information about the vtkusers mailing list