Example #1
0
        Spectr Measuring(int sp_num, float common)
        {
            Common.Dev.CheckConnection();

            SpectrCondition cond = new SpectrCondition(Common.Dev.Tick,
                                                       SpectrCondition.GetDefaultCondition(false, false, (float)nmExpFrom.Value, (float)nmExpTo.Value, (float)(nmExpFrom.Value + nmExpTo.Value) * 9, 10));

            Common.Dev.Measuring(cond, null);

            Dispers disp = new Dispers();
            OpticFk fk   = new OpticFk();
            Spectr  sp   = new Spectr(cond, disp, fk, "SensTest");

            for (int i = 0; i < Common.Dev.LetestResult.Count; i++)
            {
                sp.Add(Common.Dev.LetestResult[i]);
            }

            Sp[sp_num] = sp;

            string file_name = GetSpectrName(sp_num);

            Sp[sp_num].SaveAs(file_name);

            Common.Log(Common.MLS.Get(MLSConst, "Done..."));
            return(sp);
        }
 public MethodData(double con, bool en, int prob_index, int sub_prob_index, int frame_index,
                   SpectrDataView data_view_sig, SpectrDataView data_view_nul,
                   Dispers disp)
 {
     Con          = con;
     Disp         = disp;
     En           = en;
     ProbIndex    = prob_index;
     SubProbIndex = sub_prob_index;
     FrameIndex   = frame_index;
     DataViewSig  = data_view_sig;
     DataViewNull = data_view_nul;
     float[][] nul = DataViewNull.GetFullDataNoClone();
     float[][] sig = DataViewSig.GetFullDataNoClone();
     DataMinusNull = new float[nul.Length][];
     for (int s = 0; s < nul.Length; s++)
     {
         int len = nul[s].Length;
         DataMinusNull[s] = new float[len];
         for (int i = 0; i < len; i++)
         {
             DataMinusNull[s][i] = sig[s][i] - nul[s][i];
         }
     }
 }
Example #3
0
            public Data(Spectr sp, float con, double ly, bool from_next)
            {
                Sp  = sp;
                Con = con;
                Dispers    disp = sp.GetCommonDispers();
                List <int> snl  = disp.FindSensors(ly);
                int        sn;

                if (from_next)
                {
                    sn = snl[1];
                }
                else
                {
                    sn = snl[0];
                }
                int pixel = (int)disp.GetLocalPixelByLy(sn, ly);

                int[] sh_indexes = sp.GetShotIndexes();
                Analit = new double[sh_indexes.Length];
                Comp   = new double[sh_indexes.Length];
                List <SpectrDataView> views = sp.GetViewsSet();

                for (int i = 0; i < Analit.Length; i++)
                {
                    float[] sig     = views[sh_indexes[i]].GetSensorData(sn);
                    float[] nul     = sp.GetNullFor(sh_indexes[i]).GetSensorData(sn);
                    float[] sig_nul = new float[sig.Length];
                    for (int j = 0; j < sig.Length; j++)
                    {
                        sig_nul[j] = sig[j] - nul[j];
                    }
                    Analit[i] = CalcAnalit(sig_nul, pixel);
                }
            }
        bool GetSnNum(List <GLogRecord> log, string log_section,
                      Dispers disp, float max_val,
                      out int sn)
        {
            //Dispers disp = sp.GetDispersRO();
            List <int> snr = disp.FindSensors((double)nmLy.Value);

            if (cbFromSnNum.SelectedIndex != 0)
            {
                if (snr.Count < 2)
                {
                    log.Add(new GLogMsg(log_section, Common.MLS.Get(MLSConst, "Предупреждение: Длина волны не на пересечении сенсоров. Ly:") + nmLy.Value, Color.Red));
                    sn = snr[0];
                    return(true);
                }
                sn = snr[1];
            }
            else
            {
                if (snr != null && snr.Count > 0)
                {
                    sn = snr[0];
                }
                else
                {
                    sn = -1;
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        private void btSaveAll_Click(object sender, EventArgs e)
        {
            try
            {
                string[] list = Directory.GetFiles(DirToSave, tbFilePrefix.Text + "*.*");
                if (list != null && list.Length != 0)
                {
                    DialogResult dr = MessageBox.Show(MainForm.MForm, "Существуют файлы с такой маской. Продолжать?", "Возможный конфликт",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
                    if (dr != DialogResult.Yes)
                    {
                        return;
                    }
                }
                //for (int i = 0; i < ToSave.Count; i++)
                //    ToSave[i].SaveToFile(DirToSave + "\\" + tbFilePrefix.Text, (ViewElementTypes)cbType.SelectedIndex);
                Dispers disp = Sp.GetCommonDispers();
                SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " спектр для отображения.csv", disp, Sp.OFk, Sp.GetDefultView(), null);
                //SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " спектр для отображения.csv", disp, Sp.GetDefultView(), null);

                int[] indexes            = Sp.GetShotIndexes();
                List <SpectrDataView> vs = Sp.GetViewsSet();
                for (int i = 0; i < indexes.Length; i++)
                {
                    SpectrDataView nul = Sp.GetNullFor(indexes[i]);
                    SpectrDataView sig = vs[indexes[i]];
                    SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " экспозиция " + (i + 1) + ".csv", disp, Sp.OFk, sig, nul);
                }
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Example #6
0
        double CheckLine(int sn, double ly, float[][] data, Dispers disp, int plus_minus, out double ly_real, out float[] data_cur)
        {
            int pixel = (int)disp.GetLocalPixelByLy(sn, ly);

            for (int i = 0; i < plus_minus && i < data[sn].Length - 2 &&
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel - 1]) <
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel + 2]);
                 i++, pixel++)
            {
                ;
            }
            for (int i = 0; i < plus_minus && i > 2 &&
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel - 1]) <
                 (data[sn][pixel - 2] + data[sn][pixel - 1] + data[sn][pixel]);
                 i++, pixel--)
            {
                ;
            }
            double left_v  = data[sn][pixel - 3] + data[sn][pixel - 2] + data[sn][pixel - 1],
                   midl_v  = data[sn][pixel - 1] + data[sn][pixel] + data[sn][pixel + 1],
                   right_v = data[sn][pixel + 1] + data[sn][pixel + 2] + data[sn][pixel + 3];

            if (left_v < midl_v && midl_v > right_v)
            {
                int left = 1;
                for (; left < plus_minus && (pixel - 2 - left) > 0 &&
                     (data[sn][pixel - left] + data[sn][pixel + 1 - left] + data[sn][pixel - 1 - left]) >
                     (data[sn][pixel - left] + data[sn][pixel - 1 - left] + data[sn][pixel - 2 - left]); left++)
                {
                    ;
                }
                int right = 1;
                for (; right < plus_minus && (pixel + 2 + right) < data[sn].Length &&
                     (data[sn][pixel + right] + data[sn][pixel + 1 + right] + data[sn][pixel - 1 + right]) >
                     (data[sn][pixel + right] + data[sn][pixel + 1 + right] + data[sn][pixel + 2 + right]); right++)
                {
                    ;
                }
                if (left > 2 && right > 2 && left + right >= numMinWidth.Value)
                {
                    ly_real  = disp.GetLyByLocalPixel(sn, pixel);
                    data_cur = new float[5];
                    for (int i = 0; i < 5; i++)
                    {
                        data_cur[i] = data[sn][pixel - 2 + i];
                    }
                    return(midl_v);//return disp.GetLyByLocalPixel(sn,pixel);
                }
            }
            ly_real  = -1;
            data_cur = null;
            return(0);
        }
