Click here to Skip to main content
15,896,727 members
Articles / Programming Languages / C#

Reconstruction of Charts from Images

Rate me:
Please Sign up or sign in to vote.
4.92/5 (13 votes)
18 Mar 2010CPOL7 min read 38K   4.1K   42  
Usage of universal framework for chart reconstruction
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI;
using BaseTypes;
using DataPerformer.Interfaces;

namespace DataPerformer
{
    /// <summary>
    /// Vector series
    /// </summary>
    [Serializable()]
    public class SeriesVectorData : Series, IDataConsumer, INamedCoordinates, IPostSetArrow
    {
        #region Fields

        IMeasure xm;

        IMeasure ym;

        List<IMeasurements> measurements = new List<IMeasurements>();

 
 
        new const Double a = 0;

        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public SeriesVectorData()
        {
        }


        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected SeriesVectorData(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion
 
        #region IDataConsumer Members

        void IDataConsumer.Add(IMeasurements measurements)
        {
            this.measurements.Add(measurements);
        }

        void IDataConsumer.Remove(IMeasurements measurements)
        {
            this.measurements.Remove(measurements);
        }

        void IDataConsumer.UpdateChildrenData()
        {
            measurements.UpdateMeasurements(true);
        }

        int IDataConsumer.Count
        {
            get { return measurements.Count; }
        }

        IMeasurements IDataConsumer.this[int n]
        {
            get { return measurements[n]; }
        }

        void IDataConsumer.Reset()
        {
        }

        #endregion

        #region IPostSetArrow Members

        /// <summary>
        /// The operation that performs after arrows setting
        /// </summary>
        public void PostSetArrow()
        {
            xm = this.FindMeasure(X, true);
            ym = this.FindMeasure(Y, true);
        }

        #endregion

        #region Members

        /// <summary>
        /// List of measurements
        /// </summary>
        public List<string> Measurements
        {
            get
            {
                List<string> l = new List<string>();
                Dictionary<string, object> d = this.GetAllMeasuresType();
                foreach (string s in d.Keys)
                {
                    object t = d[s];
                    if (!(t is ArrayReturnType))
                    {
                        continue;
                    }
                    ArrayReturnType at = t as ArrayReturnType;
                    if (at.ElementType.Equals(a))
                    {
                        l.Add(s);
                    }
                }
                return l;
            }
        }

        /// <summary>
        /// Sets measurements
        /// </summary>
        /// <param name="x">Abscissa</param>
        /// <param name="y">Ordinate</param>
        public void Set(string x, string y)
        {
            X = x;
            Y = y;
            PostSetArrow();
        }

        /// <summary>
        /// Updates itself
        /// </summary>
        public void Update()
        {
            points.Clear();
            if ((xm == null) | (ym == null))
            {
                return;
            }
            this.FullReset();
            IDataConsumer dc = this;
            dc.UpdateChildrenData();
            object ox = xm.Parameter();
            object oy = ym.Parameter();
            try
            {

            double[] x = ox as double[];
                 if (x == null)
                {
                    object[] obx = ox as object[];
                    x = new double[obx.Length];
                    for (int i = 0; i < x.Length; i++)
                    {
                        x[i] = (double)obx[i];
                    }
                }
                double[] y = oy as double[];
                if (y == null)
                {
                    object[] oby = oy as object[];
                    y = new double[oby.Length];
                    for (int i = 0; i < y.Length; i++)
                    {
                        y[i] = (double)oby[i];
                    }
                }
  
            if (x == null | y == null)
            {
                return;
            }
            int n = x.Length;
            if (y.Length < n)
            {
                n = y.Length;
            }
            for (int i = 0; i < n; i++)
            {
                double[] p = new double[] { x[i], y[i] };
                points.Add(p);
            }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
        }

        #endregion

        #region INamedCoordinates Members

        IList<string> INamedCoordinates.GetNames(string coordinateName)
        {
            return Measurements;
        }

        string INamedCoordinates.X
        {
            get 
            {
                Series s = this;
                return s.X;
            }
        }

        string INamedCoordinates.Y
        {
            get 
            {
                Series s = this;
                return s.Y;
            }
        }

        void INamedCoordinates.Set(string x, string y)
        {
            X = x;
            Y = y;
            PostSetArrow();
            Update();
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions