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)); } }
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); }
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); }
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); }
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); }
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); } }
public override bool RunProc() { try { Shifts = null; SensK = null; DbFolder folder = Common.Db.GetFolder(Common.DbNameSystemFolder); Spectr sp_base = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile); folder = Common.Db.GetFolder(Common.DbNameTestingFolder); Spectr sp_cur; if (DevTest.DoNotStart == false) { Common.Dev.Measuring(sp_base.GetMeasuringCondition(), null); sp_cur = Common.Dev.GetLetestDataAsSpectr(); string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last"); sp_cur.SaveAs(path); } else { //string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last"); sp_cur = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile + "_last"); } Res = GetReportPrefix(); //Res += Common.MLS.Get(MLSConst, "Спектр промерен и сохранён... ")+serv.Endl; int[] ss = Common.Dev.Reg.GetSensorSizes(); sp_cur.OFk.ResetSens(); sp_cur.ResetDefaultView(); SpectrDataView base_view = sp_base.GetDefultView(); SpectrDataView cur_view = sp_cur.GetDefultView(); double[] shifts = new double[ss.Length]; int max_shift = 800; Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре:") + serv.Endl + " "; for (int s = Common.Conf.ValidSensorFrom - 1; s < ss.Length && s < Common.Conf.ValidSensorTo; s++) { //Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре #") + (s + 1); float[] input_data = base_view.GetSensorData(s); float[] hi_base = SpectrFunctions.FoldingGaus(input_data, 1F, 10); float[] rez_data = cur_view.GetSensorData(s); float[] hi_rez = SpectrFunctions.FoldingGaus(rez_data, 1F, 10); double crit = 0; int shift = 0; for (int sh = -max_shift; sh <= max_shift; sh++) { double cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10); if (serv.IsValid(cand) == false || cand < 0 || cand > 32000.0 * 32000.0 * hi_rez.Length) { cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10); continue; } if (cand > crit) { crit = cand; shift = sh; SpectroWizard.gui.MainForm.MForm.SetupPersents(100.0 * (s * 1001 + sh) / (ss.Length * 1001)); } } shifts[s] = -(shift / 10.0); //Res += Common.MLS.Get(MLSConst, " Значение сдвижки:") + shifts[s]; Res += " " + Math.Round(shifts[s], 1) + " "; if (Math.Abs(shifts[s]) > max_shift / 20) { Res += Common.MLS.Get(MLSConst, " Слишком много!") + serv.Endl; Res += serv.Endl; } } Res += serv.Endl; for (int i = 0; i < Common.Conf.ValidSensorFrom - 1; i++) { shifts[i] = shifts[Common.Conf.ValidSensorFrom - 1]; } for (int i = Common.Conf.ValidSensorTo; i < shifts.Length; i++) { shifts[i] = shifts[Common.Conf.ValidSensorTo - 1]; } for (int i = 0; i < shifts.Length; i++) { if (Math.Abs(shifts[i]) > max_shift / 20) { Res += Common.MLS.Get(MLSConst, "Слишком большие сдвижки.") + serv.Endl; return(false); } } for (int i = 2; i < shifts.Length; i += 2) { if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff) { Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] + Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl; return(false); } } for (int i = 3; i < shifts.Length; i += 2) { if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff) { Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] + Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl; return(false); } } double[] sensk = new double[ss.Length]; bool is_ok = true; if (Common.Conf.UseLineAmpl) { Res += Common.MLS.Get(MLSConst, "Проверка уровня освещённости сенсоров:") + serv.Endl + " "; List <SpectrDataView> views = sp_base.GetViewsSet(); int[] active_indexes = sp_base.GetShotIndexes(); int use_view = -1; float use_max = -1; for (int i = 0; i < active_indexes.Length; i++) { SpectrDataView data = views[active_indexes[i]]; if (data.GetCondition().Lines[0].CommonTime > use_max) { use_view = active_indexes[i]; use_max = data.GetCondition().Lines[0].CommonTime; } } SpectrDataView base_sig = views[use_view]; SpectrDataView base_nul = sp_base.GetNullFor(use_view); views = sp_cur.GetViewsSet(); SpectrDataView cur_sig = views[use_view]; SpectrDataView cur_nul = sp_cur.GetNullFor(use_view); for (int s = 0; s < ss.Length; s++) { float[] input_data = base_view.GetSensorData(s); float[] rez_data = cur_view.GetSensorData(s); //double sens = CheckSensK(input_data, rez_data, s, shifts[s]); double sens = CheckSensK(base_sig, base_nul, cur_sig, cur_nul, s, shifts[s]); if (double.IsNaN(sens)) { sens = 1; Res += Common.MLS.Get(MLSConst, "Неполучилось сбалансировать линейку №") + (s + 1) + " " + Common.MLS.Get(MLSConst, "Причина :") + CheckSensKErrors; Res += serv.Endl; is_ok = false; } else { //Res += " "; Res += " " + Math.Round(sens, 3) + " "; } sensk[s] = sens; } if (is_ok == true) { Res += serv.Endl; StatLineBalansCompiler(ref sensk); //sp_cur.ApplyLineLevelK(sensk); //sp_cur.ResetDefaultView(); }//*/ } else { //Res += Common.MLS.Get(MLSConst, "Проверка уровней засветок не проводилась т.к. данная опция на включена в конфигурации...") + serv.Endl; for (int s = 0; s < ss.Length; s++) { sensk[s] = 1; } } Res += serv.Endl; //for (int s = 0; s < ss.Length; s++) // sp_cur.GetCommonDispers().ApplyShifts(shifts[s], s); sp_cur.ApplySifts(shifts); sp_cur.Save(); if (is_ok == true) { Shifts = shifts; SensK = sensk; Common.Env.Store(); } else { return(false); } return(true); } catch (Exception ex) { Common.Log(ex); Res += Common.MLS.Get(MLSConst, "Критическая ошибка! ") + ex; return(false); } //return true; }