Example #7
0
 public ProbInfo(
     int prob, int sub_prob, int frame,
     double ever, double value,
     float[][] data, Dispers disp)
 {
     ProbNum    = prob;
     SubProbNum = sub_prob;
     Frame      = frame;
     EverAnalit = ever;
     Analit     = value;
     Data       = data;
     Disp       = disp;
 }
Example #8
0
        void Init(float[] val, string description, string fsufix, Dispers disp, int sn)
        {
            float[] noise = new float[val.Length - 1];
            ValueLevel = 0;
            int l = 0;

            for (int i = 0; i < val.Length - 1; i++)
            {
                noise[i] = val[i] - val[i + 1];
                if (noise[i] > -1000000 && noise[i] < 1000000)
                {
                    ValueLevel += val[i];
                    l++;
                }
            }
            ValueLevel /= val.Length;
            NoiseEver   = 0;
            NoiseSKO    = 0;
            l           = 0;
            for (int i = 0; i < noise.Length; i++)
            {
                if (noise[i] > -100000 && noise[i] < 100000)
                {
                    NoiseEver += Math.Abs(noise[i]);
                    NoiseSKO  += noise[i] * noise[i];
                    l++;
                }
            }
            NoiseEver /= l;
            NoiseSKO   = Math.Sqrt(NoiseSKO) / (l - 1);

            Disp      = disp;
            Sn        = sn;
            Dt        = val;
            Desc      = description;
            FileSufix = "";//fsufix;
            for (int i = 0; i < fsufix.Length; i++)
            {
                if (fsufix[i] != ':' && fsufix[i] != ';')
                {
                    FileSufix += fsufix[i];
                }
                else
                {
                    FileSufix += ' ';
                }
            }
        }
