Ejemplo n.º 1
0
        /// <summary>
        /// Loads file from disk, file must exist
        /// </summary>
        public void Load(string filename)
        {
            PreviousComments.Clear();
            Solution.Functions.Clear();
            Points.Clear();
            FileStream   fs = null;
            StreamReader sr = null;

            try
            {
                fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs);
                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine();
                    if (s.StartsWith("#"))
                    {
                        if (Calibration.LoadCalibrationLine(s))
                        {
                            continue;
                        }
                        if (Solution.LoadSolutionLine(s))
                        {
                            continue;
                        }
                        PreviousComments.Add(s);
                        continue;
                    }
                    Calibration.LoadHeaderLine(s);
                    break;
                }
                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine();
                    if (s.StartsWith("#"))
                    {
                        continue;
                    }
                    DigitizerPoint p = new DigitizerPoint(s);
                    Points.Add(p);
                }
                CalibrateToLocation();
                Solution.SelectedFunctionIndex = Solution.Functions.Count - 1;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Computes an entire soluton
        /// </summary>
        public double Compute(DigitizerPoint dp)
        {
            dp.FitValue.X    = dp.Value.X;
            dp.PrefitValue.X = dp.Value.X;
            double y1 = this.Compute(dp.Value.X);

            if (double.IsNaN(y1))
            {
                dp.FitValue.Y    = float.NaN;
                dp.PrefitValue.Y = float.NaN;
                return(y1);
            }
            double y2 = y1;

            if (m_SelectedFunctionIndex >= 0)
            {
                y2 -= Functions[m_SelectedFunctionIndex].Compute(dp.Value.X);
            }
            try
            {
                dp.FitValue.Y    = (float)y1;
                dp.PrefitValue.Y = (float)y2;
            }
            catch
            {
                dp.FitValue.Y    = float.NaN;
                dp.PrefitValue.Y = float.NaN;
            }
            return(y1);
        }
Ejemplo n.º 3
0
 public void SetData(DigitizerPoint p)
 {
     Location.X = p.Location.X;
     Location.Y = p.Location.Y;
     Value.X    = p.Value.X;
     Value.Y    = p.Value.Y;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts pixel location to value
        /// </summary>
        public PointF LocationToValue(DigitizerPoint p)
        {
            float x = InterpolateLocation(p.Location.X, LeftBottomLocation.X, RightTopLocation.X, LeftBottomValue.X, RightTopValue.X);
            float y = InterpolateLocation(p.Location.Y, LeftBottomLocation.Y, RightTopLocation.Y, LeftBottomValue.Y, RightTopValue.Y);

            p.SetValue(x, y);
            return(p.Value);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts fit value to pixel location
        /// </summary>
        public Point FitValueToLocation(DigitizerPoint p)
        {
            if (!p.isFitted)
            {
                return(new Point(int.MaxValue, int.MaxValue));
            }
            int x = InterpolateValue(p.FitValue.X, LeftBottomValue.X, RightTopValue.X, LeftBottomLocation.X, RightTopLocation.X);
            int y = InterpolateValue(p.FitValue.Y, LeftBottomValue.Y, RightTopValue.Y, LeftBottomLocation.Y, RightTopLocation.Y);

            return(new Point(x, y));
        }