Esempio n. 1
0
        private QuadTreeNode LocateChild(SpatialObject obj)
        {
            float        xMid = (bounds.xMin + bounds.xMax) / 2;
            float        zMid = (bounds.zMin + bounds.zMax) / 2;
            QuadTreeNode node;

            if (obj.x < xMid)
            {
                if (obj.z < zMid)
                {
                    node = children[2];
                }
                else
                {
                    node = children[0];
                }
            }
            else
            {
                if (obj.z < zMid)
                {
                    node = children[3];
                }
                else
                {
                    node = children[1];
                }
            }
            return(node);
        }
Esempio n. 2
0
 public override void Add(SpatialObject obj)
 {
     if (count < bucketLimit)
     {
         list.Add(obj);
     }
     else
     {
     }
 }
Esempio n. 3
0
    public static void Main(String[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("testleak.dbs");
#if USE_GENERICS
        SpatialIndexR2 <SpatialObject> root = db.CreateSpatialIndexR2 <SpatialObject>();
#else
        SpatialIndexR2 root = db.CreateSpatialIndexR2();
#endif
        RectangleR2[] rectangles = new RectangleR2[nObjects];
        Random        rnd        = new Random(2014);
        db.Root = root;
        for (int i = 0; i < nObjects; i++)
        {
            SpatialObject so  = new SpatialObject();
            double        lat = rnd.NextDouble() * 180;
            double        lng = rnd.NextDouble() * 180;
            so.rect = rectangles[i] = new RectangleR2(lat, lng, lat + 10, lng + 10);
            so.body = new byte[minObjectSize + rnd.Next(maxObjectSize - minObjectSize)];
            root.Put(so.rect, so);
        }
        db.Commit();

        for (int i = 0; i < nIterations; i++)
        {
            if (i % 1000 == 0)
            {
                Console.WriteLine("Iteration " + i);
            }
            for (int j = 0; j < batchSize; j++)
            {
                int  k     = rnd.Next(nObjects);
                bool found = false;
                foreach (SpatialObject oldObj in root.Overlaps(rectangles[k]))
                {
                    if (oldObj.rect.Equals(rectangles[k]))
                    {
                        root.Remove(oldObj.rect, oldObj);
                        SpatialObject newObj = new SpatialObject();
                        newObj.rect = oldObj.rect;
                        newObj.body = new byte[minObjectSize + rnd.Next(maxObjectSize - minObjectSize)];
                        root.Put(newObj.rect, newObj);
                        oldObj.Deallocate();
                        found = true;
                        break;
                    }
                }
                Debug.Assert(found);
            }
            db.Commit();
        }
        db.Close();
    }
Esempio n. 4
0
        public void Register(NSUuid id, SpatialObject spatialObject)
        {
            if (!_knownObjects.ContainsKey(id))
            {
                _knownObjects.Add(id, spatialObject);
                //Debug.WriteLine("Added new spatial object to store");
                HandleStoreChanged();
                return;
            }

            _knownObjects[id] = spatialObject;
            HandleStoreChanged();
        }
Esempio n. 5
0
        /// <summary>
        /// Loads its needed content.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            playerIcon          = Game.Content.Load <Texture2D>("Textures/player");
            toolPanelBackground = Game.Content.Load <Texture2D>("Textures/toolPanel");
            actionAvailableIcon = Game.Content.Load <Texture2D>("Textures/actionIcon");
            font = Game.Content.Load <SpriteFont>("Fonts/SpriteFont1");
            Model   panoramaModel = Game.Content.Load <Model>("Objects/panorama");
            Vector3 pDiff         = panoramaModel.GetSize(worldMatrix) * 0.5f;

            pDiff.Y  = 0;
            panorama = new SpatialObject(panoramaModel, null, new Vector3(0, -5, 0) - pDiff, 0, worldMatrix);

            messageBackground = Game.Content.Load <Texture2D>("Textures/green");
        }