Example #9
0
        public TaskLinkingMatrixControl()
        {
            Disp = new Dispers();
            InitializeComponent();
            if (Common.Db != null)
            {
                Folder  = Common.Db.GetFolder(Common.DbNameLinkingFolder);
                Control = new CheckedSpectrCollectionControl(
                    Folder, clSpList, SpView,
                    null,
                    null,
                    null);
                Control.AfterMeasuringProc += new AfterMeasuringDel(AfterMeasuringCall);
                Control.FirstFileName       = BaseMatrixName;
            }
            if (Common.Env != null)
            {
                if (Common.Env.LinkintEditorText == null ||
                    Common.Env.LinkintEditorText.Length == 0)
                {
                    cmtLoadDefaultLinks_Click(null, null);

                    /*string def_d = Common.Dev.DefaultDipsers();
                     * if (def_d == null)
                     *  tbLinks.Text = "#Заготовка" + serv.Endl + serv.Endl +
                     *      "s1:3 #сенс.1 полином3" + serv.Endl +
                     *      "10-2200" + serv.Endl +
                     *      "200-2210" + serv.Endl;
                     * else
                     *  tbLinks.Text = def_d;*/
                }
                else
                {
                    tbLinks.Text = Common.Env.LinkintEditorText;
                }
            }
            try
            {
                tbLinks.Cursor = Common.GetCursor("TextWithMenu.cur");
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            Common.SetupFont(menuStrip1);
            Log.Reg(MLSConst, menuStrip1);
        }
Example #10
0
        List <double> HasLine(int sn, double ly, Dispers disp, int plus_minus, out double ly_real, out List <float[]> data)
        {
            int prob_count = Method.GetProbCount();
            //double ret = 0;
            int n_ret = 0;

            ly_real = 0;
            List <double> ret = new List <double>();

            data = new List <float[]>();
            for (int pr = 0; pr < prob_count; pr++)
            {
                MethodSimpleProb msp = Method.GetProbHeader(pr);
                for (int spr = 0; spr < msp.MeasuredSpectrs.Count; spr++)
                {
                    MethodSimpleProbMeasuring pm = msp.MeasuredSpectrs[spr];
                    if (pm.Sp == null)
                    {
                        continue;
                    }
                    SpectrDataView sdv      = pm.Sp.GetDefultView();
                    double         tmp      = 0;
                    double         ly_cur   = 0;
                    float[]        data_cur = null;
                    try
                    {
                        tmp = CheckLine(sn, ly, sdv.GetFullDataNoClone(), disp, plus_minus, out ly_cur, out data_cur);
                    }
                    catch
                    {
                    }
                    if (tmp == 0)
                    {
                        ly_real = -1;
                        data    = null;
                        return(null);
                    }
                    ly_real += ly_cur;
                    ret.Add(tmp);
                    data.Add(data_cur);
                    n_ret++;
                }
            }
            ly_real /= n_ret;
            return(ret);// / n_ret;
        }
Example #11
0
        void LoadLinks(int n, Dispers d)
        {
            try
            {
                string endl = SpectroWizard.serv.Endl;
                string ret  = "";
                //Dispers d = SpView.GetSpectr(0).GetCommonDispers();
                for (int sn = 0; sn < d.GetSensorSizes().Length; sn++)
                {
                    double[] k = d.GetK(sn);
                    ret += "s" + (sn + 1) + ":";
                    if (k[3] != 0)
                    {
                        ret += "3";
                    }
                    else
                    {
                        ret += "2";
                    }
                    ret += endl;
                    for (int i = 0; i < k.Length; i++)
                    {
                        ret += "      #K" + (i + 1) + "=" + k[i] + endl;
                    }
                    ret += endl;

                    float local_pixel = 0;
                    float step        = d.GetSensorSizes()[0] / (float)(n - 1) - 1;
                    for (int i = 0; i < n; i++)
                    {
                        local_pixel = i * step;
                        ret        += Math.Round(d.GetGlobalPixelByLy(sn, d.GetLyByLocalPixel(sn, local_pixel))) + "-" +
                                      Math.Round(d.GetLyByLocalPixel(sn, local_pixel), 3) + endl;
                    }
                    ret += endl;
                }
                tbLinks.Text = ret;
            }
            catch (Exception ex)
            {
                Log.Out(ex);
            }
        }
Example #12
0
 public ViewElementData(SpectrDataView spv, string description, string fsufix, Dispers disp, int sn)
 {
     if (spv.BlankStart != null)
     {
         BlankStart = new float[spv.BlankStart[sn].Length];
         for (int i = 0; i < BlankStart.Length; i++)
         {
             BlankStart[i] = spv.BlankStart[sn][i];
         }
         //BlankStartFFT = GetFFT(BlankStart);
     }
     if (spv.BlankEnd != null)
     {
         BlankEnd = new float[spv.BlankEnd[sn].Length];
         for (int i = 0; i < BlankEnd.Length; i++)
         {
             BlankEnd[i] = spv.BlankEnd[sn][i];
         }
         //BlankEndFFT = GetFFT(BlankEnd);
     }
     Init(spv.GetSensorData(sn), description, fsufix, disp, sn);
     //DtFFT = GetFFT(Dt);
 }
Example #13
0
 public ViewElementDispers(Dispers val, string description, string fsufix)
 {
     Dt        = val;
     Desc      = description;
     FileSufix = fsufix;
 }
Example #14
0
        public void SetupSpectr(Spectr sp)
        {
            BackColor = SystemColors.Control;
            Sp        = sp;
            trStructure.BeginUpdate();
            trStructure.Nodes.Clear();
            ToSave.Clear();

            TreeNode node = new TreeNode(Common.MLS.Get(MLSConst, "Блок предпросмотра"));

            trStructure.Nodes.Add(node);

            TreeNode tmp = new TreeNode(Common.MLS.Get(MLSConst, "Дата измерения"));

            tmp.Tag = new ViewElementDate(sp.CreatedDate, sp.GetViewsSet()[0].MaxLinarLevel, sp.GetViewsSet()[0].OverloadLevel,
                                          Common.MLS.Get(MLSConst, "Дата измерения спектра"),
                                          null);
            node.Nodes.Add(tmp);

            tmp     = new TreeNode(Common.MLS.Get(MLSConst, "Диагностика"));
            tmp.Tag = new ViewElementString(sp.SpectrInfo,
                                            Common.MLS.Get(MLSConst, "Сообщения внутренней диагностической системы"),
                                            null);
            node.Nodes.Add(tmp);

            tmp = new TreeNode(Common.MLS.Get(MLSConst, "Дисперсия"));
            ToSave.Add(new ViewElementDispers(sp.GetCommonDispers(),
                                              Common.MLS.Get(MLSConst, "Коэффициенты дисперсионной кривой [ A B C D E ] для полинома вида: A + B*x + C*x*x + D*x*x*x + E*x*x*x*x"),
                                              null));
            tmp.Tag = ToSave[ToSave.Count - 1];
            node.Nodes.Add(tmp);

            Dispers disp = sp.GetCommonDispers();

            int[] ss = disp.GetSensorSizes();
            for (int s = 0; s < ss.Length; s++)
            {
                try
                {
                    tmp = new TreeNode(Common.MLS.Get(MLSConst, "Данные для линейки №") + (s + 1));
                    ToSave.Add(new ViewElementData(sp.GetDefultView(),
                                                   Common.MLS.Get(MLSConst, "Номера пикселов; их амплитуда; длина волны; для линейки №") + (s + 1),
                                                   "_данные для отображения_SN" + (s + 1), disp, s));
                    tmp.Tag = ToSave[ToSave.Count - 1];
                    node.Nodes.Add(tmp);
                }
                catch (Exception ex)
                {
                    Common.LogNoMsg(ex);
                    break;
                }
            }

            for (int s = 0; s < ss.Length; s++)
            {
                try{
                    tmp = new TreeNode(Common.MLS.Get(MLSConst, "Коэффициенты чувствительностей для линейки №") + (s + 1));
                    ToSave.Add(new ViewElementData(sp.OFk.GetSensKForTesting()[s],
                                                   Common.MLS.Get(MLSConst, "Номера пикселов; Коэффифиенты чувствительностей; для линейки №") + (s + 1),
                                                   "_чувствительности_SN" + (s + 1), disp, s));
                    tmp.Tag = ToSave[ToSave.Count - 1];
                    node.Nodes.Add(tmp);
                }
                catch (Exception ex)
                {
                    Common.LogNoMsg(ex);
                    break;
                }
            }

            node = new TreeNode(Common.MLS.Get(MLSConst, "Блок с данными"));
            trStructure.Nodes.Add(node);

            List <SpectrDataView> views = Sp.GetViewsSet();

            for (int v = 0; v < views.Count; v++)
            {
                string cond = views[v].GetCondition().SourceCode;
                tmp     = new TreeNode(Common.MLS.Get(MLSConst, cond));
                tmp.Tag = new ViewElementString(cond,
                                                Common.MLS.Get(MLSConst, "Строка инициализации оборудования"),
                                                null);
                node.Nodes.Add(tmp);

                for (int s = 0; s < ss.Length; s++)
                {
                    TreeNode ttmp = new TreeNode(Common.MLS.Get(MLSConst, "Данные для линейки №") + (s + 1));
                    ToSave.Add(new ViewElementData(views[v],
                                                   Common.MLS.Get(MLSConst, "Номера пикселов; их амплитуда; длина волны; для линейки №") + (s + 1),
                                                   "_исходные данные" + (v + 1) + "_SN" + (s + 1) + cond, disp, s));
                    ttmp.Tag = ToSave[ToSave.Count - 1];
                    tmp.Nodes.Add(ttmp);
                }
            }
            btSaveSelected.Visible = false;

            trStructure.EndUpdate();
            trStructure.ExpandAll();
        }
        public bool SetupLy(float ly, bool force)//,int PixelDlt)
        {
            Spectr sp = Sp;

            if (sp == null)
            {
                return(false);
            }

            float      _ForLy = ly;//(float)nmLy.Value;
            Dispers    disp   = sp.GetCommonDispers();
            List <int> fsn    = disp.FindSensors(_ForLy);

            if (fsn.Count == 0)
            {
                return(false);
            }
            int sn = 0;

            if (cbFromSnNum.SelectedIndex == 0 || fsn.Count == 1)
            {
                sn = fsn[0];
            }
            else
            {
                sn = fsn[1];
            }
            float _LySpectrLocalPixel = (float)disp.GetLocalPixelByLy(sn, _ForLy);
            int   ss = disp.GetSensorSizes()[sn];

            int pixel_from = (int)(_LySpectrLocalPixel - PixelDlt * 4);
            int pixel_to   = (int)(_LySpectrLocalPixel + PixelDlt * 4);
            int _LySpectrEtalonPixelFrom = pixel_from;

            int[]          short_indexes = sp.GetShotIndexes();
            int            sh_ind        = short_indexes[short_indexes.Length / 2];
            SpectrDataView nul           = sp.GetNullFor(sh_ind);
            SpectrDataView sig           = sp[sh_ind];

            float[] nul_data = nul.GetSensorData(sn);
            float[] sig_data = sig.GetSensorData(sn);
            float[] ly_cand  = new float[pixel_to - pixel_from + 1];
            for (int i = 0; i < ly_cand.Length; i++)
            {
                if (i + pixel_from >= 0 && i + pixel_from < sig_data.Length)
                {
                    ly_cand[i] = (sig_data[i + pixel_from] - nul_data[i + pixel_from]) + 10;
                }
                else
                {
                    ly_cand[i] = 0;
                }
            }
            GraphPreview gp = new GraphPreview();

            if (force || gp.check(ParentForm, ly_cand))
            {
                double min = double.MaxValue, max = -double.MaxValue;
                for (int i = 0; i < ly_cand.Length; i++)
                {
                    if (ly_cand[i] == 0)
                    {
                        continue;
                    }
                    if (min > ly_cand[i])
                    {
                        min = ly_cand[i];
                    }
                    if (max < ly_cand[i])
                    {
                        max = ly_cand[i];
                    }
                }

                double weight = 0;
                double noise  = 0;
                for (int i = Common.Conf.MultFactor; i < ly_cand.Length - Common.Conf.MultFactor; i += Common.Conf.MultFactor)
                {
                    if (ly_cand[i] == 0 || ly_cand[i - Common.Conf.MultFactor] == 0)
                    {
                        continue;
                    }
                    double dlt  = Math.Abs(ly_cand[i - Common.Conf.MultFactor] - ly_cand[i]);
                    double ever = (ly_cand[i - Common.Conf.MultFactor] + ly_cand[i]) / 2;
                    noise  += dlt / ever;
                    weight += 1 / ever;
                }
                noise /= weight;
                noise *= gp.NoiseCenselationLevel;
                float   level    = (float)(min + noise);
                float[] fly_cand = new float[ly_cand.Length];
                for (int i = 0; i < ly_cand.Length; i++)
                {
                    if (ly_cand[i] < level)
                    {
                        fly_cand[i] = 0;
                    }
                    else
                    {
                        fly_cand[i] = ly_cand[i] - level;
                    }
                }

                if (force || gp.check(ParentForm, fly_cand))
                {
                    ly_cand = fly_cand;
                }

                ForLy = _ForLy;
                LySpectrLocalPixel      = _LySpectrLocalPixel;
                LySpectrEtalon          = ly_cand;
                LySpectrEtalonPixelFrom = _LySpectrEtalonPixelFrom;

                return(true);
            }
            return(false);
        }
Example #16
0
        void SaveFile(string file_name, Dispers disp, OpticFk ofk, SpectrDataView sig, SpectrDataView nul)
        {
            string separator = "; ", endl = serv.Endl;

            if (cbType.SelectedIndex == 0)
            {
                separator = "; ";
            }
            else
            {
                separator = ", ";
            }
            string tmp = "id" + separator +
                         " ccd" + separator +
                         " pixel" + separator +
                         " vpixel" + separator +
                         " signal" + separator +
                         " null" + separator +
                         " ly" + separator +
                         " sens_k" + separator + endl;

            int[]   sn, vpix, pix;
            float[] sigd, nuld, sens;

            GetData(sig, disp, ofk, out sn, out pix, out vpix, out sigd, out sens);
            if (nul != null)
            {
                GetData(nul, disp, ofk, out sn, out pix, out vpix, out nuld, out sens);
            }
            else
            {
                nuld = null;
            }

            FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Write);

            try
            {
                fs.SetLength(0);

                byte[] buf = Encoding.ASCII.GetBytes(tmp);
                fs.Write(buf, 0, buf.Length);

                for (int i = 0; i < sn.Length; i++)
                {
                    tmp  = "" + (i + 1) + separator;
                    tmp += (sn[i] + 1) + separator;
                    tmp += pix[i] + separator;
                    tmp += vpix[i] + separator;
                    tmp += sigd[i] + separator;
                    if (nuld != null)
                    {
                        tmp += nuld[i] + separator;
                    }
                    else
                    {
                        tmp += "0" + separator;
                    }
                    tmp += disp.GetLyByLocalPixel(sn[i], vpix[i]) + separator;
                    tmp += sens[i] + separator;
                    tmp += endl;

                    buf = Encoding.ASCII.GetBytes(tmp);
                    fs.Write(buf, 0, buf.Length);
                }
                fs.Flush();
            }
            finally
            {
                fs.Close();
            }
        }
        public List <ExtraLineInfo> CheckSpectr(Spectr sp)
        {
            List <ExtraLineInfo> ret = new List <ExtraLineInfo>();

            if (EmptySpaces.Count == 0)
            {
                return(ret);
            }

            List <SpectrDataView> views = sp.GetViewsSet();

            int[] active_view_indexes = sp.GetShotIndexes();
            int[] ss = sp.GetCommonDispers().GetSensorSizes();

            for (int esi = 0; esi < EmptySpaces.Count; esi++)
            {
                for (int vi = 0; vi < active_view_indexes.Length; vi++)
                {
                    SpectrDataView view = views[active_view_indexes[vi]];
                    SpectrDataView nul  = sp.GetNullFor(active_view_indexes[vi]);
                    Dispers        d    = sp.GetCommonDispers();

                    List <int> sns = d.FindSensors(EmptySpaces[esi][1]);
                    if (sns.Count == 0)
                    {
                        continue;
                    }

                    int sn         = sns[0];
                    int pixel_from = (int)d.GetLocalPixelByLy(sn, EmptySpaces[esi][1]) - (int)nmMargine.Value;
                    if (pixel_from < 0)
                    {
                        pixel_from = 0;
                    }
                    int pixel_to = (int)d.GetLocalPixelByLy(sn, EmptySpaces[esi][2]) + (int)nmMargine.Value;
                    if (pixel_to >= ss[sn])
                    {
                        pixel_to = ss[sn] - 1;
                    }

                    float[] data_s = view.GetSensorData(sn); //.GetFullData()[sn];
                    float[] data_n = nul.GetSensorData(sn);  //.GetFullData()[sn];
                    float[] data   = new float[pixel_to - pixel_from];
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = data_s[pixel_from + i] - data_n[pixel_from + i];
                    }
                    int side = (int)nmMinLineWidth.Value / 2;
                    for (int i = (int)nmMinLineWidth.Value; i < data.Length - (int)nmMinLineWidth.Value; i++)
                    {
                        while (i < data.Length - 5 && data[i] < data[i + 1])
                        {
                            i++;
                        }
                        int left  = 0;
                        int right = 0;
                        if (isLine(data, data.Length - 2, i, view.MaxLinarLevel, side, side * 2 + 2, ref left, ref right))
                        {
                            int start_pixel = i - 2;
                            int final_pixel = i + 2;
                            for (; start_pixel > 0 && data[start_pixel] < data[start_pixel + 1]; start_pixel--)
                            {
                                ;
                            }
                            for (; final_pixel < data.Length - 1 && data[final_pixel] < data[final_pixel - 1]; final_pixel++)
                            {
                                ;
                            }
                            if (data[i] - (data[start_pixel] + data[final_pixel]) / 2 > (int)nmMinAmpl.Value)
                            {
                                ret.Add(new ExtraLineInfo(sn, i + pixel_from, d, (data[i] + data[i + 1] + data[i - 1]) / 3));
                            }
                            i += right;
                        }
                    }
                }
            }
            return(ret);
        }
        public bool Calc(List <GLogRecord> log,
                         string log_section, string log_prefix,
                         SpectrDataView sig,
                         SpectrDataView nul,
                         Spectr spectr,
                         out double analit,
                         out double aq,
                         ref CalcLineAtrib attrib,
                         bool is_calibr)
        {
            if (nmLy.Value < 10)
            {
                nmLy.Value = 0;
                analit     = 1;
                aq         = 0;
                return(true);
            }
            analit = 0;
            aq     = 0;

            int sn;

            if (GetSnNum(log, log_section, spectr.GetCommonDispers(),
                         sig.MaxLinarLevel, out sn) == false)
            {
                return(false);
            }

            Dispers disp         = spectr.GetCommonDispers();//sig.GetDispersRO();
            int     ss           = disp.GetSensorSizes()[sn];
            float   base_pixel_f = (float)disp.GetLocalPixelByLy(sn, (double)nmLy.Value);
            int     base_pixel   = (int)base_pixel_f;

            int pixel_from = base_pixel - PixelDlt;

            if (pixel_from < 0)
            {
                pixel_from = 0;
            }
            int pixel_to = base_pixel + PixelDlt;

            if (pixel_to > ss - 1)
            {
                pixel_to = ss - 1;
            }
            float[] sig_data         = sig.GetSensorDataWithCorrection(sn);
            float[] nul_data         = nul.GetSensorDataWithCorrection(sn);
            int     start_pixel      = (int)((base_pixel_f - pixel_from) * Common.Conf.MultFactor);
            int     start_pixel_orig = start_pixel;

            //float max_val = sig.MaxLinarLevel;
            float max_val = Common.Conf.MaxLevel;

            float[] sig_nul = new float[pixel_to - pixel_from + 1];
            OpticFk ofk     = spectr.OFk;

            //float[][] sensK = ofk.GetSensK();
            for (int i = 0; i < sig_nul.Length; i++)
            {
                sig_nul[i] = ofk.GetCorrectedValue(sn, i + pixel_from, sig_data, nul_data, max_val);// sig_data[i + pixel_from] - nul_data[i + pixel_from];
                //sig_nul[i] *= sensK[sn][i+pixel_from];
            }

            int max_pix = base_pixel;

            for (; max_pix < sig_data.Length - 1 &&
                 sig_data[max_pix] - nul_data[max_pix] < sig_data[max_pix + 1] - nul_data[max_pix + 1];
                 max_pix++)
            {
                ;
            }
            for (; max_pix > 1 &&
                 sig_data[max_pix] - nul_data[max_pix] < sig_data[max_pix - 1] - nul_data[max_pix - 1];
                 max_pix--)
            {
                ;
            }

            int sig_val = (int)(sig_data[max_pix] - nul_data[max_pix]);

            if (sig_val < MinSignalAmpl)
            {
                MinSignalAmpl = sig_val;
            }
            if (sig_val > MaxSignalAmpl)
            {
                MaxSignalAmpl = sig_val;
            }

            double[] working_data = PrepareData(sig_data, sig_nul, sn, pixel_from, spectr, max_val, Common.Conf.MultFactor);

            if (LySpectrEtalon != null)
            {
                if (LySpectrEtalonCalc == null)
                {
                    LySpectrEtalonCalc = PrepareData(sig_data, LySpectrEtalon, sn, 0, spectr, max_val, Common.Conf.MultFactor);
                }

                double min_etalon = double.MaxValue;
                double min_sig    = double.MaxValue;
                int    shift      = (int)(LySpectrLocalPixel - LySpectrEtalonPixelFrom) * Common.Conf.MultFactor - start_pixel;

                double crit = Corel(LySpectrEtalonCalc, working_data,
                                    shift, start_pixel, spectr.OverloadLevel,
                                    ref min_etalon, ref min_sig);
                for (int i = 0; i < 4 * Common.Conf.MultFactor; i++)
                {
                    double cand_crit = Corel(LySpectrEtalonCalc, working_data,
                                             shift + 1, start_pixel, spectr.OverloadLevel,
                                             ref min_etalon, ref min_sig);
                    if (cand_crit > crit)
                    {
                        shift++;
                        start_pixel--;
                        crit = cand_crit;
                    }
                    else
                    {
                        break;
                    }
                }
                for (int i = 0; i < 4 * Common.Conf.MultFactor; i++)
                {
                    double cand_crit = Corel(LySpectrEtalonCalc, working_data,
                                             shift - 1, start_pixel, spectr.OverloadLevel,
                                             ref min_etalon, ref min_sig);
                    if (cand_crit > crit)
                    {
                        shift--;
                        start_pixel++;
                        crit = cand_crit;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                log.Add(new GLogMsg(log_section,
                                    log_prefix + Common.MLS.Get(MLSConst, "Нет профиля линии. Для устаноки Ly используйте 'Устан.'") + nmLy.Value,
                                    Color.Orange));
            }


            if (cbMaximumType.SelectedIndex == 0 || cbMaximumType.SelectedIndex == 1)
            {
                int steps;
                if (cbMaximumType.SelectedIndex == 0)
                {
                    steps = 5;
                }
                else
                {
                    steps = 30;
                }
                if (working_data[start_pixel] < working_data[start_pixel + 1])
                {
                    for (int i = 0; i < steps &&
                         working_data[start_pixel] < working_data[start_pixel + 1];
                         i++, start_pixel++)
                    {
                        start_pixel++;
                    }
                    start_pixel--;
                }
                if (working_data[start_pixel] < working_data[start_pixel - 1])
                {
                    for (int i = 0; i < steps &&
                         working_data[start_pixel] < working_data[start_pixel - 1];
                         i++, start_pixel--)
                    {
                        start_pixel--;
                    }
                    start_pixel++;
                }
            }

            analit = working_data[start_pixel];
            if (cbExtraCalcType.SelectedIndex == 1)
            {
                double bkg_analit, bkg_aq;
                CalcBackGround(log, log_section, log_prefix + "bkg", sig, nul, spectr, out bkg_analit, out bkg_aq);
                analit /= bkg_analit;
            }
            //double min = working_data[0];//1 = working_data[start_pixel - 10];
            //double min2 = working_data[start_pixel + 10];
            //for (int i = start_pixel - 10; i > 0 && working_data[i] < working_data[i + 1]; i--)
            //if (working_data[i] < min1)
            //min1 = working_data[i];
            //for (int i = start_pixel + 10; i < working_data.Length-1 && working_data[i] < working_data[i - 1]; i++)
            //if (working_data[i] < min2)
            //min2 = working_data[i];
            double ampl = analit;// - (min1+min2)/2;

            if (is_calibr)
            {
                if (ampl < MinAnalitValue)
                {
                    MinAnalitValue = (float)ampl;
                }
                if (ampl > MaxAnalitValue)
                {
                    MaxAnalitValue = (float)ampl;
                }
            }
            else
            {
                //double dlt = (MinAnalitValue-MinAnalitValue)
                float extr_val = MinAnalitValue * (1 - Common.Env.MaxAmplDlt);
                if (ampl < extr_val)
                {
                    attrib.IsTooLow = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия слишком слабая: ") + nmLy.Value + "   " + (int)ampl + "<" + (int)extr_val,
                                        Color.Red));
                }
                extr_val = MaxAnalitValue * (1 + Common.Env.MaxAmplDlt);
                if (ampl > extr_val)
                {
                    attrib.IsTooHi = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия слишком сильная: ") + nmLy.Value + "   " + (int)ampl + ">" + (int)extr_val,
                                        Color.Red));
                }
                int pix = (int)(pixel_from + start_pixel / Common.Conf.MultFactor);
                if (sig_data[pix] > max_val ||
                    sig_data[pix + 1] > max_val ||
                    sig_data[pix + 2] > max_val ||
                    sig_data[pix + 3] > max_val ||
                    sig_data[pix - 1] > max_val ||
                    sig_data[pix - 2] > max_val ||
                    sig_data[pix - 3] > max_val)
                {
                    attrib.IsNonLinar = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия превысила допустимое значение: ") + nmLy.Value,
                                        Color.Red));
                }
            }
            log.Add(new GLogMsg(log_section,
                                log_prefix + "A(" + nmLy.Value + ")=" + serv.GetGoodValue(analit, 3) + " [" + serv.GetGoodValue(ampl, 2) + "]",// + " min_analit_val=" + MinAnalitValue,
                                Color.Black));
            log.Add(new GLogSpData(log_section,
                                   log_prefix + "Ly(" + nmLy.Value + ")",
                                   working_data, start_pixel, start_pixel,
                                   start_pixel_orig, (double)nmLy.Value, Color.Blue, Color.Red));

            if (LySpectrEtalonCalc != null)
            {
                int center = LySpectrEtalonCalc.Length / 2;
                log.Add(new GLogSpData(log_section,
                                       log_prefix + "Ly(" + nmLy.Value + ")",
                                       formatEtalon(working_data, LySpectrEtalonCalc), center, center,
                                       center - 10, (double)nmLy.Value, Color.LightGray, Color.Black));
            }

            return(true);
        }
