Esempio n. 1
0
        private List <ObjAndNode <NodeType> > FindNearestRectToPoint(Point p, NodeType node)
        {
            List <ObjAndNode <NodeType> >  answer_list     = new List <ObjAndNode <NodeType> >();
            SimplePriorityQueue <NodeType> searching_nodes = new SimplePriorityQueue <NodeType>();

            searching_nodes.Enqueue(node, 0);

            RectangleObj answer      = null;
            NodeType     answer_node = default(NodeType);

            double min_distance_sq = region_width * region_width;

            while (searching_nodes.Count > 0)
            {
                NodeType current_node = searching_nodes.Dequeue();
                Dictionary <RectangleObj, double> nearest_rect = current_node.GetNearestRectangle(p);
                if (nearest_rect.Count > 0)
                {
                    foreach (KeyValuePair <RectangleObj, double> entry in nearest_rect)
                    {
                        if (entry.Value <= min_distance_sq || entry.Value < 0.01)
                        {
                            min_distance_sq = entry.Value;
                            answer          = entry.Key;
                            answer_node     = current_node;
                            if (min_distance_sq < 0.01)
                            {
                                ObjAndNode <NodeType> ans = new ObjAndNode <NodeType>();
                                ans.node = answer_node;
                                ans.rect = answer;
                                answer_list.Add(ans);
                                answer = null;
                            }
                        }
                    }
                }
                if (current_node.HasChildren())
                {
                    foreach (KeyValuePair <int, NodeType> child in current_node.getChildern())
                    {
                        NodeType     child_node = child.Value;
                        RectangleObj field_rect = new RectangleObj();
                        field_rect.SetRectangleByCenter(child_node.getCenter(), child_node.getNodeSize(), child_node.getNodeSize());
                        double field_dist = field_rect.GetDistanceSqToPoint(p);
                        if (field_dist <= min_distance_sq)
                        {
                            searching_nodes.Enqueue(child_node, (float)field_dist);
                        }
                    }
                }
            }
            if (answer != null)
            {
                ObjAndNode <NodeType> ans = new ObjAndNode <NodeType>();
                ans.node = answer_node;
                ans.rect = answer;
                answer_list.Add(ans);
            }
            return(answer_list);
        }
Esempio n. 2
0
 public PartitionNode(int node_layer, int size, Point center_coord, int cap)
 {
     Parents  = new Dictionary <int, PartitionNode>();
     Children = new Dictionary <int, PartitionNode>();
     layerNum = node_layer;
     bounds   = new RectangleObj();
     bounds.SetRectangleByCenter(center_coord, size, size);
     capacity = cap;
 }
Esempio n. 3
0
        public CoverNode(int size, Point center_coord, int cap, CoverNode node_parent, double p_value)
        {
            children        = new Dictionary <int, CoverNode>();
            bounds          = new RectangleObj();
            original_bounds = new RectangleObj();
            capacity        = cap;
            parent          = node_parent;
            double expanded_size = (1.0 + p_value) * size;

            original_bounds.SetRectangleByCenter(center_coord, size, size);
            bounds.SetRectangleByCenter(center_coord, (int)expanded_size, (int)expanded_size);
            pVal = p_value;

            if (node_parent == null)
            {
                layerNum = 0;
            }
            else
            {
                layerNum = node_parent.layerNum + 1;
            }
        }
Esempio n. 4
0
        public List <RectangleObj> IncrementalNNFindNext()
        {
            // 1st entry is the object found, the rest are the bounding boxes of circular search steps.
            List <RectangleObj> answer = new List <RectangleObj>();
            Random rand = new Random();

            while (incrNN_queue.Count > 0)
            {
                NodeOrObj current_element = incrNN_queue.Dequeue();
                while (incrNN_queue.Count > 0 && incrNN_queue.First().Equals(current_element))
                {
                    incrNN_queue.Dequeue();
                }

                if (current_element.IsObj())
                {
                    double       dist      = current_element.GetObj().GetDistanceSqToPoint(incrNN_origin);
                    RectangleObj circleObj = new RectangleObj();
                    int          radius    = (int)(Math.Sqrt(dist) * 2.0);
                    circleObj.SetRectangleByCenter(incrNN_origin, radius, radius);
                    circleObj.rect_color = Color.Orange;
                    answer.Add(circleObj);

                    answer.Insert(0, current_element.GetObj());
                    return(answer);
                }
                else
                {
                    NodeType     current_node = current_element.GetNode();
                    double       current_dist = current_node.GetBounds().GetDistanceSqToPoint(incrNN_origin);
                    RectangleObj circleObj    = new RectangleObj();
                    int          radius       = (int)(Math.Sqrt(current_dist) * 2.0);
                    circleObj.SetRectangleByCenter(incrNN_origin, radius, radius);
                    Color col = Color.FromArgb(0, rand.Next(50, 256), rand.Next(50, 256));
                    circleObj.rect_color = col;

                    answer.Add(circleObj);
                    if (!current_node.IsEmpty())
                    {
                        foreach (RectangleObj obj in current_node.GetAllStoredObjs())
                        {
                            double distance = obj.GetDistanceSqToPoint(incrNN_origin);
                            if (distance >= current_dist)
                            {
                                NodeOrObj obj_nodeOrObj = new NodeOrObj();
                                obj_nodeOrObj.SetObj(obj);
                                incrNN_queue.Enqueue(obj_nodeOrObj, (float)distance);
                            }
                        }
                    }
                    if (current_node.HasChildren())
                    {
                        foreach (KeyValuePair <int, NodeType> child_node in current_node.getChildern())
                        {
                            double distance = child_node.Value.GetBounds().GetDistanceSqToPoint(incrNN_origin);
                            if (distance >= current_dist)
                            {
                                NodeOrObj node_nodeOrObj = new NodeOrObj();
                                node_nodeOrObj.SetNode(child_node.Value);
                                incrNN_queue.Enqueue(node_nodeOrObj, (float)distance);
                            }
                        }
                    }
                }
            }
            return(answer);
        }