Esempio n. 1
0
 public void search(MBR mbr, HashSet <Edge> searchPts, Point p, double angle)
 {
     if (this.isLeaf())
     {
         foreach (Edge e in this.elements)
         {
             if (e.getMBR().isIntersectWith(mbr))
             {
                 if (e.isIntersectWith(mbr))
                 {
                     if (Geometry.getAnglediff(p.Direction, e) <= angle)
                     {
                         searchPts.Add(e);
                     }
                 }
             }
         }
     }
     else
     {
         foreach (rtree rt in this.children)
         {
             if (rt.m_br.isIntersectWith(mbr))
             {
                 rt.search(mbr, searchPts, p, angle);
             }
         }
     }
 }
Esempio n. 2
0
        protected rtree handleOverflowNodes(rtree node)
        {
            List <rtree> set_one = new List <rtree>();
            List <rtree> set_two = new List <rtree>();

            MBR mbr_one = new MBR();
            MBR mbr_two = new MBR();

            List <rtree> oldItems = new List <rtree>();

            foreach (rtree tr in this.children)
            {
                oldItems.Add(tr);
            }

            this.children.Clear();

            quadraticSplitNodes(oldItems, node, set_one, set_two, mbr_one, mbr_two);

            rtree child_one = buildNode(set_one, mbr_one);

            setChildren(set_two, mbr_two);

            if (this.isRoot())
            {
                return(makeNewRoot(child_one));
            }
            else
            {
                return(this.parent.insert(child_one));
            }
        }
        private void searchEdgeWithMaximumRadiusAngle(rtree rt, Point p, HashSet <Edge> cands, double radius, double step, int leastNum, double max_radius, double angle)
        {
            double xmin, ymin, xmax, ymax;

            ymin = p.Y - radius;
            ymax = p.Y + radius;
            xmin = p.X - radius;
            xmax = p.X + radius;

            double current_radius = radius;

            while (cands.Count < leastNum && current_radius <= max_radius)
            {
                MBR rect = new MBR(xmin, ymin, xmax, ymax);

                rt.search(rect, cands, p, angle);

                ymin = ymin - step;
                ymax = ymax + step;
                xmin = xmin - step;
                xmax = xmax + step;

                current_radius += step;
            }
        }
