public static ManualContourDTO PrepareContour(ManualContourDTO contour) { List <Point> result = new List <Point>(); int count = contour.lines.First().points.Count; int i; for (i = 0; i < count; i++) { Point p1 = contour.lines.First().points[i]; Point p2 = contour.lines.First().points[(i + 1) % count]; result.Add(p1); result.Add(p2); result.AddRange(BresenhamClass.Bresenham(new List <Point>(), p1.x, p1.y, p2.x, p2.y)); } contour.lines.First().points = new List <Point>(result); return(contour); }
public static SemiAutomaticContourDTO TrivialContour(SemiAutomaticPointsDTO points) { List <Point> pixels = new List <Point>(); int count = points.lines.First().points.Count; for (int i = 0; i < points.lines.First().points.Count; i++) { int x1 = points.lines.First().points[i].x; int y1 = points.lines.First().points[i].y; int x2 = points.lines.First().points[(i + 1) % count].x; int y2 = points.lines.First().points[(i + 1) % count].y; List <Point> pixelsBresenham = new List <Point>(); BresenhamClass.Bresenham(pixelsBresenham, x1, y1, x2, y2); pixels = pixels.Concat(pixelsBresenham).ToList(); } List <LinePointsAndPixels> lines = new List <LinePointsAndPixels>(); LinePointsAndPixels line = new LinePointsAndPixels(); line.points = new List <Point>(points.lines.First().points); line.pixels = new List <Point>(pixels); line.brushColor = points.lines.First().brushColor; lines.Add(line); System.Drawing.Bitmap bitmap = OrthancConnection.GetBitmapByInstanceId(points.dicomid); int[,] matrixWithContour = CannyAlgorithm.MakeMatrixFromPoints(bitmap.Width, bitmap.Height, pixels); int[,] image = CannyAlgorithm.ReadMatrixFromBitmap(bitmap); StatisticsResult statisticsResult = Statistics.GenerateStatistics(pixels, matrixWithContour, image, 0, bitmap.Width, 0, bitmap.Height, 0, 0, points.centralPoints.First()); SemiAutomaticContourDTO contour = new SemiAutomaticContourDTO(points.guid, points.dicomid, points.tag, lines, points.width, points.height, statisticsResult, points.centralPoints, points.pixelSpacing); return(contour); }
public List <Point> FindShortestPath(List <Point> points, double weight) { List <Point> result = new List <Point>(); List <Vertex> pointsVertices = new List <Vertex>(); foreach (var point in points) { Vertex vertex = new Vertex(); vertex.point = point; vertex.Vertices = new Dictionary <Vertex, int>(); vertex.Edges = new List <Edge>(); Vertices.Add(vertex); pointsVertices.Add(vertex); result.Add(point); } double maxDistance = 0; int ip = 0; for (ip = 0; ip < points.Count; ip++) { Point p1 = points[ip]; Point p2 = points[(ip + 1) % points.Count]; double distance = ManhattanDistance(p1, p2); if (distance > maxDistance) { maxDistance = distance; } } //PrepareGraph(pointsVertices, weight, maxDistance * 2); PrepareGraph(pointsVertices, weight, maxDistance * 1.2); // foreach (var e in Edges) // { // // if (e.Artificial) // // result.AddRange(BresenhamClass.Bresenham(new List<Point>(), e.vertex1.point.x, e.vertex1.point.y, e.vertex2.point.x, e.vertex2.point.y)); // // else // // result.AddRange(e.points); // if(!e.Artificial) // result.AddRange(e.points); // //result.Add(e.vertex1.point); // //result.Add(e.vertex2.point); // } for (int i = 0; i < points.Count; i++) { Vertex startVertex = pointsVertices[i]; Vertex endVertex = pointsVertices[(i + 1) % points.Count]; Dictionary <Vertex, Vertex> previous = AStarAlgotihm(startVertex, endVertex, ManhattanDistance); Vertex currentVertex = endVertex; result.Add(currentVertex.point); Vertex exists = previous[currentVertex]; int count = 0; while (currentVertex != startVertex) { count++; Vertex previousVertex = previous[currentVertex]; Edge e = previousVertex.Edges.First(f => ((f.vertex1 == currentVertex && f.vertex2 == previousVertex) || (f.vertex2 == currentVertex && f.vertex1 == previousVertex))); if (e == null) { throw new Exception("Censored - don't searched edge after A* algorithm"); } if (e.points == null) { result.AddRange(BresenhamClass.Bresenham(new List <Point>(), previousVertex.point.x, previousVertex.point.y, currentVertex.point.x, currentVertex.point.y)); } else { result.AddRange(e.points); } result.Add(currentVertex.point); currentVertex = previousVertex; } } return(result); }