Ejemplo n.º 1
0
        public SemiAutomaticContourDTO Add(SemiAutomaticPointsDTO contour)
        {
            SemiAutomaticContourDTO result = SemiAutomatic.Default(contour);

            repository.Save(result);
            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult <SemiAutomaticContourDTO> Post([FromBody] SemiAutomaticPointsDTO points)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (points == null)
            {
                return(BadRequest());
            }

            if (points.lines == null)
            {
                return(BadRequest());
            }

            if (points.lines.Count == 0)
            {
                return(BadRequest());
            }

            foreach (var l in points.lines)
            {
                if (l.points == null)
                {
                    return(BadRequest());
                }

                if (l.points.Count < 3)
                {
                    return(BadRequest());
                }
            }

            SemiAutomaticContourDTO result = logic.Add(points);

            return(CreatedAtAction(nameof(Get),
                                   new { guid = result.guid }, result));
        }
        public static SemiAutomaticContourDTO Canny(SemiAutomaticPointsDTO points)
        {
            List <Point>     pixels;
            StatisticsResult statisticsResult;

            (pixels, statisticsResult) = CannyAlgorithm.Canny(points.dicomid, points.lines.First().points, points.width, points.height,
                                                              points.centralPoints, points.pixelSpacing);

            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);

            SemiAutomaticContourDTO contour = new SemiAutomaticContourDTO(points.guid,
                                                                          points.dicomid, points.tag, lines, points.width, points.height, statisticsResult, points.centralPoints, points.pixelSpacing);

            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);
        }
Ejemplo n.º 5
0
        public bool Edit(SemiAutomaticContourDTO contour)
        {
            SemiAutomaticContourDTO old = repository.Load(contour.guid);

            if (old == null)
            {
                return(false);
            }

            List <Point> newListOfPoints = new List <Point>();

            int i        = 0;
            int j        = 0;
            int countOld = old.lines.First().points.Count;
            int countNew = contour.lines.First().points.Count;

            Point currentInOld = old.lines.First().points[i];
            Point currentInNew = contour.lines.First().points[j];

            while (i < countOld)
            {
                currentInOld = old.lines.First().points[i];
                currentInNew = contour.lines.First().points[j];
                while (currentInOld.x != currentInNew.x || currentInOld.y != currentInNew.y)
                {
                    i++;
                    currentInOld = old.lines.First().points[i];
                }
                newListOfPoints.Add(currentInOld);
                i++;
                j++;
                if (j == countNew)
                {
                    break;
                }
            }
            while (j < countNew)
            {
                double minDistance = double.MaxValue;
                int    index       = 0;

                for (int k = 0; k < newListOfPoints.Count; k++)
                {
                    Point point1 = newListOfPoints[k];
                    Point point2 = newListOfPoints[(k + 1) % newListOfPoints.Count];

                    double A = point2.y - point1.y;
                    double B = point1.x - point2.x;
                    double C = point2.x * point1.y - point1.x * point2.y;

                    double m        = Math.Sqrt(A * A + B * B);
                    double distance = Math.Abs(A * currentInNew.x + B * currentInNew.y + C) / m;

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        index       = k;
                    }
                }

                newListOfPoints.Insert(index, currentInNew);
                j++;
            }

            contour.lines.First().points = new List <Point>(newListOfPoints);

            List <LinePoints> list = new List <LinePoints>();
            LinePoints        line = new LinePoints();

            line.points     = new List <Point>(newListOfPoints);
            line.brushColor = contour.lines.First().brushColor;
            list.Add(line);

            SemiAutomaticPointsDTO contourPointsDTO = new SemiAutomaticPointsDTO(contour.guid, contour.dicomid, contour.tag, list, contour.width, contour.height,
                                                                                 contour.centralPoints, contour.pixelSpacing);
            SemiAutomaticContourDTO result = SemiAutomatic.Default(contourPointsDTO);

            return(repository.Edit(result));
        }
 public static SemiAutomaticContourDTO Default(SemiAutomaticPointsDTO points)
 => Canny(points);