[vtkusers] vtk AddObserver C++ (not understood)

Mark Wyszomierski markww at gmail.com
Wed May 11 11:02:56 EDT 2005


Abhishek,

You can check some of the existing vtk classes to see how it works.
For example, look at vtkImageViewer2. You will see how the observers
are added in
SetupInteractor(), and how an observer class is defined to handle the
signaling of the observers (vtkImageViewer2Callback). It's all in that
one source file, it should get you going.

As for passing the individual components to the observer class
instance, I've found there are a few options. Since you are deriving
your own class from vtkCommand, you can create some member variables
which are pointers to the types you want to have access to. When you
are then actually adding the observer, just point the member variables
to the actual concrete objects.

I've found it cleaner to just encapsulate all my vtk 'stuff' in one
logical class, then pass a pointer (this) to the observer, in which it
can access all the smaller components with ease,

Mark

On 5/10/05, Abhishek <gattani at aktina.com> wrote:
> Hello All, 
>  
> I am a little confused using vtk's AddObserver feature in C++. Most of the
> existing examples are in TCL where it is very easy to simply pass a
> procedure that gets called on an event. In C++, to add an observer a class
> needs to be first derived from vtkCommand and then the execute method must
> be overwritten. Within my Execute method how can I get pointers to multiple
> objects such as the vtkRenderer, vtkInteractor, or vtkCellPicker? VTK mouse
> picking article in Wikipedia, uses picker, iren and ren1 (3 object pointers)
> in procedure cbLBR(). While, in C++ my vtkCommand derived class gets one
> vtkObject*. I hope I have been clear in explaining my problem. I do
> obviously not understand something simple here. Can someone please comment
> and guide me to C++ examples that demonstrate. Further, the wikipedia
> article mentioned that the C++ example is also available. Where can I get
> access to it? Many thanks.
> 
> 
>  
> 
> -Cheers,
> 
> Abhishek 
> 
>  
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 
>



More information about the vtkusers mailing list