[vtkusers] Question regarding sphere example

Christian Zemlin zemlinc at upstate.edu
Mon Jun 4 12:22:29 EDT 2007


Dear vtk gurus,

One of the standard vtk examples renders a blue sphere (I attached the code at the end of this mail for reference).  The color of the sphere is set by the command:

 aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue ,

where aSphere is a vtkActor.

My question is:  How can I color the vertices of the sphere individually?  For example, if I want all triangles containing the north pole red and the rest blue, how do I do it?

-- Christian


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



Blue sphere example
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"

void main ()
{

  // create sphere geometry
  vtkSphereSource *sphere = vtkSphereSource::New();
  sphere->SetRadius(1.0);
  sphere->SetThetaResolution(18);
  sphere->SetPhiResolution(18);

  // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
  map->SetInput(sphere->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
  aSphere->SetMapper(map);
  aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue

  // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  // an interactor
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  // add the actor to the scene
  ren1->AddActor(aSphere);
  ren1->SetBackground(1,1,1); // Background color white

  // render an image (lights and cameras are created automatically)
  renWin->Render();

  // begin mouse interaction
  iren->Start();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070604/468bcf7c/attachment.htm>


More information about the vtkusers mailing list