Esempio n. 6
0
    public static void Main(String[] args) 
    { 
        Storage db = StorageFactory.Instance.CreateStorage();
        db.Open("testleak.dbs");
#if USE_GENERICS
        SpatialIndexR2<SpatialObject> root = db.CreateSpatialIndexR2<SpatialObject>();
#else
        SpatialIndexR2 root = db.CreateSpatialIndexR2();
#endif
        RectangleR2[] rectangles = new RectangleR2[nObjects];
        Random rnd = new Random(2014);
        db.Root = root;
        for (int i = 0; i < nObjects; i++) { 
            SpatialObject so = new SpatialObject();
            double lat = rnd.NextDouble()*180;
            double lng = rnd.NextDouble()*180;
            so.rect = rectangles[i] = new RectangleR2(lat, lng, lat+10, lng+10);
            so.body = new byte[minObjectSize + rnd.Next(maxObjectSize - minObjectSize)];
            root.Put(so.rect, so);
        } 
        db.Commit();

        for (int i = 0; i < nIterations; i++) {
            if (i % 1000 == 0) { 
                Console.WriteLine("Iteration " + i);
            }
            for (int j = 0; j < batchSize; j++) { 
                int k = rnd.Next(nObjects);
                bool found = false;
                foreach (SpatialObject oldObj in root.Overlaps(rectangles[k])) { 
                    if (oldObj.rect.Equals(rectangles[k])) {
                        root.Remove(oldObj.rect, oldObj);
                        SpatialObject newObj = new SpatialObject();
                        newObj.rect = oldObj.rect;
                        newObj.body = new byte[minObjectSize + rnd.Next(maxObjectSize - minObjectSize)];
                        root.Put(newObj.rect, newObj);
                        oldObj.Deallocate();
                        found = true;
                        break;
                    }
                }
                Debug.Assert(found);
            }
            db.Commit();
        }
        db.Close();
    }
Esempio n. 7
0
        private void picture_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //Get the Spatial Image it belongs to
            SpatialObject obj = GetSpatialObjectFromPicture((PictureBox)sender);

            if (obj == null)
            {
                return;
            }

            _mouseX       = e.X;
            _mouseY       = e.Y;
            _movingObject = obj;

            Select(obj.Tag);
            ObjectSelected(obj.Tag);
        }
        public void OnStreamAssetEvent(SyncedData <StreamAsset> streamAsset, StreamEvent eventType)
        {
            if (!settings.isActive ||
                !PersistentKey.IsKeyFor <SyncObjectInstance>(streamAsset.key.key) ||
                streamAsset.data.boundingBox.Max.Equals(streamAsset.data.boundingBox.Min))
            {
                m_StreamOutput.SendStreamEvent(streamAsset, eventType);
                return;
            }

            SpatialObject obj;

            if (eventType == StreamEvent.Added)
            {
                obj = new SpatialObject(streamAsset);
            }
            else if (!m_ObjectsByStreamKey.TryGetValue(streamAsset.key, out obj))
            {
                return;
            }

            switch (eventType)
            {
            case StreamEvent.Added:
                m_ObjectsByStreamKey.Add(streamAsset.key, obj);
                Add(obj);
                break;

            case StreamEvent.Changed:
                Remove(obj);
                Add(obj);
                m_StreamOutput.SendStreamChanged(streamAsset);
                break;

            case StreamEvent.Removed:
                m_ObjectsByStreamKey.Remove(streamAsset.key);
                Remove(obj);
                obj.Dispose();
                m_StreamOutput.SendStreamRemoved(streamAsset);
                break;
            }
        }
