[vtkusers] vtkCallbackCommand in ActiveViz
Jochen K.
jochen.kling at email.de
Fri Jun 22 12:59:07 EDT 2012
Hi Dieter,
as so often an example is worth a thousand words:
private void InteractorStyleUser() {
// Create a sphere.
vtkSphereSource sphereSource = vtkSphereSource.New();
sphereSource.SetRadius(0.5);
// retrieve renderWindow from our renderWindowControl
vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
// define interactorStyle of type vtkInteractorStyleUser
vtkInteractorStyleUser interactorStyleUser =
vtkInteractorStyleUser.New();
// tell renderWindow to use our own interactorStyle
renderWindow.GetInteractor().SetInteractorStyle(interactorStyleUser);
// define eventhandler
interactorStyleUser.LeftButtonPressEvt += new
vtkObject.vtkObjectEventHandler(interactorStyleUser_LeftButtonPressEvt);
interactorStyleUser.LeftButtonReleaseEvt += new
vtkObject.vtkObjectEventHandler(interactorStyleUser_LeftButtonReleaseEvt);
interactorStyleUser.KeyPressEvt += new
vtkObject.vtkObjectEventHandler(interactorStyleUser_KeyPressEvt);
/* here you can define more eventhandler
all available eventhandler are marked in Intellisense with a
lightning symbol
to create the handler type for instance
interactorStyleUser.RightButtonPressEvt+=
and then press the tab key
the eventhandler method is being created automatically
*/
// mapper
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(sphereSource.GetOutputPort());
// actor
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
vtkRenderer renderer =
renderWindow.GetRenderers().GetFirstRenderer();
renderer.SetBackground(0.3, 0.2, 0.1);
renderer.AddActor(actor);
}
void interactorStyleUser_KeyPressEvt(vtkObject sender,
vtkObjectEventArgs e) {
vtkInteractorStyleUser style = vtkInteractorStyleUser.New();
style = (vtkInteractorStyleUser)e.Caller;
int keyCode = style.GetChar();
string keySym = style.GetKeySym();
bool IsShiftKeyPressed = ( style.GetShiftKey() == 1 ? true : false
);
bool IsCtrlKeyPressed = ( style.GetCtrlKey() == 1 ? true : false );
Debug.WriteLine("keyCode: " + keyCode);
Debug.WriteLine("keySym: " + keySym);
Debug.WriteLine("shift key: " + IsShiftKeyPressed);
Debug.WriteLine("ctrl key: " + IsCtrlKeyPressed);
}
void interactorStyleUser_LeftButtonReleaseEvt(vtkObject sender,
vtkObjectEventArgs e) {
vtkInteractorStyleUser caller = vtkInteractorStyleUser.New();
caller = (vtkInteractorStyleUser)e.Caller;
int[] mousePosition = caller.GetLastPos();
Debug.WriteLine("left mouse button released -> mouse position: "
+ mousePosition[0] + " " + mousePosition[1]);
}
void interactorStyleUser_LeftButtonPressEvt(vtkObject sender,
vtkObjectEventArgs e) {
vtkInteractorStyleUser caller = vtkInteractorStyleUser.New();
caller = (vtkInteractorStyleUser)e.Caller;
int[] mousePosition = caller.GetLastPos();
Debug.WriteLine("left mouse button pressed -> mouse position: "
+ mousePosition[0] + " " + mousePosition[1]);
}
> And does anyone know if there is an official replacement for the factory
>
> vtkStandardNewMacro(InteractorStyle)
>
> I was using a simple static New here, which works, but probably is not
> dogmatic.
There is no replacement in C# for vtkStandardNewMacro(...)
In C# it's just fine to instantiate a class the way you doing it:
vtkObject myObject = vtkObject.New();
Note: All classes are static, that's the reason why you cannot inherit from
any wrapped vtk class.
But as I learned a few days ago there's a way to extent a static
class.
If you like I can show you how to do that.
with best regards
Jochen
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkCallbackCommand-in-ActiveViz-tp5714143p5714151.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120622/db0787cd/attachment.htm>
More information about the vtkusers
mailing list