Click here to Skip to main content
15,894,291 members
Articles / Desktop Programming / WPF

Integration: Kinematics + Digital Image Processing + 3D Graphics

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
9 Sep 2012CPOL12 min read 25.4K   3.4K   18  
Further promotion of integration ideas
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI;

using DataPerformer.Interfaces;

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

        /// <summary>
        /// Change input event
        /// </summary>
        private event Action onChangeInput = () => { };
        
        /// <summary>
        /// Measurements of coordinates
        /// </summary>
        protected IMeasure[] coordinates = new IMeasure[2];

        /// <summary>
        /// List of iterators
        /// </summary>
        protected List<IIterator> iterators = new List<IIterator>();

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

        #endregion

        #region Ctors

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


        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected SeriesIterator(SerializationInfo info, StreamingContext context)
        {
            x = info.GetValue("X", typeof(string)) as string;
            y = info.GetValue("Y", typeof(string)) as string;
        }

        #endregion

        #region Overriden Members

        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("X", x, typeof(string));
            info.AddValue("Y", y, typeof(string));
        }

        #endregion

        #region IDataConsumer Members

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

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

        void IDataConsumer.UpdateChildrenData()
        {
            foreach (IMeasurements m in measurementsData)
            {
                m.UpdateMeasurements();
            }
        }

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

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

        void IDataConsumer.Reset()
        {
            this.FullReset();
        }

        event Action IDataConsumer.OnChangeInput
        {
            add { onChangeInput += value; }
            remove { onChangeInput -= value; }
        }

        #endregion

        #region INamedCoordinates Members

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

        string INamedCoordinates.X
        {
            get { return this.X; }
        }

        string INamedCoordinates.Y
        {
            get { return this.Y; }
        }

        void INamedCoordinates.Set(string x, string y)
        {
            this.Set(x, y);
        }

        void INamedCoordinates.Update()
        {
        }


        #endregion
 
        #region IIteratorConsumer Members

        void IIteratorConsumer.Add(IIterator iterator)
        {
            iterators.Add(iterator);
        }

        void IIteratorConsumer.Remove(IIterator iterator)
        {
            iterators.Remove(iterator);
        }

        #endregion

        #region IPostSetArrow Members

        void IPostSetArrow.PostSetArrow()
        {
            Set();
            Post();
        }

        #endregion

        #region Specific Members

        /// <summary>
        /// Sets names of variables
        /// </summary>
        /// <param name="x">The X - coordinate name</param>
        /// <param name="y">The Y - coordinate name</param>
        public void Set(string x, string y)
        {
            this.x = x;
            this.y = y;
            Set();
        }

        /// <summary>
        /// Names of variables
        /// </summary>
        public IList<string> Names
        {
            get
            {
                Double a = 0;
                IList<string> l = this.GetAllMeasuresType(a);
                return l;
            }
        }

        /// <summary>
        /// Sets all own settings
        /// </summary>
        protected void Set()
        {
            points = new List<double[]>();
            List<IIterator> iter = iterators;
            if (iter.Count == 0)
            {
                iter = new List<IIterator>();
                this.GetIterators(iter);
            }
            IDataConsumer consumer = this;
            for (int i = 0; i < consumer.Count; i++)
            {
                IMeasurements m = consumer[i];
                IAssociatedObject ao = m as IAssociatedObject;
                string on = this.GetRelativeName(ao) + ".";
                for (int j = 0; j < m.Count; j++)
                {
                    IMeasure mea = m[j];
                    string s = on + mea.Name;
                    if (s.Equals(x))
                    {
                        coordinates[0] = mea;
                        continue;
                    }
                    if (s.Equals(y))
                    {
                        coordinates[1] = mea;
                    }
                }
            }
            foreach (IMeasure m in coordinates)
            {
                if (m == null)
                {
                    return;
                }
            }

            foreach (IIterator it in iter)
            {
                it.Reset();
            }
            while (true)
            {
                consumer.Reset();
                consumer.UpdateChildrenData();
                object ox = coordinates[0].Parameter();
                if (ox is DBNull | ox == null)
                {
                    goto iterate;
                }
                object oy = coordinates[1].Parameter();
                if (oy is DBNull | oy == null)
                {
                    goto iterate;
                }
                double xx = (double)ox;
                double yy = (double)oy;
                points.Add(new double[] { xx, yy });
            iterate:
                foreach (IIterator it in iter)
                {
                    if (!it.Next())
                    {
                        goto fin;
                    }
                }
            }
        fin:
            return;
        }

        /// <summary>
        /// Names of measurements
        /// </summary>
        public List<string> AllMeasurements
        {
            get
            {
                Double a = 0;
                IDataConsumer c = this;
                List<string> list = new List<string>();
                for (int i = 0; i < c.Count; i++)
                {
                    IMeasurements m = c[i];
                    IAssociatedObject ao = m as IAssociatedObject;
                    string on = this.GetRelativeName(ao) + ".";
                    for (int j = 0; j < m.Count; j++)
                    {
                        IMeasure mea = m[j];
                        if (mea.Type.Equals(a))
                        {
                            string s = on + mea.Name;
                            list.Add(s);
                        }
                    }
                }
                return list;
            }
        }



        #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