[vtkusers] display tens of thousands of cubes

David Doria daviddoria at gmail.com
Tue Feb 7 11:15:51 EST 2012


On Tue, Feb 7, 2012 at 11:12 AM, Alex Southern <mrapsouthern at gmail.com> wrote:
>
> Hi,
>
> I'm wondering what the best way to do this is?
>
> Currently the cubes are defined in a dynamic array of vtkCubeSources, see code below. This results in very slow interaction.
>
> Is there a more lightweight approach to this problem? There is a typical image below.
>
> // Create a cube array.
>     int numCubes = 44582; // in practice this value could be anything
>     vtkCubeSource **cubeSource = new vtkCubeSource* [numCubes];
>     vtkPolyDataMapper **mapper = new vtkPolyDataMapper* [numCubes];
>     vtkActor **actor = new vtkActor* [numCubes];
>
>     for (int i = 0; i < ca.numCubes; i++)
>     {
>         cubeSource[i] = vtkCubeSource::New();
>         mapper[i] = vtkPolyDataMapper::New();
>         actor[i] = vtkActor::New();
>
>         cubeSource[i]->SetCenter(ca.cubeCentre[i].x , ca.cubeCentre[i].y, ca.cubeCentre[i].z);
>         cubeSource[i]->SetXLength(ca.cubeLength[i] );
>         cubeSource[i]->SetYLength(ca.cubeLength[i] );
>         cubeSource[i]->SetZLength(ca.cubeLength[i] );
>
>         mapper[i]->SetInputConnection(cubeSource[i]->GetOutputPort());
>         actor[i]->SetMapper(mapper[i]);
>         actor[i]->GetProperty()->SetColor(255,0,0);
>         actor[i]->GetProperty()->SetRepresentationToWireframe();
>
>         renderer->AddActor(actor[i]);
>
>     }
>

Combine the data with vtkAppendPolyData(
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filters/CombinePolydata  )
then using a single mapper and a single actor.

David



More information about the vtkusers mailing list