コード例 #1
0
        /// <summary>
        /// Calculates the mean of the current image
        /// </summary>
        public double Mean(int X, int Y, int W, int H)
        {
            double mean = -1;

            try
            {
                MWArray res = new MWNumericArray(1);
                res  = FEC.imageMean(this.imagePath, X, Y, W, H);
                mean = double.Parse(res.ToString());
                return(mean);
            }
            catch (Exception ex)
            {
                return(mean);
            }
        }
コード例 #2
0
        /// <summary>
        /// Simulate the steady-state problem with the given strut
        /// and cooler.  Output the results.
        /// </summary>
        /// <param name="strut"></param>
        /// <param name="cooler"></param>
        private void simulate(Strut strut, Cooler cooler)
        {
            Cursor savedCursor = this.Cursor;

            try {
                this.Cursor = Cursors.WaitCursor;

                this.Refresh();

                SteadyStateTempclass ssTemp = new SteadyStateTempclass();
                MWNumericArray       temp   = (MWNumericArray)ssTemp.steadystatetemperature(
                    strut.Length, strut.CrossSectionalArea, strut.Material.getData("PM"), cooler.getData("CPM"));

                answerBox.Text = temp.ToString();
            } finally {
                this.Cursor = savedCursor;
            }
        }
コード例 #3
0
        private void IndoorWindow_Simulation_Apply_Click(object sender, RoutedEventArgs e)
        {
            double[] Location_Tx = { 1, 14, 1 };
            double[] Location_Rx = { 2, 12, 2 };

            MWNumericArray Location_Tx_m = new MWNumericArray(1, 3, Location_Tx);
            MWNumericArray Location_Rx_m = new MWNumericArray(1, 3, Location_Rx);

            Console.Write(Location_Tx_m.ToString());


            MWArray[]       agrsOut      = new MWArray[14];
            raytracingClass raytracing_m = new raytracingClass();

            agrsOut = raytracing_m.raytracing(14, 0, rayparameter.Power_Tx, rayparameter.Frequency_Tx, 6.4, 0.0004, 1, 1, Location_Tx_m, Location_Rx_m, 0);
            OutputWindow OutputWin = new OutputWindow();

            OutputWin.Show();
        }
コード例 #4
0
ファイル: Settings.cs プロジェクト: yangzibib/PSOAlgorithms
        private void calcMATLAB(string benchmark, string algorithm)
        {
            double genum = (Double)numericUpDown2.Value;
            double psize = (Double)numericUpDown1.Value;
            double w     = (Double)numericUpDown3.Value;
            double c1    = (Double)numericUpDown4.Value;
            double c2    = (Double)numericUpDown5.Value;
            double run   = (Double)numericUpDown6.Value;

            MWArray[] results = new MWArray[6];
            MWArray[] inputs  = new MWArray[] { (MWArray)genum, (MWArray)psize, (MWArray)w, (MWArray)c1, (MWArray)c2, (MWArray)run };

            switch (benchmark)
            {
            case "FT06(6×6)":
                this.label22.Text = "55";
                FT06 myFT06 = new FT06();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT06.mainPSO_6c6(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT06.mainCPSO_6c6(6, ref results, inputs);
                }
                break;

            case "FT10(10×10)":
                this.label22.Text = "930";
                FT10 myFT10 = new FT10();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT10.mainPSO_10c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT10.mainCPSO_10c10(6, ref results, inputs);
                }
                break;

            case "FT20(20×5)":
                this.label22.Text = "1165";
                FT20 myFT20 = new FT20();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT20.mainPSO_20c5(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT20.mainCPSO_20c5(6, ref results, inputs);
                }
                break;

            case "LA01(10×5)":
                this.label22.Text = "666";
                LA01 myLA01 = new LA01();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA01.mainPSO_10c5(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA01.mainCPSO_10c5(6, ref results, inputs);
                }
                break;

            case "LA21(15×10)":
                this.label22.Text = "1046";
                LA21 myLA21 = new LA21();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA21.mainPSO_15c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA21.mainCPSO_15c10(6, ref results, inputs);
                }
                break;

            case "LA26(20×10)":
                this.label22.Text = "1218";
                LA26 myLA26 = new LA26();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA26.mainPSO_20c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA26.mainCPSO_20c10(6, ref results, inputs);
                }
                break;

            case "LA31(30×10)":
                this.label22.Text = "1784";
                LA31 myLA31 = new LA31();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA31.mainPSO_30c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA31.mainCPSO_30c10(6, ref results, inputs);
                }
                break;

            case "LA36(15×15)":
                this.label22.Text = "1268";
                LA36 myLA36 = new LA36();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA36.mainPSO_15c15(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA36.mainCPSO_15c15(6, ref results, inputs);
                }
                break;

            default:
                MessageBox.Show("请选择有效的调度算例");
                break;
            }

            finishTime = DateTime.Now.ToString();
            MWNumericArray exc      = results[0] as MWNumericArray;
            MWNumericArray min      = results[1] as MWNumericArray;
            MWNumericArray wre      = results[2] as MWNumericArray;
            MWNumericArray are      = results[3] as MWNumericArray;
            MWNumericArray t        = results[4] as MWNumericArray;
            MWArray        filename = results[5] as MWArray;

            ganttAdress       = filename.ToString();
            this.label26.Text = exc.ToString();
            this.label23.Text = min.ToString();
            this.label25.Text = wre.ToString();
            this.label24.Text = are.ToString();
            this.label27.Text = t.ToString();
            this.label28.Text = "计算完成!";
        }