Esempio n. 9
0
        void OnSpatialDataChanged(NetContext <SpatialDataChanged> ctx)
        {
            foreach (var entry in ctx.Data.Added)
            {
                var obj = new SpatialObject(entry.Id, entry.Spatial.Box);

                m_IdToSpatialObjects.Add(entry.Id, obj);
                Add(obj);
            }

            foreach (var entry in ctx.Data.Removed)
            {
                if (!m_IdToSpatialObjects.TryGetValue(entry.Id, out var obj))
                {
                    return;
                }

                m_IdToSpatialObjects.Remove(entry.Id);
                Remove(obj);
                obj.Dispose();
            }

            foreach (var entry in ctx.Data.Changed)
            {
                if (m_IdToSpatialObjects.TryGetValue(entry.OldInfo.Id, out var obj))
                {
                    m_IdToSpatialObjects.Remove(entry.OldInfo.Id);
                    Remove(obj);
                    obj.Dispose();
                }

                obj = new SpatialObject(entry.NewInfo.Id, entry.NewInfo.Spatial.Box);
                m_IdToSpatialObjects.Add(entry.NewInfo.Id, obj);
                Add(obj);
            }

            m_GlobalBoundsSize      = m_SpatialCollection.Bounds.size;
            m_GlobalMaxSqrDistance  = Mathf.Max(m_GlobalBoundsSize.x, m_GlobalBoundsSize.y, m_GlobalBoundsSize.z);
            m_GlobalMaxSqrDistance *= m_GlobalMaxSqrDistance;
        }
Esempio n. 10
0
 /// <summary>
 /// Destroys and removes object from this quarter evidence.
 /// </summary>
 /// <param name="obj">The destroyed object</param>
 public void DestroyObject(SpatialObject obj)
 {
     if (!updateProcessing)
     {
         if (obj is Human)
         {
             guards.Remove(obj as Human);
             walkers.Remove(obj as Human);
         }
         else if (obj is Box)
         {
             //solidObjects.Remove(obj);
             boxes.Remove(obj as Box);
         }
         game.Drawer.StopDrawingObject(obj);
         spaceGrid.RemoveObject(obj);
     }
     else
     {
         awaitingDestroy.Add(obj);
     }
 }
Esempio n. 11
0
        public void AddElement(object tag, double x, double y, bool redraw = false)
        {
            PictureBox picture = new PictureBox();

            picture.Image      = Highland64CourseImporter.Properties.Resources.blip;
            picture.MouseDown += new MouseEventHandler(picture_MouseDown);
            picture.MouseUp   += new MouseEventHandler(picture_MouseUp);
            picture.MouseMove += new MouseEventHandler(picture_MouseMove);
            SpatialObject obj = new SpatialObject();

            obj.X           = x; // (x - MinX) / (MaxX - MinX) * this.Width;
            obj.Y           = y; // (y - MinY) / (MaxY - MinY) * this.Height;
            obj.PBReference = picture;
            obj.Tag         = tag;
            Elements.Add(obj);
            ObjectToDot.Add(tag, obj);

            if (redraw)
            {
                ReDraw();
            }
        }
Esempio n. 12
0
        private void picture_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (_movingObject != null)
            {
                //Release & update the X/Y of the object
                int newX = _movingObject.PBReference.Left;
                int newY = _movingObject.PBReference.Top;

                //Offset from center
                newX += 2;
                newY += 2;

                //Inverse the X direction
                newX = (int)Math.Round((this.Width / 2.0) - (newX - this.Width / 2.0));

                //Convert
                _movingObject.X = newX * (MaxX - MinX) / this.Width + MinX;
                _movingObject.Y = newY * (MaxY - MinY) / this.Height + MinY;

                ObjectXYChanged(_movingObject.Tag, +_movingObject.X, _movingObject.Y);

                _movingObject = null;
            }
        }
