Ejemplo n.º 1
0
        private async Task MariusCvStitch()
        {
            _currentMapping = _dataExchangeService.Payload["CurrentMapping"] as Mapping;

            await _downloadCache.GetAndCacheFile(_currentMapping.Measurements.First().ImageUrl);

            var img1Path = _currentMapping.Measurements.First().ImageUrl;
            var img2Path = _currentMapping.Measurements.ElementAt(1).ImageUrl;

            var imageStitcher = Mvx.Resolve<IImageStitcher>();
            var panoBytes = await imageStitcher.StitchImages(new List<string>() { img1Path, img2Path });

            Directory.CreateDirectory($"/data/data/de.marius.depthviewer/files/_Caches/Pictures.MvvmCross/");
            var docsDirPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var path = Path.Combine(docsDirPath, $"s{DateTime.Now.Millisecond}s.jpg");

            System.IO.File.WriteAllBytes(path, panoBytes);

            InvokeOnMain(() =>
            {
                var stitchNode = _scene.CreateChild("StitchedNode");
                stitchNode.Position = new Vector3(0, 0, -2);
                stitchNode.SetScale(1.0f);
                //await PlaceSpriteInNode(path, stitchNode);
                // Display in sprite
                var sprite = new Sprite2D();
                var imgFile = new File(Context, path, FileMode.Read);
                sprite.Load(imgFile);

                StaticSprite2D staticSprite2D = stitchNode.CreateComponent<StaticSprite2D>();
                //staticSprite2D.Color = (new Color(NextRandom(1.0f), NextRandom(1.0f), NextRandom(1.0f), 1.0f));
                staticSprite2D.BlendMode = BlendMode.Alpha;
                staticSprite2D.Sprite = sprite;
            });
        }
Ejemplo n.º 2
0
        public async Task<Mapping> GetMapping(string mappingId)
        {
            Mapping result = null;
            try
            {
                var mappingParseObject = await ParseObject.GetQuery(typeof(Mapping).Name).Include("measurements").GetAsync(mappingId);
                var measurementsParseObjects = mappingParseObject.Get<List<object>>("measurements");
                var localMeasurements = new List<Measurement>();
                foreach (var measurement in measurementsParseObjects)
                {
                    var newLocalMeasurement = await GetMeasurement(measurement as ParseObject);
                    localMeasurements.Add(newLocalMeasurement);
                }

                result = new Mapping(mappingId, new List<Measurement>(localMeasurements), mappingParseObject.CreatedAt.Value);
            }
            catch (Exception ex)
            {
#if AZURE
                Trace.TraceError("ImageProcessingController.GetMappingPano(): " + ex.Message);
                Debug.WriteLine("ImageProcessingController.GetMappingPano(): " + ex.Message);
#endif
                result = null;
            }

            return result;
        }