コード例 #5
0
        private void Start_Click(object sender, EventArgs e)
        {
            //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_;
            // pictureBox2.Image.Dispose();
            // pictureBox2.Image = null;
            textBox1.Text = ("加载图片");
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBox1.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            string str1 = file.FileName;

            //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范
            textBox1.Text = (str1);
            //textBox1.Text = (file.FileName);
            DiameterCalculation.Class1 c1 = new DiameterCalculation.Class1();
            //Object sandNumber;
            MWArray        a1 = c1.linktocsharp(str1);
            MWNumericArray a2 = (MWNumericArray)a1;

            textBox2.Text = a2.ToString();

            linktocsharpV3.Class1 v3c1 = new linktocsharpV3.Class1();
            //MWArray DiameterArray = v3c1.linktocsharpV3(str1);
            MWArray[] resultlist = new MWArray[2];
            resultlist = v3c1.linktocsharpV3(2, str1);                    //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数
            MWNumericArray DiameterArray = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组
            MWNumericArray SandNumber    = (MWNumericArray)resultlist[1]; //沙尘个数

            double[,] DA = new double[(int)SandNumber, 1];                //matlab函数返回值为二维数组,因此需要用二维数组接收
            DA           = (double[, ])DiameterArray.ToArray();
            //textBox3.Text = DA[(int)a2 - 1, 0].ToString();
            //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString();



            //textBox2.Text = (sandNumber.ToString);
            string pathname2;

            pathname2 = "D:\\op\\tempresult.png";  //获得文件的绝对路径
            //this.pictureBox2.Load(pathname2);//load貌似过时了?
            // this.pictureBox2.Image = Image.FromFile(pathname2);
            //    pictureBox2.Image.Dispose();
            FileStream pFileStream = new FileStream(pathname2, FileMode.Open, FileAccess.Read);

            pictureBox2.Image = Image.FromStream(pFileStream);
            pFileStream.Close();
            pFileStream.Dispose();
        }
コード例 #6
0
    // PARSE ENV_CHECK OUTPUT
    public string parse_results(MWStructArray result, int print_level)
    {
        Console.WriteLine("\n======================= ENVIRONMENT CHECK RESULT =======================");
        String[] checker_names = { "vpd_check", "dewpoint_check", "crop_temp_check" };

        // READ OUTPUT DETAILS
        MWStructArray  result_checker        = new MWStructArray();
        MWNumericArray result_code           = null;
        MWNumericArray checker_code          = null;
        MWCharArray    result_type           = null;
        MWCharArray    result_state          = null;
        MWCharArray    result_checkvar_name  = null;
        MWNumericArray result_checkvar_value = null;
        MWCharArray    result_checkvar_unit  = null;
        MWNumericArray result_adjust         = null;
        MWCharArray    result_adjust_unit    = null;

        result_code = (MWNumericArray)result.GetField("code");
        int    nFields    = result.NumberOfFields - 1;
        string result_out = null;

        for (int ifield = 1; ifield <= nFields; ifield++)
        {
            result_checker = (MWStructArray)result.GetField(checker_names[ifield - 1]);
            checker_code   = (MWNumericArray)result_checker.GetField("code");

            switch (print_level)
            {
            case 0:     // PRINT ABNORMAL RESULTS
                if ((int)checker_code > 0)
                {
                    result_type  = (MWCharArray)result_checker.GetField("type");
                    result_state = (MWCharArray)result_checker.GetField("state");
                    result_out   = "\n" + result_type.ToString() + " STATUS : " + result_state.ToString();
                    Console.WriteLine(result_out);
                }
                break;

            case 1:     //  PRINT ABNORMAL RESULTS + DETAILS
                if ((int)checker_code > 0)
                {
                    result_type           = (MWCharArray)result_checker.GetField("type");
                    result_state          = (MWCharArray)result_checker.GetField("state");
                    result_checkvar_name  = (MWCharArray)result_checker.GetField("checkvar_name");
                    result_checkvar_value = (MWNumericArray)result_checker.GetField("checkvar_value");
                    result_checkvar_unit  = (MWCharArray)result_checker.GetField("checkvar_unit");
                    result_adjust         = (MWNumericArray)result_checker.GetField("adjust");
                    result_adjust_unit    = (MWCharArray)result_checker.GetField("adjust_unit");

                    result_out  = "\n" + result_type.ToString() + " STATUS : " + result_state.ToString();
                    result_out += "\n" + result_checkvar_name.ToString() + " : " + result_checkvar_value.ToString() + " " + result_checkvar_unit.ToString();
                    result_out += "\n" + "ADJUST : " + result_adjust.ToString() + " " + result_adjust_unit.ToString();

                    Console.WriteLine(result_out);
                }
                break;

            case 2:     //  PRINT ALL RESULTS + DETAILS

                result_type           = (MWCharArray)result_checker.GetField("type");
                result_state          = (MWCharArray)result_checker.GetField("state");
                result_checkvar_name  = (MWCharArray)result_checker.GetField("checkvar_name");
                result_checkvar_value = (MWNumericArray)result_checker.GetField("checkvar_value");
                result_checkvar_unit  = (MWCharArray)result_checker.GetField("checkvar_unit");
                result_adjust         = (MWNumericArray)result_checker.GetField("adjust");
                result_adjust_unit    = (MWCharArray)result_checker.GetField("adjust_unit");

                result_out  = "\n" + result_type.ToString() + " STATUS : " + result_state.ToString();
                result_out += "\n" + result_checkvar_name.ToString() + " : " + result_checkvar_value.ToString() + " " + result_checkvar_unit.ToString();
                result_out += "\n" + "ADJUST : " + result_adjust.ToString() + " " + result_adjust_unit.ToString();

                Console.WriteLine(result_out);
                break;
            } // end of switch statement
        }

        return(result_out);
    }
