[vtkusers] AddActor - Help

Nasos Iliopoulos nasos_i at hotmail.com
Wed Jun 24 12:01:54 EDT 2009


You have a couple of options,
(1) Like in the example in the
previous message, it is generally convenient that when you create an
object (i.e. vtkSphereSource), to keep a pointer (either encapsulated
in a class, or maybe as a global variable (bad!), so that you can just
modify it when you need to.

(2) Another way, but not as
convenient in terms of getting the handle of the objects is by using
getxxx methods. i.e. if you look in the vtkRenderer, there is a method
that returns the list of actors of this renderer:
http://www.vtk.org/doc/nightly/html/classvtkRenderer.html   (look at the method GetActors)
To
use it you have to go through the actors, in the vtkActorCollection and
use their getMapper method to get the mapper. The same thing with
mapper, by using their GetInput() method and so on till you get to the
source. But beyond that point it gets too complicated, because you then
need to be sure you do the correct type casting, so that you get the
object you want (unless of course your pipeline is simple and you can
control it). Another problem of this approach is that you must also
keep track of which actor is which (I am not sure if vtk has a standard
approach for that).

Also, when you call the method Delete(), the
object is NOT deleted, it still exists but it is referenced by another
object, like an actor is referenced from a renderer. When you call the
renderer's delete, it will invoke Delete on all it's actors, and that's
when the memory will be freed (assuming that no other renderer or
object is referencing it). Vtk is using what is called "reference
counting", see 
http://en.wikipedia.org/wiki/Reference_counting
and
http://en.wikipedia.org/wiki/Smart_pointer
so
when you call vtkObject->Delete(), the object's reference count is
decreased by one and the object is only deleted when the reference
count is 0 (i.e. when nothing is using it).

Instead of having to
deal with the delete statements it is highly recommended to use
vtkSmartPointer in combination with (1), that does all the memory
handling almost automatically.

Best
Nasos

From: ilferraresebono at hotmail.it
To: nasos_i at hotmail.com; claude.gangolf at gmail.com; vtkusers at vtk.org
Subject: RE: [vtkusers] AddActor - Help
Date: Wed, 24 Jun 2009 16:50:15 +0200








Hi,

I have a question regarding the pipeline.
If all the objects are stored in the pipeline structure, how is that possible to retrieve them and modify. I mean...let's say that after the 
ren->AddActor(x) I call
x->Delete() because I want to save memory and I know It's in the actor collection stored in the renderer...is there a way to collect that actor from the collection and get back to the original source (let's say the origina sphereSource)

Many thanks.
Giancarlo

From: nasos_i at hotmail.com
To: claude.gangolf at gmail.com; vtkusers at vtk.org
Date: Wed, 24 Jun 2009 09:49:15 -0400
Subject: Re: [vtkusers] AddActor - Help








Claude,
You have to think the actor as a real-life actor. The actor has not
written the script of a play, he (or she) is just the one that presents
it on the scene. The script (or data) is founded in the source object and
is been manipulated through filters, then inputed to a mapper (that
translates the data into graphical backend instructions - i.e. OpenGL) 
and then guided through the actor (that can have properties like where
to position itself, what it's scale will be, what color the objects it
acts upon should be, etc.).



Also the pipeline approach is not as the procedural approach. When you
modify an object in the pipeline, all the rest will be updated to
relfect those changes. Take for example:



(1)vtkConeSource

    |

    v

(2)vtkPolyData

    |

    v

(3)vtkActor


    |


    v

(4)vtkRenderer->Window

    |



    v


(5)vtkRenderWindow

    |

    v

(6)vtkRenderWindowInteractor



if you change vtkPolyData (2), everything down the pipeline (3,4,5,6)
will be changed to relfect those changes. Similarly if you change only
the vtkActor (3), everything down the pipeline (4,5,6) will be changed.

>how can i create such pointers:
Look at the example at the end of this message. If you post your code I can help you even further.

> will it only show me the object with the new
> properties but not creating a new windo in the memory and if you said that
> the old properties are lost

The old object will not be "lost", some data of it (i.e. the source) will still be there. So if you want to plot two incarnations of the same object, you will need two different actors with the same input. Look at the cone example to see how it is done:
http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTK/Examples/Tutorial/Step4/Cxx/Cone4.cxx
(on lines 59 and 82, two different actors share the same mapper, but the actors have different properties).

Now if you want a new renderer (that will plot the two objects side by side for example as in two windows) you should go for a combination of the above example and the example in:
http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTK/Examples/Tutorial/Step3/Cxx/Cone3.cxx
In this case you have one actor but two renderers.

it will be nice to read some documentation on how vtk pipeline works. Here is a nice link that has some nice info:
http://www.imaging.robarts.ca/~dgobbi/vtk/vtkcourse/index.html

I suppose you work on c++, so here is a sort code snippet of how to keep a pointer to your actor:

vtkActor *createDisk()
{
    ....
    .... (1)

    vtkActor *diskActor=vtkActor::New();
    diskActor->SetInput(...); // Something you have created in (1)
    return diskActor; //Dangerous, user must take care of cleaning up.
}

int main()
{
    ...
    vtkActor *disk;
    disk = createDisk();
    disk->SetScale(1.0);

    ren->AddActor(disk);

    ...
    // Later in your program
    disk->SetScale(2.0);
    ren->GetRenderWindow()->Render();

    // When the program exits, or when you no longer need the actor (alternatively you may use a vtkSmartPointer and don't have to worry about the following).
    disk->Delete();
    // Don't forget to delete any other vtk objects you have created!    
    return 0;
} 

Best 
Nasos




> Date: Wed, 24 Jun 2009 06:01:22 -0700
> From: claude.gangolf at gmail.com
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] AddActor - Help
> 
> 
> I want to change the properties of the actor, but you told me of pointers to
> the actor, how can i create such pointers, and when i call, for example the
> function render() twice, will it only show me the object with the new
> properties but not creating a new windo in the memory and if you said that
> the old properties are lost, would that mean that the there is no old disk
> with the old property saved int the merory but only one disk with the new
> merory?
> 
> Thx for your help you have given to me already
> -- 
> View this message in context: http://www.nabble.com/AddActor---Help-tp24181683p24184332.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> 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

Insert movie times and more without leaving Hotmail®. See how.
Chiama da PC a PC e. taglia i costi delle chiamate!
_________________________________________________________________
Microsoft brings you a new way to search the web.  Try  Bing™ now
http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try_bing_1x1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090624/5683d00b/attachment.htm>


More information about the vtkusers mailing list