Esempio n. 13
0
 public abstract void Add(SpatialObject obj);
    public static void Main(String[] args)
    {
        Storage       db = StorageFactory.Instance.CreateStorage();
        SpatialObject so;
        RectangleR2   r;
        DateTime      start = DateTime.Now;

        if (args.Length > 0 && "noflush" == args[0])
        {
            db.SetProperty("perst.file.noflush", true);
        }
        db.Open("testr2.dbs");
        TestR2 root = (TestR2)db.Root;

        if (root == null)
        {
            root = new TestR2();
#if USE_GENERICS
            root.index = db.CreateSpatialIndexR2 <SpatialObject>();
#else
            root.index = db.CreateSpatialIndexR2();
#endif
            db.Root = root;
        }

        RectangleR2[] rectangles = new RectangleR2[nObjectsInTree];
        long          key        = 1999;
        for (int i = 0; i < nIterations; i++)
        {
            int j = i % nObjectsInTree;
            if (i >= nObjectsInTree)
            {
                r = rectangles[j];
#if USE_GENERICS
                SpatialObject[] sos = root.index.Get(r);
                SpatialObject   po  = null;
#else
                object[] sos = root.index.Get(r);
                object   po  = null;
#endif
                int n = 0;
                for (int k = 0; k < sos.Length; k++)
                {
#if USE_GENERICS
                    so = sos[k];
#else
                    so = (SpatialObject)sos[k];
#endif
                    if (r.Equals(so.rect))
                    {
                        po = so;
                    }
                    else
                    {
                        Debug.Assert(r.Intersects(so.rect));
                    }
                }
                Debug.Assert(po != null);
                for (int k = 0; k < nObjectsInTree; k++)
                {
                    if (r.Intersects(rectangles[k]))
                    {
                        n += 1;
                    }
                }
                Debug.Assert(n == sos.Length);

                n = 0;
                foreach (SpatialObject o in root.index.Overlaps(r))
                {
                    Debug.Assert(o == sos[n++]);
                }
                Debug.Assert(n == sos.Length);

                root.index.Remove(r, po);
                db.Deallocate(po);
            }
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int top  = (int)(key % 1000);
            int left = (int)(key / 1000 % 1000);
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int bottom = top + (int)(key % 100);
            int right  = left + (int)(key / 100 % 100);
            so            = new SpatialObject();
            r             = new RectangleR2(top, left, bottom, right);
            so.rect       = r;
            rectangles[j] = r;
            root.index.Put(r, so);

            if (i % 100 == 0)
            {
                double minDistance = 0;
                j = 0;
                foreach (SpatialObject obj in root.index.Neighbors(0, 0))
                {
                    double distance = Math.Sqrt(obj.rect.Left * obj.rect.Left + obj.rect.Top * obj.rect.Top);
                    Debug.Assert(distance >= minDistance);
                    minDistance = distance;
                    j          += 1;
                }
                Debug.Assert((i >= nObjectsInTree && j == nObjectsInTree) || (i < nObjectsInTree && j == i + 1));
                Console.Write("Iteration " + i + "\r");
                db.Commit();
            }
        }
        root.index.Clear();
        Console.WriteLine();
        Console.WriteLine("Elapsed time " + (DateTime.Now - start));
        db.Close();
    }
Esempio n. 15
0
 public bool IsSamePlace(SpatialObject so)
 {
     return(IsSamePlace(so.GridPosition));
 }
