[vtkusers] Plotting Multiple Spheres

Alex Southern mrapsouthern at gmail.com
Tue Aug 3 09:22:23 EDT 2010


Hi,

I was wondering what the best way is to add multiple spheres to the 
render window is. This is what I have currently but I expect that there 
must be a shorter way? or is the the most efficient approach?

I would typically have anywhere between 1 and 100 spheres usually.

         // numREC = number of spheres.....

         vtkSphereSource **rec_sph = new vtkSphereSource* [numREC];
         vtkPolyDataMapper **rec_mapper = new vtkPolyDataMapper* [numREC];
         vtkActor **sphere_actor = new vtkActor* [numREC];

         for(int x = 0; x<numREC;x++)
         {
             rec_sph[x] = vtkSphereSource::New();
             rec_mapper[x] = vtkPolyDataMapper::New();
             sphere_actor[x] = vtkActor::New();

             rec_mapper[x]->SetInputConnection(rec_sph[x]->GetOutputPort());
             sphere_actor[x]->SetMapper(rec_mapper[x]);

             rx = some x co-ordinate
             ry = some y co-ordinate

             rec_sph[x]->SetCenter(rx,ry,0);
             rec_sph[x]->SetRadius(0.025);
             sphere_actor[x]->GetProperty()->SetColor(0,255,0);

             ren->AddActor(sphere_actor[x]);
         }

Thanks
A.






More information about the vtkusers mailing list