[vtkusers] How to replace 'p' key by left click mouse button?
Leguay Romain
romain.leguay at etu.u-bordeaux1.fr
Thu Jun 16 10:49:01 EDT 2011
Hi everyone,
I try to finish my picking.
To do this I need to replace the default key by a left click mouse button.
This next class colorized the dataSet selected in another color.
public class Test {
vtkInteractorStyle style = null;
vtkRenderer renderer = null;
vtkCellPicker picker = null;
vtkActor actor = new Actor();
public void execute () {
//Add my mesh to the renderer
renderer.AddActor(actorMesh);
....
//add the picking actor
actor.SetMapper(<my_mapper>);
renderer.AddActor(actor);
picker = new vtkCellPicker();
picker.RemoveAllObservers();
picker.AddObserver("EndPickEvent", this, "pickerFunction");
style = new vtkInteractorStyleUser();//TrackballCamera();
style.AddObserver("LeftButtonPressEvent", this, "mycallback");
vtkCanvas canvas = new vtkCanvas();
canvas.setInteractorStyle(style);
}
public void mycallback() {
//Go inside
//Get mouse position
vtkRenderWindowInteractor iren = style.GetInteractor();
int [] position = iren.GetEventPosition();
//Launch picking
picker.Pick(position[0], position[1], 0, renderer);
}
public void pickerFunction() {
//Go inside
if (((vtkCellPicker) picker).GetCellId() < 0) {
Logger.log(Activator.getDefault(), IExtendedStatus.DEBUG,
"Aucune zone sélectionnée");
actor.SetMapper(null);// Delete();
} else {
vtkDataSet dataSetPicked = ((vtkCellPicker) picker).GetDataSet();
IZone currentZone = null;
for (IZone zone : dataSet.getZones()) {
if (dataSetPicked == zone.getVtkDataSet()) {
currentZone = zone;
break;
}
}
setZone(currentZone);
if (currentZone != null) {
mapper = new VtkMapper(currentZone);
mapper.getVtkMapper().ScalarVisibilityOff();
actor.VisibilityOn();
actor.SetMapper(mapper.getVtkMapper());
actor.GetProperty().SetColor(1, 0, 0)
actor.GetProperty().SetOpacity(1);
}
}
}
}
This class works just fine with the 'p' key (it's not disabled...) but when I push left mouse button, my actor is not displayed in my window (but it's going into observer methods).
I don't find the method "default action picking".
Has anyone got any clues?
Regards,
Romain
More information about the vtkusers
mailing list