Ejemplo n.º 1
0
        public SpectrCalc(MethodSimple ms, int el_index, int formula_index)
        {
            MethodSimpleElement mse = ms.GetElHeader(el_index);

            Formula = mse.Formula[formula_index];
            double ly   = (double)Formula.Formula.analitParamCalc.methodLineCalc1.nmLy.Value;
            bool   next = Formula.Formula.analitParamCalc.methodLineCalc1.cbFromSnNum.SelectedIndex == 1;

            int pr_count = ms.GetProbCount();

            for (int pr = 0; pr < pr_count; pr++)
            {
                List <Data>      prob_data = new List <SpectrCalc.Data>();
                MethodSimpleProb msp       = ms.GetProbHeader(pr);
                int sp_count = msp.MeasuredSpectrs.Count;
                for (int sp = 0; sp < sp_count; sp++)
                {
                    MethodSimpleCell msc = ms.GetCell(el_index, pr);
                    MethodSimpleCellFormulaResult mscfr = msc.GetData(sp, formula_index);
                    MethodSimpleProbMeasuring     mspm  = msp.MeasuredSpectrs[sp];
                    if (mscfr.Enabled)
                    {
                        prob_data.Add(new Data(mspm.Sp, (float)msc.Con, ly, next));
                    }
                }
                DataSet.Add(prob_data);
            }
        }
