Esempio n. 1
0
        private double GetCurrentLength()
        {
            Units units = Units.Centimeters;

            IPointsGraphic line = LineGraphic;

            line.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                double length = RoiLengthAnalyzer.CalculateLength(line.Points[0], line.Points[1],
                                                                  Frame.NormalizedPixelSpacing, ref units);

                if (units == Units.Centimeters)
                {
                    return(length);
                }
                else
                {
                    return(0.0);
                }
            }
            finally
            {
                line.ResetCoordinateSystem();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs a new polygonal region of interest, specifying an <see cref="IPointsGraphic"/> as the source of the definition and pixel data.
        /// </summary>
        /// <param name="polygon">The polygonal graphic that represents the region of interest.</param>
        public PolygonalRoi(IPointsGraphic polygon)
            : base(polygon.ParentPresentationImage)
        {
            if (polygon.Points.Count < 4 || !polygon.Points.IsClosed)             // a valid points graphic needs 4 endpoints to define 3 sides
            {
                throw new ArgumentException("Supplied graphic must be a valid closed polygon.", "polygon");
            }

            polygon.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                // this list of vertices *has* the repeated start point, so we remove it here
                // the repeated point is an artifact of the polyline graphics system, and should not be replicated in abstract polygon models.
                List <PointF> vertices = new List <PointF>(polygon.Points.Count - 1);
                for (int n = 0; n < polygon.Points.Count - 1; n++)
                {
                    vertices.Add(polygon.Points[n]);
                }
                _polygon = new PolygonF(vertices);
            }
            finally
            {
                polygon.ResetCoordinateSystem();
            }
        }
Esempio n. 3
0
        private static void ApplyCalibration(double lengthInMm, IPointsGraphic line, Frame frame, IDesktopWindow desktopWindow)
        {
            double aspectRatio;

            if (frame.PixelAspectRatio.IsNull)
            {
                // When there is no aspect ratio tag, the image is displayed with the aspect ratio
                // of the pixel spacing, so just keep the aspect ratio the same as
                // what's displayed.  Otherwise, after calibration, a 2cm line drawn horizontally
                // would be visibly different from a 2cm line drawn vertically.
                if (!frame.NormalizedPixelSpacing.IsNull)
                {
                    aspectRatio = frame.NormalizedPixelSpacing.AspectRatio;
                }
                else
                {
                    aspectRatio = 1;
                }
            }
            else
            {
                aspectRatio = frame.PixelAspectRatio.Value;
            }

            line.CoordinateSystem = CoordinateSystem.Source;
            double widthInPixels  = line.Points[1].X - line.Points[0].X;
            double heightInPixels = line.Points[1].Y - line.Points[0].Y;

            line.ResetCoordinateSystem();

            if (widthInPixels == 0 && heightInPixels == 0)
            {
                desktopWindow.ShowMessageBox(SR.ErrorCannotCalibrateZeroLengthRuler, MessageBoxActions.Ok);
                return;
            }

            double pixelSpacingWidth, pixelSpacingHeight;

            CalculatePixelSpacing(
                lengthInMm,
                widthInPixels,
                heightInPixels,
                aspectRatio,
                out pixelSpacingWidth,
                out pixelSpacingHeight);

            frame.NormalizedPixelSpacing.Calibrate(pixelSpacingHeight, pixelSpacingWidth);
            line.ParentPresentationImage.Draw();
        }
Esempio n. 4
0
        /// <summary>
        /// Constructs a new linear region of interest, specifying an <see cref="IPointsGraphic"/> as the source of the definition and pixel data.
        /// </summary>
        /// <param name="polyline">The linear graphic that represents the region of interest.</param>
        public LinearRoi(IPointsGraphic polyline) : base(polyline.ParentPresentationImage)
        {
            polyline.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                List <PointF> points = new List <PointF>();
                foreach (PointF point in polyline.Points)
                {
                    points.Add(point);
                }
                _points = points.AsReadOnly();
            }
            finally
            {
                polyline.ResetCoordinateSystem();
            }

            Platform.CheckTrue(_points.Count >= 2, "At least 2 points must be specified.");
        }
Esempio n. 5
0
		/// <summary>
		/// Constructs a new linear region of interest, specifying an <see cref="IPointsGraphic"/> as the source of the definition and pixel data.
		/// </summary>
		/// <param name="polyline">The linear graphic that represents the region of interest.</param>
		public LinearRoi(IPointsGraphic polyline) : base(polyline.ParentPresentationImage)
		{
			polyline.CoordinateSystem = CoordinateSystem.Source;
			try
			{
				List<PointF> points = new List<PointF>();
				foreach(PointF point in polyline.Points)
				{
					points.Add(point);
				}
				_points = points.AsReadOnly();
			}
			finally
			{
				polyline.ResetCoordinateSystem();
			}

			Platform.CheckTrue(_points.Count >= 2, "At least 2 points must be specified.");
		}
Esempio n. 6
0
        /// <summary>
        /// Called to insert a vertex at the point where the context menu was last invoked.
        /// </summary>
        protected virtual void InsertVertex()
        {
            if (!_canAddRemoveVertices)
            {
                return;
            }

            object memento = this.CreateMemento();

            IPointsGraphic subject = this.Subject;

            subject.CoordinateSystem = CoordinateSystem.Destination;
            try
            {
                int index = this.HitTestControlPoint(Point.Round(_lastContextMenuPoint));

                if (index < 0)
                {
                    // if inserting in middle of line, find which index to insert at
                    index = IndexOfNextClosestPoint(subject, _lastContextMenuPoint);
                }
                else if (index == subject.Points.Count - 1)
                {
                    // if inserting on last point, append instead of inserting before
                    index++;
                }

                if (index >= 0)
                {
                    subject.Points.Insert(index, _lastContextMenuPoint);
                }
            }
            finally
            {
                subject.ResetCoordinateSystem();
            }

            AddToCommandHistory(this, memento, this.CreateMemento());
        }
