[vtkusers] Picking Points with Java
Richard Haney
cosmoh2o at hotmail.com
Wed Feb 22 17:30:47 EST 2006
Hello,
I am trying to create a simple visualizer using VTK with Java bindings and
have a quick question I hope someone out there has an answer to.
I am trying to "pick" a point in the vtkPanel.Renderer object after
displaying them on the current vtkPanel. I can do this with no problem,
however there are a couple of issues:
1. The point labels displayed by the panel appear backwards in location
(e.g., given point 0 is at the top-left of a generated square mesh and 5 is
at the botom-left - if you select point 0 with the mouse the ID of 5 is
shown)
2. Whenever you move the displayed actor with them mouse, the points stay
constant but if you select it with a mouse click they are usually very off.
Attached is a sample copy of the code:
...
// Called initially to set the point labels:
public void addPointLabels() {
this.PIDs = new vtkIdFilter();
// Where this.reader is an vtkXMLUnstructuredGridReader
this.PIDs.SetInput(this.reader.GetOutput());
this.PIDs.PointIdsOn();
this.PIDs.FieldDataOn();
this.dm = new vtkLabeledDataMapper();
this.dm.SetInput(this.PIDs.GetOutput());
this.dm.SetLabelFormat("%g");
this.dm.SetLabelModeToLabelIds();
this.pointLabels = new vtkActor2D();
this.pointLabels.SetMapper(this.dm);
// Where this.renWin is a vtkPanel
// Add the "Label" Actor to the renderer:
this.renWin.GetRenderer().AddActor(this.pointLabels);
// Re-Draw Panel:
this.renWin.Render();
}//End of addPointLabels()
...
// Called everytime the MouseClicked event is fired
// X is given value MouseEvent e.getX(), and
// Y is given value MouseEvent e.getY()
public synchronized void picked(int X, int Y) {
// To select an ACTOR from the vtkPanel:
vtkPointPicker picker = new vtkPointPicker();
// Add this actor to the list:
picker.AddPickList(this.actor);
picker.PickFromListOn();
// Where this.renWin is the vtkPanel object defined in this class
picker.Pick(X, Y, 0, this.renWin.GetRenderer());
if (picker.GetPointId() != -1) {
System.out.println("You Selected the Point: " + picker.GetPointId());
}else {
System.out.println("You did NOT select a Point!");
}
}// End of picked()
The above code doesn't generate any errors, just the strange output I
described.
Whoever can solve this is truly a Java-VTK expert and has my thanks. I can't
seem to find much info about Java-VTK issues.
Thank you.
More information about the vtkusers
mailing list