[vtkusers] How to use the method “AddObserver” that lies in the file “vtkObject.java”?(Java)

Jarek Sacha jarek at ieee.org
Sat Oct 30 23:08:24 EDT 2004


肥肥:

Here is Java example of calling AddObserver():
picker.AddObserver("EndPickEvent", AnnotatePick.this, "annotatePick");

The first argument specifies the event you want to observe, second is a
reference of object that will handle callback, the third parameter is a
name of a method that should be called by callback.
Here is the full code of AnnotatePick.java
http://cvs.sourceforge.net/viewcvs.py/ij-plugins/VTK-Examples/Examples/Annotation/Java/AnnotatePick.java?rev=HEAD&view=auto

You can find Java version of AnnotatePick and over 70 other Java
examples at
http://ij-plugins.sourceforge.net/vtk-examples/

Jarek

肥肥 wrote:

> Hi,all I am replant the example “annotatePick.tcl” using Java. But I
> don’t how to use the method “AddObserver” in java. “AddObserver”
> method has three parameters. In C++, we can carry a function pointer
> as the second parameter, but in “vtkObject.java”, the method defined
> as follow: public native int AddObserver(String id0, Object id1,
> String id2); so what can I do to translate the real parameter to the
> second formal parameter? The script of annotatePick.tcl as follow:
> …………………. # Create a cell picker. vtkCellPicker picker picker
> AddObserver EndPickEvent annotatePick …………………. # Create a Tcl
> procedure to create the text for the text mapper used to # display the
> results of picking. proc annotatePick {} { if { [picker GetCellId] < 0
> } { textActor VisibilityOff } else { set selPt [picker
> GetSelectionPoint] set x [lindex $selPt 0] set y [lindex $selPt 1] set
> pickPos [picker GetPickPosition] set xp [lindex $pickPos 0] set yp
> [lindex $pickPos 1] set zp [lindex $pickPos 2] textMapper SetInput
> "($xp, $yp, $zp)" textActor SetPosition $x $y textActor VisibilityOn }
> renWin Render } Thanks in advance. 





More information about the vtkusers mailing list