SGPeriod GetNextPeriod(SGPeriod _prev) { SGPeriod period = new SGPeriod(_prev); int start = FindPoint(period.start, true); if (start < 0) { return(null); } int middle = FindPoint(start, false); if (middle < 0) { return(null); } if (FullPeriod) { int stop = FindPoint(middle, true); if (stop < 0) { return(null); } period.start = start; period.size = stop - start; } else { period.start = start; period.size = middle - start; } return(period); }
SGPeriod GetNextPeriodHalf(SGPeriod _prev) { SGPeriod period = new SGPeriod(_prev); int start = FindPoint(period.start, true); if (start < 0) { return(null); } int stop = FindPoint(start, false); if (stop < 0) { return(null); } period.start = start; period.size = stop - start; return(period); }
IEnumerator Calc0( SqlBoolean _pars, SqlString _img, SqlString _stresh, SqlInt32 _HalfPeriod, SqlInt32 _HalfPeriodDif, SqlBoolean _FullPeriod, SqlString _ByU, SqlString _ValIU, SqlInt32 _BorderStart, SqlInt32 _BorderStop, SqlInt32 _SOPLenght, SqlInt32 _SOPStart, SqlInt32 _SOPStop ) { if (_img.IsNull) { yield break; } StartPoint = ParceEStartPoint(_ByU.Value); ValIU = ParceEValIU(_ValIU.Value); iu = IU.StrToIUfloat(_img.Value); periodMin = periodMin = _HalfPeriod.Value - _HalfPeriodDif.Value; if (periodMin < 0) { periodMin = 0; } periodMax = _HalfPeriod.Value + _HalfPeriodDif.Value; if (_SOPLenght.IsNull) { if (_BorderStart.IsNull) { Start = 0; } else { Start = Convert.ToInt32(Math.Floor(Convert.ToDouble(iu.Length) * _BorderStart.Value / 100)); } if (_BorderStop.IsNull) { Stop = iu.Length - 1; } else { Stop = iu.Length - 1 - Convert.ToInt32(Math.Floor(Convert.ToDouble(iu.Length) * _BorderStop.Value / 100)); } } else { double per_mm = iu.Length; per_mm /= _SOPLenght.Value; Start = Convert.ToInt32(Math.Ceiling(per_mm * (_SOPStart.IsNull ? 0 : _SOPStart.Value))); Stop = Convert.ToInt32(Math.Ceiling(per_mm * (_SOPStop.IsNull ? 0 : _SOPStop.Value))); if (Start < 0) { Start = 0; } if (Stop < Start) { Stop = Start; } if (Stop > iu.Length - 1) { Stop = iu.Length - 1; } } FullPeriod = _FullPeriod.Value; win = Convert.ToInt32(Math.Ceiling(_HalfPeriod.Value * 0.05)); int[] tresh; int treshMax; if (_stresh.IsNull) { tresh = new int[0]; treshMax = 0; } else { string[] mtresh = _stresh.Value.Split(';'); tresh = new int[mtresh.Length]; double k = _HalfPeriod.Value; k /= 100; treshMax = 0; for (int i = 0; i < mtresh.Length; i++) { tresh[i] = (int)(k * Convert.ToDouble(mtresh[i].Replace('.', ','))); if (treshMax < tresh[i]) { treshMax = tresh[i]; } } } double[] coords = new double[tresh.Length]; for (int i = 0; i < tresh.Length; i++) { coords[i] = 0; } List <SGHalfPeriod> Lsghp = new List <SGHalfPeriod>(); int nn = 0; SGPeriod prev_period = new SGPeriod() { start = Start, size = 0 }; for (; ;) { SGPeriod period = GetNextPeriod(prev_period); if (period == null) { break; } if (period.start + treshMax >= iu.Length) { break; } if (period.size > periodMax || period.size < periodMin) { prev_period = period; continue; } Lsghp.Add(new SGHalfPeriod(nn, period.start, period.size)); for (int i = 0; i < coords.Length; i++) { coords[i] += iu[period.start + tresh[i]].Val(ValIU); } nn++; prev_period = period; } for (int i = 0; i < coords.Length; i++) { coords[i] = Math.Round(coords[i] / nn, 2); if (double.IsNaN(coords[i])) { coords[i] = 0; } } if (_pars.Value) { for (int i = 0; i < coords.Length; i++) { yield return(new Result(i, coords[i], "")); } } else { for (int i = 0; i < Lsghp.Count; i++) { yield return(new Result(Lsghp[i].start, Lsghp[i].size, "")); } } }