コード例 #7
0
ファイル: initFullScan.cs プロジェクト: AndreiBer/MSOM3
        public void startMulti(string comment, ViewRSOM.MSOT.Hardware.ViewModels.Laser.ViewModelLaserInnolas multiLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            // Some parameters are adjusted to the OPO.
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }
            //else
            //{
            //    Console.Write("WARNING: acquisition folder exists already. Proceed with reconstruction. Previous reconstructions may be overwritten.");
            //}
            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = 500; // PRR of the OPO. Dont Change
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                    = acquisitionParameters.f_s;
            MWNumericArray inputRange             = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low                  = acquisitionParameters.z_low;
            MWNumericArray z_target               = acquisitionParameters.z_target;
            MWNumericArray z_high                 = acquisitionParameters.z_high;
            MWNumericArray v_x                    = 10; // dx/PRR
            MWNumericArray acc                    = 300;
            MWNumericArray acqDelay               = 3;
            MWNumericArray d_acc                  = 0.17;
            MWNumericArray acqRes                 = acquisitionParameters.acqRes;
            MWArray        acqMode                = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel           = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength     = acquisitionParameters.numberOfWavelength;
            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan              = 0;
            MWArray        ArrayOfWavelength      = acquisitionParameters.ArrayOfWavelength;

            // MWNumericArray ArrayOfWavelength = new MWNumericArray(acquisitionParameters.ArrayOfWavelength);
            //MWNumericArray ArrayOfWavelength = new MWNumericArray[acquisitionParameters.numberOfWavelength];

            //get number of wavelength from comment box
            if (!string.IsNullOrEmpty(comment))
            {
                try
                {
                    numberOfWavelength = multiLaser.retrieveWL(comment).Length;
                    int[]  tempArr   = multiLaser.retrieveWL(comment);
                    string stringArr = "";
                    for (int i = 0; i < multiLaser.retrieveWL(comment).Length; i++)
                    {
                        if (i == 0)
                        {
                            stringArr = tempArr[i].ToString();
                        }
                        else
                        {
                            stringArr = stringArr + " " + tempArr[i].ToString();
                        }
                    }
                    ArrayOfWavelength = stringArr;
                }
                catch (Exception)
                {
                    multiLaser.illuminationOFF();
                    Console.WriteLine("Wavelengths - wrong syntaxis");
                    //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    Thread.Sleep(5000);
                    Environment.Exit(1);
                }
            }
            else
            {
                ArrayOfWavelength = LaserParameter.LaserDefaultWavelength.ToString();
            }

            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",          "x_0",          "l_y",                    "l_x",        "ds",
                                          "PRR",               "triggerWidth", "f_s",                    "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",               "acc",          "acqDelay",               "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "ArrayOfWavelength", "BscanUpdate",  "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("ArrayOfWavelength", ArrayOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                //if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                if (systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage

                        // if (acquisitionParameters.triggerMode == 0)
                    {
                        iScanClass_OPO obj = null;
                        obj = new iScanClass_OPO();
                        obj.iScan_dual(fP, aP, dP, rP);
                    }

                        /*else
                         * {
                         *  iScanClass_trig obj_trig = null;
                         *  obj_trig = new iScanClass_trig();
                         *  obj_trig.iScan_trig(fP, aP, dP, rP);
                         * }*/
                        break;

                    case 2:     // Alazar
                        //if (acquisitionParameters.triggerMode == 0)
                    {
                        iScanClass_OPO obj = null;
                        obj = new iScanClass_OPO();
                        obj.iScan_dual(fP, aP, dP, rP);
                    }
                        //else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    {
                        multiLaser.illuminationOFF();
                        cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (multiLaser != null)
                {
                    try
                    {
                        multiLaser.illuminationOFF();
                        string StatusMessage;
                        StatusMessage = multiLaser.CheckShutterState();
                        if (StatusMessage == "OPEN")
                        {
                            Console.WriteLine("WARNING: switch off OPO EMISSION if necessary.");
                        }
                        cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);
        }
コード例 #8
0
ファイル: initFullScan.cs プロジェクト: AndreiBer/MSOM3
        public void start(string comment, Hardware.LaserSW.ViewModelBrightSolutions ondaLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }


            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = acquisitionParameters.PRR;
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                = acquisitionParameters.f_s;
            MWNumericArray inputRange         = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low              = acquisitionParameters.z_low;
            MWNumericArray z_target           = acquisitionParameters.z_target;
            MWNumericArray z_high             = acquisitionParameters.z_high;
            MWNumericArray v_x                = acquisitionParameters.v_x;
            MWNumericArray acc                = acquisitionParameters.acc;
            MWNumericArray acqDelay           = acquisitionParameters.acqDelay;
            MWNumericArray d_acc              = acquisitionParameters.d_acc;
            MWNumericArray acqRes             = acquisitionParameters.acqRes;
            MWArray        acqMode            = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel       = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength = acquisitionParameters.numberOfWavelength;


            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan = 0;

            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",    "x_0",                    "l_y",      "l_x",        "ds",
                                          "PRR",         "triggerWidth",           "f_s",      "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",         "acc",                    "acqDelay", "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "BscanUpdate", "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass obj = null;
                            obj = new iScanClass();
                            obj.iScan(fP, aP, dP, rP);
                        }
                        else
                        {
                            iScanClass_trig obj_trig = null;
                            obj_trig = new iScanClass_trig();
                            obj_trig.iScan_trig(fP, aP, dP, rP);
                        }
                        break;

                    case 2:     // Alazar
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_Alazar obj_Alazar = null;
                            obj_Alazar = new iScanClass_Alazar();
                            obj_Alazar.iScan_Alazar(fP, aP, dP, rP);
                        }
                        else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    if (systemState.LASERconnected == 1 || systemState.LASERconnected == 2)
                    {
                        // switch laser off and close connection
                        ondaLaser.EmissionOFF();
                        ondaLaser.closeConnection();
                        cancelAcq_Button.Click -= ondaLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (ondaLaser != null)
                {
                    try
                    {
                        ondaLaser.EmissionOFF();
                        ondaLaser.closeConnection();
                        cancelAcq_Button.Click -= ondaLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);

            //// write RSOMpreset xml-file
            //XDocument presetXML = new XDocument(
            //    new XElement("RSOMpreset",
            //        new XElement("laserSettings",
            //            new XElement("energy", acquisitionParameters.laserPower.ToString())
            //            )
            //        )
            //   );

            //presetXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            //string filenamePreset = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\iThera\\ViewRSOM\\RSOMpreset.xml";
            //presetXML.Save(@filenamePreset);
        }
コード例 #9
0
        private void Start_Click(object sender, EventArgs e)
        {
            //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_;
            // pictureBox2.Image.Dispose();
            // pictureBox2.Image = null;
            textBox1.Text = ("加载图片");
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBox1.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string str1 = file.FileName;

            //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范
            textBox1.Text = (str1);

            linktocsharpV6.Class1 v5c1 = new linktocsharpV6.Class1();
            //MWArray DiameterArray = v3c1.linktocsharpV3(str1);
            MWArray[] resultlist = new MWArray[2];
            resultlist = v5c1.linktocsharpV6(5, str1);                     //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数
            MWNumericArray DiameterArray  = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组
            MWNumericArray SandNumber     = (MWNumericArray)resultlist[1]; //沙尘个数
            MWNumericArray DiameterNumber = (MWNumericArray)resultlist[2]; //返回以50um为单位的粒径累加结果数组
            MWNumericArray xlength        = (MWNumericArray)resultlist[3]; //返回粒径累加结果数组长度
            MWNumericArray TypeNumber     = (MWNumericArray)resultlist[4]; //返回三种沙粒:石砾,粗沙粒,细沙粒个数数组

            textBox2.Text = SandNumber.ToString();
            double[,] DA  = new double[(int)SandNumber, 1]; //matlab函数返回值为二维数组,因此需要用二维数组接收
            DA            = (double[, ])DiameterArray.ToArray();
            double[,] DN  = new double[(int)xlength, 1];    //matlab函数返回值为二维数组,因此需要用二维数组接收
            DN            = (double[, ])DiameterNumber.ToArray();
            double[,] TN  = new double[3, 1];               //matlab函数返回值为二维数组,因此需要用二维数组接收
            TN            = (double[, ])TypeNumber.ToArray();
            //textBox3.Text = DA[(int)a2 - 1, 0].ToString();
            //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString();

            chart1.Series.Clear();
            ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Column, Color.Transparent, Color.Red, true);
            //   ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Spline, Color.Red, Color.Red);
            //   ChartHelper.SetTitle(chart1, "由小到大每一粒沙尘的粒径", new Font("微软雅黑", 8), Docking.Top, Color.Black);
            ChartHelper.SetStyle(chart1, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart1, "", "粒径(*50um)", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 0, 0);
            ChartHelper.SetMajorGrid(chart1, Color.Transparent, 20, 50);
            List <int> xData = new List <int>()
            {
            };
            int i, j;

            for (i = 1; i <= (int)SandNumber; i++)
            {
                xData.Add(i);
            }
            List <double> yData = new List <double>()
            {
            };

            for (j = 0; j <= (int)SandNumber - 1; j++)
            {
                yData.Add(DA[j, 0]);
            }
            chart1.Series[0].Points.DataBindXY(xData, yData);

            chart2.Series.Clear();
            ChartHelper.AddSeries(chart2, "该粒径范围内沙尘个数", SeriesChartType.Column, Color.Lime, Color.Blue, true);
            //      ChartHelper.AddSeries(chart2, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red);
            //      ChartHelper.SetTitle(chart2, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black);
            ChartHelper.SetStyle(chart2, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart2, "粒径(*50um)", "个数", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 4, (int)(DN[0, 0] / 10));
            ChartHelper.SetMajorGrid(chart2, Color.Transparent, 20, 2);
            List <int> xData2 = new List <int>()
            {
            };
            int i2, j2;

            for (i2 = 1; i2 <= (int)xlength; i2++)
            {
                xData2.Add(i2);
            }
            List <double> yData2 = new List <double>()
            {
            };

            for (j2 = 0; j2 <= (int)xlength - 1; j2++)
            {
                yData2.Add(DN[j2, 0]);
            }
            chart2.Series[0].Points.DataBindXY(xData2, yData2);

            chart3.Series.Clear();
            ChartHelper.AddSeries(chart3, "饼状图", SeriesChartType.Pie, Color.Lime, Color.Black, true);
            ChartHelper.SetStyle(chart3, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart3, Docking.Bottom, StringAlignment.Center, Color.Transparent, Color.Black);
            List <double> y1 = new List <double>()
            {
            };
            int j3;

            for (j3 = 0; j3 <= 2; j3++)
            {
                y1.Add(TN[j3, 0]);
            }
            string        t1    = String.Format("石砾(>1000㎛):         {0}个", TN[0, 0]);
            string        t2    = String.Format("粗沙粒(250-1000㎛):    {0}个", TN[1, 0]);
            string        t3    = String.Format("细沙粒(50-250㎛):      {0}个", TN[2, 0]);
            List <string> nameX = new List <string>()
            {
                t1, t2, t3
            };

            chart3.Series[0].Points.DataBindXY(nameX, y1);
            chart3.Series[0]["PieLabelStyle"] = "Outside"; //将文字移到外侧
            chart3.Series[0]["PieLineColor"]  = "Black";   //绘制黑色的连线。
            chart3.Series[0].Label            = "#PERCENT{P2}";

            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            Console.WriteLine("DateTime costed for this function is: {0}ms", ts.TotalMilliseconds);
        }