Example #19
0
 public ViewElementData(float[] val, string description, string fsufix, Dispers disp, int sn)
 {
     Init(val, description, fsufix, disp, sn);
 }
        public bool CalcBackGround(List <GLogRecord> log,
                                   string log_section,
                                   string log_prefix,
                                   //Spectr ly_spectr,
                                   SpectrDataView sig,
                                   SpectrDataView nul,
                                   Spectr spectr,
                                   out double analit,
                                   out double err)
        {
            analit = 0;
            err    = 0;

            int sn;

            if (GetSnNum(log, log_section, spectr.GetCommonDispers(),
                         sig.MaxLinarLevel, out sn) == false)
            {
                log.Add(new GLogMsg(log_section,
                                    Common.MLS.Get(MLSConst, "Не корректная длина волны."),
                                    Color.Black));
                return(false);
            }

            Function fk;

            bool[] mask;
            sig.GetBackGroundFunction(sn, out fk, out mask);
            float[] sg = sig.GetSensorData(sn);
            if (fk == null)
            {
                #region calc backgound region level
                double  max_level = sig.MaxLinarLevel * 0.5;
                float[] sg_plav   = sig.GetSensorData(sn);
                float[] nl        = nul.GetSensorData(sn);

                for (int i = 0; i < sg.Length; i++)
                {
                    if (sg[i] < max_level)
                    {
                        sg[i] -= nl[i];
                    }
                    else
                    {
                        sg[i] = float.MaxValue;
                    }
                }

                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (sg[i] < float.MaxValue &&
                        sg[i + 1] < float.MaxValue &&
                        sg[i - 1] < float.MaxValue)
                    {
                        sg_plav[i] = (sg[i] + sg[i - 1] + sg[i + 1] + sg[i - 2] + sg[i + 2]) / 5;
                    }
                }

                bool[] flags = new bool[sg_plav.Length];
                for (int i = 1; i < sg.Length - 1; i++)
                {
                    flags[i] = true;
                }
                for (int i = 2; i < sg.Length - 2; i++)
                {
                    if (sg[i] == float.MaxValue ||
                        sg[i - 1] == float.MaxValue ||
                        sg[i + 1] == float.MaxValue ||
                        sg[i - 2] == float.MaxValue ||
                        sg[i + 2] == float.MaxValue)
                    {
                        flags[i - 2] = false;
                        flags[i - 1] = false;
                        flags[i]     = false;
                        flags[i + 1] = false;
                        flags[i + 2] = false;
                        continue;
                    }
                    if (sg_plav[i] > sg_plav[i + 1] &&
                        sg_plav[i] > sg_plav[i - 1] &&
                        sg_plav[i + 1] > sg_plav[i + 2] &&
                        sg_plav[i - 1] > sg_plav[i - 2])
                    {
                        for (int j = i; j < sg.Length - 1 && sg_plav[j] > sg_plav[j + 1]; j++)
                        {
                            flags[j] = false;
                        }
                        for (int j = i; j > 1 && sg_plav[j] > sg_plav[j - 1]; j--)
                        {
                            flags[j] = false;
                        }
                    }
                }
                for (int i = 1; i < sg.Length; i++)
                {
                    if (flags[i - 1] == false && flags[i] == true)
                    {
                        flags[i] = false;
                        i++;
                    }
                }
                for (int i = 1; i < sg.Length; i++)
                {
                    if (flags[i - 1] == true && flags[i] == false)
                    {
                        flags[i - 1] = true;
                        i++;
                    }
                }
                int count = 0;
                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        int from = i;
                        for (int j = 0; i < sg.Length && flags[i] && j < 4; i++, j++)
                        {
                            ;
                        }
                        int to  = i - 1;
                        int len = to - from;
                        if (len <= 2)
                        {
                            for (int j = from; j <= to; j++)
                            {
                                flags[j] = false;
                            }
                        }
                        i--;
                    }
                }

                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        count++;
                    }
                }

                double[] pixel = new double[count];
                double[] val   = new double[count];
                count = 0;
                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        pixel[count] = i;
                        val[count]   = sg[i];
                        count++;
                    }
                }
                fk   = new Function(Function.Types.Polinom3, pixel, val, false, false, 1);
                mask = flags;
                sig.SetBackGroundFunction(sn, fk, mask);
                #endregion
            }

            //Dispers disp = ly_spectr.GetCommonDispers();
            Dispers disp = spectr.GetCommonDispers();
            int[]   ss   = disp.GetSensorSizes();

            /*double ly_from = disp.GetLyByLocalPixel(sn,40);
             * double ly_to = disp.GetLyByLocalPixel(sn,ss[sn]-40);
             * disp = spectr.GetCommonDispers();// sig.GetDispersRO();
             * int pixel_from = (int)disp.GetLocalPixelByLy(sn,ly_from);
             * int pixel_to = (int)disp.GetLocalPixelByLy(sn,ly_to);*/
            int    pixel_from = 5;
            int    pixel_to   = ss[sn] - 5;
            double ever       = 0;
            double sko        = 0;
            int    sko_num    = 0;
            for (int i = pixel_from; i <= pixel_to; i++)
            {
                double val = fk.CalcY(i);
                ever += val;
                if (mask[i])
                {
                    double tmp = sg[i] - val;
                    sko += tmp * tmp;
                    sko_num++;
                }
            }

            ever  /= (pixel_to - pixel_from + 1);
            sko   /= sko_num;
            sko    = Math.Sqrt(sko) * 100 / ever;
            analit = ever;
            err    = sko;

            log.Add(new GLogMsg(log_section,
                                Common.MLS.Get(MLSConst, "Уровень фона=") + ever +
                                Common.MLS.Get(MLSConst, " с СКО=") + sko,
                                Color.Black));

            return(true);
        }
