Beispiel #1
0
        /// <summary>
        /// Performs a hit test on the <see cref="InvariantEllipsePrimitive"/> at a given point.
        /// </summary>
        /// <param name="point">The mouse position in destination coordinates.</param>
        /// <returns>
        /// <b>True</b> if <paramref name="point"/> "hits" the <see cref="InvariantEllipsePrimitive"/>,
        /// <b>false</b> otherwise.
        /// </returns>
        /// <remarks>
        /// A "hit" is defined as when the mouse position is <see cref="VectorGraphic.HitTestDistance"/>
        /// screen pixels away from any point on the arc.
        /// </remarks>
        public override bool HitTest(Point point)
        {
            this.CoordinateSystem = CoordinateSystem.Source;
            bool result = EllipsePrimitive.HitTest(
                this.SpatialTransform.ConvertToSource(point),
                this.Rectangle,
                this.SpatialTransform);

            this.ResetCoordinateSystem();

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the point where the ellipse intersects the line whose end points
        /// are the center of the ellipse and the specified point.
        /// </summary>
        /// <param name="point">A point in either source or destination coordinates.</param>
        /// <returns>The point on the graphic closest to the given <paramref name="point"/>.</returns>
        /// <remarks>
        /// <para>
        /// Depending on the value of <see cref="Graphic.CoordinateSystem"/>,
        /// the computation will be carried out in either source
        /// or destination coordinates.</para>
        /// </remarks>
        public override PointF GetClosestPoint(PointF point)
        {
            // Semi major/minor axes
            float a = this.Width / 2;
            float b = this.Height / 2;

            // Center of ellipse
            RectangleF rect = this.Rectangle;
            float      x1   = rect.Left + a;
            float      y1   = rect.Top + b;

            PointF center = new PointF(x1, y1);

            return(EllipsePrimitive.IntersectEllipseAndLine(a, b, center, point));
        }
        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;
        }
Beispiel #4
0
		/// <summary>
		/// Draws a <see cref="EllipsePrimitive"/>.  Must be overridden and implemented.
		/// </summary>
		protected abstract void DrawEllipsePrimitive(EllipsePrimitive ellipse);
Beispiel #5
0
		/// <summary>
		/// Draws a <see cref="EllipsePrimitive"/>.
		/// </summary>
		protected override void DrawEllipsePrimitive(EllipsePrimitive ellipse)
		{
			InternalDrawEllipsePrimitive(ellipse);
		}
Beispiel #6
0
		/// <summary>
		/// Draws a <see cref="EllipsePrimitive"/>.
		/// </summary>
		protected override void DrawEllipsePrimitive(EllipsePrimitive ellipse)
		{
			DrawEllipsePrimitive(Surface.FinalBuffer, _pen, ellipse, Dpi);
		}
Beispiel #7
0
        internal static PointF GetClosestPoint(
            PointF point,
            RectangleF boundingBox,
            float startAngle,
            float sweepAngle)
        {
            // Semi major/minor axes
            float a = boundingBox.Width / 2;
            float b = boundingBox.Height / 2;

            // Center of ellipse
            float x1 = boundingBox.Left + a;
            float y1 = boundingBox.Top + b;

            // normalize the angles
            float normalizedSweepAngle = Math.Sign(sweepAngle) * Math.Min(360, Math.Abs(sweepAngle));

            float normalizedStartAngle = startAngle % 360;

            if (normalizedStartAngle < 0)
            {
                normalizedStartAngle += 360;
            }

            float normalizedEndAngle = (normalizedStartAngle + normalizedSweepAngle);

            if (normalizedSweepAngle < 0)
            {
                //swap start and end angles
                float t = normalizedStartAngle;
                normalizedStartAngle = normalizedEndAngle;
                normalizedEndAngle   = t;

                //the sweep angle is now positive
                normalizedSweepAngle *= -1;
            }

            // find the closest endpoint
            const double degreesToRadians = Math.PI / 180;

            PointF center = new PointF(x1, y1);
            double normalizedStartAngleRadians = normalizedStartAngle * degreesToRadians;
            double normalizedEndAngleRadians   = normalizedEndAngle * degreesToRadians;
            PointF start = new PointF(center.X + a * (float)Math.Cos(normalizedStartAngleRadians), center.Y + b * (float)Math.Sin(normalizedStartAngleRadians));
            PointF end   = new PointF(center.X + a * (float)Math.Cos(normalizedEndAngleRadians), center.Y + b * (float)Math.Sin(normalizedEndAngleRadians));

            float distanceToStartX = start.X - point.X;
            float distanceToStartY = start.Y - point.Y;
            float distanceToEndX   = end.X - point.X;
            float distanceToEndY   = end.Y - point.Y;

            float squareDistanceToStart = distanceToStartX * distanceToStartX + distanceToStartY * distanceToStartY;
            float squareDistanceToEnd   = distanceToEndX * distanceToEndX + distanceToEndY * distanceToEndY;

            PointF closestPoint      = (squareDistanceToStart < squareDistanceToEnd) ? start : end;
            float  minSquareDistance = Math.Min(squareDistanceToStart, squareDistanceToEnd);

            // find the intersection along the ray eminating from center towards point, and calculate its angle from the x-axis
            PointF result = EllipsePrimitive.IntersectEllipseAndLine(a, b, center, point);

            //Check if the angle between 'start' and 'result' is positive and less than 'sweep'.
            double angleStartToPoint = Vector.SubtendedAngle(result, center, start);

            if (angleStartToPoint < normalizedSweepAngle && angleStartToPoint > 0)
            {
                float distanceToResultX      = result.X - point.X;
                float distanceToResultY      = result.Y - point.Y;
                float squareDistanceToResult = distanceToResultX * distanceToResultX + distanceToResultY * distanceToResultY;
                if (squareDistanceToResult < minSquareDistance)
                {
                    closestPoint = result;
                }
            }

            return(closestPoint);
        }