public void setStartPoint(nfloat x, nfloat y, int roomFloor, bool shouldPf = true) { var test = this.pf.FloorGraphs [roomFloor].FindClosestNode((float)x, (float)y, 6); if (test == null) { var okAlertController = UIAlertController.Create("Error!", "Please select a location within the floor plan.", UIAlertControllerStyle.Alert); //Add Action okAlertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); // Present Alert PresentViewController(okAlertController, true, null); return; } locationArrow.setLocation((float)x, (float)y); col.SetLocation((float)x, (float)y); pathView.RemoveFromSuperview(); pathView = new PathView(wallColTest, this); pathView.ScaleFactor = floorplanView.ZoomScale; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); floorplanImageView.AddSubview(pathView); SearchBar.ShowsCancelButton = false; SearchBar.ResignFirstResponder(); directionCount = 0; StartNavigationPosition = new GraphLocatable((float)x, (float)y, roomFloor); if (shouldPf) { findUserPath(); } drawUserPath(); }
private void removePath(bool removePath = false) { InvokeOnMainThread(() => { Console.Out.WriteLine("DROPPING THE F*****G SHIT"); foreach (PathView subview in floorplanImageView.Subviews) { subview.RemoveFromSuperview(); } if (removePath) { CurrentUserPath = new Dictionary <int, List <UndirEdge> >(); StartNavigationPosition = null; EndNavgiationPosition = null; } pathView = new PathView(wallColTest, this); pathView.ScaleFactor = floorplanView.ZoomScale; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); floorplanImageView.AddSubview(pathView); pathDisplayed = false; directionCount = 0; }); }
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(); }; }
public void setStartPoint(nfloat x, nfloat y) { locationArrow.setLocation ((float)x, (float)y); col.SetLocation ((float)x, (float)y); pathView.RemoveFromSuperview (); pathView = new PathView(wallColTest); pathView.ScaleFactor = floorplanView.ZoomScale; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); floorplanImageView.AddSubview(pathView); SearchBar.ShowsCancelButton = false; SearchBar.ResignFirstResponder(); }
private void removePath() { pathView.RemoveFromSuperview (); pathView = new PathView(wallColTest); pathView.ScaleFactor = floorplanView.ZoomScale; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); floorplanImageView.AddSubview(pathView); pathDisplayed = false; }
private void drawPathFromUser(float endX, float endY) { pathView.RemoveFromSuperview (); pathView = new PathView(wallColTest); pathView.ScaleFactor = floorplanView.ZoomScale; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); floorplanImageView.AddSubview(pathView); //Get nearest node to user location var userNode = floorPlanGraph.FindClosestNode(locationArrow.X, locationArrow.Y, 6); //Get x and y of this nearest node var pathStart = floorPlanGraph.Vertices.First(x => x == userNode.ToPointString()); //Get nearest node to end location var destinationNode = floorPlanGraph.FindClosestNode(endX, endY, 6); //Get x and y of this node var pathEnd = floorPlanGraph.Vertices.First(x => x == destinationNode.ToPointString()); //Calculate path var path = floorPlanGraph.FindPath(pathStart, pathEnd); //Get path length var pathLength = path.Count(); //Extract node along path var pathPoints = new CGPoint[pathLength]; //Iterate over all nodes and create a list of CGpoints for (var i = 0; i < pathLength; i++) { var dash = path.ElementAt(i).Source.IndexOf("-"); var yVal = float.Parse(path.ElementAt(i).Source.Substring(dash + 1), CultureInfo.InvariantCulture.NumberFormat); var xVal = float.Parse(path.ElementAt(i).Source.Remove(dash), CultureInfo.InvariantCulture.NumberFormat); pathPoints[i] = new CGPoint(xVal, yVal); } //Draw path on screen pathView.setPoints(pathPoints); }
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"); var asset2 = assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsFloor1.xml"); var assetSci = assembly.GetManifestResourceStream("Navigator.iOS.Resources.ConFloor.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") }, { 2, assembly.GetManifestResourceStream("Navigator.iOS.Resources.ConFloor.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 SearchBar.TintColor = UIColor.White; UITextView.AppearanceWhenContainedIn(typeof(UISearchBar)).BackgroundColor = UIColor.White; UITextView.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor = UIColor.White; UITextField.AppearanceWhenContainedIn(typeof(UISearchBar)).BackgroundColor = UIColor.White; UITextField.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor = UIColor.White; var shadowView = new UIView(SearchPredictionTable.Frame); shadowView.BackgroundColor = UIColor.White; shadowView.Layer.ShadowColor = UIColor.DarkGray.CGColor; shadowView.Layer.ShadowOpacity = 1.0f; shadowView.Layer.ShadowRadius = 6.0f; shadowView.Layer.ShadowOffset = new System.Drawing.SizeF(0f, 3f); shadowView.Layer.ShouldRasterize = true; shadowView.Layer.MasksToBounds = false; Add(shadowView); var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.Dark); topblurView = new UIVisualEffectView(blur) { Frame = new RectangleF(0, 0, (float)View.Frame.Width, 90) }; bottomblurView = new UIVisualEffectView(blur) { Frame = new RectangleF(0, (float)View.Frame.Height - 70, (float)View.Frame.Width, 70) }; View.Add(topblurView); View.Add(bottomblurView); View.BringSubviewToFront(SearchPredictionTable); View.BringSubviewToFront(returnButton); View.BringSubviewToFront(SearchBar); View.BringSubviewToFront(directionsButton); var searchController = new CustomSearchController(this, SearchBar, SearchPredictionTable, shadowView, pf.Rooms); //var directionsController = new CustomDirectionsController (this, directionsTable, pf.Rooms); floorPlanGraph = Graph.Load(asset); floorplanWallCol = UIImage.FromBundle("Images/dcsfloorWideDoors.png"); wallCollImg = floorplanWallCol; 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, this); 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"); floorplanFirstFloorNoGrid = UIImage.FromBundle("Images/final2ndFloorDisplay.png"); floorplanSci = UIImage.FromBundle("Images/ConFloorGrid"); floorplanFirstFloorWallCol = UIImage.FromBundle("Images/dcsFloor1.png"); //Initiate the location arrow locationArrow = new LocationArrowImageView(); locationArrow.ScaleFactor = floorplanView.ZoomScale; pathView.ScaleFactor = floorplanView.ZoomScale; setStartPoint(690.0f, 840.0f, this.floor); //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; }; floorplanView.DraggingStarted += (sender, e) => { handleAnimate(topblurView, bottomblurView, true); }; var tapGestureRecognizer = new UITapGestureRecognizer(); tapGestureRecognizer.NumberOfTapsRequired = 1; tapGestureRecognizer.AddTarget(() => { handleAnimate(topblurView, bottomblurView, false); }); floorplanView.AddGestureRecognizer(tapGestureRecognizer); //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(); //Another testing button returnButton.TouchUpInside += delegate { returnToMenu(); }; directionsButton.TouchUpInside += delegate { if (!initStep) { //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); }); directionsButton.SetTitle("Change Floor", UIControlState.Normal); initStep = true; } else if (floor == 0) { Console.Out.WriteLine("Changing to floor 1 "); floor = 1; changeFloorPlanImage(floorplanImageView, floorplanFirstFloorNoGrid); setStartPoint(447.0f, 850.0f, this.floor, false); wallCollImg = floorplanFirstFloorWallCol; 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, this); col.SetLocation(447, 850); col.PositionChanged += HandleStepsTaken; } else if (floor == 1) { Console.Out.WriteLine("Changing to floor 0 "); floor = 0; changeFloorPlanImage(floorplanImageView, floorplanImageNoGrid); setStartPoint(486.0f, 980.0f, this.floor, false); wallCollImg = floorplanWallCol; 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, this); col.SetLocation(486, 980); col.PositionChanged += HandleStepsTaken; } else { floor = 0; } }; }