public void CompareFileTestBlockSizeone() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 5); image1.printArray("../../testImagecomp_block5.txt"); int filebyte1; int filebyte2; // fs1 contains the newly created array file while fs2 contains the standard to check against for this block size 5 FileStream fs1 = new FileStream("../../testImagecomp_block5.txt", FileMode.Open); FileStream fs2 = new FileStream("../../created.txt", FileMode.Open); if (fs1.Length != fs2.Length) { fs1.Close(); fs2.Close(); Assert.IsTrue(false,"Incorrect file created - File lengths are different!"); return; } do { filebyte1 = fs1.ReadByte(); filebyte2 = fs2.ReadByte(); } while ((filebyte1 == filebyte2) && (filebyte1 != -1)); Assert.IsTrue((filebyte1 == filebyte2), "Newly created file and Original file does not match"); fs1.Close(); fs2.Close(); }
public Form1(FloorPlan fp, List<FloorTile> path) { InitializeComponent(); this.fp = fp; this.path = path; this.Draw(); }
public QGPathFinder(FloorPlan floorPlan) { this.messages += "- Checking Floor Plan...\n"; graph = new AdjacencyGraph<string, Edge<string>>(true); edgeCost = new Dictionary<Edge<string>, double>(graph.EdgeCount); this.fp = floorPlan; if (this.fp.getStartTile() != null) { this.messages += " Start Point is OK...\n"; startPoint = this.fp.getStartTile().Position.X + "_" + this.fp.getStartTile().Position.Y; } else { this.messages += " Start Point is not valid...\n"; startPoint = "4_4"; } if (this.fp.getTargetTile() != null) { this.messages += " Target Point is OK...\n"; targetPoint = this.fp.getTargetTile().Position.X + "_" + this.fp.getTargetTile().Position.Y; } else { this.messages += " Target Point is not valid...\n"; targetPoint = "4_6"; } buildGraph(); }
public static FloorTile getTileByIndex(FloorPlan fp, string index) { string[] outPoint1 = Regex.Split(index, "_"); return fp.getTile( System.Convert.ToInt32(outPoint1[0]), System.Convert.ToInt32(outPoint1[1])); }
private void drawFloorPlan(FloorPlan fp) { for (int i = 0; i < fp.getXTileNum(); i++) { for (int j = 0; j < fp.getYTileNum(); j++) { drawTile(fp.getTile(i, j)); } } }
public void buildGraphTest() { Image myimage = new Bitmap("../../testImage.jpg"); FloorPlan floorPlan = new FloorPlan(myimage, 5); // TODO: Initialize to an appropriate value QGPathFinder target = new QGPathFinder(floorPlan); // TODO: Initialize to an appropriate value int expected = 6354; // TODO: Initialize to an appropriate value int actual; actual = target.buildGraph().VertexCount; Assert.AreEqual(expected, actual); }
public FloorTile(int x, int y, bool walkable, FloorPlan floorPlan) { m_location.X = x; m_location.Y = y; m_walkable = walkable; m_endPoint = false; m_floorPlan = floorPlan; m_neighbours = new List<FloorTile>(); m_start = false; m_target = false; }
/// <summary> /// Constructor /// </summary> /// <param name="floorPlan">An image of the floorplan to be constructed</param> /// <param name="scale">The scale of the image provided in pixels per foot</param> public Status(FloorPlan fp) { m_FloorPlan = fp; m_Moves = new List <FloorTile>(); m_Images = null; m_Moves = new List <FloorTile>(); m_Position = new Position(new Point(0, 0), 0); m_EndPoint = new Point(0, 0); }
/// <summary> /// Constructor /// </summary> /// <param name="floorPlan">An image of the floorplan to be constructed</param> /// <param name="scale">The scale of the image provided in pixels per foot</param> public Status(Image floorplan, double scale) { m_FloorPlan = new FloorPlan(floorplan, scale); m_Moves = new List <FloorTile>(); m_Images = null; m_Moves = new List <FloorTile>(); m_Position = new Position(new Point(0, 0), 0); m_EndPoint = new Point(0, 0); }
private Position m_Position; // The robot's current location and facing #endregion Fields #region Constructors /// <summary> /// Constructor /// </summary> /// <param name="floorPlan">An image of the floorplan to be constructed</param> /// <param name="scale">The scale of the image provided in pixels per foot</param> public Status(Image floorplan, double scale) { m_FloorPlan = new FloorPlan(floorplan, scale); m_Moves = new List<FloorTile>(); m_Images = null; m_Moves = new List<FloorTile>(); m_Position = new Position(new Point(0, 0), 0); m_EndPoint = new Point(0, 0); }
/// <summary> /// Constructor /// </summary> /// <param name="floorPlan">An image of the floorplan to be constructed</param> /// <param name="scale">The scale of the image provided in pixels per foot</param> public Status(FloorPlan fp) { m_FloorPlan = fp; m_Moves = new List<FloorTile>(); m_Images = null; m_Moves = new List<FloorTile>(); m_Position = new Position(new Point(0, 0), 0); m_EndPoint = new Point(0, 0); }
/// <summary> ///get executing time for a path ///</summary> public Int64 getPathExecutingTime(FloorPlan floorPlan, int StartX, int StartY, int TargetX, int TargetY) { Int64 ExecutingTime = 0; floorPlan.setStartTile(StartX, StartY); floorPlan.setTargetTile(TargetX, TargetY); QGPathFinder target = new QGPathFinder(floorPlan); List<FloorTile> actual; DateTime StartTime = DateTime.Now; actual = target.getPath(); DateTime EndTime = DateTime.Now; TimeSpan t= EndTime - StartTime; if (actual != null){ ExecutingTime = (Int64) t.TotalMilliseconds; } return ExecutingTime; }
public void TestGetTile() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 5); FloorTile tile = image1.getTile(10,12); System.Diagnostics.Debug.WriteLine(tile.Position.X); System.Diagnostics.Debug.WriteLine(tile.Position.Y); System.Diagnostics.Debug.WriteLine(tile.Iswalkable()); Assert.IsTrue((tile.ToString().Equals("1")), "Incorret Tile Returned!"); }
public void TestCreateImageOfBlockOne() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 1); Bitmap test_image = image1.toImage(); test_image.Save("../../testImage_block1.bmp"); }
public void TestCreateImageOfBlockFive() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 5); Bitmap b = image1.toImage(); b.Save("../../testImage_block5.bmp"); }
public void TestConnectBlockFive() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg")); int width = image1.getXTileNum(); int height = image1.getYTileNum(); System.Diagnostics.Debug.WriteLine("Height " + height + " Width " + width); FloorTile tile = image1.getTile(2, 4); FloorTile n1,n2,n3,n4; System.Diagnostics.Debug.WriteLine(""); List<FloorTile> neighbour = tile.getNeighbours(); if (neighbour.Count > 3) { n1 = neighbour[0]; n2 = neighbour[1]; n3 = neighbour[2]; n4 = neighbour[3]; System.Diagnostics.Debug.WriteLine("1st \t" + n1.Position.X + "\t" + n1.Position.Y + "\t" + n1.Iswalkable()); System.Diagnostics.Debug.WriteLine("2nd \t" + n2.Position.X + "\t" + n2.Position.Y + "\t" + n2.Iswalkable()); System.Diagnostics.Debug.WriteLine("3rd \t" + n3.Position.X + "\t" + n3.Position.Y + "\t" + n3.Iswalkable()); System.Diagnostics.Debug.WriteLine("4th \t" + n4.Position.X + "\t" + n4.Position.Y + "\t" + n4.Iswalkable()); } else if (neighbour.Count == 3) { n1 = neighbour[0]; n2 = neighbour[1]; n3 = neighbour[2]; System.Diagnostics.Debug.WriteLine("1st \t" + n1.Position.X + "\t" + n1.Position.Y + "\t" + n1.Iswalkable()); System.Diagnostics.Debug.WriteLine("2nd \t" + n2.Position.X + "\t" + n2.Position.Y + "\t" + n2.Iswalkable()); System.Diagnostics.Debug.WriteLine("3rd \t" + n3.Position.X + "\t" + n3.Position.Y + "\t" + n3.Iswalkable()); } else if (neighbour.Count == 2) { n1 = neighbour[0]; n2 = neighbour[1]; System.Diagnostics.Debug.WriteLine("1st \t" + n1.Position.X + "\t" + n1.Position.Y + "\t" + n1.Iswalkable()); System.Diagnostics.Debug.WriteLine("2nd \t" + n2.Position.X + "\t" + n2.Position.Y + "\t" + n2.Iswalkable()); } else if (neighbour.Count == 1) { n1 = neighbour[0]; System.Diagnostics.Debug.WriteLine("1st \t" + n1.Position.X + "\t" + n1.Position.Y + "\t" + n1.Iswalkable()); } else System.Diagnostics.Debug.WriteLine("No Walkable Neighbours"); }
public void getPathTimeTest() { Image myimage = new Bitmap("../../testImage.jpg"); FloorPlan floorPlan = new FloorPlan(myimage, 5); TextWriter tw = new StreamWriter("../../ExecutingTime.txt"); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int m = 0; m<3; m++) { for (int n = 0; n < 3; n++) { int StartX = i; int StartY = j; int TargetX = m; int TargetY = n; if (floorPlan.getWalkableValue(i, j) == 1 & floorPlan.getWalkableValue(m, n) == 1) { Int64 t = 0;// getPathExecutingTime(floorPlan, StartX, StartY, TargetX, TargetY); tw.WriteLine(StartX + "," + StartY + "," + TargetX + "," + TargetY + "," + t); } } } } } tw.Close(); }
public void TestBlockSizefive() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 5); image1.printArray("../../testImage_block5.txt"); }
/// <summary> ///get executing time for a path ///</summary> public void visualizeFloorPlan(FloorPlan floorPlan, int StartX, int StartY, int TargetX, int TargetY) { floorPlan.setStartTile(StartX, StartY); floorPlan.setTargetTile(TargetX, TargetY); QGPathFinder target = new QGPathFinder(floorPlan); List<FloorTile> actual; actual = target.getPath(); Form f = new WindowsFormsApplication1.Form1(floorPlan, actual); Application.Run(f); //f.Invoke(); //f.Draw(floorPlan, actual); }
public void QGPathFinderConstructorTest() { Image myimage = new Bitmap("../../testImage.jpg"); FloorPlan floorPlan = new FloorPlan(myimage, 5); // TODO: Initialize to an appropriate value QGPathFinder target = new QGPathFinder(floorPlan); Type actual = target.GetType(); Type expected = typeof(QGPathFinder); Assert.AreEqual(expected, actual); }
public void getTileByIndexTest() { Image myimage = new Bitmap("../../testImage.jpg"); FloorPlan floorPlan = new FloorPlan(myimage, 5); // TODO: Initialize to an appropriate value String index = "1_1"; // TODO: Initialize to an appropriate value FloorTile expected = floorPlan.getTile(1, 1); // TODO: Initialize to an appropriate value FloorTile actual; actual = QGPathFinder.getTileByIndex(floorPlan, index); Assert.AreEqual(expected, actual); }
public void getPathVisualizationTest() { Image myimage = new Bitmap("../../testImage.jpg"); FloorPlan floorPlan = new FloorPlan(myimage, 5); int StartX = 8; int StartY = 8; int TargetX = 40; int TargetY = 20; TextWriter tw = new StreamWriter("../../ExecutingTimeVis.txt"); Int64 t = getPathExecutingTime(floorPlan, StartX, StartY, TargetX, TargetY); tw.WriteLine(StartX + "," + StartY + "," + TargetX + "," + TargetY + "," + t); tw.Close(); //visualizeFloorPlan(floorPlan, StartX, StartY, TargetX, TargetY); }
public void TestTargetTileWalkable() { FloorPlan image1 = new FloorPlan(new Bitmap("../../testImage.jpg"), 5); bool result = image1.setTargetTile(4, 4); FloorTile tile = image1.getTile(4, 4); bool t_res = tile.IsStart(); bool t_res2 = tile.IsTarget(); Assert.AreEqual(true, result); System.Diagnostics.Debug.WriteLine("Start:" + t_res); System.Diagnostics.Debug.WriteLine("Target:" + t_res2); }
public void MySerializer() { Image myimage = new Bitmap("../../testImage.jpg"); // TODO: Initialize to an appropriate value FloorPlan target = new FloorPlan(myimage); // TODO: Initialize to an appropriate value // XmlSerializer s = new XmlSerializer(typeof (FloorPlan)); String testFileName = "../../testImage.xml"; using (Stream s = File.Open(testFileName, FileMode.Create)) { SoapFormatter formatter = new SoapFormatter(); formatter.Serialize(s, target); } target = null; using (Stream s = File.Open(testFileName, FileMode.Open)) { SoapFormatter formatter = new SoapFormatter(); target = (FloorPlan)formatter.Deserialize(s); } }
public void getPathTest() { TextWriter tw = new StreamWriter("../../getPathResult.txt"); Image myimage = new Bitmap("../../floorplan.bmp"); FloorPlan floorPlan = new FloorPlan(myimage, 3); // TODO: Initialize to an appropriate value int StartX = 106; int StartY = 74; int TargetX = 107; int TargetY = 43; floorPlan.setStartTile(StartX, StartY); floorPlan.setTargetTile(TargetX, TargetY); String TargetString = TargetX + "_" + TargetY; QGPathFinder qgpf = new QGPathFinder(floorPlan); //show neighbors List<FloorTile> TargetNeighbors = floorPlan.getTargetTile().getNeighbours(); String neighborString = ""; for (int i = 0; i < TargetNeighbors.Count; i++) { neighborString = TargetNeighbors[i].Position.X + "_" + TargetNeighbors[i].Position.Y; //tw.WriteLine("Target Neighbors: " + neighborString + ": " + isContainEdge); } List<FloorTile> actual; actual = qgpf.getPath(); tw.WriteLine(qgpf.GetMessages()); tw.Close(); visualizeFloorPlan(floorPlan, StartX, StartY, TargetX, TargetY); List<FloorTile> expected = new List<FloorTile>(); FloorTile t1 = new FloorTile(0, 0, true, floorPlan); FloorTile t2 = new FloorTile(0, 1, true, floorPlan); FloorTile t3 = new FloorTile(0, 2, true, floorPlan); expected.Add(t1); expected.Add(t2); expected.Add(t3); //String actualString = actual[1].Position.X + "," + actual[1].Position.Y; //String expectedString = expected[1].Position.X + "," + expected[1].Position.Y; //Assert.AreEqual(expectedString, actualString); }
/// <summary> /// Creates a new FloorPlan object in m_Status, then uses that to create a new PathFinder object /// </summary> /// <param name="FloorPlanImage">an image of the floorplan</param> /// <param name="ppf">the scale of the image, in pixels per foot</param> public void CreateStatus(FloorPlan fp) { m_status = new Status(fp); m_pathfinder = new QGPathFinder(m_status.FloorPlan); }
public void getXTileNumTest() { Image myimage = new Bitmap("../../testImage.jpg"); // TODO: Initialize to an appropriate value FloorPlan target = new FloorPlan(myimage); // TODO: Initialize to an appropriate value int expected = 95; // TODO: Initialize to an appropriate value int actual; actual = target.getXTileNum(); Assert.AreEqual(expected, actual); }
public void ConnectTest() { Image myimage = new Bitmap("../../testImage.jpg"); // TODO: Initialize to an appropriate value FloorPlan target = new FloorPlan(myimage); // TODO: Initialize to an appropriate value target.Connect(); Assert.AreEqual(0, 0); }