[vtkusers] zoom on a single vtkChartXY axis with the mouse's wheel

amine.mz amine.mzoughi at febus-optics.com
Wed May 2 03:15:27 EDT 2018


I'm working with Qt and I have a code that rely on QCustomPlot that I want to
port to VTK.

I want to select only a single axis (left or bottom) of a vtkChartXY,
highlight it (increase its width and maybe change its color), and use
mouse's wheel forward/backward movements to increase/decrease its range
(zoom only the left or bottom part). When I click elsewhere on the plot, the
last selected axis must be unhighlithed and mouse's wheel movements will
change zoom/unzoom both axis (the native zoom mode of vtkChartXY).

For the moment, I proceeded like this (and I don't know if there is a better
solution) :

* I created a class "MouseInteractor" that inherits from
vtkContextInteractorStyle, in this class, I overrode the following methods :
OnLeftButtonDown, OnMouseWheelForward, OnMouseWheelBackward but also
OnRightButtonDown because I want to show a context menu to clear all plots
or move legends.

In this class, I also put a pointer to the class that manage the QVTKWidget
(contains the X and Y arrays, the view etc...)

* Then I register an object of this class in the render window interactor :
example :
m_view->GetRenderWindow()->GetInteractor()->SetInteractorStyle(m_mouseIntStyle);

I encounter a lot of difficulties in the implementation of the user's
interactions : 

- how check if the user has clicked on one of the two axis ? (I need 2
coordinates of the axis box but I don't know how, in the class I can get an
axis pointer (example : m_chart->GetAxis(vtkAxis::BOTTOM) but I don't know
to get the right coords), mouse coords can be gotten with something like :
this->Interactor->GetEventPosition()[0] in the MouseInteractor methods.

- Otherwise, setting the interactor style made me lose the vtkChartXY's
native zoom which works on both axes. How to keep it along with the new
interactor style ?

- How to implement the zoom on a single axis ?

Thanks in advance for any suggestion



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list