Ejemplo n.º 2
0
        private void btSetLy_Click(object sender, EventArgs e)
        {
            try
            {
                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                double ly1 = msef.Formula.Founds[chFixList.SelectedIndex].Ly1;
                int    sn1 = msef.Formula.Founds[chFixList.SelectedIndex].Sn1;
                double ly2 = msef.Formula.Founds[chFixList.SelectedIndex].Ly2;
                int    sn2 = msef.Formula.Founds[chFixList.SelectedIndex].Sn1;
                if (PrCorels[0] > 0)
                {
                    msef.Formula.analitParamCalcServ.methodLineCalc1.nmLy.Value = (decimal)ly1;
                    msef.Formula.analitParamCalcServ.methodLineCalc2.nmLy.Value = (decimal)ly2;
                }
                else
                {
                    msef.Formula.analitParamCalcServ.methodLineCalc2.nmLy.Value = (decimal)ly1;
                    msef.Formula.analitParamCalcServ.methodLineCalc1.nmLy.Value = (decimal)ly2;
                }

                Close();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Ejemplo n.º 3
0
        private void btnUseThis_Click(object sender, EventArgs e)
        {
            try
            {
                if (listLines.SelectedIndex < 0)
                {
                    return;
                }

                //Method.GetElHeader(Element).Formula[Formula]
                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                double ly1 = Calibrations[listLines.SelectedIndex].Ly1;
                double ly2 = Calibrations[listLines.SelectedIndex].Ly2;

                if (sender == btnUseThis)
                {
                    msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value = (decimal)ly1;
                    msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value = (decimal)ly2;
                }
                else
                {
                    msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value = (decimal)ly2;
                    msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value = (decimal)ly1;
                }

                msef.Formula.analitParamCalc.methodLineCalc1.cbMaximumType.SelectedIndex = 1;
                msef.Formula.analitParamCalc.methodLineCalc2.cbMaximumType.SelectedIndex = 1;
                msef.Formula.analitParamCalc.methodLineCalc1.SetupLy();
                msef.Formula.analitParamCalc.methodLineCalc2.SetupLy();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Ejemplo n.º 4
0
        void InitList()
        {
            MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];

            chFixList.Items.Clear();
            for (int i = 0; i < msef.Formula.Founds.Count; i++)
            {
                chFixList.Items.Add(msef.Formula.Founds[i].ToString());
            }
        }
Ejemplo n.º 5
0
        public static List <MethodData> getData(MethodSimple method, int element, int formula, bool use_all, out int used)
        {
            MethodSimpleElementFormula msef = method.GetElHeader(element).Formula[formula];

            bool[]            used_frames = msef.Formula.GetUsedFrames();
            List <MethodData> ret         = new List <MethodData>();
            int prob_count = method.GetProbCount();

            used = 0;
            for (int pr = 0; pr < prob_count; pr++)
            {
                MethodSimpleProb m_prob = method.GetProbHeader(pr);
                MethodSimpleCell m_cell = method.GetCell(element, pr);
                double           con    = m_cell.Con;
                if (con < 0)
                {
                    continue;
                }
                int sub_prob_count = method.GetSubProbCount(pr);
                for (int sub_pr = 0; sub_pr < sub_prob_count; sub_pr++)
                {
                    MethodSimpleProbMeasuring m_prob_measuring = m_prob.MeasuredSpectrs[sub_pr];
                    Spectr sp = m_prob_measuring.Sp;
                    if (sp == null)
                    {
                        continue;
                    }
                    bool en = m_cell.GetData(sub_pr, formula).Enabled;
                    if (use_all == true)
                    {
                        en = true;
                    }
                    int   short_count = sp.GetShotCount();
                    int[] shorts      = sp.GetShotIndexes();
                    for (int short_index = 0; short_index < shorts.Length; short_index++)
                    {
                        bool fl = en & used_frames[short_index];
                        if (fl)
                        {
                            used++;
                        }
                        MethodData md = new MethodData(con, fl, pr, sub_pr, short_index,
                                                       sp.GetViewsSet()[shorts[short_index]],
                                                       sp.GetNullFor(shorts[short_index]), sp.GetCommonDispers());
                        ret.Add(md);
                    }
                }
            }
            if (ret.Count == 0)
            {
                return(null);
            }
            return(ret);
        }
Ejemplo n.º 6
0
        public void ShowSearchDlg(TaskMethodSimple tms, MethodSimpleElementFormula formula,
                                  MethodSimple method, SpectrView spv, string element_name, int el_index, int sel_col)
        {
            ElementIndex = el_index;
            ElementName  = element_name;
            TMS          = tms;
            Method       = method;
            Formula      = formula;
            Spv          = spv;
            SelectedCol  = sel_col;
            Sp           = spv.GetSpectr(0);
            if (Sp == null)
            {
                MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Необходимо выбрать спектры по котором будет производится привязка к профилю..."),
                                Common.MLS.Get(MLSConst, "Предупреждение"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            btSearchStart.Text = Common.MLS.Get(MLSConst, MLSStartButtonText);
            Saved = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(Saved);

            try
            {
                Formula.Save(bw);
            }
            catch (Exception ex)
            {
                Common.LogNoMsg(ex);
                MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Нельзя подбирать линии для незаконченной формулы..."),
                                Common.MLS.Get(MLSConst, "Предупреждение"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (Formula.Formula.SeachBuffer != null)
            {
                MemoryStream ms  = new MemoryStream(Formula.Formula.SeachBuffer);
                BinaryReader br  = new BinaryReader(ms);
                int          ver = br.ReadInt32();
                if (ver == 1)
                {
                    int size = br.ReadInt32();
                    for (int i = 0; i < size; i++)
                    {
                        Results.Add(new CalcResult(br));
                    }
                    br.Close();
                    ReloadResultList();
                }
            }

            this.ShowDialog(MainForm.MForm);
        }
Ejemplo n.º 7
0
 public StandartHistryRecord(MethodSimpleElement mse, int formula,
                             MethodSimpleElementFormula msef,
                             MethodSimpleCellFormulaResult mscfr,
                             DateTime measured)
 {
     Time        = new DateTime(DateTime.Now.Ticks);
     Element     = mse.Element.Name;
     Formula     = formula;
     FormulaName = msef.Name;
     LogData     = mscfr.LogData;
     Cons        = mscfr.ReCalcCon;
     Time        = new DateTime(measured.Ticks);
 }
Ejemplo n.º 8
0
 private void buttonSetInMethod_Click(object sender, EventArgs e)
 {
     try
     {
         Result res = Candidates[listboxResult.SelectedIndex];
         MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
         msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value = (decimal)res.ALy;
         msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value = (decimal)res.CLy;
         Hide();
     }
     catch (Exception ex)
     {
         Log.Out(ex);
     }
 }
Ejemplo n.º 9
0
 private void chFixList_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (chFixList.SelectedIndex < 0)
         {
             return;
         }
         MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
         msef.Formula.Founds[chFixList.SelectedIndex].InitData(this);
         pGraph.Refresh();
         panel4.Refresh();
     }
     catch (Exception ex)
     {
         Common.Log(ex);
     }
 }
Ejemplo n.º 10
0
        public void Init(MethodSimple ms, int element, int formula)
        {
            Method       = ms;
            this.Element = element;
            Formula      = formula;

            Element[] elist = ms.GetElementList();

            MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];

            LyFrom = Common.Env.DefaultDisp.GetLyByLocalPixel(0, 10);
            int[] sizes = Common.Env.DefaultDisp.GetSensorSizes();
            LyTo = Common.Env.DefaultDisp.GetLyByLocalPixel(sizes.Length - 1, sizes[sizes.Length - 1] - 10);

            candidateLineListAnalit.init(elist[element].Name, formula, ms, true,
                                         Convert.ToDouble(msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value), LyFrom, LyTo);
            candidateLineListComp.init(null, formula, ms, false,
                                       Convert.ToDouble(msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value), LyFrom, LyTo);
        }
Ejemplo n.º 11
0
        public void Add(MethodSimple method, int prob, int sub_prob)
        {
            DateTime now = DateTime.Now;

            Element[]        elem = method.GetElementList();
            MethodSimpleProb msp  = method.GetProbHeader(prob);

            for (int el = 0; el < elem.Length; el++)
            {
                MethodSimpleCell    cell = method.GetCell(el, prob);
                MethodSimpleElement mse  = method.GetElHeader(el);
                for (int f = 0; f < mse.Formula.Count; f++)
                {
                    MethodSimpleElementFormula    formula = mse.Formula[f];
                    MethodSimpleCellFormulaResult mscfr   = cell.GetData(sub_prob, f);
                    Records.Add(new StandartHistryRecord(mse, f, formula, mscfr, now));
                }
            }
            Save();
        }
Ejemplo n.º 12
0
        static public List <DataShot> extract(MethodSimple method, string element, int formula,
                                              double ly, int widthPlusMinus, bool useConDlt,
                                              double min, double max, bool relative)
        {
            int             mul_k   = (int)Common.Conf.MultFactor;
            int             is_ok   = 0;
            int             is_over = 0;
            List <DataShot> ret     = new List <DataShot>();

            Element[] list = method.GetElementList();
            for (int el = 0; el < list.Length; el++)
            {
                if (list[el].Name.Equals(element) || element == null)
                {
                    MethodSimpleElementFormula calcFormula = method.GetElHeader(el).Formula[formula];
                    bool[] frames = calcFormula.Formula.GetUsedFrames();
                    for (int prob_index = 0; prob_index < method.GetProbCount(); prob_index++)
                    {
                        MethodSimpleProb prob = method.GetProbHeader(prob_index);
                        MethodSimpleCell msc  = method.GetCell(el, prob_index);
                        if (useConDlt == false)
                        {
                            double fkVal = msc.Con;
                            double con   = fkVal;

                            /*if (useConDlt)
                             * {
                             *  double sko, sko1;
                             *  double rcon = //msc.CalcRealCon(out sko, out sko1);
                             *  fkVal -= rcon;
                             * }//*/
                            for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++)
                            {
                                MethodSimpleCellFormulaResult mscfr = msc.GetData(measuring_index, formula);
                                if (mscfr.Enabled == false)
                                {
                                    continue;
                                }
                                MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index];
                                Spectr sp = mspm.Sp;
                                if (sp == null)
                                {
                                    continue;
                                }
                                List <SpectrDataView> viewSet = sp.GetViewsSet();
                                int[]      shotIndexes        = sp.GetShotIndexes();
                                Dispers    disp    = sp.GetCommonDispers();
                                List <int> sensors = disp.FindSensors(ly);
                                bool       isEnabled;
                                if (con >= 0)
                                {
                                    isEnabled = msc.Enabled;
                                }
                                else
                                {
                                    isEnabled = false;
                                }
                                for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++)
                                {
                                    if (frames[shot_index] == false)
                                    {
                                        continue;
                                    }
                                    SpectrDataView sig = viewSet[shotIndexes[shot_index]];
                                    SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]);
                                    for (int sn = 0; sn < 1 && sn < sensors.Count; sn++)
                                    {
                                        int     sensorIndex = sensors[sn];
                                        int     n           = (int)disp.GetLocalPixelByLy(sensorIndex, ly);
                                        float[] sigData     = sig.GetSensorData(sensorIndex);
                                        float[] nulData     = nul.GetSensorData(sensorIndex);
                                        float   minSignal   = float.MaxValue;
                                        float[] signal      = new float[sigData.Length];
                                        for (int i = 0; i < signal.Length; i++)
                                        {
                                            signal[i] = sigData[i] - nulData[i];
                                        }
                                        for (int i = 500; i < sigData.Length - 500; i++)
                                        {
                                            float val = (signal[i - 1] + signal[i] + signal[i + 1]) / 3;
                                            if (val < minSignal)
                                            {
                                                minSignal = val;
                                            }
                                        }

                                        float[] data      = new float[widthPlusMinus * 2 + 1];
                                        double  maxSignal = -double.MaxValue;
                                        for (int i = 0; i < data.Length; i++)
                                        {
                                            int index = n - widthPlusMinus + i;
                                            if (index < 0 || index >= sigData.Length)
                                            {
                                                data[i]   = -float.MaxValue;
                                                isEnabled = false;
                                                continue;
                                            }
                                            data[i] = signal[index];//sigData[index] - nulData[index];
                                            if (data[i] > max)
                                            {
                                                isEnabled = false;
                                            }
                                            if (data[i] > maxSignal && i > widthPlusMinus - 4 && i < widthPlusMinus + 4)
                                            {
                                                maxSignal = data[i];
                                            }
                                        }
                                        if (maxSignal < min)
                                        {
                                            isEnabled = false;
                                        }
                                        if (isEnabled)
                                        {
                                            is_ok++;
                                        }
                                        else
                                        {
                                            is_over++;
                                        }
                                        DataShot dsh = new DataShot(ly, fkVal, data, isEnabled);
                                        ret.Add(dsh);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++)
                            {
                                MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index];
                                Spectr sp = mspm.Sp;
                                if (sp == null)
                                {
                                    continue;
                                }
                                List <SpectrDataView> viewSet = sp.GetViewsSet();
                                int[]      shotIndexes        = sp.GetShotIndexes();
                                Dispers    disp    = sp.GetCommonDispers();
                                List <int> sensors = disp.FindSensors(ly);
                                bool       isEnabled;
                                if (msc.Con >= 0)
                                {
                                    isEnabled = msc.Enabled;
                                }
                                else
                                {
                                    isEnabled = false;
                                }
                                MethodSimpleCellFormulaResult result = msc.GetData(measuring_index, formula);
                                int data_index = 0;
                                for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++)
                                {
                                    if (frames[shot_index] == false)
                                    {
                                        continue;
                                    }
                                    double tmpAnalit = result.AnalitValue[data_index];
                                    double fkVal;
                                    if (relative == false)
                                    {
                                        fkVal = calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con;
                                    }
                                    else
                                    {
                                        if (msc.Con > 0.01)
                                        {
                                            fkVal = (calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con) / msc.Con;
                                        }
                                        else
                                        {
                                            fkVal = Double.NaN;
                                        }
                                    }
                                    SpectrDataView sig = viewSet[shotIndexes[shot_index]];
                                    SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]);
                                    for (int sn = 0; sn < sensors.Count; sn++)
                                    {
                                        int     sensorIndex = sensors[sn];
                                        int     n           = (int)disp.GetLocalPixelByLy(sensorIndex, ly);
                                        float[] sigData     = sig.GetSensorData(sensorIndex);
                                        float[] nulData     = nul.GetSensorData(sensorIndex);

                                        float[] data = new float[widthPlusMinus * 2 + 1];
                                        for (int i = 0; i < data.Length; i++)
                                        {
                                            int index = n - widthPlusMinus + i;
                                            if (index < 0 || index >= sigData.Length)
                                            {
                                                data[i]   = -float.MaxValue;
                                                isEnabled = false;
                                                continue;
                                            }
                                            data[i] = sigData[index] - nulData[index];
                                            if (data[i] > max)
                                            {
                                                isEnabled = false;
                                            }
                                        }
                                        if (isEnabled)
                                        {
                                            is_ok++;
                                        }
                                        else
                                        {
                                            is_over++;
                                        }
                                        DataShot dsh = new DataShot(ly, fkVal, data, isEnabled);
                                        ret.Add(dsh);
                                    }
                                    data_index++;
                                }
                            }
                        }
                    }
                    break;
                }
            }
            if (is_ok == 0 || is_over / is_ok > 0.1)
            {
                return(null);
            }
            return(ret);
        }
