Example #1
0
        /// <summary>
        /// Reads a node from a stream recursively
        /// </summary>
        /// <param name="depth">Current depth</param>
        /// <param name="br">Binary reader reference</param>
        /// <returns></returns>
        private static QuadTree ReadNode(uint depth, ref System.IO.BinaryReader br)
        {
            QuadTree node = new QuadTree();

            node._Depth = depth;
            node.Box    = new SharpMap.Geometries.BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble());
            bool IsLeaf = br.ReadBoolean();

            if (IsLeaf)
            {
                int FeatureCount = br.ReadInt32();
                node._objList = new List <BoxObjects>();
                for (int i = 0; i < FeatureCount; i++)
                {
                    BoxObjects box = new BoxObjects();
                    box.box = new SharpMap.Geometries.BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble());
                    box.ID  = (uint)br.ReadInt32();
                    node._objList.Add(box);
                }
            }
            else
            {
                node.Child0 = ReadNode(node._Depth + 1, ref br);
                node.Child1 = ReadNode(node._Depth + 1, ref br);
            }
            return(node);
        }
Example #2
0
        /// <summary>
        /// Reads a node from a stream recursively
        /// </summary>
        /// <param name="depth">Current depth</param>
        /// <param name="br">Binary reader reference</param>
        /// <returns></returns>
        private static QuadTree ReadNode(uint depth, ref BinaryReader br)
        {
            QuadTree node = new QuadTree
            {
                _depth = depth,
                Box    = new BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble())
            };
            var isLeaf = br.ReadBoolean();

            if (isLeaf)
            {
                int featureCount = br.ReadInt32();
                node._objList = new List <BoxObjects>();
                for (int i = 0; i < featureCount; i++)
                {
                    BoxObjects box = new BoxObjects
                    {
                        Box = new BoundingBox(
                            br.ReadDouble(), br.ReadDouble(),
                            br.ReadDouble(), br.ReadDouble()),
                        Id = (uint)br.ReadInt32()
                    };
                    node._objList.Add(box);
                }
            }
            else
            {
                node.Child0 = ReadNode(node._depth + 1, ref br);
                node.Child1 = ReadNode(node._depth + 1, ref br);
            }
            return(node);
        }
Example #3
0
        /// <summary>
        /// Reads a node from a stream recursively
        /// </summary>
        /// <param name="depth">Current depth</param>
        /// <param name="br">Binary reader reference</param>
        /// <returns></returns>
        private static QuadTree ReadNode(uint depth, BinaryReader br)
        {
            var bbox = new Envelope(new Coordinate(br.ReadDouble(), br.ReadDouble()),
                                    new Coordinate(br.ReadDouble(), br.ReadDouble()));
            var node = new QuadTree(bbox, depth);

            var isLeaf = br.ReadBoolean();

            if (isLeaf)
            {
                var featureCount = br.ReadInt32();
                node._objList = new List <BoxObjects>();
                for (int i = 0; i < featureCount; i++)
                {
                    var box = new BoxObjects();
                    box.Box = new Envelope(new Coordinate(br.ReadDouble(), br.ReadDouble()),
                                           new Coordinate(br.ReadDouble(), br.ReadDouble()));
                    box.ID = (uint)br.ReadInt32();
                    node._objList.Add(box);
                }
            }
            else
            {
                node.Child0 = ReadNode(depth + 1, br);
                node.Child1 = ReadNode(depth + 1, br);
            }
            return(node);
        }
Example #4
0
        /// <summary>
        /// Adds a new <see cref="BoxObjects"/> to this node.
        /// </summary>
        /// <param name="o">The boxed object</param>
        /// <param name="h">The child node creation heuristic</param>
        public void AddNode(BoxObjects o, Heuristic h)
        {
            /* -------------------------------------------------------------------- */
            /*      If there are subnodes, then consider whether this object        */
            /*      will fit in them.                                               */
            /* -------------------------------------------------------------------- */
            if (_child0 != null && _depth < h.maxdepth)
            {
                if (_child0.Box.Contains(o.Box.Centre))
                {
                    _child0.AddNode(o, h);
                }
                else if (_child1.Box.Contains(o.Box.Centre))
                {
                    _child1.AddNode(o, h);
                }
                return;
            }

            /* -------------------------------------------------------------------- */
            /*      Otherwise, consider creating two subnodes if could fit into     */
            /*      them, and adding to the appropriate subnode.                    */
            /* -------------------------------------------------------------------- */
            if (h.maxdepth > _depth && !IsLeaf)
            {
                Envelope half1, half2;
                SplitBoundingBox(Box, out half1, out half2);


                if (half1.Contains(o.Box.Centre))
                {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
                    _child0.AddNode(o, h);
                    return;
                }
                if (half2.Contains(o.Box.Centre))
                {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
                    _child1.AddNode(o, h);
                    return;
                }
            }

            /* -------------------------------------------------------------------- */
            /*      If none of that worked, just add it to this nodes list.         */
            /* -------------------------------------------------------------------- */
            //Debug.Assert(_child0 == null);

            if (_objList == null)
            {
                _objList = new List <BoxObjects>();
            }

            Box.ExpandToInclude(o.Box);

            _objList.Add(o);
        }
 /// <summary>
 /// Reads a node from a stream recursively
 /// </summary>
 /// <param name="depth">Current depth</param>
 /// <param name="br">Binary reader reference</param>
 /// <returns></returns>
 private static QuadTree ReadNode(uint depth, ref System.IO.BinaryReader br)
 {
     QuadTree node = new QuadTree();
     node._Depth = depth;
     node.Box = new SharpMap.Geometries.BoundingBox(br.ReadDouble(),br.ReadDouble(),br.ReadDouble(),br.ReadDouble());
     bool IsLeaf = br.ReadBoolean();
     if (IsLeaf)
     {
         int FeatureCount = br.ReadInt32();
         node._objList = new List<BoxObjects>();
         for (int i = 0; i < FeatureCount; i++)
         {
             BoxObjects box = new BoxObjects();
             box.box = new SharpMap.Geometries.BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble());
             box.ID = (uint)br.ReadInt32();
             node._objList.Add(box);
         }
     }
     else
     {
         node.Child0 = ReadNode(node._Depth + 1, ref br);
         node.Child1 = ReadNode(node._Depth + 1, ref br);
     }
     return node;
 }
