[vtkusers] display tens of thousands of cubes
Alex Southern
mrapsouthern at gmail.com
Tue Feb 7 12:01:00 EST 2012
I made the changes using the vtkAppendPolyData approach, see code below.
This did improve the interaction alot, but it was still a little
slugish. Is this because I implemented badly?
Thanks
Alex
// Create a cube.
vtkCubeSource **cubeSource = new vtkCubeSource* [ca.numCubes];
vtkSmartPointer<vtkAppendPolyData> appendFilter =
vtkSmartPointer<vtkAppendPolyData>::New();
for (int i = 0; i < ca.numCubes; i++)
{
cubeSource[i] = vtkCubeSource::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] );
appendFilter->AddInputConnection(cubeSource[i]->GetOutput()->GetProducerPort());
}
appendFilter->Update();
// Remove any duplicate points.
vtkSmartPointer<vtkCleanPolyData> cleanFilter =
vtkSmartPointer<vtkCleanPolyData>::New();
cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
cleanFilter->Update();
// create mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cleanFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(255,0,0);
actor->GetProperty()->SetRepresentationToWireframe();
renderer->AddActor(actor);
etc....
On 2/7/2012 6:39 PM, Bryn Lloyd wrote:
> Use the glyph mapper for even faster GPU rendering.
>
> http://www.vtk.org/doc/nightly/html/classvtkGlyph3DMapper.html
>
>
> On 2/7/2012 5:17 PM, David E DeMarle wrote:
>>
>> Use the glyph filter to make one actor with thousands of cubes.
>>
>> On Feb 7, 2012 11:12 AM, "Alex Southern" <mrapsouthern at gmail.com
>> <mailto: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]);
>>
>> }
>>
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com <http://www.kitware.com>
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>>
>> _______________________________________________
>> Powered bywww.kitware.com
>>
>> Visit other Kitware open-source projects athttp://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120207/9d96a030/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 148968 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120207/9d96a030/attachment.png>
More information about the vtkusers
mailing list