Ejemplo n.º 13
0
        private void SearchThread()
        {
            try
            {
                Lines        = new List <SpectrFunctions.LineInfo>();
                Calibrations = new List <Calibrator>();

                panel1.Enabled  = false;
                btnStop.Enabled = true;

                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                msef.Formula.Founds.Clear();
                msef.Formula.Pairs.Clear();

                Cons = DataExtractor.getData(Method, Element, Formula);
                if (Th != null && Cons != null)
                {
                    Log("Загруженно " + Cons.Count + " прожигов.");
                    int sn_count = Cons[0].DataMinusNull.Length;

                    for (int sn = 0; sn < sn_count && Th != null; sn++)
                    {
                        SpectrFunctions.LineInfo candidat = new SpectrFunctions.LineInfo(sn, Cons);
                        Dispers disp = Cons[0].Disp;
                        int     l    = Cons[0].DataMinusNull[sn].Length;
                        for (int p = 10; p < l - 10 && Th != null; p++)
                        {
                            double ly      = disp.GetLyByLocalPixel(sn, p);
                            bool   found   = false;
                            double real_ly = 0;
                            for (int sp = 0; sp < Cons.Count && Th != null; sp++)
                            {
                                try
                                {
                                    int pixel = (int)Cons[sp].Disp.GetLocalPixelByLy(sn, ly);
                                    candidat.Values[sp] = SpectrFunctions.CheckLine(ref pixel, Cons[sp].DataMinusNull[sn],
                                                                                    (int)numSearchMax.Value, (int)numMaxValue.Value, (int)numMinWidth.Value, (int)numMinValue.Value,
                                                                                    ref candidat.Profile[sp]);
                                    if (candidat.Values[sp] <= 0)
                                    {
                                        found = false;
                                        break;
                                    }
                                    else
                                    {
                                        real_ly += Cons[sp].Disp.GetLyByLocalPixel(sn, pixel);
                                        found    = true;
                                    }
                                    candidat.DLy = Math.Abs(Cons[sp].Disp.GetLyByLocalPixel(sn, pixel + 1) - Cons[sp].Disp.GetLyByLocalPixel(sn, pixel));
                                }
                                catch (Exception ex)
                                {
                                    found = false;
                                }
                            }
                            if (found == true)
                            {
                                candidat.Ly = (float)(real_ly / Cons.Count);
                                Lines.Add(candidat);
                                candidat = new SpectrFunctions.LineInfo(sn, Cons);
                                p       += (int)numSearchMax.Value;
                            }
                        }
                    }
                    Log("Найдено " + Lines.Count + " линий.");

                    int analitic_count = 0;
                    //int element = Method.GetElHeader(Element).Element.Num-1;
                    String element_name = Method.GetElHeader(Element).Element.Name;
                    for (int l = 0; l < Lines.Count; l++)
                    {
                        if (chbAllLinesAnalize.Checked == false)
                        {
                            double ly = Lines[l].Ly;
                            for (int i = 0; i < Common.LDb.Data.Count; i++)
                            {
                                String name = Common.LDb.Data[i].ElementName;
                                if (name.Equals(element_name) && Math.Abs(Common.LDb.Data[i].Ly - ly) < Lines[l].DLy * 3)
                                {
                                    Lines[l].HasLine = true;
                                    analitic_count++;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Lines[l].HasLine = true;
                        }
                    }
                    Log("Из них " + analitic_count + " могут быть аналитическими.");

                    cboxLyList.Items.Clear();
                    for (int i = 0; i < Lines.Count; i++)
                    {
                        String str = "" + Lines[i].Ly + ":" + Lines[i].Sn;
                        if (Lines[i].HasLine)
                        {
                            str += "   A";
                        }
                        cboxLyList.Items.Add(str);
                    }
                    long out_time = DateTime.Now.Ticks;
                    for (int l1 = 0; l1 < Lines.Count && Th != null; l1++)
                    {
                        if (Lines[l1].HasLine == false)
                        {
                            continue;
                        }
                        for (int l2 = 0; l2 < Lines.Count && Th != null; l2++)
                        {
                            if (l1 == l2 || chbAtTheSameSensor.Checked && Lines[l1].Sn != Lines[l2].Sn)
                            {
                                continue;
                            }

                            Calibrator cal = new Calibrator(Lines[l1], Lines[l2], Cons);
                            cal.ReCalc();
                            for (int i = 0; i < Calibrations.Count; i++)
                            {
                                if (cal.SKO < Calibrations[i].SKO)
                                {
                                    Calibrations.Insert(i, cal);
                                    cal = null;
                                    break;
                                }
                            }

                            if (cal != null)
                            {
                                Calibrations.Add(cal);
                            }

                            while (Calibrations.Count > 1000)
                            {
                                Calibrations.RemoveAt(Calibrations.Count - 1);
                            }

                            if (DateTime.Now.Ticks - out_time > 10000000)
                            {
                                LogTmp("Найлучшее СКО: " + Calibrations[0].SKO + "%.");
                                out_time = DateTime.Now.Ticks;
                            }
                        }
                    }
                    if (Calibrations.Count > 0)
                    {
                        Log("Найлучшее СКО: " + Calibrations[0].SKO + "%.");
                    }
                    else
                    {
                        Log("Не найдено отношений...");
                    }
                }
                else
                {
                    Log("Не найдено данных по прожигам...");
                }
                InitList();
                chbViewFilter.Items.Clear();
                chbViewFilter.Items.Add("");
                for (int i = 0; i < Calibrations.Count; i++)
                {
                    bool   already_in_list = false;
                    String ly = Calibrations[i].Ly1.ToString();
                    for (int j = 0; j < chbViewFilter.Items.Count; j++)
                    {
                        if (chbViewFilter.Items[j].Equals(ly))
                        {
                            already_in_list = true;
                            break;
                        }
                    }
                    if (already_in_list == false)
                    {
                        chbViewFilter.Items.Add(ly);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            btnStop.Enabled = false;
            panel1.Enabled  = true;
        }
Ejemplo n.º 14
0
            public void InitData(CorelSearch b)
            {
                MethodSimpleElementFormula msef = b.Method.GetElHeader(b.Element).Formula[b.Formula];

                b.Corel(msef.Formula.Pairs, Ly1, Sn1, Ly2, Sn2);
            }
Ejemplo n.º 15
0
        private void panel4_Paint(object sender, PaintEventArgs e)
        {
            try
            {
                e.Graphics.Clip = new Region(new Rectangle(0, 0, panel4.Width, panel4.Height));
                e.Graphics.FillRectangle(Brushes.White, 0, 0, pGraph.Width, pGraph.Height);
                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                if (msef.Formula.Pairs.Count == 0)
                {
                    return;
                }
                float min = 0, max = msef.Formula.Pairs[0].Line1[0];
                for (int p = 0; p < msef.Formula.Pairs.Count; p++)
                {
                    for (int i = 0; i < msef.Formula.Pairs[p].Line1.Length; i++)
                    {
                        if (msef.Formula.Pairs[p].Line1[i] < min && msef.Formula.Pairs[p].Line1[i] < float.MaxValue)
                        {
                            min = msef.Formula.Pairs[p].Line1[i];
                        }
                        if (msef.Formula.Pairs[p].Line1[i] > max && msef.Formula.Pairs[p].Line1[i] < float.MaxValue)
                        {
                            max = msef.Formula.Pairs[p].Line1[i];
                        }

                        if (msef.Formula.Pairs[p].Line2[i] < min && msef.Formula.Pairs[p].Line2[i] < float.MaxValue)
                        {
                            min = msef.Formula.Pairs[p].Line2[i];
                        }
                        if (msef.Formula.Pairs[p].Line2[i] > max && msef.Formula.Pairs[p].Line2[i] < float.MaxValue)
                        {
                            max = msef.Formula.Pairs[p].Line2[i];
                        }
                    }
                }

                float dlt = (max - min) / 20;
                if (dlt == 0)
                {
                    dlt = 1;
                }
                max += dlt;
                min -= dlt;

                e.Graphics.DrawString("" + max, DefaultFont, Brushes.Black, 1, 1);

                double ky = (panel4.Height - 10) / (max - min);
                int    xs = panel4.Width / 25;

                for (int p = 0; p < msef.Formula.Pairs.Count; p++)
                {
                    int px = xs;
                    int py = panel4.Height - 5 - (int)((msef.Formula.Pairs[p].Line1[0] - min) * ky);
                    for (int i = 0; i < msef.Formula.Pairs[p].Line1.Length; i++)
                    {
                        int y = panel4.Height - 5 - (int)((msef.Formula.Pairs[p].Line1[i] - min) * ky);
                        int x = px + xs;
                        e.Graphics.DrawLine(Pens.Blue, px, py, px, y);
                        e.Graphics.DrawLine(Pens.Blue, px, y, x, y);
                        px = x;
                        py = y;
                        x += xs;
                    }

                    px += xs;
                    py  = panel4.Height - 5 - (int)((msef.Formula.Pairs[p].Line2[0] - min) * ky);
                    for (int i = 0; i < msef.Formula.Pairs[p].Line2.Length; i++)
                    {
                        int y = panel4.Height - 5 - (int)((msef.Formula.Pairs[p].Line2[i] - min) * ky);
                        int x = px + xs;
                        e.Graphics.DrawLine(Pens.Red, px, py, px, y);
                        e.Graphics.DrawLine(Pens.Red, px, y, x, y);
                        px = x;
                        py = y;
                        x += xs;
                    }
                }
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Ejemplo n.º 16
0
        private void btSeachStart_Click(object sender, EventArgs e)
        {
            try
            {
                tbLog.Text = "";
                Log("Поиск линий...");
                int prc = Method.GetProbCount();
                //List<int> found_sn = new List<int>();
                //List<double> found_ly = new List<double>();
                List <SpectrData> found_lines = new List <SpectrData>();
                Dispers           disp        = null;
                for (int pr = 0; pr < prc; pr++)
                {
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sprc             = msp.MeasuredSpectrs.Count;
                    for (int spr = 0; spr < sprc; spr++)
                    {
                        if (msp.MeasuredSpectrs[spr].Sp != null)
                        {
                            disp = msp.MeasuredSpectrs[spr].Sp.GetCommonDispers();
                            break;
                        }
                    }
                }
                int[] ss   = disp.GetSensorSizes();
                int   step = (int)(numMinWidth.Value / 2);
                for (int sn = 0; sn < ss.Length; sn++)
                {
                    double prev_found_ly = 0;
                    for (int p = 15; p < ss[sn] - 15; p += step)
                    {
                        double         ly;
                        List <float[]> spectr_data = null;
                        List <double>  vals        = HasLine(sn, disp.GetLyByLocalPixel(sn, p), disp, step, out ly, out spectr_data);
                        if (vals == null)
                        {
                            continue;
                        }
                        if (Math.Abs(prev_found_ly - ly) < 0.1)
                        {
                            continue;
                        }
                        found_lines.Add(new SpectrData(sn, ly, vals, spectr_data));
                        prev_found_ly = ly;
                    }
                }
                Log("Найдено " + found_lines.Count + " линий.");
                for (int i = 0; i < found_lines.Count - 1; i++)
                {
                    if (found_lines[i].Value.Count != found_lines[i + 1].Value.Count)
                    {
                        for (i = 0; i < found_lines.Count - 3; i++)
                        {
                            if (found_lines[i].Value.Count == found_lines[i + 1].Value.Count &&
                                found_lines[i + 1].Value.Count == found_lines[i + 2].Value.Count &&
                                found_lines[i + 2].Value.Count == found_lines[i + 3].Value.Count)
                            {
                                int real_num = found_lines[i].Value.Count;
                                int skipped  = 0;
                                for (i = 0; i < found_lines.Count - 3; i++)
                                {
                                    if (found_lines[i].Value.Count == real_num)
                                    {
                                        found_lines.RemoveAt(i);
                                        i--;
                                        skipped++;
                                    }
                                }
                                Log("Отбраковано по количеству " + skipped + " линий.");
                                break;
                            }
                        }
                        break;
                    }
                }

                //List<ProbInfo> pairs = new List<ProbInfo>();
                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                msef.Formula.Founds.Clear();
                msef.Formula.Pairs.Clear();
                bool[] used          = msef.Formula.GetUsedFrames();
                int[]  used_to_index = new int[used.Length];
                int    to_index      = 0;
                // формируем массив пересчёта индекса в массиве отношений в номер кадра
                for (int i = 0; i < used_to_index.Length; i++)
                {
                    if (used[i] == false)
                    {
                        continue;
                    }
                    used_to_index[to_index] = i;
                    to_index++;
                }
                for (int pr = 0; pr < prc; pr++)
                {
                    MethodSimpleCell msc = Method.GetCell(Element, pr);
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sub_prob_count   = msp.MeasuredSpectrs.Count;
                    for (int sub_prob_i = 0; sub_prob_i < sub_prob_count; sub_prob_i++)
                    {
                        if (msp.MeasuredSpectrs[sub_prob_i].Sp != null)
                        {
                            MethodSimpleProbMeasuring     mspm  = msp.MeasuredSpectrs[sub_prob_i];
                            MethodSimpleCellFormulaResult mscfr = msc.GetData(sub_prob_i, Formula);
                            if (mscfr.Enabled == false)
                            {
                                continue;
                            }
                            double ever_analit = 0;
                            for (int i = 0; i < mscfr.ReCalcCon.Length; i++)
                            {
                                ever_analit += mscfr.AnalitValue[i];
                            }
                            ever_analit /= mscfr.AnalitValue.Length;
                            List <SpectrDataView> data = msp.MeasuredSpectrs[sub_prob_i].Sp.GetViewsSet();
                            int[] active_sp            = msp.MeasuredSpectrs[sub_prob_i].Sp.GetShotIndexes();
                            for (int i = 0; i < mscfr.AnalitValue.Length; i++)
                            {
                                //pr, spr, used_to_index[i],
                                SpectrDataView sig = data[active_sp[used_to_index[i]]];
                                SpectrDataView nul = msp.MeasuredSpectrs[sub_prob_i].Sp.GetNullFor(active_sp[used_to_index[i]]);
                                float[][]      d   = msp.MeasuredSpectrs[sub_prob_i].Sp.OFk.GetCorrectedData(sig, nul).GetFullDataNoClone();
                                msef.Formula.Pairs.Add(new ProbInfo(pr, sub_prob_i, used_to_index[i], ever_analit, mscfr.AnalitValue[i],
                                                                    d, msp.MeasuredSpectrs[sub_prob_i].Sp.GetCommonDispers()));
                            }
                        }
                    }
                }
                Log("Сформирован список из " + msef.Formula.Pairs.Count + " отклонений от среднего.");
                string tmp      = (string)tbLog.Text.Clone();
                int    ps_max   = found_lines.Count * (found_lines.Count / 2 - 1);
                int    ps_count = 0;
                for (int i = 0; i < found_lines.Count; i++)
                {
                    for (int j = i + 1; j < found_lines.Count; j++)
                    {
                        if (chTheSameLine.Checked && found_lines[i].Sn != found_lines[j].Sn)
                        {
                            continue;
                        }
                        CorellFounds rez;
                        try
                        {
                            rez = Corel(msef.Formula.Pairs, found_lines[i].Ly, found_lines[i].Sn, found_lines[j].Ly, found_lines[j].Sn);
                            if (rez.CorellAbs > 0.1)
                            {
                                bool inserted = false;
                                for (int k = 0; k < msef.Formula.Founds.Count; k++)
                                {
                                    if (rez.CorellAbs > msef.Formula.Founds[k].CorellAbs)
                                    {
                                        msef.Formula.Founds.Insert(k, rez);
                                        inserted = true;
                                        break;
                                    }
                                }
                                if (inserted == false)
                                {
                                    msef.Formula.Founds.Add(rez);
                                }
                                while (msef.Formula.Founds.Count > 80)
                                {
                                    msef.Formula.Founds.RemoveAt(msef.Formula.Founds.Count - 1);
                                }
                            }
                            if (msef.Formula.Founds.Count > 0)
                            {
                                tbLog.Text = "Проверено " + Math.Round(ps_count * 100.0 / ps_max, 1) + "% пар... K=" +
                                             msef.Formula.Founds[0].Corell + serv.Endl + tmp;
                            }
                            else
                            {
                                tbLog.Text = "Проверено " + Math.Round(ps_count * 100.0 / ps_max, 1) + "% пар..." +
                                             serv.Endl + tmp;
                            }
                            tbLog.Refresh();
                        }
                        catch (Exception ex)
                        {
                        }
                        ps_count++;
                    }
                }
                tbLog.Text = tmp;
                if (msef.Formula.Founds.Count == 0)
                {
                    Log("Поиск зависимостей завершён.Зависимостей нет.");
                }
                else
                {
                    Log("Поиск зависимостей завершён.Максимальный коэффициент корелляции = " +
                        msef.Formula.Founds[0].Corell);
                }
                InitList();//*/
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }