[vtkusers] Plotting Multiple Spheres
David Doria
daviddoria+vtk at gmail.com
Tue Aug 3 09:52:15 EDT 2010
On Tue, Aug 3, 2010 at 9:22 AM, Alex Southern <mrapsouthern at gmail.com> wrote:
> 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.
>
>
I would recommend using
vtkstd::vector<vtkSmartPointer<vtkActor> >
instead of doulbe pointers. Anytime I see ** I cringe...
Here is an example that is the same as you have done:
http://www.cmake.org/Wiki/VTK/Examples/Visualization/VectorOfActors
If anyone has a better way for Alex you could also update the example :)
Thanks,
David
More information about the vtkusers
mailing list