Ejemplo n.º 3
0
        protected override async void InitFromBundle(IMvxBundle parameters)
        {
            base.InitFromBundle(parameters);

            try
            {
                if (parameters.Data.ContainsKey("Id"))
                {
                    var id = "";
                    if (parameters.Data.TryGetValue("Id", out id))
                    {
                        _currentMapping = _mappingServices.GetMapping(id).Result;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in MappingViewModel.InitFromBundle(): "+ex);
                //Close(this);
            }
        }
Ejemplo n.º 4
0
        public async Task<List<Mapping>> GetAllMappings()
        {
            var mappings = new List<Mapping>();

            var getAllMappingsQuery = ParseObject.GetQuery("Mapping").Include("measurements");
            var results = await getAllMappingsQuery.FindAsync();

            // Get all local mappings to cross compare
            var localMappingService = Mvx.Resolve<ILocalMappingServices>();
            var localMappingIds = (await localMappingService.GetAllLocalMappings()).Select(m => m.Id);

            foreach (var mapping in results)
            {
                var measurements = mapping.Get<List<object>>("measurements");
                var localMeasurements = new List<Measurement>();
                foreach (var measurement in measurements)
                {
                    var newLocalMeasurement = await GetMeasurement(measurement as ParseObject);
                    localMeasurements.Add(newLocalMeasurement);
                }

                var mappingId = mapping.ObjectId;
                var newLocalMapping = new Mapping(mappingId, new List<Measurement>(localMeasurements), mapping.CreatedAt.Value);
                newLocalMapping.IsSavedLocally = localMappingIds.Contains(mappingId);
                mappings.Add(newLocalMapping);
            }

            return mappings;

        }
Ejemplo n.º 5
0
        public async Task<Mapping> GetMapping(string mappingId)
        {
            Mapping result = null;
            try
            {
                var mappingParseObject = await ParseObject.GetQuery(typeof(Mapping).Name).Include("measurements").GetAsync(mappingId);
                var measurementsParseObjects = mappingParseObject.Get<List<object>>("measurements");
                var localMeasurements = new List<Measurement>();
                foreach (var measurement in measurementsParseObjects)
                {
                    var newLocalMeasurement = await GetMeasurement(measurement as ParseObject);
                    localMeasurements.Add(newLocalMeasurement);
                }

                result = new Mapping(mappingId, new List<Measurement>(localMeasurements), mappingParseObject.CreatedAt.Value);
            }
            catch (Exception)
            {
                result = null;
            }

            return result;
        }
Ejemplo n.º 6
0
        public Task DeleteLocalMapping(Mapping mapping)
        {
            return Task.Run(() =>
            {
                try
                {
                    // Delete serialized Mapping object
                    var path = Path.Combine(_mappingsDir, mapping.Id + ".json");
                    _fileStore.DeleteFile(path);

                    // Delete its cached images
                    foreach (var measurement in mapping.Measurements)
                    {
                        Mvx.Resolve<IMvxFileDownloadCache>().Clear(measurement.ImageUrl);
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception deleting {0}: {1}", mapping.Id, ex);
                }
            });
        }
Ejemplo n.º 7
0
        public async Task PersistMapping(Mapping mapping)
        {
            // Persist the Mapping instance as a json
            var jsonMapping = JsonConvert.SerializeObject(mapping);
            var path = Path.Combine(_mappingsDir, mapping.Id + ".json");
            await _fileStoreAsync.WriteFileAsync(path, jsonMapping);

            // Cache the measurement images
            foreach (var measurement in mapping.Measurements)
            {
                await Task.Run(async () =>
                {
                    var downloadTcs = new TaskCompletionSource<string>();
                    Mvx.Resolve<IMvxFileDownloadCache>().RequestLocalFilePath(measurement.ImageUrl, s =>
                    {
                        var downloadPath = Path.Combine(_baseDir, s);
                        downloadTcs.SetResult(true.ToString());
                        Debug.WriteLine("File cached to:{0}", downloadPath);
                    }, exception =>
                    {
                        Debug.WriteLine("Ex: " + exception);
                        downloadTcs.SetException(exception);
                    });

                    await downloadTcs.Task;
                });
            }
        }
Ejemplo n.º 8
0
        async Task CreateScene()
        {
            // Create a top-level _scene, must add the Octree
            // to visualize any 3D content.
            _scene = new Scene();
            _scene.CreateComponent<Octree>();
            _scene.CreateComponent<DebugRenderer>();

            // Get parameter payload
            _currentMapping = _dataExchangeService.Payload["CurrentMapping"] as Mapping;
            if (_currentMapping == null)
            {
                await Task.Delay(1000).ConfigureAwait(true);
                _currentMapping = _dataExchangeService.Payload["CurrentMapping"] as Mapping;
            }

            // Add boxes and images
            await PlaceBoxes();
            PlaceImages();

            // Zone
            var zoneNode = _scene.CreateChild(name: "zoneNode");
            zoneNode.Position = new Vector3(0, 0, 0);

            var zone = zoneNode.CreateComponent<Zone>();
            zone.SetBoundingBox(new BoundingBox(-1000, 1000));
            zone.AmbientColor = new Color(0.1f, 0.2f, 0.4f);
            //zone.FogColor = new Color(0.1f, 0.2f, 0.3f);
            //zone.FogStart = 10;
            //zone.FogEnd = 100;


            // Camera
            CameraNode = _scene.CreateChild("Camera");
            Camera camera = CameraNode.CreateComponent<Camera>();
            CameraNode.Position = new Vector3(0f, 0f, 0);
            camera.Fov = 90f;

            // Add a light to the camera node
            var cameraLight = CameraNode.CreateComponent<Light>();
            cameraLight.Range = 200;
            cameraLight.LightType = LightType.Point;
            cameraLight.Color = Color.Yellow;


            // Viewport
            Renderer.SetViewport(0, new Viewport(_scene, camera, null));
            Renderer.DrawDebugGeometry(true);
        }