private void InsertVertexPath(Vertex vertex, Path path) { int key = VertexExtractor.GetVertexKey(vertex); List <Path> paths; if (vertexPaths.ContainsKey(key)) { paths = vertexPaths[key]; } else { paths = new List <Path>(); vertexPaths.Add(key, paths); } paths.Add(path); }
public List <Path> FindLoosePaths() { List <Path> loosePaths = new List <Path>(); foreach (Path p in paths) { int v1Key = VertexExtractor.GetVertexKey(p.V1); int v2Key = VertexExtractor.GetVertexKey(p.V2); int v1PathCount = vertexPaths[v1Key].Count; int v2PathCount = vertexPaths[v2Key].Count; if (v1PathCount == 1 || v2PathCount == 1) { loosePaths.Add(p); } } return(loosePaths); }
public void RemovePath(Path path) { long key = GetPathKey(path); paths.Remove(path); pathMap.Remove(key); int v1Key = VertexExtractor.GetVertexKey(path.V1); int v2Key = VertexExtractor.GetVertexKey(path.V2); vertexPaths[v1Key].Remove(path); if (vertexPaths[v1Key].Count == 0) { ve.Vertices.Remove(path.V1); ve.VertexMap.Remove(v1Key); vertexPaths.Remove(v1Key); } vertexPaths[v2Key].Remove(path); if (vertexPaths[v2Key].Count == 0) { ve.Vertices.Remove(path.V2); ve.VertexMap.Remove(v2Key); vertexPaths.Remove(v2Key); } }
public PathExtractor(VertexExtractor segmentExtractor) { ve = segmentExtractor; }
private void buttonStart_Click(object sender, EventArgs e) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); pointExt = new PointExtractor(bmp); points = pointExt.Points; pointMap = pointExt.PointMap; stopWatch.Stop(); Log("Done extracting points in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); segExt = new SegmentExtractor(pointExt); segments = segExt.ExtractSegments(); pointSegments = segExt.PointSegments; stopWatch.Stop(); Log("Done extracting segments in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); vertExt = new VertexExtractor(segExt); vertices = vertExt.Vertices; vertexMap = vertExt.VertexMap; stopWatch.Stop(); Log("Done extracting vertices in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); pathExt = new PathExtractor(vertExt); paths = pathExt.Paths; vertexPaths = pathExt.VertexPaths; stopWatch.Stop(); Log("Done extracting paths in " + stopWatch.ElapsedMilliseconds + "ms"); double ct = Double.Parse(textBoxCollapse.Text, CultureInfo.InvariantCulture); stopWatch.Restart(); int collapsed = pathExt.CollapseVertices(ct); stopWatch.Stop(); Log("Collapsed " + collapsed + " vertices in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); int loose = pathExt.RemoveLooseEnds(); stopWatch.Stop(); Log("Removed " + loose + " loose ends in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); int merged = pathExt.MergeConsecutivePaths(); stopWatch.Stop(); Log("Merged " + merged + " consecutive paths in " + stopWatch.ElapsedMilliseconds + "ms"); double st = Double.Parse(textBoxSimplify.Text, CultureInfo.InvariantCulture); stopWatch.Restart(); pathExt.SimplifyPaths(st); stopWatch.Stop(); Log("Simplified paths in " + stopWatch.ElapsedMilliseconds + "ms"); stopWatch.Restart(); polyExt = new PolygonExtractor(pathExt.Paths, bmp); polygons = polyExt.ExtractPolygons(); stopWatch.Stop(); Log("Extracted polygons in " + stopWatch.ElapsedMilliseconds + "ms"); jsonExport = new JsonExport(polyExt, bmp); labelPoints.Text = points.Count.ToString(); labelSegments.Text = segments.Count.ToString(); labelVertices.Text = vertices.Count.ToString(); labelPaths.Text = paths.Count.ToString(); labelPolygons.Text = polygons.Count.ToString(); }