Pregunta

I have created a simple line plot using the ILNumerics Math Library for .Net. I would like to interact with the plotted data. It should be possible to select a subset of the plotted data and perform different mathematical operations on it. I wanted to use the markers for the selection, but I couldn't retrieve the correct values for the positions. I guess I have to transform the points somehow...Maybe someone can help me out?

Here's a simplified version of the code:

    private void ilPanel1_Load(object sender, EventArgs e)
    {
        var scene = new ILScene();
        //create 2D data
        ILArray<float> line1 = new float[,] { 
                    {0.0f,  1.0f, 2.0f }, 
                    {0.0f,  2.0f , 3.0f} };


        var linePlot1 = new ILLinePlot(line1.T,
            lineColor: Color.Blue,
            lineWidth: 3,
            markerStyle: MarkerStyle.Dot);

        var plot = scene.Add(new ILPlotCube());
        plot.Add(linePlot1);

        linePlot1.Marker.MouseClick += Marker_MouseClick;
        ilPanel1.Scene = scene;
    }

The Marker_MouseClick event is called once I click on one of the markers.

    void Marker_MouseClick(object sender, ILMouseEventArgs e)
    {
        ILGroup group = e.Target.Parent;
        ILMarker marker = group.First<ILMarker>();

        var posx = e.LocationF.X;
        var posY = e.LocationF.Y;
    }

But the positions are not refering to the scaling of my axis. Is there a simple way to convert the LocationF-values to the scaling of my axis? Or is there another way to get the x and y-values of the marker after triggering an event?

Tim

¿Fue útil?

Solución

The mouse event arguments gives you the LocationF property. It reflects the mouse position in the (2D) coordinate system of the viewport. Viewports in ILNumerics are established by ILCamera. So we have the mouse position in a coordinate system of the parent camera node.

In order to transform the mouse position into the coord system of the plot cube, the transform matrices from the camera to the plot cube node must get accumulated. The resulting transformation matrix will transform any mouse position into the plot cube coord system.

There is a similar question on SO: How to find the 3D coordinates of a surface from the click location of the mouse on the ILNumerics surface plots? 3d-coordinates-of-a-surface-from-the-click-location-of-the-mouse/17681163#17681163

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top