Example #21
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);
            }
        }
Example #22
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;
        }
Example #23
0
        void ShearchThread()
        {
            try
            {
                lbSearchResult.Enabled = false;
                List <int> sn_list = new List <int>();
                //float x, y;
                //List<float> pixt;
                List <int> snt;

                Dispers disp = Sp.GetCommonDispers();
                int[]   ss   = disp.GetSensorSizes();

                Results.Clear();
                bool is_line = cbGraphType.SelectedIndex == 0;
                switch (cbSearchType.SelectedIndex)
                {
                case 0:
                    snt = disp.FindSensors((float)Formula.Formula.analitParamCalc.methodLineCalc1.nmLy.Value);
                    if (Formula.Formula.analitParamCalc.methodLineCalc1.cbFromSnNum.SelectedIndex == 0)
                    {
                        sn_list.Add(snt[0]);
                    }
                    else
                    {
                        sn_list.Add(snt[1]);
                    }
                    break;

                case 1:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if ((i % 2) != 0)
                        {
                            sn_list.Add(i);
                        }
                    }
                    break;

                case 2:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if ((i % 2) == 0)
                        {
                            sn_list.Add(i);
                        }
                    }
                    break;

                case 3:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        sn_list.Add(i);
                    }
                    break;
                }


                SimpleFormulaEditor.Setup(ElementName, Formula.Formula,
                                          Method, Spv, ElementIndex, SelectedCol);

                int redraw_count = 0;
                //DelRecalcFormula frd = new DelRecalcFormula(DelRecalcFormulaProc);

                MaxSize = 0;
                for (int s_index = 0; s_index < sn_list.Count; s_index++)
                {
                    MaxSize += ss[sn_list[s_index]] - 60;
                }
                Passed = 0;
                SpectrDataView def_viwe = Sp.GetDefultView();
                for (int s_index = 0; s_index < sn_list.Count && Visible && Th != null && Common.IsRunning; s_index++)
                {
                    SpectrCalc calc = new SpectrCalc(Method, ElementIndex, SelectedCol);
                    calc.InitData(sn_list[s_index]);
                    //Thread.Sleep(10);
                    int sn = sn_list[s_index];
                    CurrentSN = sn;

                    float[] data = def_viwe.GetSensorData(sn);
                    for (int pix = 30; pix < ss[sn] - 30; pix++)
                    {
                        if (analit.SpectrFunctions.IsPick(data, pix, Common.Conf.MaxLevel) == false)
                        {
                            continue;
                        }
                        CurrentPix = pix;
                        float ly = (float)disp.GetLyByLocalPixel(sn, pix);

                        double     sko = calc.CalcSKO(pix, is_line);
                        CalcResult cr  = new CalcResult(ly, sn, sko, pix);
                        if (Results.Count == 0)
                        {
                            Results.Add(cr);
                        }
                        else
                        {
                            bool added = false;
                            for (int i = 0; i < Results.Count; i += 100)
                            {
                                if (Results[i].SKO > sko || i + 100 >= Results.Count)
                                {
                                    int ifrom = i - 100;
                                    if (ifrom < 0)
                                    {
                                        ifrom = 0;
                                    }
                                    int ito = i + 10;
                                    if (ito >= Results.Count)
                                    {
                                        ito = Results.Count;
                                    }
                                    for (i = ifrom; i < ito; i++)
                                    {
                                        if (Results[i].SKO > sko)
                                        {
                                            Results.Insert(i, cr);
                                            added = true;
                                            break;
                                        }
                                    }
                                    //Results.Insert(i, cr);
                                    //added = true;
                                    break;
                                }
                            }

                            if (added == false && Results.Count < 2000)
                            {
                                Results.Add(cr);
                            }
                            while (Results.Count > 2000)
                            {
                                Results.RemoveAt(Results.Count - 1);
                            }
                        }
                        if ((redraw_count % 100) == 0)
                        {
                            This.Invoke(new MethodInvoker(UpdateLb));
                        }
                        redraw_count++;
                        Passed++;
                        pix += 3;
                    }
                    for (int i = 0; i < Results.Count; i++)
                    {
                        int pixel = Results[i].Pixel;
                        int s     = Results[i].Sn;
                        for (int j = i + 1; j < Results.Count; j++)
                        {
                            if (s == Results[j].Sn && Math.Abs(pixel - Results[j].Pixel) < 10)
                            {
                                Results.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }

                This.Invoke(new MethodInvoker(UpdateLb));

                MemoryStream ms = new MemoryStream();
                BinaryWriter bw = new BinaryWriter(ms);
                bw.Write(1);
                bw.Write(Results.Count);
                for (int i = 0; i < Results.Count; i++)
                {
                    Results[i].Save(bw);
                }
                bw.Flush();
                Formula.Formula.SeachBuffer = ms.GetBuffer();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            finally
            {
                This.Invoke(new MethodInvoker(AfterThread));
            }
        }
Example #24
0
 public InputLinks()
 {
     InitializeComponent();
     Disp = new Dispers();
 }
 public ExtraLineInfo(int sn, int pixel, Dispers disp, float ampl)
 {
     Ampl = ampl;
     Ly   = (float)disp.GetLyByLocalPixel(sn, pixel);
 }
Example #26
0
        private void mmLineToPik_Click(object sender, EventArgs e)
        {
            try
            {
                bool result;

                LastLinks = Disp.Compile(tbLinks.Text, true, out result);
                //result = ApplyDispers();
                //ApplyDispersDelProc();
                //if (ApplyDispResult != 1)//
                if (result == false)
                {
                    MessageBox.Show(MainForm.MForm,
                                    Common.MLS.Get(MLSConst, "Обнаружены ошибки. Их необходимо исправить."), //"Compilation error. Correct problem first."),
                                    Common.MLS.Get(MLSConst, "Проблема"),                                    //"Problem"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    return;
                }
                Dispers disp = Disp;
                Control.SelectSpectr();
                if (SelectedMarker < 0)
                {
                    return;
                }
                int s = 0;
                if (sender == mmLineToPik1)
                {
                    s = 0;
                }
                else
                {
                    if (sender == mmLineToPik2)
                    {
                        s = 1;
                    }
                    else
                    {
                        if (sender == mmLineToPik3)
                        {
                            s = 2;
                        }
                    }
                }

                Spectr sp = GetSpectr(s);
                if (sp == null)
                {
                    return;
                }

                SpectrDataView view = sp.GetDefultView();
                //Dispers disp = sp.GetCommonDispers();

                int     sn    = LastLinks[SelectedMarker].Sn;
                float[] data  = view.GetSensorData(sn);
                int     pixel = (int)disp.GetLocalPixelByLy(sn, LastLinks[SelectedMarker].Ly);

                try
                {
                    if (data[pixel] < data[pixel + 1])
                    {
                        while (data[pixel] < data[pixel + 1])
                        {
                            pixel++;
                        }
                    }
                    else
                    {
                        if (data[pixel] < data[pixel - 1])
                        {
                            while (data[pixel] < data[pixel - 1])
                            {
                                pixel--;
                            }
                        }
                    }
                }
                catch { }

                float  nly    = (float)disp.GetLyByLocalPixel(sn, pixel);
                float  gpixel = (float)disp.GetGlobalPixelByLy(sn, nly);
                string text   = (string)tbLinks.Text.Clone();
                int    from   = tbLinks.SelectionStart;
                int    len    = tbLinks.SelectionLength;
                string txt1   = text.Substring(0, from);
                string txt2   = text.Substring(from + len + 1);
                text = txt1 + Math.Round(gpixel, 1) + "-" + Math.Round(gpixel, 2) + txt2;
                //tbLinks.Text = text;
                //SetupMarkers(false);
                ApplyDispers();
            }
            catch (Exception ex) { Common.Log(ex); }
        }
Example #27
0
        void GetData(SpectrDataView data, Dispers disp, OpticFk fk,
                     out int[] sn, out int[] pixel, out int[] vpixel, out float[] signal, out float[] sens)
        {
            int[]     ss   = disp.GetSensorSizes();
            float[][] vals = data.GetFullDataNoClone();
            int       len  = 0;

            for (int s = 0; s < ss.Length; s++)
            {
                if (data.BlankStart != null)
                {
                    len += data.BlankStart[s].Length;
                }
                if (data.BlankEnd != null)
                {
                    len += data.BlankEnd[s].Length;
                }
                len += vals[s].Length;
            }

            sn     = new int[len];
            pixel  = new int[len];
            vpixel = new int[len];
            signal = new float[len];
            sens   = new float[len];

            int ind = 0;

            for (int s = 0; s < ss.Length; s++)
            {
                int pix  = 0;
                int vpix = 0;
                int l;
                if (data.BlankStart != null)
                {
                    l = data.BlankStart[s].Length;
                    for (int i = 0; i < l; i++, ind++, pix++)
                    {
                        sn[ind]     = s;
                        pixel[ind]  = pix;
                        vpixel[ind] = -1;
                        sens[ind]   = 1;
                        signal[ind] = data.BlankStart[s][i];
                    }
                }
                l = vals[s].Length;
                for (int i = 0; i < l; i++, ind++, pix++, vpix++)
                {
                    sn[ind]     = s;
                    pixel[ind]  = pix;
                    vpixel[ind] = vpix;
                    signal[ind] = vals[s][i];
                    sens[ind]   = 1;//fk.SensK[s][i];
                }
                if (data.BlankEnd != null)
                {
                    l = data.BlankEnd[s].Length;
                    for (int i = 0; i < l; i++, ind++, pix++)
                    {
                        sn[ind]     = s;
                        pixel[ind]  = pix;
                        vpixel[ind] = -1;
                        sens[ind]   = 1;
                        signal[ind] = data.BlankEnd[s][i];
                    }
                }
            }
        }
        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);
        }
        private void btCallectSpaces_Click(object sender, EventArgs e)
        {
            try
            {
                EmptySpaces.Clear();
                //ExceptionLy.Clear();
                Dispers d        = null;
                int     pr_count = Method.GetProbCount();
                int[]   ss       = Common.Dev.Reg.GetSensorSizes();
                int[][] founds   = new int[ss.Length][];
                for (int i = 0; i < ss.Length; i++)
                {
                    founds[i] = new int[ss[i]];
                }
                int side = (int)nmMinLineWidth.Value / 2;
                for (int pr = 0; pr < pr_count; pr++)
                {
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sp_count         = msp.MeasuredSpectrs.Count;
                    for (int sp = 0; sp < sp_count; sp++)
                    {
                        MethodSimpleProbMeasuring mspm = msp.MeasuredSpectrs[sp];
                        Spectr spectr = mspm.Sp;
                        if (spectr.IsEmpty())
                        {
                            continue;
                        }
                        int[] view = mspm.Sp.GetShotIndexes();
                        List <SpectrDataView> views = mspm.Sp.GetViewsSet();
                        int sum = side * 2 + 2;
                        for (int vi = 0; vi < view.Length; vi++)
                        {
                            SpectrDataView cur_view  = views[view[vi]];
                            float          max_level = cur_view.MaxLinarLevel;
                            SpectrDataView nul_view  = mspm.Sp.GetNullFor(view[vi]);
                            d = spectr.GetCommonDispers();//cur_view.GetDispersRO();
                            for (int sn = 0; sn < ss.Length; sn++)
                            {
                                float[] sig  = cur_view.GetSensorData(sn);
                                float[] nul  = nul_view.GetSensorData(sn);
                                float[] data = new float[sig.Length];
                                for (int pix = 0; pix < data.Length; pix++)
                                {
                                    data[pix] = sig[pix] - nul[pix];
                                }
                                int   len = ss[sn] - 10;
                                float min = 0;
                                for (int pix = 0; pix < 10; pix++)
                                {
                                    min += data[pix];
                                }
                                for (int pix = 0; pix < len; pix++)
                                {
                                    float tmp = 0;
                                    for (int j = pix; j < pix + 10; j++)
                                    {
                                        tmp += data[j];
                                    }
                                    if (tmp < min)
                                    {
                                        min = tmp;
                                    }
                                }
                                len  = ss[sn] - side - 3;
                                min /= 10;
                                min *= 3;
                                int left  = 0;
                                int right = 0;
                                for (int pix = side + 3; pix < len; pix++)
                                {
                                    if (isLine(data, len + side + 1, pix, max_level, side, sum, ref left, ref right))
                                    {
                                        for (int i = pix - left; i <= pix + right; i++)
                                        {
                                            founds[sn][i]++;
                                        }
                                        pix += right;
                                    }
                                }
                            }
                        }
                    }
                }

                for (int sn = 0; sn < ss.Length; sn++)
                {
                    int margin_before = (int)nmMargine.Value;
                    int len           = 0;
                    int pix_from      = 0;
                    for (int pix = 0; pix < ss[sn]; pix++)
                    {
                        if (founds[sn][pix] <= 1 && pix < ss[sn] - 1)
                        {
                            if (margin_before > 0)
                            {
                                margin_before--;
                                pix_from = pix;
                            }
                            else
                            {
                                len++;
                            }
                        }
                        else
                        {
                            len -= (int)nmMargine.Value;
                            if (len >= nmMinFreeSpaceSize.Value)
                            {
                                float[] es = { 1,                             (float)d.GetLyByLocalPixel(sn, pix_from),
                                               (float)d.GetLyByLocalPixel(sn, pix - (int)nmMargine.Value),   len };
                                EmptySpaces.Add(es);
                            }
                            margin_before = (int)nmMargine.Value;
                            len           = 0;
                        }
                    }
                }

                ReInitList();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }