Beispiel #1
0
        private static void TestCalibration(string pixelShape, bool uncalibrated, PointF pt1, PointF pt2, double calibrationValue, double expectedRowSpacing, double expectedColSpacing)
        {
            using (IPresentationImage image = GetCalibrationTestImage(pixelShape, uncalibrated))
            {
                Trace.WriteLine(string.Format("TEST {0} image with {1} pixels", uncalibrated ? "uncalibrated" : "calibrated", pixelShape));
                Trace.WriteLine(string.Format("calibrating [{0}, {1}] to {2} mm", pt1, pt2, calibrationValue));

                PolylineGraphic          lineGraphic;
                IOverlayGraphicsProvider overlayGraphicsProvider = (IOverlayGraphicsProvider)image;
                overlayGraphicsProvider.OverlayGraphics.Add(new VerticesControlGraphic(lineGraphic = new PolylineGraphic()));
                lineGraphic.CoordinateSystem = CoordinateSystem.Source;
                lineGraphic.Points.Add(pt1);
                lineGraphic.Points.Add(pt2);
                lineGraphic.ResetCoordinateSystem();

                CalibrationTool.TestCalibration(calibrationValue, lineGraphic);

                IImageSopProvider imageSopProvider = (IImageSopProvider)image;

                Trace.WriteLine(string.Format("Pixel Spacing (Actual)/(Expected): ({0:F4}:{1:F4})/({2:F4}:{3:F4})",
                                              imageSopProvider.Frame.NormalizedPixelSpacing.Row, imageSopProvider.Frame.NormalizedPixelSpacing.Column,
                                              expectedRowSpacing, expectedColSpacing));

                float percentErrorRow = Math.Abs((float)((imageSopProvider.Frame.NormalizedPixelSpacing.Row - expectedRowSpacing) / expectedRowSpacing * 100F));
                float percentErrorCol = Math.Abs((float)((imageSopProvider.Frame.NormalizedPixelSpacing.Column - expectedColSpacing) / expectedColSpacing * 100F));

                Trace.WriteLine(String.Format("Percent Error (Row/Column): {0:F3}%/{1:F3}%", percentErrorRow, percentErrorCol));

                Assert.AreEqual(expectedColSpacing, imageSopProvider.Frame.NormalizedPixelSpacing.Column, 0.005, "Column Spacing appears to be wrong");
                Assert.AreEqual(expectedRowSpacing, imageSopProvider.Frame.NormalizedPixelSpacing.Row, 0.005, "Row Spacing appears to be wrong");

                Assert.IsTrue(percentErrorCol < 1.5, "Column Spacing appears to be wrong");
                Assert.IsTrue(percentErrorRow < 1.5, "Row Spacing appears to be wrong");
            }
        }
Beispiel #2
0
        protected override Roi CreateRoiFromGraphic(IOverlayGraphicsProvider overlayGraphics, Line shapeData)
        {
            PolylineGraphic graphic = new PolylineGraphic();

            overlayGraphics.OverlayGraphics.Add(graphic);
            graphic.CoordinateSystem = CoordinateSystem.Source;
            graphic.Points.Add(shapeData.Point1);
            graphic.Points.Add(shapeData.Point2);
            graphic.ResetCoordinateSystem();
            return(graphic.GetRoi());
        }
Beispiel #3
0
        protected override Roi CreateRoiFromGraphic(IOverlayGraphicsProvider overlayGraphics, IEnumerable <PointF> shapeData)
        {
            PolylineGraphic graphic = new PolylineGraphic();

            overlayGraphics.OverlayGraphics.Add(graphic);
            graphic.CoordinateSystem = CoordinateSystem.Source;
            foreach (PointF data in shapeData)
            {
                graphic.Points.Add(data);
            }
            graphic.Points.Add(graphic.Points[0]);
            graphic.ResetCoordinateSystem();
            return(graphic.GetRoi());
        }
        private GeometricShutter ConvertToGeometricShutter()
        {
            GeometricShutter shutter;

            if (_selectedShutterType == ShutterType.Rectangle)
            {
                RectanglePrimitive primitive = (RectanglePrimitive)_primitiveGraphic;
                primitive.CoordinateSystem = CoordinateSystem.Source;
                Rectangle rectangle =
                    new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
                primitive.ResetCoordinateSystem();

                shutter = new RectangularShutter(rectangle);
            }
            else if (_selectedShutterType == ShutterType.Polygon)
            {
                PolylineGraphic polyLine = (PolylineGraphic)_primitiveGraphic;
                polyLine.CoordinateSystem = CoordinateSystem.Source;

                List <Point> points = new List <Point>();
                for (int i = 0; i < polyLine.Points.Count; ++i)
                {
                    points.Add(new Point((int)polyLine.Points[i].X, (int)polyLine.Points[i].Y));
                }

                polyLine.ResetCoordinateSystem();
                shutter = new PolygonalShutter(points);
            }
            else
            {
                EllipsePrimitive primitive = (EllipsePrimitive)_primitiveGraphic;
                primitive.CoordinateSystem = CoordinateSystem.Source;
                Rectangle rectangle = new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
                rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle);
                int   radius = rectangle.Width / 2;
                Point center = new Point(rectangle.X + radius, rectangle.Y + radius);
                primitive.ResetCoordinateSystem();

                shutter = new CircularShutter(center, radius);
            }

            RemoveDrawShutterGraphic();
            return(shutter);
        }