Esempio n. 7
0
		/// <summary>
		/// Constructs a new polygonal region of interest, specifying an <see cref="IPointsGraphic"/> as the source of the definition and pixel data.
		/// </summary>
		/// <param name="polygon">The polygonal graphic that represents the region of interest.</param>
		public PolygonalRoi(IPointsGraphic polygon)
			: base(polygon.ParentPresentationImage)
		{
			if (polygon.Points.Count < 4 || !polygon.Points.IsClosed) // a valid points graphic needs 4 endpoints to define 3 sides
				throw new ArgumentException("Supplied graphic must be a valid closed polygon.", "polygon");

			polygon.CoordinateSystem = CoordinateSystem.Source;
			try
			{
				// this list of vertices *has* the repeated start point, so we remove it here
				// the repeated point is an artifact of the polyline graphics system, and should not be replicated in abstract polygon models.
				List<PointF> vertices = new List<PointF>(polygon.Points.Count - 1);
				for (int n = 0; n < polygon.Points.Count - 1; n++)
				{
					vertices.Add(polygon.Points[n]);
				}
				_polygon = new PolygonF(vertices);
			}
			finally
			{
				polygon.ResetCoordinateSystem();
			}
		}
Esempio n. 8
0
		private static void ApplyCalibration(double lengthInMm, IPointsGraphic line, Frame frame, IDesktopWindow desktopWindow)
		{
			double aspectRatio;
			
			if (frame.PixelAspectRatio.IsNull)
			{
				// When there is no aspect ratio tag, the image is displayed with the aspect ratio
				// of the pixel spacing, so just keep the aspect ratio the same as
				// what's displayed.  Otherwise, after calibration, a 2cm line drawn horizontally
				// would be visibly different from a 2cm line drawn vertically.
				if (!frame.NormalizedPixelSpacing.IsNull)
					aspectRatio = frame.NormalizedPixelSpacing.AspectRatio;
				else
					aspectRatio = 1;
			}
			else
			{
				aspectRatio = frame.PixelAspectRatio.Value;
			}

			line.CoordinateSystem = CoordinateSystem.Source;
			double widthInPixels = line.Points[1].X - line.Points[0].X;
			double heightInPixels = line.Points[1].Y - line.Points[0].Y;
			line.ResetCoordinateSystem();

			if (widthInPixels == 0 && heightInPixels == 0)
			{
				desktopWindow.ShowMessageBox(SR.ErrorCannotCalibrateZeroLengthRuler, MessageBoxActions.Ok);
				return;
			}

			double pixelSpacingWidth, pixelSpacingHeight;

			CalculatePixelSpacing(
				lengthInMm, 
				widthInPixels, 
				heightInPixels,
				aspectRatio,
				out pixelSpacingWidth,
				out pixelSpacingHeight);

			frame.NormalizedPixelSpacing.Calibrate(pixelSpacingHeight, pixelSpacingWidth);
			line.ParentPresentationImage.Draw();
		}
            public override void OnDrawing()
            {
                base.OnDrawing();

                if (!_isDirty)
                {
                    return;
                }

                IOverlayGraphicsProvider overlayGraphicsProvider = this.ParentPresentationImage as IOverlayGraphicsProvider;

                if (overlayGraphicsProvider == null)
                {
                    return;
                }

                IList <ShowAnglesToolGraphic> freeAngleGraphics = CollectionUtils.Cast <ShowAnglesToolGraphic>(this.Graphics);

                if (this.Visible && _selectedLine != null && _selectedLine.Points.Count == 2)
                {
                    _selectedLine.CoordinateSystem = CoordinateSystem.Source;
                    try
                    {
                        foreach (IGraphic otherLineGraphic in overlayGraphicsProvider.OverlayGraphics)
                        {
                            IPointsGraphic otherLine = GetLine(otherLineGraphic);
                            if (otherLine != null && !ReferenceEquals(otherLine, _selectedLine) && otherLine.Points.Count == 2)
                            {
                                ShowAnglesToolGraphic showAnglesToolGraphic;
                                if (freeAngleGraphics.Count > 0)
                                {
                                    freeAngleGraphics.Remove(showAnglesToolGraphic = freeAngleGraphics[0]);
                                }
                                else
                                {
                                    this.Graphics.Add(showAnglesToolGraphic = new ShowAnglesToolGraphic());
                                }

                                showAnglesToolGraphic.CoordinateSystem = otherLine.CoordinateSystem = CoordinateSystem.Source;
                                try
                                {
                                    showAnglesToolGraphic.SetEndpoints(_selectedLine.Points[0], _selectedLine.Points[1], otherLine.Points[0], otherLine.Points[1]);
                                }
                                finally
                                {
                                    showAnglesToolGraphic.ResetCoordinateSystem();
                                    otherLine.ResetCoordinateSystem();
                                }
                            }
                        }
                    }
                    finally
                    {
                        _selectedLine.ResetCoordinateSystem();
                    }
                }

                foreach (IGraphic freeAngleGraphic in freeAngleGraphics)
                {
                    this.Graphics.Remove(freeAngleGraphic);
                    freeAngleGraphic.Dispose();
                }
            }