コード例 #10
0
ファイル: initFullScan.cs プロジェクト: AndreiBer/MSOM2
        public void startMulti(string comment, ViewRSOM.MSOT.Hardware.ViewModels.Laser.ViewModelLaserInnolas multiLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }
            //else
            //{
            //    Console.Write("WARNING: acquisition folder exists already. Proceed with reconstruction. Previous reconstructions may be overwritten.");
            //}
            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = acquisitionParameters.PRR;
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                    = acquisitionParameters.f_s;
            MWNumericArray inputRange             = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low                  = acquisitionParameters.z_low;
            MWNumericArray z_target               = acquisitionParameters.z_target;
            MWNumericArray z_high                 = acquisitionParameters.z_high;
            MWNumericArray v_x                    = acquisitionParameters.v_x;
            MWNumericArray acc                    = acquisitionParameters.acc;
            MWNumericArray acqDelay               = acquisitionParameters.acqDelay;
            MWNumericArray d_acc                  = acquisitionParameters.d_acc;
            MWNumericArray acqRes                 = acquisitionParameters.acqRes;
            MWArray        acqMode                = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel           = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength     = acquisitionParameters.numberOfWavelength;
            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan              = 0;

            //get number of wavelength from comment box
            if (!string.IsNullOrEmpty(comment))
            {
                char[]   delimiterChars = { ' ', ',', '.', ':', ';', '\t' };
                string[] tokens         = comment.Split(delimiterChars);
                int[]    convertedItems = Array.ConvertAll <string, int>(tokens, int.Parse);
                numberOfWavelength = convertedItems.Length;
                //Console.WriteLine(convertedItems);
            }
            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",    "x_0",                    "l_y",      "l_x",        "ds",
                                          "PRR",         "triggerWidth",           "f_s",      "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",         "acc",                    "acqDelay", "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "BscanUpdate", "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                //if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                if (systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage

                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_OPO obj = null;
                            obj = new iScanClass_OPO();
                            obj.iScan_dual(fP, aP, dP, rP);
                        }
                        else
                        {
                            iScanClass_trig obj_trig = null;
                            obj_trig = new iScanClass_trig();
                            obj_trig.iScan_trig(fP, aP, dP, rP);
                        }
                        break;

                    case 2:     // Alazar
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_Alazar obj_Alazar = null;
                            obj_Alazar = new iScanClass_Alazar();
                            obj_Alazar.iScan_Alazar(fP, aP, dP, rP);
                        }
                        else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    //if (systemState.LASERconnected == 1 || systemState.LASERconnected == 2)
                    {
                        // switch laser off and close connection
                        multiLaser.q_switch(false);

                        multiLaser.lamp(false);
                        //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (multiLaser != null)
                {
                    try
                    {
                        multiLaser.q_switch(false);
                        multiLaser.lamp(false);
                        //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);
        }
コード例 #11
0
ファイル: search.cs プロジェクト: AjithaRaj/cbir
        /// <summary>
        /// Finds an image that matches the example image
        /// </summary>
        /// <param name="ExampleImagePath">The path of the example image</param>
        /// <param name="DBC">The controller through which the search will be done</param>
        public List <string[]> SearchByExample(string ExampleImagePath, databaseController DBC, double Max, double Min)
        {
            try
            {
                List <string[]> res = new List <string[]>();

                //Get the features of the example image
                featureExtractor fe = new featureExtractor(ExampleImagePath);
                List <Feature>   fv = fe.AllFeatures();

                double area    = fv[fv.Count - 1].FeatureValue * fv[fv.Count - 2].FeatureValue;
                double MaxArea = area * Max;
                double MinArea = area * Min;

                fv.RemoveAt(fv.Count - 1);
                fv.RemoveAt(fv.Count - 1);
                fv.RemoveAt(fv.Count - 1);
                fv.RemoveAt(fv.Count - 1);

                //Example color features
                double[] exCF = new double[4];
                for (int i = 0; i < 4; i++)
                {
                    exCF[i] = fv[i].FeatureValue;
                }

                //Example shape features
                double[] exSF = new double[7];
                for (int i = 4; i < 11; i++)
                {
                    exSF[i - 4] = fv[i].FeatureValue;
                }

                //Example texture features
                double[] exTF = new double[24];
                for (int i = 11; i < 35; i++)
                {
                    exTF[i - 11] = fv[i].FeatureValue;
                }

                //Example edge features
                double[] exEF = new double[37];
                for (int i = 35; i < 72; i++)
                {
                    exEF[i - 35] = fv[i].FeatureValue;
                }

                //Calculate similarities between example image and images in the database
                FeatureExtractorclass fec = new FeatureExtractorclass();
                MWArray mwXCF             = new MWNumericArray(exCF.Length, 1, exCF);
                MWArray mwXSF             = new MWNumericArray(exSF.Length, 1, exSF);
                MWArray mwXTF             = new MWNumericArray(exTF.Length, 1, exTF);
                MWArray mwXEF             = new MWNumericArray(exEF.Length, 1, exEF);

                DBC.CommandText = "SELECT * FROM FeaturesVector where (CropH*CropW >=" + MinArea.ToString() + ") AND (CropH*CropW <=" + MaxArea.ToString() + ");";
                DataSet ds = DBC.ExecuteQuery();
                if (ds.Tables[0].Rows.Count < 1)
                {
                    throw new Exception("The database is empty or there are no matches!");
                }

                //Calculate similiraties for each group of feature . . .
                List <Result> ColorSimilarties   = new List <Result>();
                List <Result> ShapeSimilarties   = new List <Result>();
                List <Result> TextureSimilarties = new List <Result>();
                List <Result> EdgeSimilarties    = new List <Result>();

                double[] Cfrow;
                double[] Sfrow;
                double[] Tfrow;
                double[] Efrow;

                MWArray mwRes = new MWNumericArray(1);
                MWArray mwCC;   //Color features for current image
                MWArray mwCS;   //Shape features for current image
                MWArray mwCT;   //Texture features for current image
                MWArray mwCE;   //Edge features for current image

                for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                {
                    int ID = int.Parse(ds.Tables[0].Rows[j].ItemArray[0].ToString());

                    //Current image color features
                    Cfrow = new double[4];
                    for (int i = 1; i < 5; i++)
                    {
                        Cfrow[i - 1] = double.Parse(ds.Tables[0].Rows[j].ItemArray[i].ToString());
                    }
                    mwCC  = new MWNumericArray(Cfrow.Length, 1, Cfrow);
                    mwRes = fec.minkowski(mwXCF, mwCC, 4);

                    double Distance = double.Parse(mwRes.ToString());
                    Result sim      = new Result(ID, Distance);
                    ColorSimilarties.Add(sim);

                    //Current image shape features
                    Sfrow = new double[7];
                    for (int i = 5; i < 12; i++)
                    {
                        Sfrow[i - 5] = double.Parse(ds.Tables[0].Rows[j].ItemArray[i].ToString());
                    }
                    mwCS  = new MWNumericArray(Sfrow.Length, 1, Sfrow);
                    mwRes = fec.minkowski(mwXSF, mwCS, 4);

                    Distance = double.Parse(mwRes.ToString());
                    sim      = new Result(ID, Distance);
                    ShapeSimilarties.Add(sim);

                    //Current image texture features
                    Tfrow = new double[24];
                    for (int i = 12; i < 36; i++)
                    {
                        Tfrow[i - 12] = double.Parse(ds.Tables[0].Rows[j].ItemArray[i].ToString());
                    }
                    mwCT  = new MWNumericArray(Tfrow.Length, 1, Tfrow);
                    mwRes = fec.minkowski(mwXTF, mwCT, 4);

                    Distance = double.Parse(mwRes.ToString());
                    sim      = new Result(ID, Distance);
                    TextureSimilarties.Add(sim);

                    //Current image edge features
                    Efrow = new double[37];
                    for (int i = 36; i < 73; i++)
                    {
                        Efrow[i - 36] = double.Parse(ds.Tables[0].Rows[j].ItemArray[i].ToString());
                    }
                    mwCE  = new MWNumericArray(Efrow.Length, 1, Efrow);
                    mwRes = fec.minkowski(mwXEF, mwCE, 4);

                    Distance = double.Parse(mwRes.ToString());
                    sim      = new Result(ID, Distance);
                    EdgeSimilarties.Add(sim);
                }

                ShapeSimilarties = sortList(ShapeSimilarties);

                double resAvg = ListAverag(ShapeSimilarties);
                while (ShapeSimilarties[ShapeSimilarties.Count - 1].Distance > resAvg)
                {
                    Result R = ShapeSimilarties[ShapeSimilarties.Count - 1];
                    ShapeSimilarties.RemoveAt(ShapeSimilarties.Count - 1);
                    for (int r = 0; r < EdgeSimilarties.Count; r++)
                    {
                        if (EdgeSimilarties[r].ID == R.ID)
                        {
                            EdgeSimilarties.RemoveAt(r);
                            TextureSimilarties.RemoveAt(r);
                            ColorSimilarties.RemoveAt(r);
                            break;
                        }
                    }
                }

                EdgeSimilarties = sortList(EdgeSimilarties);

                resAvg = ListAverag(EdgeSimilarties);
                while (EdgeSimilarties[EdgeSimilarties.Count - 1].Distance > resAvg)
                {
                    Result R = EdgeSimilarties[EdgeSimilarties.Count - 1];
                    EdgeSimilarties.RemoveAt(EdgeSimilarties.Count - 1);
                    for (int r = 0; r < TextureSimilarties.Count; r++)
                    {
                        if (TextureSimilarties[r].ID == R.ID)
                        {
                            TextureSimilarties.RemoveAt(r);
                            ColorSimilarties.RemoveAt(r);
                            break;
                        }
                    }
                }

                TextureSimilarties = sortList(TextureSimilarties);

                resAvg = ListAverag(TextureSimilarties);
                while (TextureSimilarties[TextureSimilarties.Count - 1].Distance > resAvg)
                {
                    Result R = TextureSimilarties[TextureSimilarties.Count - 1];
                    TextureSimilarties.RemoveAt(TextureSimilarties.Count - 1);
                    for (int r = 0; r < ColorSimilarties.Count; r++)
                    {
                        if (ColorSimilarties[r].ID == R.ID)
                        {
                            ColorSimilarties.RemoveAt(r);
                            break;
                        }
                    }
                }

                ColorSimilarties = sortList(ColorSimilarties);

                resAvg = ListAverag(ColorSimilarties);
                while (ColorSimilarties[ColorSimilarties.Count - 1].Distance > resAvg)
                {
                    ColorSimilarties.RemoveAt(ColorSimilarties.Count - 1);
                }

                List <Result> similarties = ColorSimilarties;

                //Ranking :
                double   farestImg = (double)similarties[similarties.Count - 1].Distance; //The worst match.
                double   rank      = 0;
                string[] resStr;

                for (int i = 0; i < similarties.Count; i++)
                {
                    resStr = new string[4];
                    int x = similarties[i].ID;

                    DBC.CommandText  = "SELECT I.FileName, S.FolderPath ";
                    DBC.CommandText += "FROM Image AS I INNER JOIN Series AS S ON FLOOR(I.ImageID / 100) = S.SID ";
                    DBC.CommandText += "WHERE (I.ImageID = " + x + ")";

                    ds        = DBC.ExecuteQuery();
                    rank      = (1 - ((double)similarties[i].Distance / farestImg)) * 100;
                    rank      = Math.Round(rank, 5);
                    resStr[0] = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                    resStr[1] = ds.Tables[0].Rows[0].ItemArray[1].ToString();
                    resStr[2] = " - " + rank.ToString() + "%";
                    resStr[3] = x.ToString();
                    res.Add(resStr);
                    resStr = null;
                }
                return(res);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #12
0
        private void Start_Click(object sender, EventArgs e)
        {
            //pictureBox2.Image = SandDiameterMeasuring.Properties.Resources.屏幕截图_1654_;
            // pictureBox2.Image.Dispose();
            // pictureBox2.Image = null;
            textBox1.Text = ("加载图片");
            OpenFileDialog file = new OpenFileDialog();

            file.InitialDirectory = ".";
            file.Filter           = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBox1.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            string str1 = file.FileName;

            //str1 = "'" + str1 + "'";//加单引号为符合matlab输入规范
            textBox1.Text = (str1);
            //textBox1.Text = (file.FileName);
            DiameterCalculation.Class1 c1 = new DiameterCalculation.Class1();
            //Object sandNumber;
            MWArray        a1 = c1.linktocsharp(str1);
            MWNumericArray a2 = (MWNumericArray)a1;

            textBox2.Text = a2.ToString();

            linktocsharpV5.Class1 v5c1 = new linktocsharpV5.Class1();
            //MWArray DiameterArray = v3c1.linktocsharpV3(str1);
            MWArray[] resultlist = new MWArray[2];
            resultlist = v5c1.linktocsharpV5(4, str1);                     //重要!!!m函数有多个返回值时在第一个参数里写入返回值个数,第二个参数才是输入m函数的第一个输入参数
            MWNumericArray DiameterArray  = (MWNumericArray)resultlist[0]; //返回每一粒沙子的直径数组,为n行1列的二维数组
            MWNumericArray SandNumber     = (MWNumericArray)resultlist[1]; //沙尘个数
            MWNumericArray DiameterNumber = (MWNumericArray)resultlist[2]; //返回以50um为单位的粒径累加结果数组
            MWNumericArray xlength        = (MWNumericArray)resultlist[3]; //返回以50um为单位的粒径累加结果数组

            double[,] DA = new double[(int)SandNumber, 1];                 //matlab函数返回值为二维数组,因此需要用二维数组接收
            DA           = (double[, ])DiameterArray.ToArray();
            double[,] DN = new double[(int)xlength, 1];                    //matlab函数返回值为二维数组,因此需要用二维数组接收
            DN           = (double[, ])DiameterNumber.ToArray();
            //textBox3.Text = DA[(int)a2 - 1, 0].ToString();
            //textBox3.Text = DA[(int)SandNumber - 1, 0].ToString();

            chart1.Series.Clear();
            ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Column, Color.Transparent, Color.Red, true);
            //   ChartHelper.AddSeries(chart1, "由小到大每一粒沙尘的粒径", SeriesChartType.Spline, Color.Red, Color.Red);
            //   ChartHelper.SetTitle(chart1, "由小到大每一粒沙尘的粒径", new Font("微软雅黑", 8), Docking.Top, Color.Black);
            ChartHelper.SetStyle(chart1, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart1, "", "粒径(*50um)", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 0, 0);
            ChartHelper.SetMajorGrid(chart1, Color.Transparent, 20, 50);
            List <int> xData = new List <int>()
            {
            };
            int i, j;

            for (i = 1; i <= (int)SandNumber; i++)
            {
                xData.Add(i);
            }
            List <double> yData = new List <double>()
            {
            };

            for (j = 0; j <= (int)SandNumber - 1; j++)
            {
                yData.Add(DA[j, 0]);
            }
            chart1.Series[0].Points.DataBindXY(xData, yData);

            chart2.Series.Clear();
            ChartHelper.AddSeries(chart2, "该粒径范围内沙尘个数", SeriesChartType.Column, Color.Lime, Color.Blue, true);
            //      ChartHelper.AddSeries(chart2, "曲线图", SeriesChartType.Spline, Color.Red, Color.Red);
            //      ChartHelper.SetTitle(chart2, "柱状图与曲线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black);
            ChartHelper.SetStyle(chart2, Color.Transparent, Color.Black);
            ChartHelper.SetLegend(chart2, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
            ChartHelper.SetXY(chart2, "粒径(*50um)", "个数", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.SharpTriangle, 4, (int)(DN[0, 0] / 10));
            ChartHelper.SetMajorGrid(chart2, Color.Transparent, 20, 2);
            List <int> xData2 = new List <int>()
            {
            };
            int i2, j2;

            for (i2 = 1; i2 <= (int)xlength; i2++)
            {
                xData2.Add(i2);
            }
            List <double> yData2 = new List <double>()
            {
            };

            for (j2 = 0; j2 <= (int)xlength - 1; j2++)
            {
                yData2.Add(DN[j2, 0]);
            }
            chart2.Series[0].Points.DataBindXY(xData2, yData2);


            //textBox2.Text = (sandNumber.ToString);
            string pathname2;

            pathname2 = "D:\\op\\tempresult.png";  //获得文件的绝对路径
            //this.pictureBox2.Load(pathname2);//load貌似过时了?
            // this.pictureBox2.Image = Image.FromFile(pathname2);
            //    pictureBox2.Image.Dispose();
            FileStream pFileStream = new FileStream(pathname2, FileMode.Open, FileAccess.Read);

            pictureBox2.Image = Image.FromStream(pFileStream);
            pFileStream.Close();
            pFileStream.Dispose();
        }