Esempio n. 4
0
        public bool isIntersectWith(MBR mbr)
        {
            Point left_top   = new Point(mbr.XMin, mbr.YMax);
            Point left_down  = new Point(mbr.XMin, mbr.YMin);
            Point right_top  = new Point(mbr.XMax, mbr.YMax);
            Point right_down = new Point(mbr.XMax, mbr.YMin);

            if (this.isIntersectWith(left_down, right_down))
            {
                return(true);
            }

            if (this.isIntersectWith(right_down, right_top))
            {
                return(true);
            }

            if (this.isIntersectWith(right_top, left_top))
            {
                return(true);
            }

            if (this.isIntersectWith(left_top, left_down))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        protected rtree handleOverflowElements(rtree node, Edge e)
        {
            List <Edge> set_one = new List <Edge>();
            List <Edge> set_two = new List <Edge>();

            MBR mbr_one = new MBR();
            MBR mbr_two = new MBR();

            List <Edge> oldItems = new List <Edge>();

            foreach (Edge p in node.elements)
            {
                oldItems.Add(p);
            }

            quadraticSplitElements(oldItems, e, set_one, set_two, mbr_one, mbr_two);

            rtree child_one = buildNode(set_one, mbr_one);

            node.setElement(set_two, mbr_two);

            if (node.isRoot())
            {
                return(node.makeNewRoot(child_one));
            }
            else
            {
                return(node.parent.insert(child_one));
            }
        }
Esempio n. 6
0
        protected void updateMBRLocal()
        {
            if (this.isLeaf())
            {
                this.m_br = null;

                foreach (Edge e in elements)
                {
                    if (this.m_br == null)
                    {
                        this.m_br = new MBR(e.From.toPoint(), e.To.toPoint());
                    }
                    else
                    {
                        this.m_br.unionWith(e.getMBR());
                    }
                }
            }
            else
            {
                this.m_br = null;
                foreach (rtree rt in children)
                {
                    if (this.m_br == null)
                    {
                        this.m_br = new MBR(rt.m_br);
                    }
                    else
                    {
                        this.m_br.unionWith(rt.m_br);
                    }
                }
            }
        }
Esempio n. 7
0
 public void search(MBR mbr, HashSet <Edge> searchPts)
 {
     if (this.isLeaf())
     {
         foreach (Edge p in this.elements)
         {
             if (p.getMBR().isIntersectWith(mbr))
             {
                 if (p.isIntersectWith(mbr))
                 {
                     searchPts.Add(p);
                 }
             }
         }
     }
     else
     {
         foreach (rtree rt in this.children)
         {
             if (rt.m_br.isIntersectWith(mbr))
             {
                 rt.search(mbr, searchPts);
             }
         }
     }
 }
Esempio n. 8
0
        public void createMBR()
        {
            _mbr = new MBR();
            _mbr.unionWith(this.from);
            _mbr.unionWith(this.to);

            hasMBR = true;
        }
Esempio n. 9
0
 public rtree(int min, int max)
 {
     minItems = min;
     maxItems = max;
     elements = new List <Edge>();
     children = new List <rtree>();
     pnts     = new List <Edge>();
     m_br     = new MBR();
 }
Esempio n. 10
0
        public MBR(MBR mbr1)
        {
            this.xmin = mbr1.XMin;
            this.xmax = mbr1.XMax;
            this.ymin = mbr1.YMin;
            this.ymax = mbr1.YMax;

            haspoint = true;
        }
Esempio n. 11
0
        public void become(MBR rect)
        {
            xmin = rect.XMin;
            xmax = rect.XMax;
            ymin = rect.YMin;
            ymax = rect.YMax;

            haspoint = true;
        }
        public Graph(string vfile, string efile, string edge_attribute_file)
        {
            _ext = new MBR();

            load(vfile, efile, edge_attribute_file);

            int min_item = 10;
            int max_item = 20;

            build_rtree_index(min_item, max_item);
        }
Esempio n. 13
0
 public bool isIntersectWith(MBR other)
 {
     if (Math.Max(xmin, other.XMin) <= Math.Min(xmax, other.XMax) && Math.Max(ymin, other.YMin) <= Math.Min(ymax, other.YMax))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 14
0
        public void unionWith(MBR mbr)
        {
            if (haspoint && mbr.haspoint)
            {
                unionWith(mbr.minPoint());
                unionWith(mbr.maxPoint());
            }

            if (haspoint == false && mbr.haspoint == true)
            {
                this.become(mbr);
            }
        }
Esempio n. 15
0
        protected rtree buildNode(List <Edge> input, MBR newMbr)
        {
            rtree ret = new rtree(minItems, maxItems);

            foreach (Edge pt in input)
            {
                ret.elements.Add(pt);
            }

            ret.m_br = new MBR(newMbr);

            return(ret);
        }
        private void searchEdgeWithinRadiusOneStep(rtree rt, Point p, HashSet <Edge> cands, double radius)
        {
            double xmin, ymin, xmax, ymax;

            ymin = p.Y - radius;
            ymax = p.Y + radius;
            xmin = p.X - radius;
            xmax = p.X + radius;

            MBR rect = new MBR(xmin, ymin, xmax, ymax);

            rt.search(rect, cands);
        }
Esempio n. 17
0
        protected rtree buildNode(List <rtree> input, MBR newMbr)
        {
            rtree ret = new rtree(minItems, maxItems);

            for (int i = 0; i < input.Count; i++)
            {
                ret.children.Add(input[i]);
                ret.children[i].parent = ret;
            }

            if (newMbr != null)
            {
                ret.m_br = new MBR(newMbr);
            }

            return(ret);
        }
Esempio n. 18
0
        protected void setElement(List <Edge> newElements, MBR newMbr)
        {
            this.elements.Clear();
            foreach (Edge pt in newElements)
            {
                this.elements.Add(pt);
            }

            this.children.Clear();

            if (m_br == null)
            {
                m_br = new MBR(newMbr);
            }
            else
            {
                m_br.become(newMbr);
            }
        }
Esempio n. 19
0
        protected double areaEnlarge(MBR br, Edge e)
        {
            double xmin = 0, xmax = 0, ymin = 0, ymax = 0;

            if (e.getMBR().XMax > br.XMax)
            {
                xmax = e.getMBR().XMax;
            }
            else
            {
                xmax = br.XMax;
            }

            if (e.getMBR().XMin < br.XMin)
            {
                xmin = e.getMBR().XMin;
            }
            else
            {
                xmin = br.XMin;
            }

            if (e.getMBR().YMax > br.YMax)
            {
                ymax = e.getMBR().YMax;
            }
            else
            {
                ymax = br.YMax;
            }

            if (e.getMBR().YMin < br.YMin)
            {
                ymin = e.getMBR().YMin;
            }
            else
            {
                ymin = br.YMin;
            }

            return((ymax - ymin) * (xmax - xmin) - br.area());
        }
Esempio n. 20
0
        protected double areaExpand(MBR br1, MBR br2)
        {
            double xmin = 0, xmax = 0, ymin = 0, ymax = 0;

            if (br1.XMax > br2.XMax)
            {
                xmax = br2.XMax;
            }
            else
            {
                xmax = br2.XMax;
            }

            if (br1.XMin < br2.XMin)
            {
                xmin = br1.XMin;
            }
            else
            {
                xmin = br2.XMin;
            }

            if (br1.YMax > br2.YMax)
            {
                ymax = br1.YMax;
            }
            else
            {
                ymax = br2.YMax;
            }

            if (br1.YMin < br2.YMin)
            {
                ymin = br1.YMin;
            }
            else
            {
                ymin = br2.YMin;
            }

            return((ymax - ymin) * (xmax - xmin) - br1.area() - br2.area());
        }
Esempio n. 21
0
        protected void setChildren(List <rtree> newChildren, MBR newMbr)
        {
            if (newChildren.Count == 1)
            {
                if (newChildren[0].isLeaf())
                {
                    this.setElement(newChildren[0].elements, newChildren[0].m_br);
                }
                else
                {
                    this.setChildren(newChildren[0].children, newChildren[0].m_br);
                }

                newChildren[0].children.Clear();
                newChildren[0].elements.Clear();

                return;
            }

            this.children.Clear();

            foreach (rtree rt in newChildren)
            {
                rt.parent = this;
                this.children.Add(rt);
            }

            this.elements.Clear();

            if (newMbr != null)
            {
                if (this.m_br == null)
                {
                    this.m_br = new MBR(newMbr);
                }
                else
                {
                    this.m_br.become(newMbr);
                }
            }
        }
Esempio n. 22
0
        protected void quadraticSplitElements(List <Edge> oldItems, Edge newItem, List <Edge> set_one, List <Edge> set_two, MBR br_one, MBR br_two)
        {
            oldItems.Add(newItem);

            int    m = 0, n = 1;
            double maxdis = 0;

            for (int i = 0; i < oldItems.Count; i++)
            {
                for (int j = i + 1; j < oldItems.Count; j++)
                {
                    double p1_mid_x = (oldItems[i].From.X + oldItems[i].To.X) / 2;
                    double p1_mid_y = (oldItems[i].From.Y + oldItems[i].To.Y) / 2;
                    double p2_mid_x = (oldItems[j].From.X + oldItems[j].To.X) / 2;
                    double p2_mid_y = (oldItems[j].From.Y + oldItems[j].To.Y) / 2;

                    double dis = Math.Pow(p1_mid_x - p2_mid_x, 2) +
                                 Math.Pow(p1_mid_y - p2_mid_y, 2);

                    if (dis > maxdis)
                    {
                        maxdis = dis;
                        m      = i;
                        n      = j;
                    }
                }
            }

            set_one.Add(oldItems[m]);
            set_two.Add(oldItems[n]);

            br_one.unionWith(oldItems[m].getMBR());
            br_two.unionWith(oldItems[n].getMBR());

            oldItems.RemoveAt(m);

            if (m < n)
            {
                oldItems.RemoveAt(n - 1);
            }
            else
            {
                oldItems.RemoveAt(n);
            }

            while (!(oldItems.Count == 0))
            {
                if (minItems - set_one.Count == oldItems.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_one.Add(oldItems[i]);
                        br_one.unionWith(oldItems[i].getMBR());
                    }
                    break;
                }
                else if (oldItems.Count == minItems - set_two.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_two.Add(oldItems[i]);
                        br_two.unionWith(oldItems[i].getMBR());
                    }

                    break;
                }
                int k = 0;

                double s = areaEnlarge(br_one, oldItems[k]);
                double t = areaEnlarge(br_two, oldItems[k]);

                if (s < t)
                {
                    set_one.Add(oldItems[k]);
                    br_one.unionWith(oldItems[k].getMBR());
                }
                else
                {
                    set_two.Add(oldItems[k]);
                    br_two.unionWith(oldItems[k].getMBR());
                }

                oldItems.RemoveAt(k);
            }
        }
