コード例 #1
0
    private void LoadDLL(string dllpath)
    {
        string directory = Path.GetDirectoryName(dllpath);
        string filename  = Path.GetFileName(dllpath);

        Debug.Log(directory);
        Debug.Log(filename);

        SetDllDirectory(directory);
        IntPtr LoadedDll = LoadLibrary(filename);

        if (LoadedDll == IntPtr.Zero)
        {
            Debug.Log("DLL_ID is null");
        }
        IntPtr FunctionAdress = GetProcAddress(LoadedDll, "Execute");

        if (FunctionAdress == IntPtr.Zero)
        {
            Debug.Log("FUNC_ID is null");
        }
        Debug.Log("DLL LOADED");

        if ((DllLoadOptions)dropdown.value == DllLoadOptions.ADD_COLUMN)
        {
            Debug.Log("Executing Add Column Function");
            AddColumnFunction columnfunction = (AddColumnFunction)Marshal.GetDelegateForFunctionPointer(FunctionAdress, typeof(AddColumnFunction));
            ExecuteColumnFunction(columnfunction);
        }
        else if ((DllLoadOptions)dropdown.value == DllLoadOptions.CALCULATE_VALUE)
        {
            Debug.Log("Executing Calculate Value Function");

            CalculateValueFunction valuefunction = (CalculateValueFunction)Marshal.GetDelegateForFunctionPointer(FunctionAdress, typeof(CalculateValueFunction));
            ExecuteValueFunction(valuefunction);
        }
        FunctionAdress = IntPtr.Zero;

        FreeLibrary(LoadedDll);
    }
コード例 #2
0
    private void ExecuteValueFunction(CalculateValueFunction myFunc)
    {
        List <float> TrajectoriesList = new List <float>();
        List <float> Xvalues          = new List <float>();
        List <float> Yvalues          = new List <float>();
        List <float> Zvalues          = new List <float>();
        List <float> Cvalues          = new List <float>();
        List <float> Tvalues          = new List <float>();
        List <float> PHvalues         = new List <float>();
        List <float> THvalues         = new List <float>();
        List <float> Svalues          = new List <float>();

        CloudData data        = CloudUpdater.instance.LoadCurrentStatus();
        int       pointnumber = 0;


        if (data.globalMetaData.SelectedPointsList.Count == 0)
        {
            Debug.Log("Sending all points");
            foreach (var i in data.pointDataTable)
            {
                TrajectoriesList.Add(i.Value.trajectory);
                Xvalues.Add(i.Value.position.x);
                Yvalues.Add(i.Value.position.y);
                Zvalues.Add(i.Value.position.z);
                Cvalues.Add(i.Value._color_index);
                Tvalues.Add(i.Value.time);
                PHvalues.Add(i.Value.phi_angle);
                THvalues.Add(i.Value.theta_angle);
                Svalues.Add(i.Value.size);
                pointnumber++;
            }
        }
        else
        {
            Debug.Log("Sending selected points");
            foreach (var i in data.globalMetaData.SelectedPointsList)
            {
                TrajectoriesList.Add(data.pointDataTable[i].trajectory);
                Xvalues.Add(data.pointDataTable[i].position.x);
                Yvalues.Add(data.pointDataTable[i].position.y);
                Zvalues.Add(data.pointDataTable[i].position.z);
                Cvalues.Add(data.pointDataTable[i]._color_index);
                Tvalues.Add(data.pointDataTable[i].time);
                PHvalues.Add(data.pointDataTable[i].phi_angle);
                THvalues.Add(data.pointDataTable[i].theta_angle);
                Svalues.Add(data.pointDataTable[i].size);
                pointnumber++;
            }
        }
        float[] TrajectoriesArray = TrajectoriesList.ToArray();
        float[] XvaluesArray      = Xvalues.ToArray();
        float[] YvaluesArray      = Yvalues.ToArray();
        float[] ZvaluesArray      = Zvalues.ToArray();
        float[] CvaluesArray      = Cvalues.ToArray();
        float[] TvaluesArray      = Tvalues.ToArray();
        float[] PHvaluesArray     = PHvalues.ToArray();
        float[] THvaluesArray     = THvalues.ToArray();
        float[] SvaluesArray      = Svalues.ToArray();

        List <int> intparamList    = new List <int>();
        string     intParamsString = intParametersInputField.text;

        if (intParamsString.Length > 0)
        {
            string[] entries = intParamsString.Split(',');

            for (int k = 0; k < entries.Length; k++)
            {
                int parsed = int.Parse(entries[k], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture);
                intparamList.Add(parsed);
            }
        }

        List <float> floatparamList    = new List <float>();
        string       floatParamsString = floatParametersInputField.text;

        if (floatParamsString.Length > 0)
        {
            string[] entries = floatParamsString.Split(',');

            for (int k = 0; k < entries.Length; k++)
            {
                float parsed = Single.Parse(entries[k], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture);
                floatparamList.Add(parsed);
            }
        }

        List <double> doubleparamList    = new List <double>();
        string        doubleParamsString = doubleParametersInputField.text;

        if (doubleParamsString.Length > 0)
        {
            string[] entries = doubleParamsString.Split(',');

            for (int k = 0; k < entries.Length; k++)
            {
                double parsed = Double.Parse(entries[k], System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture);
                doubleparamList.Add(parsed);
            }
        }


        int[] IntParams = intparamList.ToArray();
        //int[] IntParams = new int[1];
        float[]  FloatParams  = floatparamList.ToArray();
        double[] DoubleParams = doubleparamList.ToArray();
        if (IntParams.Length > 0)
        {
            float[] Results = new float[IntParams[0]];

            /**
             * float[][] Results = new float[3][];
             * for(int i = 0; i < Results.Length; i++)
             * {
             *  Results[i] = new float[pointnumber];
             * }
             **/
            //float[int, pointnumber]

            Debug.Log("nullcheck : " + Results[0]);


            fixed(float *Trajectoriespointer = TrajectoriesArray, xvalues = XvaluesArray, yvalues = YvaluesArray,
                  zvalues  = ZvaluesArray, cvalues  = CvaluesArray, tvalues     = TvaluesArray, thvalues = THvaluesArray,
                  phvalues = PHvaluesArray, svalues = SvaluesArray, floatparams = FloatParams, results   = Results)
            {
                fixed(int *intparams = IntParams)
                {
                    fixed(double *doubleparams = DoubleParams)
                    {
                        //fixed (float** result = Results)
                        //{
                        //*result = new float[1][1];
                        myFunc(pointnumber, xvalues, yvalues, zvalues, cvalues, tvalues, Trajectoriespointer,
                               phvalues, thvalues, svalues, intparams, floatparams, doubleparams, results);
                        //TODO

                        //Add *results in cloudData
                        //Add option to put names for the different results
                        string resultstring = "";

                        for (int i = 0; i < Results.Length; i++)
                        {
                            if (!float.IsNaN(Results[i]))
                            {
                                float res = Results[i];
                                resultstring = resultstring + "result " + i + " : " + res + "\n";
                            }
                        }

                        ModalWindowManager.instance.CreateModalWindow(resultstring);
                    }
                }
            }
        }
        else
        {
            ModalWindowManager.instance.CreateModalWindow("Error, the first int parameter in the list should be set as the number of values you wish to calculate.\nThe dll could not be loaded.");
        }
    }