Exemple #1
0
        public PathView(WallCollision wc)
        {
            BackgroundColor = UIColor.Clear;

            path = new CGPath();
            wallCol = wc;

        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            SetContentView(Resource.Layout.ScaleImage);

            // Register our sensor listener
            _sensorManager = (SensorManager) GetSystemService(SensorService);
            _sensorListener = new CustomListener(_sensorManager);
            _sensorListener.AccelerationProcessor.OnValueChanged += AccelerationProcessorOnValueChanged;
            _sensorListener.RotationProcessor.OnValueChanged += RotationProcessorOnValueChanged;

            // Class that will handle drawing of the map
            _mapMaker = new MapMaker();
            _mapMaker.Initialize(Resources);

            var graphAsset = Assets.Open("dcsGroundFloor.xml");
            var graphInstance = Graph.Load(graphAsset);

            _mapMaker.PathfindingGraph = graphInstance;

            _collision = new Collision(graphInstance, new StepDetector());
            _collision.SetLocation(707.0f, 677.0f);
            _collision.PassHeading(90);
            
            _collision.PositionChanged += CollisionOnPositionChanged;
            _collision.StepDetector.OnStep += StepDetectorOnStep;

            collisionMap = BitmapFactory.DecodeResource(Resources,Resource.Drawable.dcsFloor);

            _walCol = new WallCollision((x,y)=>collisionMap.GetPixel(x,y));
            _collision.WallCol = _walCol;


            pf = new Pathfinding.Pathfinding(new Dictionary<int, Stream>()
            {
                {0,Assets.Open("dcsGroundFloor.xml") },
                {1,Assets.Open("dcsFloor1.xml") }
            },Assets.Open("Rooms.xml") );
            pf.CurrentFloor = 0;


            while (true)
            {
                if (pf.Ready)
                    break;
                Thread.Sleep(500);
            }

            var result = pf.FindPath(new GraphLocatable(609, 457, 1), new GraphLocatable(1256, 80, 0));


            setUpUITabs();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // For accelerometer readings
            motionManager = new CMMotionManager();
            motionManager.AccelerometerUpdateInterval = 0.01; // 100Hz

            //To handle long presses and bring up path start/end menu
            var longPressManager = new UILongPressGestureRecognizer();

            //Graph loading code
			//Graph loading code
			var assembly = Assembly.GetExecutingAssembly();
			var asset = assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml");

			pf = new Pathfinding.Pathfinding(new Dictionary<int, Stream>()
				{
					{0,assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml")},
					{1,assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsFloor1.xml")}
				},assembly.GetManifestResourceStream("Navigator.iOS.Resources.Rooms.xml") );
			pf.CurrentFloor = 0;

			while (true)
			{
				if (pf.Ready)            

					break;
				Thread.Sleep(500);
			}
				
			//set up the search bar and prediction box
			var searchController = new CustomSearchController(this, SearchBar, SearchPredictionTable, pf.Rooms);
		
            floorPlanGraph = Graph.Load(asset);

            wallCollImg = UIImage.FromBundle("Images/dcsfloorWideDoors.png");

            col = new Collision(floorPlanGraph, new StepDetector());

            ((Collision)col).WallCol = new WallCollision ((x,y) => GetPixelColor(new PointF(x, y), wallCollImg));
            wallColTest = new WallCollision ((x,y) => GetPixelColor(new PointF(x, y), wallCollImg));

            pathView = new PathView (wallColTest);

            col.SetLocation(707.0f, 677.0f);
            col.PassHeading(90);
            col.PositionChanged += HandleStepsTaken;

			//Container for floorplan and any overlaid images
            var container = new UIView();

			//Will contain floorplan images
            floorplanImageView = new UIImageView();

			//Load floorplan images
            floorplanImageNoGrid = UIImage.FromBundle("Images/FinalDcsFloor1.png");
            floorplanImageWithGrid = UIImage.FromBundle("Images/dcsFloorWideDoorsGrid.png");

			//Initiate the location arrow
            locationArrow = new LocationArrowImageView();
            locationArrow.ScaleFactor = floorplanView.ZoomScale;
            pathView.ScaleFactor = floorplanView.ZoomScale;
            setStartPoint(690.0f, 840.0f);

			//Set sizes for floorplan view and path view
            floorplanView.ContentSize = floorplanImageNoGrid.Size;
            pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size);

			//Add subviews to the container (including pathview and floorplanview)
            container.AddSubview(floorplanImageView);
            container.AddSubview(locationArrow);
            floorplanImageView.AddSubview(pathView);
            changeFloorPlanImage(floorplanImageView, floorplanImageNoGrid);
            container.SizeToFit();

			//Adjust scrolling and zooming properties for the floorplanView
            floorplanView.MaximumZoomScale = 1f;
            floorplanView.MinimumZoomScale = .25f;
            floorplanView.AddSubview(container);
            floorplanView.ViewForZoomingInScrollView += (UIScrollView sv) => { return floorplanImageView; };

			//Variables needed to convert device acceleration to world z direction acceleration
			double accelX = 0, accelY = 0, accelZ = 0;

			//Scale location arrow and paths when zooming the floorplan
            floorplanView.DidZoom += (sender, e) =>
            {
                locationArrow.ScaleFactor = floorplanView.ZoomScale;
                pathView.ScaleFactor = floorplanView.ZoomScale;
            };

			//Pass acceleremoter values to the collision class
            motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue,
                (data, error) =>
                {
					accelX = data.Acceleration.X*9.8;
					accelY = data.Acceleration.Y*9.8;
					accelZ = Math.Sqrt(Math.Pow(accelX, 2) + Math.Pow(accelY, 2) + Math.Pow(data.Acceleration.Z*9.8, 2));

                    col.PassSensorReadings(CollisionSensorType.Accelometer, accelX,
                        accelY, accelZ);
                    //displayAccelVal((float)accelZ);
                });

			/*
			motionManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (data, error) =>
				{ 
					//data.Attitude.MultiplyByInverseOfAttitude(data.Attitude);
					var test = data.UserAcceleration.X;
					var accelRelZ = data.Attitude.RotationMatrix.m31 * accelX + data.Attitude.RotationMatrix.m32 * accelY + data.Attitude.RotationMatrix.m33 * accelZ;
					debugLabel.Text = "" + Math.Round(test, 2);//Math.Round(accelRelZ, 2);
				}
			);
			*/

			//LongPressManager will cause the path input menu to appear after a stationary long press
            longPressManager.AllowableMovement = 0;
            longPressManager.AddTarget(() => handleLongPress(longPressManager, floorPlanGraph));
            floorplanView.AddGestureRecognizer(longPressManager);

			//the location manager handles the phone heading
            locationManager = new CLLocationManager();
            locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
            locationManager.HeadingFilter = 1;
            locationManager.UpdatedHeading += HandleUpdatedHeading;
            locationManager.StartUpdatingHeading();

			//Button currently used for testing purposes only

			//Another testing button
            simulationButton.TouchUpInside += delegate { col.StepTaken(false); };

            returnButton.TouchUpInside += delegate{ returnToMenu(); };

        }