Ilnumerics Ilpanel not activating when compiled in a winform into a dll when loaded into matlab

爷,独闯天下 提交于 2019-12-23 17:01:12

问题


I want to compile a winform written in c# in visual-studio 2012 to a dll which I then load into matlab 2013a. Using the matlab .net interface I want to then interact with the winform, listening to its events and passing it data via a set of predefined public methods. I am working on windows 7 Ultimate SP2.

This works surprisingly well, I am able to interact with all native winform tools, buttons, trees, panels and even charts. However i want to use ILnumerics and particularly the ILpanel used to display "scenes" containing all wonder of things. This is were I hit a brick wall nothing ever gets rendered in the IPanel when it is compiled as a dll and called into matlab. It only ever shows the default oval.

I can attach matlab as a process in visual studio and run through the code. It all executes fine. It looks like the scene on line 32 is not properly attached to iLPanel1.

Any help would be appreciated.

Form1.cs primary c# code without the form1.Designer.cs

using System;
using System.Windows.Forms;
using ILNumerics;
using ILNumerics.Drawing.Plotting;
using ILNumerics.Drawing;
using MarkerStyle = ILNumerics.Drawing.MarkerStyle;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void PlotData(double[,] myX)
        {
            var myDoubleVec = new double[myX.Length];

            for (int i = 0; i < myX.Length; i++)
            {
                myDoubleVec[i] = myX[i, 0];
            }

            var scene = new ILScene(); 
            ILArray<double> myNumX = myDoubleVec;
            scene.Add(new ILPlotCube {
                new ILLinePlot(ILMath.tosingle(myNumX.T),
                 markerStyle: MarkerStyle.Dot)
            }); 
            ilPanel1.Scene = scene; 

        }

        private void ilPanel1_Load_1(object sender, EventArgs e)
        {
            var myDouble = new double[,] { { 2 }, { 4 }, {9 }, { 16 } }; ;
            PlotData(myDouble);
        }

        public void PlotRandom()
        {
            double yValue = 50.0;
            double yValue2 = 200.0;
            if (chart1.Series["Series1"].Points.Count > 0)
            {
                yValue = chart1.Series["Series1"].Points[chart1.Series["Series1"].Points.Count - 1].YValues[0];
                yValue2 = chart1.Series["Series2"].Points[chart1.Series["Series1"].Points.Count - 1].YValues[0];
            }
            Random random = new Random();
            for (int pointIndex = 0; pointIndex < 50; pointIndex++)
            {
                yValue = yValue + (float)(random.NextDouble() * 10.0 - 5.0);
                chart1.Series["Series1"].Points.AddY(yValue);

                yValue2 = yValue2 + (float)(random.NextDouble() * 10.0 - 5.0);
                chart1.Series["Series2"].Points.AddY(yValue2);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PlotRandom();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var myDouble = new double[,] { { 2 }, { 4 }, { 6 }, { 8 } }; ;
            PlotData(myDouble);
        }
    }
}

The resulting winform looks as follows.

Matlab code to load assembly and manipulate the form.

 NET.addAssembly('C:\Users\philliproso\Documents\Visual Studio 2012\Projects\WindowsFormsApplication3\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.dll')
    myForm=WindowsFormsApplication3.Form1;
    myForm.Show;
    myForm.plotRandom; %this call works fine
    myForm.PlotData(rand(50,1)); %this call has no effect

来源:https://stackoverflow.com/questions/17827935/ilnumerics-ilpanel-not-activating-when-compiled-in-a-winform-into-a-dll-when-loa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!