Example #1
0
        public static void Vectorize(
            List <Vector> trajectory,
            out List <Vector> vectors,
            bool normalize
            )
        {
            vectors = new List <Vector>();
            vectors.Clear();

            for (int ii = 1; ii < trajectory.Count; ii++)
            {
                Vector vec = trajectory[ii] - trajectory[ii - 1];

                if (normalize)
                {
                    vec.Normalize();
                }

                vectors.Add(vec);
            }
        }
Example #2
0
        public void Prepare(DeviceType deviceType,
                            List <Vector> resampled,
                            bool filtered = true)
        {
            List <Vector> rotated;
            List <Vector> dpPoints;

            this.device_id = deviceType;

            if (filtered == true)
            {
                rotated = sample.FilteredTrajectory;
            }
            else
            {
                rotated = sample.Trajectory;
            }

            // Remove duplicate points
            resampled.Add(rotated[0]);

            for (int ii = 1; ii < rotated.Count; ii++)
            {
                int    count  = resampled.Count - 1;
                double length = resampled[count].L2Norm(rotated[ii]);

                if (length <= Double.Epsilon)
                {
                    continue;
                }

                resampled.Add(rotated[ii]);
            }

            /*
             * Determine Threshold
             */
            sampleCount = resampled.Count;

            Mathematics.BoundingBox(resampled, out Vector minimum, out Vector maximum);

            double diag = maximum.L2Norm(minimum);

            /*
             * Resample the input using DP
             */
            Mathematics.DouglasPeuckerDensity(resampled, out dpPoints, diag * 0.010f);

            /*
             * Heuristically dehook the trajectory
             */
            if (deviceType == DeviceType.MOUSE)
            {
                int    ptCnt = dpPoints.Count;
                Vector v1    = dpPoints[1] - dpPoints[0];
                Vector v2    = dpPoints[2] - dpPoints[1];
                double ratio = v1.L2Norm() / v2.L2Norm();

                if (ratio < .2)
                {
                    dpPoints.RemoveAt(0);
                    ptCnt--;
                }

                v1 = dpPoints[ptCnt - 2] - dpPoints[ptCnt - 3];
                v2 = dpPoints[ptCnt - 1] - dpPoints[ptCnt - 2];

                ratio = v2.L2Norm() / v1.L2Norm();

                if (ratio < .2)
                {
                    dpPoints.RemoveAt(dpPoints.Count - 1);
                    ptCnt--;
                }
            }

            points = dpPoints;

            // Convert DP resampled points into vectors
            Mathematics.Vectorize(points, out vectors, true);

            // Determine correction factor information
            f2l_Vector = points[points.Count - 1] - points[0];
            double f2l_length = f2l_Vector.L2Norm();

            closedness  = f2l_length;
            closedness /= Mathematics.PathLength(resampled);
            f2l_Vector.Normalize();

            weightClosedness = (1.0f - f2l_length / diag);
            weightF2l        = Math.Min(1.0f, 2.0f * f2l_length / diag);
        }