public void TestGetRoiFromPolygon() { var graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 1)); graphic.Points.Add(new PointF(1, 1)); graphic.Points.Add(graphic.Points[0]); var roi = graphic.GetRoi(); Assert.IsInstanceOf(typeof(PolygonalRoi), roi, "PolylineGraphic.GetRoi() should return PolygonalRoi for shape {0}", Format(graphic.Points)); var graphic2 = new PolylineGraphic(); graphic2.Points.Add(new PointF(0, 0)); graphic2.Points.Add(new PointF(0, 1)); graphic2.Points.Add(new PointF(1, 1)); graphic2.Points.Add(new PointF(1, 0)); graphic2.Points.Add(graphic2.Points[0]); var roi2 = graphic2.GetRoi(); Assert.IsInstanceOf(typeof(PolygonalRoi), roi2, "PolylineGraphic.GetRoi() should return PolygonalRoi for shape {0}", Format(graphic2.Points)); var graphic3 = new PolylineGraphic(); graphic3.Points.Add(new PointF(0, 0)); graphic3.Points.Add(new PointF(0, 1000)); graphic3.Points.Add(new PointF(1000, 0)); graphic3.Points.Add(new PointF(1000, 1000)); graphic3.Points.Add(graphic3.Points[0]); var roi3 = graphic3.GetRoi(); Assert.IsInstanceOf(typeof(PolygonalRoi), roi3, "PolylineGraphic.GetRoi() should return PolygonalRoi for shape {0}", Format(graphic3.Points)); }
public void TestBug6614() { MockShowAnglesTool mockOwnerTool = new MockShowAnglesTool(); using (MockPresentationImage image = new MockPresentationImage(1000, 1000)) { ShowAnglesTool.ShowAnglesToolCompositeGraphic composite = new ShowAnglesTool.ShowAnglesToolCompositeGraphic(mockOwnerTool); image.OverlayGraphics.Add(composite); PolylineGraphic line1 = new PolylineGraphic(); line1.Points.Add(new PointF(274.983246f, 483.976f)); line1.Points.Add(new PointF(674.3086f, 490.196f)); VerticesControlGraphic control1 = new VerticesControlGraphic(line1); image.OverlayGraphics.Add(control1); composite.Select(control1); composite.OnDrawing(); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); var cloneAngles = FindShowAnglesTool(cloneComposite.Graphics); if (cloneAngles != null) { foreach (ICalloutGraphic calloutGraphic in cloneAngles.Graphics.Where(IsOfType <ICalloutGraphic>)) { if (calloutGraphic.Visible) { Assert.AreNotEqual(string.Format(SR.ToolsMeasurementFormatDegrees, 0), calloutGraphic.Text, "ShowAnglesToolGraphic should not have spurious 0.0 degree callout with only one line."); } } } } } }
public void TestGetRoiFromNullShape() { var graphic = new PolylineGraphic(); var roi = graphic.GetRoi(); Assert.IsNull(roi, "PolylineGraphic.GetRoi() should return null for shape {0}", Format(graphic.Points)); }
public void TestGetRoiFromPolyline() { // test 3 point polyline (closed shape) { var graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 1)); graphic.Points.Add(new PointF(0, 0)); var roi = graphic.GetRoi(); Assert.IsNull(roi, "PolylineGraphic.GetRoi() should return null for shape {0}", Format(graphic.Points)); } // test 3 point polyline (unclosed shape) { var graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 1)); graphic.Points.Add(new PointF(1, 1)); var roi = graphic.GetRoi(); Assert.IsNull(roi, "PolylineGraphic.GetRoi() should return null for shape {0}", Format(graphic.Points)); } // test 4 point polyline (unclosed shape) { var graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 1)); graphic.Points.Add(new PointF(1, 1)); graphic.Points.Add(new PointF(1, 2)); var roi = graphic.GetRoi(); Assert.IsNull(roi, "PolylineGraphic.GetRoi() should return null for shape {0}", Format(graphic.Points)); } }
private static IGraphic CreateInteractivePolyline(IList <PointF> vertices) { var closed = FloatComparer.AreEqual(vertices[0], vertices[vertices.Count - 1]); // use a standard rectangle primitive if the axes defines an axis-aligned rectangle if (closed && vertices.Count == 5 && IsAxisAligned(vertices[0], vertices[1]) && IsAxisAligned(vertices[1], vertices[2]) && IsAxisAligned(vertices[2], vertices[3]) && IsAxisAligned(vertices[3], vertices[4])) { var bounds = RectangleUtilities.ConvertToPositiveRectangle(RectangleUtilities.ComputeBoundingRectangle(vertices[0], vertices[1], vertices[2], vertices[3])); var rectangle = new RectanglePrimitive { TopLeft = bounds.Location, BottomRight = bounds.Location + bounds.Size }; return(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(rectangle)))); } else if (!closed && vertices.Count == 3) { var protractor = new ProtractorGraphic { Points = { vertices[0], vertices[1], vertices[2] } }; return(new VerticesControlGraphic(new MoveControlGraphic(protractor))); } else if (!closed && vertices.Count == 2) { var line = new PolylineGraphic { Points = { vertices[0], vertices[1] } }; return(new VerticesControlGraphic(new MoveControlGraphic(line))); } var polyline = new PolylineGraphic(closed); polyline.Points.AddRange(vertices); return(closed ? new PolygonControlGraphic(true, new MoveControlGraphic(polyline)) : new VerticesControlGraphic(true, new MoveControlGraphic(polyline))); }
private static IGraphic CreatePolyline(IList <PointF> vertices) { var closed = FloatComparer.AreEqual(vertices[0], vertices[vertices.Count - 1]); var polyline = new PolylineGraphic(closed); polyline.Points.AddRange(vertices); return(polyline); }
public void TestInvalidConstructionFromUnclosedPolyline() { PolylineGraphic plg = new PolylineGraphic(); plg.Points.Add(new PointF(0, 0)); plg.Points.Add(new PointF(0, 1)); new PolygonalRoi(plg); }
public void TestGetRoiFromLineSegment() { var graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 1)); var roi = graphic.GetRoi(); Assert.IsInstanceOf(typeof(LinearRoi), roi, "PolylineGraphic.GetRoi() should return LinearRoi for shape {0}", Format(graphic.Points)); }
private static IGraphic CreatePolyline(IList <PointF> vertices) { PolylineGraphic polyline = new PolylineGraphic(); for (int n = 0; n < vertices.Count; n++) { polyline.Points.Add(vertices[n]); } return(polyline); }
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()); }
public void DrawPolyline() { var rectangle = new Rectangle(new Point(), SelectedPresentationImage.SceneSize); rectangle.Inflate(-10, -10); var polyline = new PolylineGraphic { Points = { rectangle.Location, rectangle.Location + new Size(rectangle.Width / 2, 0), rectangle.Location + new Size(rectangle.Width, 0), rectangle.Location + rectangle.Size, rectangle.Location + new Size(0, rectangle.Height), rectangle.Location + new Size(0, rectangle.Height / 2) } }; DrawGraphic(new VerticesControlGraphic(true, polyline)); }
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()); }
public void TestCloningShowAnglesToolCompositeGraphicVisibility() { MockShowAnglesTool mockOwnerTool = new MockShowAnglesTool(); using (MockPresentationImage image = new MockPresentationImage(100, 100)) { ShowAnglesTool.ShowAnglesToolCompositeGraphic composite = new ShowAnglesTool.ShowAnglesToolCompositeGraphic(mockOwnerTool); image.OverlayGraphics.Add(composite); PolylineGraphic line1 = new PolylineGraphic(); line1.Points.Add(new PointF(0, 0)); line1.Points.Add(new PointF(10, 10)); VerticesControlGraphic control1 = new VerticesControlGraphic(line1); image.OverlayGraphics.Add(control1); composite.Select(control1); composite.OnDrawing(); PolylineGraphic line2 = new PolylineGraphic(); line2.Points.Add(new PointF(0, 10)); line2.Points.Add(new PointF(10, 0)); VerticesControlGraphic control2 = new VerticesControlGraphic(line2); image.OverlayGraphics.Add(control2); composite.Select(control2); composite.OnDrawing(); mockOwnerTool.ShowAngles = true; composite.OnDrawing(); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); Assert.IsTrue(cloneComposite.Visible, "Cloned ShowAnglesToolCompositeGraphic should retain visibility state when captured (true)."); mockOwnerTool.ShowAngles = false; composite.OnDrawing(); Assert.IsTrue(cloneComposite.Visible, "Cloned ShowAnglesToolCompositeGraphic should retain visibility state when captured (true) even when the original changes."); } mockOwnerTool.ShowAngles = false; composite.OnDrawing(); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); Assert.IsFalse(cloneComposite.Visible, "Cloned ShowAnglesToolCompositeGraphic should retain visibility state when captured (false)."); mockOwnerTool.ShowAngles = true; composite.OnDrawing(); Assert.IsFalse(cloneComposite.Visible, "Cloned ShowAnglesToolCompositeGraphic should retain visibility state when captured (false) even when the original changes."); } } }
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); }
public void TestConstructionFromPolyline() { PolylineGraphic plg = new PolylineGraphic(); plg.Points.Add(new PointF(0, 0)); plg.Points.Add(new PointF(0, 1)); plg.Points.Add(new PointF(1, 1)); plg.Points.Add(plg.Points[0]); PolygonalRoi roi = new PolygonalRoi(plg); Assert.IsNotNull(roi.Polygon); Assert.AreEqual(3, roi.Polygon.CountVertices); Assert.AreEqual(3, roi.Polygon.Vertices.Count); Assert.AreEqual(0.5, roi.Area); PolylineGraphic plg2 = new PolylineGraphic(); plg2.Points.Add(new PointF(0, 0)); plg2.Points.Add(new PointF(0, 1)); plg2.Points.Add(new PointF(1, 1)); plg2.Points.Add(new PointF(1, 0)); plg2.Points.Add(plg2.Points[0]); PolygonalRoi roi2 = new PolygonalRoi(plg2); Assert.IsNotNull(roi2.Polygon); Assert.AreEqual(4, roi2.Polygon.CountVertices); Assert.AreEqual(4, roi2.Polygon.Vertices.Count); Assert.AreEqual(1, roi2.Area); PolylineGraphic plg3 = new PolylineGraphic(); plg3.Points.Add(new PointF(0, 0)); plg3.Points.Add(new PointF(0, 1000)); plg3.Points.Add(new PointF(1000, 0)); plg3.Points.Add(new PointF(1000, 1000)); plg3.Points.Add(plg3.Points[0]); PolygonalRoi roi3 = new PolygonalRoi(plg3); Assert.IsNotNull(roi3.Polygon); Assert.AreEqual(4, roi3.Polygon.CountVertices); Assert.AreEqual(4, roi3.Polygon.Vertices.Count); Assert.AreEqual(500000, roi3.Area, 5000); }
public void TestInvalidConstructionFromClosedPolyline() { try { PolylineGraphic graphic = new PolylineGraphic(); new PolygonalRoi(graphic); Assert.Fail("PolygonalRoi constructor should have thrown an exception (0 points in graphic)."); } catch (ArgumentException) {} try { PolylineGraphic graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); new PolygonalRoi(graphic); Assert.Fail("PolygonalRoi constructor should have thrown an exception (1 point in graphic)."); } catch (ArgumentException) {} try { PolylineGraphic graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(0, 0)); new PolygonalRoi(graphic); Assert.Fail("PolygonalRoi constructor should have thrown an exception (2 points in graphic)."); } catch (ArgumentException) {} try { PolylineGraphic graphic = new PolylineGraphic(); graphic.Points.Add(new PointF(0, 0)); graphic.Points.Add(new PointF(1, 1)); graphic.Points.Add(new PointF(0, 0)); new PolygonalRoi(graphic); Assert.Fail("PolygonalRoi constructor should have thrown an exception (3 points in graphic)."); } catch (ArgumentException) {} }
internal static List <IGraphic> PopulateImageViewerWithSavedMarkup(List <IMarkup> markupList, IImageViewer imageViewer) { var graphics = new List <IGraphic>(); foreach (var markup in markupList) { foreach (var box in imageViewer.PhysicalWorkspace.ImageBoxes) { if (box.DisplaySet == null) { continue; } var imageSop = box.DisplaySet.PresentationImages.Cast <IImageSopProvider>().FirstOrDefault( pi => pi.ImageSop.SopInstanceUid == markup.PresentationImageUid && pi.Frame.FrameNumber == markup.FrameNumber); var selectedPresentationImage = imageSop as IPresentationImage; if (selectedPresentationImage == null) { continue; } var graphicsProvider = selectedPresentationImage as IOverlayGraphicsProvider; if (graphicsProvider != null) { if (markup is MarkupEllipse) { var markupEllipse = (MarkupEllipse)markup; var ellipsePrimitive = new EllipsePrimitive(); var roiGraphic = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic( new MoveControlGraphic(ellipsePrimitive)))); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; markup.GraphicHashcode = roiGraphic.GetHashCode(); graphics.Add(roiGraphic); graphicsProvider.OverlayGraphics.Add(roiGraphic); if (boundableGraphic != null) { roiGraphic.Suspend(); // prevent callout location calculation until all points are set roiGraphic.Name = markup.Name; ellipsePrimitive.BottomRight = markupEllipse.BottomRight; ellipsePrimitive.TopLeft = markupEllipse.TopLeft; roiGraphic.State = roiGraphic.CreateInactiveState(); roiGraphic.Resume(true); // Force callout location calculation roiGraphic.Callout.TextLocation = markupEllipse.CalloutLocation; } } else if (markup is MarkupPolygonal) { var markupPolygon = (MarkupPolygonal)markup; var polyline = new PolylineGraphic(true); foreach (var point in markupPolygon.Vertices) { polyline.Points.Add(point); } var roiGraphic = new RoiGraphic(new PolygonControlGraphic(true, new MoveControlGraphic(polyline))); markup.GraphicHashcode = roiGraphic.GetHashCode(); graphics.Add(roiGraphic); graphicsProvider.OverlayGraphics.Add(roiGraphic); //if (boundableGraphic != null) { roiGraphic.Suspend(); // prevent callout location calculation until all points are set roiGraphic.Name = markup.Name; roiGraphic.State = roiGraphic.CreateInactiveState(); roiGraphic.Resume(true); // Force callout location calculation roiGraphic.Callout.TextLocation = markupPolygon.CalloutLocation; } } else if (markup is MarkupRectangle) { var markupRectangle = (MarkupRectangle)markup; var rectanglePrimitive = new RectanglePrimitive(); var roiGraphic = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic( new MoveControlGraphic(rectanglePrimitive)))); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; markup.GraphicHashcode = roiGraphic.GetHashCode(); graphics.Add(roiGraphic); graphicsProvider.OverlayGraphics.Add(roiGraphic); if (boundableGraphic != null) { roiGraphic.Suspend(); // prevent callout location calculation until all points are set roiGraphic.Name = markup.Name; rectanglePrimitive.BottomRight = markupRectangle.BottomRight; rectanglePrimitive.TopLeft = markupRectangle.TopLeft; roiGraphic.State = roiGraphic.CreateInactiveState(); roiGraphic.Resume(true); // Force callout location calculation roiGraphic.Callout.TextLocation = markupRectangle.CalloutLocation; } } else if (markup is MarkupProtractor) { var markupProtractor = (MarkupProtractor)markup; var protractorGraphic = new ProtractorGraphic(); foreach (var point in markupProtractor.Points) { protractorGraphic.Points.Add(point); } var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(protractorGraphic))); markup.GraphicHashcode = roiGraphic.GetHashCode(); graphics.Add(roiGraphic); graphicsProvider.OverlayGraphics.Add(roiGraphic); roiGraphic.Suspend(); // prevent callout location calculation until all points are set roiGraphic.Name = markup.Name; roiGraphic.State = roiGraphic.CreateInactiveState(); roiGraphic.Resume(true); // Force callout location calculation roiGraphic.Callout.TextLocation = markupProtractor.CalloutLocation; } else if (markup is MarkupLinear) { var markupLinear = (MarkupLinear)markup; var polylineGraphic = new PolylineGraphic(); foreach (var point in markupLinear.Vertices) { polylineGraphic.Points.Add(point); } var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(polylineGraphic))); markup.GraphicHashcode = roiGraphic.GetHashCode(); graphics.Add(roiGraphic); graphicsProvider.OverlayGraphics.Add(roiGraphic); roiGraphic.Suspend(); // prevent callout location calculation until all points are set roiGraphic.Name = markup.Name; roiGraphic.State = roiGraphic.CreateInactiveState(); roiGraphic.Resume(true); // Force callout location calculation roiGraphic.Callout.TextLocation = markupLinear.CalloutLocation; } else if (markup is MarkupPoint) { var markupPoint = (MarkupPoint)markup; IGraphic calloutGraphic; if (markupPoint.UseCrosshair) { calloutGraphic = new UserCrosshairCalloutGraphic { AnchorPoint = markupPoint.Point, TextLocation = markupPoint.CalloutLocation, Text = markupPoint.CalloutText, ShowShaft = !String.IsNullOrEmpty(markupPoint.CalloutText), LineStyle = LineStyle.Dot }; } else { calloutGraphic = new UserCalloutGraphic { AnchorPoint = markupPoint.Point, TextLocation = markupPoint.CalloutLocation, Text = markupPoint.CalloutText, ShowArrowhead = true, LineStyle = LineStyle.Solid }; } var statefulGraphic = new StandardStatefulGraphic(calloutGraphic); statefulGraphic.State = statefulGraphic.CreateInactiveState(); var contextGraphic = new ContextMenuControlGraphic(typeof(ClearCanvas.ImageViewer.Tools.Standard.TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic); contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions; //if (markupPoint.Name != "RemoveForCalloutPlacement") { markup.GraphicHashcode = contextGraphic.GetHashCode(); graphics.Add(contextGraphic); graphicsProvider.OverlayGraphics.Add(contextGraphic); //selectedPresentationImage.Draw(); } } } box.TopLeftPresentationImage = selectedPresentationImage; box.Tiles[0].Select(); box.Draw(); break; } } return(graphics); }
public void TestCloningShowAnglesToolCompositeGraphicLineSelection() { MockShowAnglesTool mockOwnerTool = new MockShowAnglesTool(); using (MockPresentationImage image = new MockPresentationImage(100, 100)) { ShowAnglesTool.ShowAnglesToolCompositeGraphic composite = new ShowAnglesTool.ShowAnglesToolCompositeGraphic(mockOwnerTool); image.OverlayGraphics.Add(composite); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); Assert.IsNotNull(cloneComposite, "ShowAnglesToolCompositeGraphic should be cloneable."); } PolylineGraphic line1 = new PolylineGraphic(); line1.Points.Add(new PointF(0, 0)); line1.Points.Add(new PointF(10, 10)); VerticesControlGraphic control1 = new VerticesControlGraphic(line1); image.OverlayGraphics.Add(control1); composite.Select(control1); composite.OnDrawing(); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); cloneComposite.CoordinateSystem = line1.CoordinateSystem; try { Assert.IsNotNull(cloneComposite.SelectedLine, "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection."); Assert.AreEqual(line1.Points[0], cloneComposite.SelectedLine.Points[0], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (X)."); Assert.AreEqual(line1.Points[1], cloneComposite.SelectedLine.Points[1], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (Y)."); } finally { cloneComposite.ResetCoordinateSystem(); } } PolylineGraphic line2 = new PolylineGraphic(); line2.Points.Add(new PointF(0, 10)); line2.Points.Add(new PointF(10, 0)); VerticesControlGraphic control2 = new VerticesControlGraphic(line2); image.OverlayGraphics.Add(control2); composite.Select(control2); composite.OnDrawing(); using (IPresentationImage clone = image.Clone()) { var cloneComposite = FindShowAnglesToolComposite(clone); cloneComposite.CoordinateSystem = line2.CoordinateSystem; try { Assert.IsNotNull(cloneComposite.SelectedLine, "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (2)."); Assert.AreEqual(line2.Points[0], cloneComposite.SelectedLine.Points[0], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (X2)."); Assert.AreEqual(line2.Points[1], cloneComposite.SelectedLine.Points[1], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (Y2)."); } finally { cloneComposite.ResetCoordinateSystem(); } } } }
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"); } }