Example #6
0
 /// <summary>
 /// Reads a node from a stream recursively
 /// </summary>
 /// <param name="depth">Current depth</param>
 /// <param name="br">Binary reader reference</param>
 /// <returns></returns>
 private static QuadTree ReadNode(uint depth, BinaryReader br)
 {
     var bbox = new Envelope(new Coordinate(br.ReadDouble(), br.ReadDouble()),
                             new Coordinate(br.ReadDouble(), br.ReadDouble()));
     var node = new QuadTree(bbox, depth);
     
     var isLeaf = br.ReadBoolean();
     if (isLeaf)
     {
         var featureCount = br.ReadInt32();
         node._objList = new List<BoxObjects>();
         for (int i = 0; i < featureCount; i++)
         {
             var box = new BoxObjects();
             box.Box = new Envelope(new Coordinate(br.ReadDouble(), br.ReadDouble()),
                                    new Coordinate(br.ReadDouble(), br.ReadDouble()));
             box.ID = (uint) br.ReadInt32();
             node._objList.Add(box);
         }
     }
     else
     {
         node.Child0 = ReadNode(depth + 1, br);
         node.Child1 = ReadNode(depth + 1, br);
     }
     return node;
 }
Example #7
0
        /// <summary>
        /// Adds a new <see cref="BoxObjects"/> to this node.
        /// </summary>
        /// <param name="o">The boxed object</param>
        /// <param name="h">The child node creation heuristic</param>
        public void AddNode(BoxObjects o, Heuristic h)
        {
          /* -------------------------------------------------------------------- */
          /*      If there are subnodes, then consider whether this object        */
          /*      will fit in them.                                               */
          /* -------------------------------------------------------------------- */
            if (_child0 != null && _depth < h.maxdepth)
            {
                if (_child0.Box.Contains(o.Box.Centre))
                    _child0.AddNode(o, h);
                else if (_child1.Box.Contains(o.Box.Centre))
                    _child1.AddNode(o, h);
                return;
            }
        
            /* -------------------------------------------------------------------- */
            /*      Otherwise, consider creating two subnodes if could fit into     */
            /*      them, and adding to the appropriate subnode.                    */
            /* -------------------------------------------------------------------- */
            if( h.maxdepth > _depth && !IsLeaf )
            {
                Envelope half1, half2;
                SplitBoundingBox(Box, out half1, out half2);
            

                if( half1.Contains(o.Box.Centre)) 
                {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
                    _child0.AddNode(o, h);
                    return;
                }    
	            if(half2.Contains(o.Box.Centre))
	            {
                    _child0 = new QuadTree(half1, _depth + 1);
                    _child1 = new QuadTree(half2, _depth + 1);
	                _child1.AddNode(o, h);
	                return;
	            }
            }
        
            /* -------------------------------------------------------------------- */
            /*      If none of that worked, just add it to this nodes list.         */
            /* -------------------------------------------------------------------- */
            //Debug.Assert(_child0 == null);
            
            if (_objList == null)
                _objList = new List<BoxObjects>();

            Box.ExpandToInclude(o.Box); 
            
            _objList.Add(o);

        }
Example #8
0
 /// <summary>
 /// Reads a node from a stream recursively
 /// </summary>
 /// <param name="depth">Current depth</param>
 /// <param name="br">Binary reader reference</param>
 /// <returns></returns>
 private static QuadTree ReadNode(uint depth, ref BinaryReader br)
 {
     QuadTree node = new QuadTree
     {
         _depth = depth,
         Box = new BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble())
     };
     var isLeaf = br.ReadBoolean();
     if (isLeaf)
     {
         int featureCount = br.ReadInt32();
         node._objList = new List<BoxObjects>();
         for (int i = 0; i < featureCount; i++)
         {
             BoxObjects box = new BoxObjects
             {
                 Box = new BoundingBox(
                     br.ReadDouble(), br.ReadDouble(),
                     br.ReadDouble(), br.ReadDouble()),
                 Id = (uint) br.ReadInt32()
             };
             node._objList.Add(box);
         }
     }
     else
     {
         node.Child0 = ReadNode(node._depth + 1, ref br);
         node.Child1 = ReadNode(node._depth + 1, ref br);
     }
     return node;
 }