/// <summary>
        /// Visits all the hot pixels which may intersect a segment (p0-p1).
        /// The visitor must determine whether each hot pixel actually intersects
        /// the segment.
        /// </summary>
        /// <param name="p0">The segment start point</param>
        /// <param name="p1">The segment end point</param>
        /// <param name="visitor">The visitor to apply</param>
        public void Query(Coordinate p0, Coordinate p1, IKdNodeVisitor <HotPixel> visitor)
        {
            var queryEnv = new Envelope(p0, p1);

            // expand query range to account for HotPixel extent
            // expand by full width of one pixel to be safe
            queryEnv.ExpandBy(1.0 / _scaleFactor);
            _index.Query(queryEnv, visitor);
        }
Esempio n. 2
0
        private static void QueryNode(KdNode <T> currentNode,
                                      Envelope queryEnv, bool odd, IKdNodeVisitor <T> visitor)
        {
            if (currentNode == null)
            {
                return;
            }

            double min;
            double max;
            double discriminant;

            if (odd)
            {
                min          = queryEnv.MinX;
                max          = queryEnv.MaxX;
                discriminant = currentNode.X;
            }
            else
            {
                min          = queryEnv.MinY;
                max          = queryEnv.MaxY;
                discriminant = currentNode.Y;
            }
            bool searchLeft  = min < discriminant;
            bool searchRight = discriminant <= max;

            // search is computed via in-order traversal
            if (searchLeft)
            {
                QueryNode(currentNode.Left, queryEnv, !odd, visitor);
            }
            if (queryEnv.Contains(currentNode.Coordinate))
            {
                visitor.Visit(currentNode);
            }
            if (searchRight)
            {
                QueryNode(currentNode.Right, queryEnv, !odd, visitor);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Performs a range search of the points in the index.
 /// </summary>
 /// <param name="queryEnv">The range rectangle to query</param>
 /// <param name="visitor"></param>
 public void Query(Envelope queryEnv, IKdNodeVisitor <T> visitor)
 {
     QueryNode(_root, queryEnv, true, visitor);
 }