# Activiz - implementing custom interactor style

**URL:** <https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946>\
**Category:** Development\
**Created:** [July 13, 2022, 10:23am UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946 "2022-07-13T10:23:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortifiedpenguin](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mortifiedpenguin](https://discourse.vtk.org/u/mortifiedpenguin)\
**Post date:** [July 13, 2022, 10:23am UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946/1 "2022-07-13T10:23:52Z")

</div>

Hi,  
I’m using Activiz with C# and want to use a custom interactor style. To this end I subclassed vtkInteractorStyleTrackballCamera and overriden the OnLeftButtonDown function. However, the overriden method is never called. I can use other interactor styles, e.g. vtkInteractorStyleImage, without any problems, so the problem must lie with the new class itself. Is there anything else I have to do, so my custom interactor style works? I’m using the newest version 9.1.

```
class MCVTKInteractor : vtkInteractorStyleTrackballCamera
{

    public override void OnLeftButtonDown()
    {
        base.OnLeftButtonDown();
    }
}

```

---

<div class="post-metadata">

**Author:** ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)\
**Post date:** [July 13, 2022, 12:10pm UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946/2 "2022-07-13T12:10:11Z")

</div>

You can’t subclass and override the methods. You must create an interactor style object and hook into its events.

```auto
TrackballStyle = vtkInteractorStyleTrackballCamera.New();
TrackballStyle.LeftButtonPressEvt += TrackballStyle_LeftButtonPressEvt;

```

---

<div class="post-metadata">

**Author:** ![mortifiedpenguin](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mortifiedpenguin](https://discourse.vtk.org/u/mortifiedpenguin)\
**Post date:** [August 16, 2022, 8:44am UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946/3 "2022-08-16T08:44:42Z")

</div>

Thanks, I have a follow-up question. What I’m trying to do is provide a custom interaction, e.g. I want to pan with the right mouse button.  
I used a vtkInteractionStyleUser and the MouseDown / MouseUp handlers are called without any problems. I then tried to implement the behaviour by taking vtkInteractorStyleTrackballCamera as an example, so I call StartPan in MouseDown, Pan in MouseMove and EndPan in MouseUp. This doesn’t work however, the object is not getting moved.  
My suspicion is that this is due to a missing call to “GrabFocus”, but I can instantiate its parameters of type vtkCallbackCommand, the type is not available in Activiz.

```auto
        public void Start(ViewModeEnum fAction)
        {
            interactorStyle.FindPokedRenderer(Renderer.GetRenderWindow().GetInteractor().GetEventPosition()[0], Renderer.GetRenderWindow().GetInteractor().GetEventPosition()[1]);
            switch (fAction)
            {
                case ViewModeEnum.Panning:
                    interactorStyle.StartPan();
                    break;
            }
        }

        public void Move()
        {
            int x = Renderer.GetRenderWindow().GetInteractor().GetEventPosition()[0];
            int y = Renderer.GetRenderWindow().GetInteractor().GetEventPosition()[1];

            switch ((MCVTKInteractorState)interactorStyle.GetState())
            {
                case MCVTKInteractorState.VTKIS_PAN:
                    interactorStyle.FindPokedRenderer(x, y);
                    interactorStyle.Pan();
                    interactorStyle.InvokeEvent((uint)vtkCommand.EventIds.InteractionEvent, IntPtr.Zero);
                    break;
            }
        }

        public void End()
        {
            switch ((MCVTKInteractorState)interactorStyle.GetState())
            {
                case MCVTKInteractorState.VTKIS_PAN:
                    interactorStyle.EndPan();
                    break;
            }
        }

```

EDIT: Okay I see it now, the Pan() function is virtual and has an empty implementation. I managed to get it to work by providing an implementation similar to vtkInteractorStyleTrackballCamera’s Pan

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [August 29, 2022, 2:27am UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946/4 "2022-08-29T02:27:34Z")

</div>

@LucasGandel

---

<div class="post-metadata">

**Author:** ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)\
**Post date:** [August 29, 2022, 8:54am UTC](https://discourse.vtk.org/t/activiz-implementing-custom-interactor-style/8946/5 "2022-08-29T08:54:25Z")

</div>

> [@mortifiedpenguin](#):
>
> EDIT: Okay I see it now, the Pan() function is virtual and has an empty implementation. I managed to get it to work by providing an implementation similar to vtkInteractorStyleTrackballCamera’s Pan

I confirm the solution shared by @toddy is the right one. In addition, I think adding handlers on the RightButtonPressEvt/RightButtonReleaseEvt to call StartPan/EndPan should be enough if you remove the event handler on MouseMoveEvt. You don’t have to reimplement Pan() in this case.
