[vtkusers] Remove polygonal props, leave volume intact

Dženan Zukić dzenanz at gmail.com
Thu Mar 17 04:48:39 EDT 2011


I just checked, calling IsA() also crashes the program.

At first I could not understand what SafeDownCast is supposed to do from the
docs (
http://www.vtk.org/doc/release/5.6/html/a02127.html#5790c5359ba54a168bd2824ab46286b4),
but then I got it to work:

void MainWindow::on_actionClear_polygonal_data_activated()
{
    vtkPropCollection
*props=vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetViewProps();
    for (int i=props->GetNumberOfItems()-1; i>=0; i--)
        if (!vtkVolume::SafeDownCast(props->GetItemAsObject(i)))
            props->RemoveItem(i);
    vis->GetRenderWindow()->Render();
}

However before that I found a simpler way:

void MainWindow::on_actionClear_polygonal_data_activated()
{
    vtkProp
*volume=vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetVolumes()->GetLastProp();

 vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetViewProps()->RemoveAllItems();
//this also removes the volume

 vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddVolume(volume);
    vis->GetRenderWindow()->Render();
}

Thanks for help,
Dženan

2011/3/16 Dženan Zukić <dzenanz at gmail.com>

> 2011/3/16 David Doria <daviddoria at gmail.com>
>
>> 2011/3/16 Dženan Zukić <dzenanz at gmail.com>
>>
>>> Hi all,
>>>
>>> I want to remove (and delete to free the memory) all polygonal actors,
>>> but leaving the volume in the scene. This is my attempt:
>>>
>>> void MainWindow::on_actionClear_polygonal_data_activated()
>>> {
>>>     vtkPropCollection
>>> *props=vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetViewProps();
>>>     for (int i=props->GetNumberOfItems()-1; i>=0; i--)
>>>         if (!props[i].IsTypeOf("vtkVolume")) //vtkObjectBase both volume
>>> and polyogonal
>>>             props->RemoveItem(i);
>>>     vis->GetRenderWindow()->Render();
>>> }
>>>
>>> However this also removes the volume. I have a feeling the problem is in
>>> some small detail. Do you have any suggestions?
>>>
>>> Regards,
>>> Dženan
>>>
>>>
>> Did you try outputting GetClassName() for the props that are deleted?
>>
>> You could also try the IsA() function.
>>
>> Even better, try to downcast (SafeDownCast()) to a vtkVolume. If the cast
>> succeeds, do not delete the object.
>>
>> Let us know how it goes.
>>
>> David
>>
> Executing GetClassName() crashes the program. I will try IsA() tomorrow
> when I get back to university.
>
> Thanks for taking interest.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110317/84c86091/attachment.htm>


More information about the vtkusers mailing list