Esempio n. 23
0
        protected void quadraticSplitNodes(List <rtree> oldItems, rtree newItem, List <rtree> set_one, List <rtree> set_two, MBR br_one, MBR br_two)
        {
            oldItems.Add(newItem);

            int    m = 0, n = 1;
            double maxArea = areaExpand(oldItems[0].m_br, oldItems[1].m_br);

            for (int i = 0; i < oldItems.Count; i++)
            {
                for (int j = i + 1; j < oldItems.Count; j++)
                {
                    double area = areaExpand(oldItems[i].m_br, oldItems[j].m_br);
                    if (area > maxArea)
                    {
                        maxArea = area;
                        m       = i;
                        n       = j;
                    }
                }
            }

            set_one.Add(oldItems[m]);
            set_two.Add(oldItems[n]);

            MBR set_one_mbr = new MBR(oldItems[m].m_br);
            MBR set_two_mbr = new MBR(oldItems[n].m_br);

            oldItems.RemoveAt(m);

            if (m < n)
            {
                oldItems.RemoveAt(n - 1);
            }
            else
            {
                oldItems.RemoveAt(n);
            }

            while (!(oldItems.Count == 0))
            {
                if (minItems - set_one.Count == oldItems.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_one.Add(oldItems[i]);
                        set_one_mbr.unionWith(oldItems[i].m_br);
                    }
                    break;
                }
                else if (oldItems.Count == minItems - set_two.Count)
                {
                    for (int i = 0; i < oldItems.Count; i++)
                    {
                        set_two.Add(oldItems[i]);
                        set_two_mbr.unionWith(oldItems[i].m_br);
                    }
                    break;
                }

                int k = 0;

                double s = areaExpand(set_one_mbr, oldItems[k].m_br);
                double t = areaExpand(set_two_mbr, oldItems[k].m_br);

                if (s < t)
                {
                    set_one.Add(oldItems[k]);
                    set_one_mbr.unionWith(oldItems[k].m_br);
                }
                else
                {
                    set_two.Add(oldItems[k]);
                    set_two_mbr.unionWith(oldItems[k].m_br);
                }

                oldItems.RemoveAt(k);
            }

            br_one.become(set_one_mbr);
            br_two.become(set_two_mbr);
        }
