protected override void Serialize(ITextGraphic textGraphic, GraphicAnnotationSequenceItem serializationState) { // if the callout is not visible, don't serialize it! if (!textGraphic.Visible) { return; } if (string.IsNullOrEmpty(textGraphic.Text)) { return; } GraphicAnnotationSequenceItem.TextObjectSequenceItem text = new GraphicAnnotationSequenceItem.TextObjectSequenceItem(); textGraphic.CoordinateSystem = CoordinateSystem.Source; try { RectangleF boundingBox = RectangleUtilities.ConvertToPositiveRectangle(textGraphic.BoundingBox); text.BoundingBoxAnnotationUnits = GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Pixel; text.BoundingBoxTextHorizontalJustification = GraphicAnnotationSequenceItem.BoundingBoxTextHorizontalJustification.Left; text.BoundingBoxTopLeftHandCorner = boundingBox.Location; text.BoundingBoxBottomRightHandCorner = boundingBox.Location + boundingBox.Size; text.UnformattedTextValue = textGraphic.Text; } finally { textGraphic.ResetCoordinateSystem(); } serializationState.AppendTextObjectSequence(text); }
//internal for unit testing only. internal static void CalculateVisibleRectangles( ImageGraphic imageGraphic, Rectangle clientRectangle, out Rectangle dstVisibleRectangle, out RectangleF srcVisibleRectangle) { Rectangle srcRectangle = new Rectangle(0, 0, imageGraphic.Columns, imageGraphic.Rows); RectangleF dstRectangle = imageGraphic.SpatialTransform.ConvertToDestination(srcRectangle); // Find the intersection between the drawable client rectangle and // the transformed destination rectangle dstRectangle = RectangleUtilities.RoundInflate(dstRectangle); dstRectangle = RectangleUtilities.Intersect(clientRectangle, dstRectangle); if (dstRectangle.IsEmpty) { dstVisibleRectangle = Rectangle.Empty; srcVisibleRectangle = RectangleF.Empty; return; } // Figure out what portion of the image is visible in source coordinates srcVisibleRectangle = imageGraphic.SpatialTransform.ConvertToSource(dstRectangle); //dstRectangle is already rounded, this is just a conversion to Rectangle. dstVisibleRectangle = Rectangle.Round(dstRectangle); }
public void TestComplexAreaAlgorithmWithComplexPolygon() { // the complex area algorithm is very low resolution compared to simple area, so the error magnitude is higher const int side = 1000; const int expected = side * side / 2; PointF[] data = new PointF[4]; data[0] = new PointF(0, 0); data[1] = new PointF(side, 0); data[2] = new PointF(0, side); data[3] = new PointF(side, side); PolygonF.TestVertexNormalization(data); RectangleF bounding = RectangleUtilities.ComputeBoundingRectangle(data); unsafe { fixed(PointF *points = data) { // inside PolygonF, the vertexCount is always exactly the expected array length double result = PolygonF.TestComplexAreaComputation(bounding, points, data.Length); Trace.WriteLine(string.Format("Complex Area: Expected {0:f5} Got {1:f5}", expected, result), "UNIT_TESTS"); Assert.IsTrue(Math.Abs(expected - result) < expected / 100f); } } }
public void TestComplexAreaAlgorithmWithComplexPolygonNoBufferOverrun() { // the complex area algorithm is very low resolution compared to simple area, so the error magnitude is higher const int side = 1000; const int expected = side * side / 2; PointF[] data = new PointF[5]; data[0] = new PointF(0, 0); data[1] = new PointF(side, 0); data[2] = new PointF(0, side); data[3] = new PointF(side, side); data[4] = new PointF(side / 2f, side / 2f); PolygonF.TestVertexNormalization(data); RectangleF bounding = RectangleUtilities.ComputeBoundingRectangle(data); // test for a possible buffer overrun in the computation foreach (PointF garbagePoint in SimulatedBufferOverrunPoints) { data[data.Length - 1] = garbagePoint; unsafe { fixed(PointF *points = data) { // inside PolygonF, the vertexCount is always exactly the expected array length // which is 4 (the 5th point simulates garbage data beyond the array) double result = PolygonF.TestComplexAreaComputation(bounding, points, data.Length - 1); Trace.WriteLine(string.Format("Complex Area: Expected {0:f5} Got {1:f5}", expected, result), "UNIT_TESTS"); Assert.IsTrue(Math.Abs(expected - result) < expected / 100f); } } } }
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))); }
/// <summary> /// Computes the maximum bounds for scales on a given <see cref="IPresentationImage"/>. /// </summary> /// <param name="presentationImage">The image to compute bounds for.</param> /// <param name="horizontalReduction">The percentage of width to subtract from both the client bounds and the source image bounds.</param> /// <param name="verticalReduction">The percentage of height to subtract from both the client bounds and the source image bounds.</param> /// <returns>The maximum scale bounds.</returns> private static Rectangle ComputeScaleBounds(IPresentationImage presentationImage, float horizontalReduction, float verticalReduction) { RectangleF clientBounds = presentationImage.ClientRectangle; float hReduction = horizontalReduction * Math.Min(1000f, clientBounds.Width); float vReduction = verticalReduction * Math.Min(1000f, clientBounds.Height); clientBounds = new RectangleF(clientBounds.X + hReduction, clientBounds.Y + vReduction, clientBounds.Width - 2 * hReduction, clientBounds.Height - 2 * vReduction); if (presentationImage is IImageGraphicProvider) { ImageGraphic imageGraphic = ((IImageGraphicProvider)presentationImage).ImageGraphic; Rectangle srcRectangle = new Rectangle(0, 0, imageGraphic.Columns, imageGraphic.Rows); RectangleF imageBounds = imageGraphic.SpatialTransform.ConvertToDestination(srcRectangle); imageBounds = RectangleUtilities.ConvertToPositiveRectangle(imageBounds); hReduction = horizontalReduction * imageBounds.Width; vReduction = verticalReduction * imageBounds.Height; imageBounds = new RectangleF(imageBounds.X + hReduction, imageBounds.Y + vReduction, imageBounds.Width - 2 * hReduction, imageBounds.Height - 2 * vReduction); return(Rectangle.Round(RectangleUtilities.Intersect(imageBounds, clientBounds))); } else { return(Rectangle.Round(clientBounds)); } }
private static Rectangle ComputeEditBoxControlBounds(Control control, EditBox editBox) { Size sz = control.GetPreferredSize(Size.Empty); sz = new Size(Math.Max(Math.Max(sz.Width, editBox.Size.Width), 50), Math.Max(Math.Max(sz.Height, editBox.Size.Height), 21)); return(RectangleUtilities.ConvertToRectangle(editBox.Location, sz)); }
public void NoIntersection() { RectangleF rect1 = new RectangleF(0, 0, 10, 10); RectangleF rect2 = new RectangleF(-20, 0, 10, 10); RectangleF intersectRect = RectangleUtilities.Intersect(rect1, rect2); Assert.IsTrue(intersectRect.IsEmpty); }
public void IntersectOn2Sides() { RectangleF rect1 = new RectangleF(0, 0, 10, 10); RectangleF rect2 = new RectangleF(-2, -2, 5, 5); RectangleF intersectRect = RectangleUtilities.Intersect(rect1, rect2); Assert.AreEqual(new RectangleF(0, 0, 3, 3), intersectRect); }
public void Containment() { RectangleF rect1 = new RectangleF(0, 0, 10, 10); RectangleF rect2 = new RectangleF(2, 2, 5, 5); RectangleF intersectRect = RectangleUtilities.Intersect(rect1, rect2); Assert.AreEqual(rect2, intersectRect); }
private bool DeserializeNormalizedRectangle(string normalizedRectangleString, out RectangleF normalizedRectangle) { normalizedRectangle = new RectangleF(); string[] rectangleComponents = normalizedRectangleString.Split('\\'); if (rectangleComponents.Length != 4) { return(false); } float left, right, top, bottom; if (!float.TryParse(rectangleComponents[0], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out left)) { return(false); } if (!float.TryParse(rectangleComponents[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out top)) { return(false); } if (!float.TryParse(rectangleComponents[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out right)) { return(false); } if (!float.TryParse(rectangleComponents[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out bottom)) { return(false); } if (left >= right) { return(false); } if (top >= bottom) { return(false); } if (left < 0F || left > 1.0F) { return(false); } if (top < 0F || top > 1.0F) { return(false); } if (right < 0F || right > 1.0F) { return(false); } if (bottom < 0F || bottom > 1.0F) { return(false); } normalizedRectangle = RectangleF.FromLTRB(left, top, right, bottom); return(RectangleUtilities.IsRectangleNormalized(normalizedRectangle)); }
private bool IsOnFloor() { if (RectangleUtilities.GetHitbox(floor.Position, floor.Size).Intersects(RectangleUtilities.GetHitbox(position, size)) == true) { return(true); } return(false); }
/// <summary> /// Returns a bounding box that has been rounded to the nearest whole pixel(s). /// </summary> /// <remarks> /// Uses <see cref="RectangleUtilities.RoundInflate"/> to ensure the bounding box /// returned will encompass every pixel that is inside the ROI. /// </remarks> /// <param name="constrainToImage">Whether or not the returned rectangle should also be constrained to the image bounds.</param> public Rectangle GetBoundingBoxRounded(bool constrainToImage) { Rectangle bounds = RectangleUtilities.RoundInflate(BoundingBox); if (constrainToImage) { bounds.Intersect(new Rectangle(0, 0, this.ImageSize.Width - 1, this.ImageSize.Height - 1)); } return bounds; }
public void NoIntersection4() { RectangleF rect1 = new RectangleF(0, 0, -10, 10); RectangleF rect2 = new RectangleF(11, 0, -10, 10); Assert.IsFalse(RectangleUtilities.DoesIntersect(rect1, rect2)); rect2 = new RectangleF(0, 0, -10, 10); rect1 = new RectangleF(11, 0, -10, 10); Assert.IsFalse(RectangleUtilities.DoesIntersect(rect1, rect2)); }
public void Touching() { RectangleF rect1 = new RectangleF(0, 0, 10, 10); RectangleF rect2 = new RectangleF(10, 0, 10, 10); Assert.IsFalse(RectangleUtilities.DoesIntersect(rect1, rect2)); rect2 = new RectangleF(0, 0, 10, 10); rect1 = new RectangleF(10, 0, 10, 10); Assert.IsFalse(RectangleUtilities.DoesIntersect(rect1, rect2)); }
private static IGraphic CreateInteractiveEllipse(PointF majorAxisEnd1, PointF majorAxisEnd2, PointF minorAxisEnd1, PointF minorAxisEnd2) { if (IsAxisAligned(majorAxisEnd1, majorAxisEnd2) && IsAxisAligned(minorAxisEnd1, minorAxisEnd2)) { // use a standard ellipse primitive if the axes defines an axis-aligned ellipse var bounds = RectangleUtilities.ConvertToPositiveRectangle(RectangleUtilities.ComputeBoundingRectangle(majorAxisEnd1, majorAxisEnd2, minorAxisEnd1, minorAxisEnd2)); var ellipse = new EllipsePrimitive { TopLeft = bounds.Location, BottomRight = bounds.Location + bounds.Size }; return(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(ellipse)))); } return(new MoveControlGraphic(CreateEllipse(majorAxisEnd1, majorAxisEnd2, minorAxisEnd1, minorAxisEnd2))); }
protected void SerializeDisplayedArea(DisplayedAreaModuleIod displayedAreaModule, DicomPresentationImageCollection <T> images) { displayedAreaModule.InitializeAttributes(); List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem> displayedAreas = new List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem>(); foreach (T image in images) { DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem displayedArea = new DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem(); displayedArea.InitializeAttributes(); displayedArea.ReferencedImageSequence = new[] { CreateImageSopInstanceReference(image.Frame) }; ImageGraphic imageGraphic = ((IImageGraphicProvider)image).ImageGraphic; Size imageSize = new Size(imageGraphic.Columns, imageGraphic.Rows); // compute the visible area of the image as a rectangle oriented positively in screen space RectangleF visibleImageArea = imageGraphic.SpatialTransform.ConvertToSource(image.ClientRectangle); visibleImageArea = RectangleUtilities.ConvertToPositiveRectangle(visibleImageArea); visibleImageArea = RectangleUtilities.RoundInflate(visibleImageArea); visibleImageArea = RectangleUtilities.Intersect(visibleImageArea, new Rectangle(new Point(0, 0), imageSize)); // compute the pixel addresses of the visible area by intersecting area with actual pixel addresses available Rectangle visiblePixels = ConvertToPixelAddressRectangle(Rectangle.Truncate(visibleImageArea)); displayedArea.DisplayedAreaTopLeftHandCorner = visiblePixels.Location; displayedArea.DisplayedAreaBottomRightHandCorner = visiblePixels.Location + visiblePixels.Size; ISpatialTransform spatialTransform = image.SpatialTransform; switch (_displayAreaSerializationOption) { case DisplayAreaSerializationOption.SerializeAsMagnification: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.Magnify; displayedArea.PresentationPixelMagnificationRatio = spatialTransform.Scale; break; case DisplayAreaSerializationOption.SerializeAsTrueSize: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.TrueSize; displayedArea.PresentationPixelSpacing = image.Frame.NormalizedPixelSpacing; break; case DisplayAreaSerializationOption.SerializeAsDisplayedArea: default: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.ScaleToFit; break; } displayedArea.PresentationPixelAspectRatio = PixelAspectRatio.FromString(image.Frame.NormalizedPixelSpacing.GetPixelAspectRatioString()); displayedAreas.Add(displayedArea); } displayedAreaModule.DisplayedAreaSelectionSequence = displayedAreas.ToArray(); }
internal static bool HitTest(PointF point, RectangleF boundingBox, SpatialTransform transform) { GraphicsPath path = new GraphicsPath(); path.AddEllipse(RectangleUtilities.ConvertToPositiveRectangle(boundingBox)); Pen pen = new Pen(Brushes.White, HitTestDistance / transform.CumulativeScale); bool result = path.IsOutlineVisible(point, pen); path.Dispose(); pen.Dispose(); return(result); }
private void CalculateReferenceDisplayValues() { ImageSpatialTransform transform = GetImageTransform(ReferenceImage); Frame frame = GetFrame(ReferenceImage); //calculate the width (in mm) of the portion of the image that is visible on the display, //as well as the display rectangle it occupies. RectangleF sourceRectangle = new RectangleF(0, 0, frame.Columns, frame.Rows); _referenceDisplayRectangle = transform.ConvertToDestination(sourceRectangle); _referenceDisplayRectangle = RectangleUtilities.Intersect(_referenceDisplayRectangle, ReferenceImage.ClientRectangle); _referenceDisplayedWidth = GetDisplayedWidth(ReferenceImage, _referenceDisplayRectangle); }
private bool IsCollided(out Block collidedBlock) { collidedBlock = null; foreach (var block in blocks.ToArray()) { if (RectangleUtilities.GetHitbox(block.Position, block.Size).Intersects(RectangleUtilities.GetHitbox(position, size)) == true) { collidedBlock = block; return(true); } } return(false); }
/// <summary> /// Draws an arc primitive to the specified destination buffer. /// </summary> /// <param name="buffer">The destination buffer.</param> /// <param name="pen">A GDI pen to use for drawing.</param> /// <param name="arc">The arc primitive to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawArcPrimitive(IGdiBuffer buffer, Pen pen, IArcGraphic arc, float dpi = _nominalScreenDpi) { buffer.Graphics.Transform = arc.SpatialTransform.CumulativeTransform; arc.CoordinateSystem = CoordinateSystem.Source; buffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; try { var rectangle = new RectangleF(arc.TopLeft.X, arc.TopLeft.Y, arc.Width, arc.Height); rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle); var dropShadowOffset = GetDropShadowOffset(arc, dpi); // Draw drop shadow pen.Color = Color.Black; pen.Width = CalculateScaledPenWidth(arc, 1, dpi); SetDashStyle(pen, arc); buffer.Graphics.DrawArc( pen, rectangle.Left + dropShadowOffset.Width, rectangle.Top + dropShadowOffset.Height, rectangle.Width, rectangle.Height, arc.StartAngle, arc.SweepAngle); // Draw rectangle pen.Color = arc.Color; buffer.Graphics.DrawArc( pen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, arc.StartAngle, arc.SweepAngle); } finally { buffer.Graphics.SmoothingMode = SmoothingMode.None; arc.ResetCoordinateSystem(); buffer.Graphics.ResetTransform(); } }
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 static SegFrameImageGraphic AddSegFrameImageGraphicToPresentationImage( IPresentationImage presentationImage, Color color, IEnumerable <PointF> vertices) { var image = presentationImage as IImageGraphicProvider; if (image == null) { return(null); } // Get the base image ImageGraphic baseImage = image.ImageGraphic; var segFrameImageGraphic = new SegFrameImageGraphic(baseImage.Rows, baseImage.Columns, color); segFrameImageGraphic.Alpha = Seg.DefaultOpacity; RectangleF boundingBox = RectangleUtilities.ComputeBoundingRectangle(vertices.ToArray()); // Convert vector polygon to raster on a per pixel basis baseImage.PixelData.ForEachPixel( delegate(int i, int x, int y, int pixelIndex) { var point = new PointF(x, y); if (boundingBox.Contains(point)) { if (IsInPolygon(vertices.ToArray(), point)) { segFrameImageGraphic[x, y] = true; } } } ); var overlayGraphicsProvider = presentationImage as IOverlayGraphicsProvider; if (overlayGraphicsProvider != null) { overlayGraphicsProvider.OverlayGraphics.Add(segFrameImageGraphic); } return(segFrameImageGraphic); }
/// <summary> /// Draws a <see cref="ArcPrimitive"/>. /// </summary> protected override void DrawArcPrimitive(IArcGraphic arc) { Surface.FinalBuffer.Graphics.Transform = arc.SpatialTransform.CumulativeTransform; arc.CoordinateSystem = CoordinateSystem.Source; Surface.FinalBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; RectangleF rectangle = new RectangleF(arc.TopLeft.X, arc.TopLeft.Y, arc.Width, arc.Height); rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle); SizeF dropShadowOffset = GetDropShadowOffset(arc, Dpi); // Draw drop shadow _pen.Color = Color.Black; _pen.Width = CalculateScaledPenWidth(arc, 1, Dpi); SetDashStyle(arc); Surface.FinalBuffer.Graphics.DrawArc( _pen, rectangle.Left + dropShadowOffset.Width, rectangle.Top + dropShadowOffset.Height, rectangle.Width, rectangle.Height, arc.StartAngle, arc.SweepAngle); // Draw rectangle _pen.Color = arc.Color; Surface.FinalBuffer.Graphics.DrawArc( _pen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, arc.StartAngle, arc.SweepAngle); arc.ResetCoordinateSystem(); Surface.FinalBuffer.Graphics.ResetTransform(); }
public void ConvertToPositiveRectangleTest() { RectangleF rect = new RectangleF(1, 2, 5, 6); RectangleF posRect = RectangleUtilities.ConvertToPositiveRectangle(rect); Assert.AreEqual(rect, posRect); rect = new RectangleF(1, 2, -5, 6); posRect = RectangleUtilities.ConvertToPositiveRectangle(rect); Assert.AreEqual(new RectangleF(-4, 2, 5, 6), posRect); rect = new RectangleF(1, 2, 5, -6); posRect = RectangleUtilities.ConvertToPositiveRectangle(rect); Assert.AreEqual(new RectangleF(1, -4, 5, 6), posRect); rect = new RectangleF(1, 2, -5, -6); posRect = RectangleUtilities.ConvertToPositiveRectangle(rect); Assert.AreEqual(new RectangleF(-4, -4, 5, 6), posRect); }
/// <summary> /// Calculates the initial callout location only; returns false thereafter. /// </summary> public virtual bool CalculateCalloutLocation(out PointF location, out CoordinateSystem coordinateSystem) { location = PointF.Empty; coordinateSystem = CoordinateSystem.Destination; if (!_initialLocationSet) { _initialLocationSet = true; SizeF offset = new SizeF(0, 55); // Setup the callout AnnotationSubject.CoordinateSystem = CoordinateSystem.Destination; location = RectangleUtilities.ConvertToPositiveRectangle(AnnotationSubject.BoundingBox).Location - offset; AnnotationSubject.ResetCoordinateSystem(); return(true); } return(false); }
/// <summary> /// Draws an ellipse primitive to the specified destination buffer. /// </summary> /// <param name="buffer">The destination buffer.</param> /// <param name="pen">A GDI pen to use for drawing.</param> /// <param name="ellipse">The ellipse primitive to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawEllipsePrimitive(IGdiBuffer buffer, Pen pen, IBoundableGraphic ellipse, float dpi = _nominalScreenDpi) { buffer.Graphics.Transform = ellipse.SpatialTransform.CumulativeTransform; ellipse.CoordinateSystem = CoordinateSystem.Source; buffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; try { var rectangle = new RectangleF(ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.Width, ellipse.Height); rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle); var dropShadowOffset = GetDropShadowOffset(ellipse, dpi); // Draw drop shadow pen.Color = Color.Black; pen.Width = CalculateScaledPenWidth(ellipse, 1, dpi); SetDashStyle(pen, ellipse); buffer.Graphics.DrawEllipse( pen, rectangle.Left + dropShadowOffset.Width, rectangle.Top + dropShadowOffset.Height, rectangle.Width, rectangle.Height); // Draw rectangle pen.Color = ellipse.Color; buffer.Graphics.DrawEllipse( pen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height); } finally { buffer.Graphics.SmoothingMode = SmoothingMode.None; ellipse.ResetCoordinateSystem(); buffer.Graphics.ResetTransform(); } }
private static double CalculateMean ( RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; // Make sure we run the raw pixel through the modality LUT // when doing the calculation. Note that the modality LUT // can be something other than a rescale intercept, so we can't // just run the mean through the LUT. int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; sum += realValue; } }); if (pixelCount == 0) { return(0); } return(sum / pixelCount); }
private static double CalculateStandardDeviation ( double mean, RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; double deviation = realValue - mean; sum += deviation * deviation; } }); if (pixelCount == 0) { return(0); } return(Math.Sqrt(sum / pixelCount)); }
private void InternalDrawEllipsePrimitive(IBoundableGraphic ellipse) { Surface.FinalBuffer.Graphics.Transform = ellipse.SpatialTransform.CumulativeTransform; ellipse.CoordinateSystem = CoordinateSystem.Source; Surface.FinalBuffer.Graphics.SmoothingMode = SmoothingMode.AntiAlias; RectangleF rectangle = new RectangleF(ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.Width, ellipse.Height); rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle); SizeF dropShadowOffset = GetDropShadowOffset(ellipse, Dpi); // Draw drop shadow _pen.Color = Color.Black; _pen.Width = CalculateScaledPenWidth(ellipse, 1, Dpi); SetDashStyle(ellipse); Surface.FinalBuffer.Graphics.DrawEllipse( _pen, rectangle.Left + dropShadowOffset.Width, rectangle.Top + dropShadowOffset.Height, rectangle.Width, rectangle.Height); // Draw rectangle _pen.Color = ellipse.Color; Surface.FinalBuffer.Graphics.DrawEllipse( _pen, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height); ellipse.ResetCoordinateSystem(); Surface.FinalBuffer.Graphics.ResetTransform(); }