Example #1
0
        private static List <int> getCornerIdx(List <Vector3> rPoints)
        {
            List <int> corners = new List <int>();

            // first point is a corner
            corners.Add(0);

            List <float> straws = new List <float>();

            // store "straw" distances between spaced apart points
            for (int i = STRAW_WINDOW; i < (rPoints.Count - STRAW_WINDOW); i++)
            {
                Vector3 p1 = rPoints[i - STRAW_WINDOW];
                Vector3 p2 = rPoints[i + STRAW_WINDOW];
                straws.Add(Vector3.Distance(p1, p2));
            }

            // determine a threshold value in order to eliminate longer straws
            float t = QuickMedian.Median(new List <float>(straws)) * MEDIAN_THRESHOLD;

            // collect the point indeces corresponding to the shortest straws
            // in each region
            for (int i = STRAW_WINDOW; i < (rPoints.Count - STRAW_WINDOW); i++)
            {
                // check if straw corresponding to current point is below
                // median threshold
                if (straws[pointToStrawIdx(i)] < t)
                {
                    float min    = float.MaxValue;
                    int   minIdx = i;

                    // continue searching for index of point corresponding to the
                    // shortest straw in this region
                    while ((pointToStrawIdx(i)) < straws.Count &&
                           straws[pointToStrawIdx(i)] < t)
                    {
                        if (straws[pointToStrawIdx(i)] < min)
                        {
                            min    = straws[pointToStrawIdx(i)];
                            minIdx = i;
                        }
                        i++;
                    }
                    // save shortest straw in region
                    corners.Add(minIdx);
                }
            }
            // add final point as a corner
            corners.Add(rPoints.Count - 1);
            corners = postProcessCorners(rPoints, corners, straws);

            return(corners);
        }
Example #2
0
        public void MedianTest()
        {
            List <float> vals1 = new List <float> {
                5.1F, -2.0F, 10.5F, 3.2F, -1.2F, -2.0F, 4.0F
            };

            Assert.AreEqual(QuickMedian.Median(vals1), 3.2F);

            List <float> vals2 = new List <float> {
                5.1F, -2.0F, 10.5F, 3.2F, -1.2F, -2.0F, 4.0F, 11.0F
            };

            Assert.AreEqual(QuickMedian.Median(vals1), 3.2F);
        }