Beispiel #1
0
        private Tuple <Dot, RayHitTestParameters> GetMouseOver(MouseEventArgs e, DotVisuals dots)
        {
            const double MAXHITDISTANCE = .035;

            // Fire a ray from the mouse point
            Point mousePoint = e.GetPosition(grdViewPort);
            var   ray        = UtilityWPF.RayFromViewportPoint(_camera, _viewport, mousePoint);

            var hit = dots.Dots.
                      Select(o => new
            {
                Dot        = o,
                Position   = o.Position,
                DotProduct = Vector3D.DotProduct(ray.Direction, o.Position - ray.Origin)
            }).
                      Where(o => o.DotProduct > 0). // throwing out points that are behind the camera
                      Select(o => new
            {
                o.Dot,
                o.Position,
                Distance = Math3D.GetClosestDistance_Line_Point(ray.Origin, ray.Direction, o.Position)
            }).
                      Where(o => o.Distance <= MAXHITDISTANCE).
                      OrderBy(o => (o.Position - ray.Origin).LengthSquared).
                      FirstOrDefault();

            // Sooooon :)
            //hit?.Index;
            Dot dot = hit == null ? (Dot)null : hit.Dot;

            return(Tuple.Create(dot, ray));
        }
Beispiel #2
0
        private void EnsureDotsCreated()
        {
            if (_dots == null)
            {
                _dots = new DotVisuals();
                _viewport.Children.Add(_dots.Visual);
            }

            foreach (var sketch in _vectorImages)
            {
                EnsureDotCreated(sketch);
            }
        }
Beispiel #3
0
        /// <summary>
        /// This wipes out everything (call this when loading a new session)
        /// </summary>
        public void Clear()
        {
            _network        = null;
            _networkInputs  = null;
            _networkOutputs = null;

            _vectorImages.Clear();

            if (_dots != null)
            {
                _viewport.Children.Remove(_dots.Visual);
                _dots = null;
            }
        }
        private Tuple<Dot, RayHitTestParameters> GetMouseOver(MouseEventArgs e, DotVisuals dots)
        {
            const double MAXHITDISTANCE = .035;

            // Fire a ray from the mouse point
            Point mousePoint = e.GetPosition(grdViewPort);
            var ray = UtilityWPF.RayFromViewportPoint(_camera, _viewport, mousePoint);

            var hit = dots.Dots.
                Select(o => new
                {
                    Dot = o,
                    Position = o.Position,
                    DotProduct = Vector3D.DotProduct(ray.Direction, o.Position - ray.Origin)
                }).
                Where(o => o.DotProduct > 0).      // throwing out points that are behind the camera
                Select(o => new
                {
                    o.Dot,
                    o.Position,
                    Distance = Math3D.GetClosestDistance_Line_Point(ray.Origin, ray.Direction, o.Position)
                }).
                Where(o => o.Distance <= MAXHITDISTANCE).
                OrderBy(o => (o.Position - ray.Origin).LengthSquared).
                FirstOrDefault();

            // Sooooon :)
            //hit?.Index;
            Dot dot = hit == null ? (Dot)null : hit.Dot;
            return Tuple.Create(dot, ray);
        }
        private static Tuple<Dot, Vector3D>[] GetForces(DotVisuals dots, bool useOutput, double mult)
        {
            // Figure out which set of distances to use
            var distances = useOutput ? dots.Distances_Output : dots.Distances_Input;

            #region Calculate forces

            Tuple<Dot, Vector3D>[] forces = distances.
                //AsParallel().     //TODO: if distances.Length > threshold, do this in parallel
                SelectMany(o =>
                {
                    // Spring from 1 to 2
                    Vector3D spring = o.Item2.Position - o.Item1.Position;
                    double springLength = spring.Length;

                    double difference = o.Item3 - springLength;
                    difference *= mult;

                    if (Math1D.IsNearZero(springLength))
                    {
                        spring = Math3D.GetRandomVector_Spherical_Shell(Math.Abs(difference));
                    }
                    else
                    {
                        spring = spring.ToUnit() * Math.Abs(difference);
                    }

                    if (difference > 0)
                    {
                        // Gap needs to be bigger, push them away (default is closing the gap)
                        spring = -spring;
                    }

                    return new[]
                        {
                            Tuple.Create(o.Item1, spring),
                            Tuple.Create(o.Item2, -spring)
                        };
                }).
                ToArray();

            #endregion

            // Give them a very slight pull toward the origin so that the cloud doesn't drift away
            Point3D center = Math3D.GetCenter(dots.Dots.Select(o => o.Position));
            double centerMult = mult * -5;

            Vector3D centerPullForce = center.ToVector() * centerMult;

            // Group by dot
            var grouped = forces.
                GroupBy(o => o.Item1.Token);

            return grouped.
                Select(o =>
                {
                    Vector3D sum = centerPullForce;
                    Dot dot = null;

                    foreach (var force in o)
                    {
                        dot = force.Item1;
                        sum += force.Item2;
                    }

                    return Tuple.Create(dot, sum);
                }).
                ToArray();
        }
        private void EnsureDotsCreated()
        {
            if (_dots == null)
            {
                _dots = new DotVisuals();
                _viewport.Children.Add(_dots.Visual);
            }

            foreach (var sketch in _vectorImages)
            {
                EnsureDotCreated(sketch);
            }
        }
        /// <summary>
        /// This wipes out everything (call this when loading a new session)
        /// </summary>
        public void Clear()
        {
            _network = null;
            _networkInputs = null;
            _networkOutputs = null;

            _vectorImages.Clear();

            if (_dots != null)
            {
                _viewport.Children.Remove(_dots.Visual);
                _dots = null;
            }
        }
Beispiel #8
0
        private static Tuple <Dot, Vector3D>[] GetForces(DotVisuals dots, bool useOutput, double mult)
        {
            // Figure out which set of distances to use
            var distances = useOutput ? dots.Distances_Output : dots.Distances_Input;

            #region Calculate forces

            Tuple <Dot, Vector3D>[] forces = distances.
                                             //AsParallel().     //TODO: if distances.Length > threshold, do this in parallel
                                             SelectMany(o =>
            {
                // Spring from 1 to 2
                Vector3D spring     = o.Item2.Position - o.Item1.Position;
                double springLength = spring.Length;

                double difference = o.Item3 - springLength;
                difference       *= mult;

                if (Math1D.IsNearZero(springLength))
                {
                    spring = Math3D.GetRandomVector_Spherical_Shell(Math.Abs(difference));
                }
                else
                {
                    spring = spring.ToUnit() * Math.Abs(difference);
                }

                if (difference > 0)
                {
                    // Gap needs to be bigger, push them away (default is closing the gap)
                    spring = -spring;
                }

                return(new[]
                {
                    Tuple.Create(o.Item1, spring),
                    Tuple.Create(o.Item2, -spring)
                });
            }).
                                             ToArray();

            #endregion

            // Give them a very slight pull toward the origin so that the cloud doesn't drift away
            Point3D center     = Math3D.GetCenter(dots.Dots.Select(o => o.Position));
            double  centerMult = mult * -5;

            Vector3D centerPullForce = center.ToVector() * centerMult;

            // Group by dot
            var grouped = forces.
                          GroupBy(o => o.Item1.Token);

            return(grouped.
                   Select(o =>
            {
                Vector3D sum = centerPullForce;
                Dot dot = null;

                foreach (var force in o)
                {
                    dot = force.Item1;
                    sum += force.Item2;
                }

                return Tuple.Create(dot, sum);
            }).
                   ToArray());
        }