Esempio n. 24
0
 public bool contain(MBR mbr)
 {
     return((mbr.XMin >= xmin) && (mbr.XMax <= xmax) && (mbr.YMin >= ymin) && (mbr.YMax <= ymax));
 }
        public void loadTrjfile(string trjfile, double Md)
        {
            double       time_interval = 0;//时间间隔
            FileStream   fs            = new FileStream(trjfile, FileMode.Open, FileAccess.Read);
            StreamReader sr            = new StreamReader(fs);
            int          i             = 0;

            if (_trj == null)
            {
                _trj = new Trajectory();
            }
            else
            {
                _trj.Clear();
            }

            if (_ext == null)
            {
                _ext = new MBR();
            }
            else
            {
                _ext.reset();
            }

            //mode
            string line = sr.ReadLine();

            while (line != null)
            {
                if (line == "X\tY\tT\tS\tD")
                {
                    line = sr.ReadLine();
                    continue;
                }
                string[] items = line.Split(new char[] { '\t' });

                double x = double.Parse(items[0]);
                double y = double.Parse(items[1]);
                //DateTime.Parse(items[0])
                DateTime t         = Convert.ToDateTime(items[2]);
                double   speed     = double.Parse(items[3]);
                double   direction = double.Parse(items[4]);

                if (i > 0)
                {
                    //以s为时间间隔进行读取
                    TimeSpan ts = t.Subtract(_trj[_trj.Count - 1].T).Duration();
                    if (Convert.ToDouble(ts.TotalSeconds) < time_interval)
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                    if (Math.Abs(x - _trj[_trj.Count - 1].X) < 0.00000001 && Math.Abs(y - _trj[_trj.Count - 1].Y) < 0.00000001)//剔除重复的点!!!
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                    if (Point.Distance(x, y, _trj[_trj.Count - 1].X, _trj[_trj.Count - 1].Y) < 20)//聚集点除噪音 && long.Parse(items[0]) != 1381604233
                    {
                        line = sr.ReadLine();
                        continue;
                    }
                }
                Point p = new Point(t, x, y, direction, speed);
                _trj.Add(p);
                _ext.unionWith(p);


                if (i > 0)
                {
                    //斜率约束
                    if (i % 5 == 4)
                    {
                        Point p1 = _trj[_trj.Count - 5];
                        Point p2 = _trj[_trj.Count - 4];
                        Point p4 = _trj[_trj.Count - 2];
                        Point p5 = _trj[_trj.Count - 1];

                        double m1 = (p2.Y - p1.Y) / (p2.X - p1.X);
                        double m2 = (p5.Y - p4.Y) / (p5.X - p4.X);

                        if (Math.Abs(m2 - m1) <= Md)
                        {
                            _trj[_trj.Count - 3].X = (p2.X + p4.X) / 2;
                            _trj[_trj.Count - 3].Y = (p2.Y + p4.Y) / 2;
                        }
                    }
                }

                i++;

                line = sr.ReadLine();
            }

            sr.Close();
            fs.Close();

            _trj_size = _trj.Count;
        }