Esempio n. 16
0
    public static void Main(string[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();
        long start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        db.Open("testrtree.dbs");
        TestRtree root = (TestRtree) db.GetRoot();
        if (root == null)
        {
            root = new TestRtree();
            root.index = db.CreateSpatialIndex();
            db.SetRoot(root);
        }

        Rectangle[] rectangles = new Rectangle[nObjectsInTree];
        long key = 1999;
        for (int i = 0; i < nIterations; i++)
        {
            int j = i % nObjectsInTree;
            if (i >= nObjectsInTree)
            {
                Rectangle r = rectangles[j];
                IPersistent[] sos = root.index.Get(r);
                IPersistent po = null;
                int n = 0;
                for (int k = 0; k < sos.Length; k++)
                {
                    SpatialObject so = (SpatialObject) sos[k];
                    if (r.Equals(so.rect))
                    {
                        po = so;
                    }
                    else
                    {
                        Assert.That(r.Intersects(so.rect));
                    }
                }

                Assert.That(po != null);
                for (int k = 0; k < nObjectsInTree; k++)
                {
                    if (r.Intersects(rectangles[k]))
                        n += 1;
                }

                Assert.That(n == sos.Length);
                root.index.Remove(r, po);
                po.Deallocate();
            }

            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int top = (int) (key % 1000);
            int left = (int) (key / 1000 % 1000);
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int bottom = top + (int) (key % 100);
            int right = left + (int) (key / 100 % 100);
            SpatialObject so2 = new SpatialObject();
            Rectangle r2 = new Rectangle(top, left, bottom, right);
            so2.rect = r2;
            rectangles[j] = r2;
            root.index.Put(r2, so2);

            if (i % 100 == 0)
            {
                Console.Out.Write("Iteration " + i + "\r");
                Console.Out.Flush();
                db.Commit();
            }
        }

        root.index.Clear();
        Console.Out.WriteLine("\nElapsed time " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start));
        db.Close();
    }
Esempio n. 17
0
    public static void Main(String[] args)
    {
        Storage       db = StorageFactory.Instance.CreateStorage();
        SpatialObject so;
        Rectangle     r;
        DateTime      start = DateTime.Now;

        db.Open("testrtree.dbs");
        TestRtree root = (TestRtree)db.Root;

        if (root == null)
        {
            root       = new TestRtree();
            root.index = db.CreateSpatialIndex();
            db.Root    = root;
        }

        Rectangle[] rectangles = new Rectangle[nObjectsInTree];
        long        key        = 1999;

        for (int i = 0; i < nIterations; i++)
        {
            int j = i % nObjectsInTree;
            if (i >= nObjectsInTree)
            {
                r = rectangles[j];
                IPersistent[] sos = root.index.Get(r);
                IPersistent   po  = null;
                int           n   = 0;
                for (int k = 0; k < sos.Length; k++)
                {
                    so = (SpatialObject)sos[k];
                    if (r.Equals(so.rect))
                    {
                        po = so;
                    }
                    else
                    {
                        Debug.Assert(r.Intersects(so.rect));
                    }
                }
                Debug.Assert(po != null);
                for (int k = 0; k < nObjectsInTree; k++)
                {
                    if (r.Intersects(rectangles[k]))
                    {
                        n += 1;
                    }
                }
                Debug.Assert(n == sos.Length);
                root.index.Remove(r, po);
                po.Deallocate();
            }
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int top  = (int)(key % 1000);
            int left = (int)(key / 1000 % 1000);
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int bottom = top + (int)(key % 100);
            int right  = left + (int)(key / 100 % 100);
            so            = new SpatialObject();
            r             = new Rectangle(top, left, bottom, right);
            so.rect       = r;
            rectangles[j] = r;
            root.index.Put(r, so);

            if (i % 100 == 0)
            {
                Console.Write("Iteration " + i + "\r");
                db.Commit();
            }
        }
        root.index.Clear();
        Console.WriteLine();
        Console.WriteLine("Elapsed time " + (DateTime.Now - start));
        db.Close();
    }
 void OnLoad(SpatialObject obj)
 {
     m_ObjectsToLoad.Push(obj);
 }
 void OnUnload(SpatialObject obj)
 {
     obj.IsLoaded = false;
     m_StreamOutput.SendStreamRemoved(obj.StreamAsset);
 }
Esempio n. 20
0
 public bool Equals(T x, T y)
 {
     return(SpatialObject.Equals2D(x, y));
 }
Esempio n. 21
0
 public override void Add(SpatialObject obj)
 {
     LocateChild(obj).Add(obj);
 }
Esempio n. 22
0
 public bool IsOccupied(SpatialObject so)
 {
     return(IsOccupied(so.GridPosition));
 }//Returns true if the position is already
Esempio n. 23
0
 public void Add(SpatialObject obj)
 {
     root.Add(obj);
 }