Ejemplo n.º 1
0
        private void DrawScreenDebug(IBatchRenderer sbatch)
        {
            if (DebugSettings.Get("DebugBackground"))
            {
                DebugRenderHelper.DrawCrossedCircle(sbatch, Color.Red, MapViewportCenter, 8, 2);
                DebugRenderHelper.DrawHalfCrossedCircle(sbatch, Color.Red, MapOffset.Negate(), 8, 2);

                var rTop = new FRectangle(CompleteMapViewport.X, CompleteMapViewport.Y, CompleteMapViewport.Width, GuaranteedMapViewport.Y - CompleteMapViewport.Y);
                var rBot = new FRectangle(CompleteMapViewport.X, GuaranteedMapViewport.Bottom, CompleteMapViewport.Width, CompleteMapViewport.Bottom - GuaranteedMapViewport.Bottom);
                var rLef = new FRectangle(CompleteMapViewport.X, CompleteMapViewport.Y, GuaranteedMapViewport.X - CompleteMapViewport.X, CompleteMapViewport.Height);
                var rRig = new FRectangle(GuaranteedMapViewport.Right, CompleteMapViewport.Y, CompleteMapViewport.Right - GuaranteedMapViewport.Right, CompleteMapViewport.Height);

                if (rTop.Area > 0.001f)
                {
                    sbatch.FillRectangle(rTop, Color.DarkRed * 0.35f);
                }
                if (rBot.Area > 0.001f)
                {
                    sbatch.FillRectangle(rBot, Color.DarkRed * 0.35f);
                }
                if (rLef.Area > 0.001f)
                {
                    sbatch.FillRectangle(rLef, Color.DarkRed * 0.35f);
                }
                if (rRig.Area > 0.001f)
                {
                    sbatch.FillRectangle(rRig, Color.DarkRed * 0.35f);
                }

                sbatch.DrawRectangle(GuaranteedMapViewport, Color.Red * 0.8f, 1f);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the MapCanvas class.
        /// </summary>
        public MapCanvas()
        {
            CommandManager.RegisterClassCommandBinding(
                typeof(MapCanvas),
                new CommandBinding(NavigationCommands.DecreaseZoom, (sender, e) => ((MapCanvas)sender).Zoom--));

            CommandManager.RegisterClassCommandBinding(
                typeof(MapCanvas),
                new CommandBinding(NavigationCommands.IncreaseZoom, (sender, e) => ((MapCanvas)sender).Zoom++));

            _offsetX = new MapOffset(_translate.GetType().GetProperty("X"), OnOffsetChanged, _tileGenerator);
            _offsetY = new MapOffset(_translate.GetType().GetProperty("Y"), OnOffsetChanged, _tileGenerator);

            _tilePanel = new TilePanel(_tileGenerator)
            {
                RenderTransform = _translate
            };
            // Register all mouse clicks.
            Background = Brushes.Transparent;
            Children.Add(_cache);
            Children.Add(_tilePanel);
            ClipToBounds        = true;
            Focusable           = true;
            FocusVisualStyle    = null;
            SnapsToDevicePixels = true;

            // Need to set it here after ViewportKey has been initialized.
            ViewportProperty = ViewportKey.DependencyProperty;
        }
Ejemplo n.º 3
0
    public static void ShowWindow()
    {
        Rect      wr     = new Rect(0, 0, 500, 500);
        MapOffset window = (MapOffset)EditorWindow.GetWindowWithRect(typeof(MapOffset), wr, true, "Map Offset");

        window.Show();
    }
Ejemplo n.º 4
0
        private void OnOffsetChanged(object sender, EventArgs e)
        {
            BeginUpdate();
            MapOffset offset = (MapOffset)sender;

            offset.Property.SetValue(_translate, offset.Offset, null);
            EndUpdate();
        }
Ejemplo n.º 5
0
        /// <summary>Initializes a new instance of the MapCanvas class.</summary>
        public MapCanvas()
        {
            _offsetX = new MapOffset(_translate.GetType().GetProperty("X"), this.OnOffsetChanged);
            _offsetY = new MapOffset(_translate.GetType().GetProperty("Y"), this.OnOffsetChanged);

            _tilePanel.RenderTransform = _translate;
            this.Background            = Brushes.Transparent; // Register all mouse clicks
            this.Children.Add(_cache);
            this.Children.Add(_tilePanel);
            this.ClipToBounds        = true;
            this.Focusable           = true;
            this.FocusVisualStyle    = null;
            this.SnapsToDevicePixels = true;
        }
Ejemplo n.º 6
0
        public MapCanvas()
        {
            _offsetX = new MapOffset(_translate.GetType().GetProperty("X"), this.OnOffsetChanged);
            _offsetY = new MapOffset(_translate.GetType().GetProperty("Y"), this.OnOffsetChanged);

            _tilePanel.RenderTransform = _translate;
            this.Background = new ImageBrush(TileGenerator.IBackGround); // Register all mouse clicks
            this.Children.Add(_cache);
            this.Children.Add(_tilePanel);
            this.ClipToBounds = true;
            this.Focusable = true;
            this.FocusVisualStyle = null;
            this.SnapsToDevicePixels = true;

            this.Cursor = Cursors.Arrow;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new MapOffset with values copied from another.
 /// </summary>
 public MapOffset(MapOffset clone) : base(clone)
 {
     Position = clone.Position;
     Degree   = clone.Degree;
 }
        public override IEnumerator Localize()
        {
            ARCameraImageBytes image = null;
            bool isHD = HWARHelper.TryGetCameraImageBytes(out image);

            if (image != null && image.IsAvailable)
            {
                stats.localizationAttemptCount++;
                Vector3    camPos = m_Cam.transform.position;
                Quaternion camRot = m_Cam.transform.rotation;
                byte[]     pixels;
                Vector4    intrinsics = isHD ? HWARHelper.GetIntrinsics() : HWARHelper.GetIntrinsics(image.Width, image.Height);
                HWARHelper.GetPlaneData(out pixels, image);

                image.Dispose();

                Vector3    pos = Vector3.zero;
                Quaternion rot = Quaternion.identity;

                float startTime = Time.realtimeSinceStartup;

                Task <int> t = Task.Run(() =>
                {
                    return(Immersal.Core.LocalizeImage(out pos, out rot, image.Width, image.Height, ref intrinsics, pixels));
                });

                while (!t.IsCompleted)
                {
                    yield return(null);
                }

                int mapId = t.Result;

                if (mapId > 0 && ARSpace.mapIdToOffset.ContainsKey(mapId))
                {
                    if (mapId != lastLocalizedMapId)
                    {
                        if (m_ResetOnMapChange)
                        {
                            foreach (KeyValuePair <Transform, SpaceContainer> item in ARSpace.transformToSpace)
                            {
                                item.Value.filter.ResetFiltering();
                            }
                        }

                        lastLocalizedMapId = mapId;

                        OnMapChanged?.Invoke(mapId);
                    }

                    HWARHelper.GetRotation(ref rot);
                    MapOffset mo          = ARSpace.mapIdToOffset[mapId];
                    float     elapsedTime = Time.realtimeSinceStartup - startTime;
                    Debug.Log(string.Format("Relocalised in {0} seconds", elapsedTime));
                    stats.localizationSuccessCount++;

                    Matrix4x4 offsetNoScale = Matrix4x4.TRS(mo.position, mo.rotation, Vector3.one);
                    Vector3   scaledPos     = new Vector3
                                              (
                        pos.x * mo.scale.x,
                        pos.y * mo.scale.y,
                        pos.z * mo.scale.z
                                              );
                    Matrix4x4 cloudSpace   = offsetNoScale * Matrix4x4.TRS(scaledPos, rot, Vector3.one);
                    Matrix4x4 trackerSpace = Matrix4x4.TRS(camPos, camRot, Vector3.one);
                    Matrix4x4 m            = trackerSpace * (cloudSpace.inverse);
                    mo.space.filter.RefinePose(m);

                    LocalizerPose localizerPose;
                    GetLocalizerPose(out localizerPose, mapId, pos, rot, m.inverse);
                    OnPoseFound?.Invoke(localizerPose);
                }
            }

            yield return(StartCoroutine(base.Localize()));
        }
Ejemplo n.º 9
0
        public override IEnumerator Localize()
        {
            ARCameraImageBytes image = null;

            if (m_Sdk.androidResolution == ImmersalSDK.CameraResolution.Max)
            {
                try
                {
                    image = ARFrame.AcquirPreviewImageBytes();
                }
                catch (NullReferenceException e)
                {
                    Debug.LogError("Cannot acquire FullHD image: " + e.Message);

                    image = ARFrame.AcquireCameraImageBytes();
                }
            }
            else
            {
                image = ARFrame.AcquireCameraImageBytes();
            }

            if (image != null && image.IsAvailable)
            {
                stats.localizationAttemptCount++;
                Vector3    camPos = m_Cam.transform.position;
                Quaternion camRot = m_Cam.transform.rotation;
                byte[]     pixels;
                Vector4    intrinsics = HWARHelper.GetIntrinsics();
                HWARHelper.GetPlaneData(out pixels, image);

                image.Dispose();

                Vector3    pos = Vector3.zero;
                Quaternion rot = Quaternion.identity;

                float startTime = Time.realtimeSinceStartup;

                Task <int> t = Task.Run(() =>
                {
                    return(Immersal.Core.LocalizeImage(out pos, out rot, image.Width, image.Height, ref intrinsics, pixels));
                });

                while (!t.IsCompleted)
                {
                    yield return(null);
                }

                int mapId = t.Result;

                if (mapId >= 0 && ARSpace.mapIdToOffset.ContainsKey(mapId))
                {
                    if (mapId != lastLocalizedMapId)
                    {
                        if (m_ResetOnMapChange)
                        {
                            foreach (KeyValuePair <Transform, SpaceContainer> item in ARSpace.transformToSpace)
                            {
                                item.Value.filter.ResetFiltering();
                            }
                        }

                        lastLocalizedMapId = mapId;
                    }

                    HWARHelper.GetRotation(ref rot);
                    MapOffset mo          = ARSpace.mapIdToOffset[mapId];
                    float     elapsedTime = Time.realtimeSinceStartup - startTime;
                    Debug.Log(string.Format("Relocalised in {0} seconds", elapsedTime));
                    stats.localizationSuccessCount++;
                    Matrix4x4 cloudSpace   = mo.offset * Matrix4x4.TRS(pos, rot, Vector3.one);
                    Matrix4x4 trackerSpace = Matrix4x4.TRS(camPos, camRot, Vector3.one);
                    Matrix4x4 m            = trackerSpace * (cloudSpace.inverse);
                    mo.space.filter.RefinePose(m);
                }
            }

            yield return(StartCoroutine(base.Localize()));
        }