Example #1
0
        /// <summary>
        /// Convenience method to create a common polygonal, interactive region of interest.
        /// </summary>
        /// <returns>A new interactive region of interest graphic.</returns>
        public static RoiGraphic CreatePolygon()
        {
            RoiGraphic roiGraphic = new RoiGraphic(new PolygonControlGraphic(true, new MoveControlGraphic(new PolylineGraphic(true))));

            roiGraphic.State = roiGraphic.CreateInactiveState();
            return(roiGraphic);
        }
Example #2
0
        /// <summary>
        /// Convenience method to create a common rectangular, interactive region of interest.
        /// </summary>
        /// <returns>A new interactive region of interest graphic.</returns>
        public static RoiGraphic CreateRectangle()
        {
            RoiGraphic roiGraphic = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(new RectanglePrimitive()))));

            roiGraphic.State = roiGraphic.CreateInactiveState();
            return(roiGraphic);
        }
Example #3
0
        /// <summary>
        /// Invokes an interactive edit box on the name of the graphic, allowing the user to assign a name to the <see cref="RoiGraphic"/>.
        /// </summary>
        public void Rename()
        {
            RoiGraphic parent = this.ParentGraphic;

            if (parent == null)
            {
                return;
            }

            this.CoordinateSystem = CoordinateSystem.Destination;
            try
            {
                EditBox editBox = new EditBox(parent.Name ?? string.Empty);
                editBox.Location        = Point.Round(base.TextGraphic.Location);
                editBox.Size            = Size.Round(base.TextGraphic.BoundingBox.Size);
                editBox.FontName        = base.TextGraphic.Font;
                editBox.FontSize        = base.TextGraphic.SizeInPoints;
                editBox.Multiline       = false;
                editBox.ValueAccepted  += OnEditBoxAccepted;
                editBox.ValueCancelled += OnEditBoxCancelled;
                base.ParentPresentationImage.Tile.EditBox = editBox;
            }
            finally
            {
                this.ResetCoordinateSystem();
            }
        }
Example #4
0
        private void ToggleShowAnalysis()
        {
            this.ShowAnalysis = !_showAnalysis;

            RoiGraphic parent = this.ParentGraphic;

            if (parent != null)
            {
                if (_showAnalysis)
                {
                    parent.Refresh();
                }
                else
                {
                    parent.Draw();
                }
            }
        }
Example #5
0
        private void OnEditBoxAccepted(object sender, EventArgs e)
        {
            EditBox editBox = (EditBox)sender;

            editBox.ValueAccepted  -= OnEditBoxAccepted;
            editBox.ValueCancelled -= OnEditBoxCancelled;
            if (base.ParentPresentationImage != null)
            {
                base.ParentPresentationImage.Tile.EditBox = null;
            }

            RoiGraphic parent = base.ParentGraphic as RoiGraphic;

            if (parent != null)
            {
                parent.Name = editBox.Value;
                this.Update();
                this.Draw();
            }
        }
Example #6
0
        /// <summary>
        /// Forces the callout to update, allowing all the analyzers to recompute and update the text content of the callout.
        /// </summary>
        /// <param name="roi">A particular region of interest information object to use when computing statistics.</param>
        /// <param name="mode">A value indicating whether or not the current region of interest is in the state of changing, and therefore whether or not analyzers should skip expensive computations.</param>
        public void Update(Roi roi, RoiAnalysisMode mode)
        {
            if (this.ImageViewer == null)
            {
                return;
            }

            StringBuilder builder = new StringBuilder();
            RoiGraphic    parent  = this.ParentGraphic;

            if (parent != null && !string.IsNullOrEmpty(parent.Name))
            {
                builder.AppendLine(parent.Name);
            }

            if (_showAnalysis && _roiAnalyzers.Count > 0 && roi != null)
            {
                try
                {
                    foreach (IRoiAnalyzer analyzer in _roiAnalyzers)
                    {
                        if (analyzer.SupportsRoi(roi))
                        {
                            var analysis = analyzer.Analyze(roi, mode);
                            if (analysis != null)
                            {
                                builder.AppendLine(analysis.SerializedAsString());
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e);
                    builder.AppendLine(SR.MessageRoiAnalysisError);
                }
            }

            base.Text = builder.ToString().Trim();
        }
        private static List<aim_dotnet.Calculation> CreateCalculations(RoiGraphic roiGraphic, int referencedGeoShapeId)
        {
            var calculations = new List<aim_dotnet.Calculation>();
            List<aim_dotnet.ReferencedGeometricShape> referencedGeometricShapes = null;
            if (referencedGeoShapeId >= 0)
            {
                referencedGeometricShapes = new List<aim_dotnet.ReferencedGeometricShape>();
                referencedGeometricShapes.Add(new aim_dotnet.ReferencedGeometricShape {ReferencedShapeIdentifier = referencedGeoShapeId});
            }

            var roi = roiGraphic.Roi;
            foreach (var analyzer in roiGraphic.Callout.RoiAnalyzers)
            {
                if (analyzer.SupportsRoi(roi))
                {
                    var calculation = new aim_dotnet.Calculation();
                    calculation.UID = DicomUid.GenerateUid().UID;
                    calculation.CalculationResultCollection = new List<aim_dotnet.CalculationResult>();
                    if (analyzer is RoiLengthAnalyzer)
                    {
                        calculation.CodeValue = CodeList.CalculationCodeForLength.CodeValue;
                        calculation.CodeMeaning = CodeList.CalculationCodeForLength.CodeMeaning;
                        calculation.CodingSchemeDesignator = CodeList.CalculationCodeForLength.CodingSchemeDesignator;
                        calculation.CodingSchemeVersion = CodeList.CalculationCodeForLength.CodingSchemeVersion;
                        calculation.Description = "Length";
                        calculation.ReferencedGeometricShapeCollection = referencedGeometricShapes;
                        var roiLengthProvider = (IRoiLengthProvider) roi;

                        var oldUnits = roiLengthProvider.Units;
                        roiLengthProvider.Units = roiLengthProvider.IsCalibrated ? Units.Millimeters : Units.Pixels;
                        calculation.CalculationResultCollection.Add(CreateScalarCalculationResult(roiLengthProvider.Length, UnitsToName(roiLengthProvider.Units), "Value"));
                        roiLengthProvider.Units = oldUnits;

                        calculations.Add(calculation);
                    }
                    else if (analyzer is RoiAreaAnalyzer)
                    {
                        calculation.CodeValue = CodeList.CalculationCodeForArea.CodeValue;
                        calculation.CodeMeaning = CodeList.CalculationCodeForArea.CodeMeaning;
                        calculation.CodingSchemeDesignator = CodeList.CalculationCodeForArea.CodingSchemeDesignator;
                        calculation.CodingSchemeVersion = CodeList.CalculationCodeForArea.CodingSchemeVersion;
                        calculation.Description = "Area";
                        calculation.ReferencedGeometricShapeCollection = referencedGeometricShapes;
                        var roiAreaProvider = (IRoiAreaProvider) roi;

                        var oldUnits = roiAreaProvider.Units;
                        roiAreaProvider.Units = roiAreaProvider.IsCalibrated ? Units.Millimeters : Units.Pixels;
                        calculation.CalculationResultCollection.Add(CreateScalarCalculationResult(roiAreaProvider.Area, UnitsToName(roiAreaProvider.Units), "Value"));
                        roiAreaProvider.Units = oldUnits;

                        calculations.Add(calculation);
                    }
                    else if (analyzer is RoiStatisticsAnalyzer)
                    {
                        if (roi.PixelData is GrayscalePixelData && IsBoundingBoxInImage(roi.BoundingBox, roi.ImageColumns, roi.ImageRows))
                        {
                            var statisticsProvider = (IRoiStatisticsProvider) roi;
                            var mean = statisticsProvider.Mean;
                            var stdDev = statisticsProvider.StandardDeviation;
                            var calcStdDev = new aim_dotnet.Calculation(calculation);

                            calculation.CodeValue = CodeList.CalculationCodeForMean.CodeValue;
                            calculation.CodeMeaning = CodeList.CalculationCodeForMean.CodeMeaning;
                            calculation.CodingSchemeDesignator = CodeList.CalculationCodeForMean.CodingSchemeDesignator;
                            calculation.CodingSchemeVersion = CodeList.CalculationCodeForMean.CodingSchemeVersion;
                            calculation.Description = "Mean";
                            calculation.ReferencedGeometricShapeCollection = referencedGeometricShapes;
                            calculation.CalculationResultCollection.Add(CreateScalarCalculationResult(mean, roi.Modality == "CT" ? "HU" : "1", "Value"));

                            calcStdDev.CodeValue = CodeList.CalculationCodeForStandardDeviation.CodeValue;
                            calcStdDev.CodeMeaning = CodeList.CalculationCodeForStandardDeviation.CodeMeaning;
                            calcStdDev.CodingSchemeDesignator = CodeList.CalculationCodeForStandardDeviation.CodingSchemeDesignator;
                            calcStdDev.CodingSchemeVersion = CodeList.CalculationCodeForStandardDeviation.CodingSchemeVersion;
                            calcStdDev.Description = "Standard Deviation";
                            calcStdDev.ReferencedGeometricShapeCollection = referencedGeometricShapes;
                            calcStdDev.CalculationResultCollection.Add(CreateScalarCalculationResult(stdDev, roi.Modality == "CT" ? "HU" : "1", "Value"));

                            calculations.Add(calculation);
                            calculations.Add(calcStdDev);
                        }
                    }
                    else if (analyzer is ProtractorAngleCalculator)
                    {
                        var protractorRoiInfo = roi as ProtractorRoiInfo;
                        if (protractorRoiInfo != null && protractorRoiInfo.Points.Count >= 3)
                        {
                            var normalizedPoints = NormalizePoints(protractorRoiInfo);
                            var angle = Math.Abs(Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]));

                            calculation.CodeValue = CodeList.CalculationCodeForAngle.CodeValue;
                            calculation.CodeMeaning = CodeList.CalculationCodeForAngle.CodeMeaning;
                            calculation.CodingSchemeDesignator = CodeList.CalculationCodeForAngle.CodingSchemeDesignator;
                            calculation.CodingSchemeVersion = CodeList.CalculationCodeForAngle.CodingSchemeVersion;
                            calculation.Description = "Angle";
                            calculation.ReferencedGeometricShapeCollection = referencedGeometricShapes;
                            calculation.CalculationResultCollection.Add(CreateScalarCalculationResult(angle, "deg", "Value"));

                            calculations.Add(calculation);
                        }
                    }
                }
            }

            return calculations;
        }
        private static aim_dotnet.IGeometricShape Create2DGeoShape(RoiGraphic roiGraphic, string imageUID, int frameNumber)
        {
            Platform.CheckForEmptyString(imageUID, "imageUID");

            aim_dotnet.IGeometricShape geoShape = null;
            var roi = roiGraphic.Roi;
            if (roi is EllipticalRoi)
            {
                var ellipticalRoi = roi as EllipticalRoi;
                Platform.CheckForNullReference(ellipticalRoi, "ellipticalRoi");
                var ellipseShape = new aim_dotnet.Ellipse();
                ellipseShape.EllipseCollection = new List<aim_dotnet.ISpatialCoordinate>();
                ellipseShape.EllipseCollection.Add(
                    Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 0));
                ellipseShape.EllipseCollection.Add(
                    Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Right, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 1));
                ellipseShape.EllipseCollection.Add(
                    Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Top, imageUID, frameNumber, 2));
                ellipseShape.EllipseCollection.Add(
                    Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Bottom, imageUID, frameNumber, 3));

                geoShape = ellipseShape;
            }
            else if (roi is PolygonalRoi)
            {
                var polygonalRoi = roi as PolygonalRoi;
                Platform.CheckForNullReference(polygonalRoi, "polygonalRoi");
                var polylineShape = new aim_dotnet.Polyline();
                polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
                polylineShape.IsIncludeFlag = true;
                for (var i = 0; i < polygonalRoi.Polygon.Vertices.Count; i++)
                {
                    polylineShape.SpatialCoordinateCollection.Add(
                        Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[i].X, polygonalRoi.Polygon.Vertices[i].Y, imageUID, frameNumber, i));
                }
                if (polygonalRoi.Polygon.Vertices.Count > 0 && polygonalRoi.Polygon.Vertices[polygonalRoi.Polygon.Vertices.Count - 1] != polygonalRoi.Polygon.Vertices[0])
                {
                    polylineShape.SpatialCoordinateCollection.Add(
                        Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[0].X, polygonalRoi.Polygon.Vertices[0].Y, imageUID,
                                                  frameNumber, 0));
                }
                geoShape = polylineShape;
            }
            else if (roi is ProtractorRoiInfo)
            {
                var protractorRoi = roi as ProtractorRoiInfo;
                Platform.CheckForNullReference(protractorRoi, "protractorRoi");
                var multipointShape = new aim_dotnet.MultiPoint();
                multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
                multipointShape.IsIncludeFlag = true;
                for (var i = 0; i < protractorRoi.Points.Count; i++)
                {
                    multipointShape.SpatialCoordinateCollection.Add(
                        Create2DSpatialCoordinate(protractorRoi.Points[i].X, protractorRoi.Points[i].Y, imageUID, frameNumber, i));
                }
                geoShape = multipointShape;
            }
            else if (roi is LinearRoi)
            {
                var linearRoi = roi as LinearRoi;
                Platform.CheckForNullReference(linearRoi, "linearRoi");
                var multipointShape = new aim_dotnet.MultiPoint();
                multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
                multipointShape.IsIncludeFlag = true;
                for (var i = 0; i < linearRoi.Points.Count; i++)
                {
                    multipointShape.SpatialCoordinateCollection.Add(
                        Create2DSpatialCoordinate(linearRoi.Points[i].X, linearRoi.Points[i].Y, imageUID, frameNumber, i));
                }
                geoShape = multipointShape;
            }
            else if (roi is RectangularRoi)
            {
                var rectangularRoi = roi as RectangularRoi;
                Platform.CheckForNullReference(rectangularRoi, "rectangularRoi");
                var polylineShape = new aim_dotnet.Polyline();
                polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
                // Top Left
                polylineShape.SpatialCoordinateCollection.Add(
                    Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 0));
                // Top Right
                polylineShape.SpatialCoordinateCollection.Add(
                    Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 1));
                // Buttom Right
                polylineShape.SpatialCoordinateCollection.Add(
                    Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 2));
                // Buttom Left
                polylineShape.SpatialCoordinateCollection.Add(
                    Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 3));

                geoShape = polylineShape;
            }
            else
                Platform.Log(LogLevel.Error, "AIMHelper.CreateGeoShape. Unhandled ROI type: " + roi.GetType().FullName);

            return geoShape;
        }
		private void WatchRoiGraphic(RoiGraphic roiGraphic)
		{
			if (roiGraphic != null)
				roiGraphic.RoiChanged += OnRoiChanged;
		}
Example #10
0
		/// <summary>
		/// Cloning constructor.
		/// </summary>
		/// <param name="source">The source object from which to clone.</param>
		/// <param name="context">The cloning context object.</param>
		protected RoiGraphic(RoiGraphic source, ICloningContext context)
			: base(source, context)
		{
			context.CloneFields(source, this);
		}
Example #11
0
		/// <summary>
		/// Convenience method to create a common rectangular, interactive region of interest.
		/// </summary>
		/// <returns>A new interactive region of interest graphic.</returns>
		public static RoiGraphic CreateRectangle()
		{
			RoiGraphic roiGraphic = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(new RectanglePrimitive()))));
			roiGraphic.State = roiGraphic.CreateInactiveState();
			return roiGraphic;
		}
		private static aim_dotnet.IGeometricShape Create2DGeoShape(RoiGraphic roiGraphic, string imageUID, int frameNumber)
		{
			Platform.CheckForEmptyString(imageUID, "imageUID");

			aim_dotnet.IGeometricShape geoShape = null;
			Roi roi = roiGraphic.Roi;

			//Platform.CheckTrue(graphics.CoordinateSystem == CoordinateSystem.Source, "Source Coordinate System");

			if (roi is EllipticalRoi)
			{
				EllipticalRoi ellipticalRoi = roi as EllipticalRoi;
				Platform.CheckForNullReference(ellipticalRoi, "ellipticalRoi");

				aim_dotnet.Ellipse ellipseShape = new aim_dotnet.Ellipse();
				ellipseShape.EllipseCollection = new List<aim_dotnet.ISpatialCoordinate>();

				// Bounding box coordinates to DICOM ellipse conversion.
				// Since ellipse's bounding box is not rotated, we just need to find major axis
				// and store the center points of bounding box' side as ellipse vertices.

				//    if (ellipseGraphics.Width >= ellipseGraphics.Height)
				{
					// Horizontal major axis points
					ellipseShape.EllipseCollection.Add(
						Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 0));

					ellipseShape.EllipseCollection.Add(
						Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Right, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 1));

					// Vertical minor axis points
					ellipseShape.EllipseCollection.Add(
						Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Top, imageUID, frameNumber, 2));

					ellipseShape.EllipseCollection.Add(
						Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Bottom, imageUID, frameNumber, 3));
				}
				//else
				//{
				//    // Vertical major axis
				//    ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate(
				//                                           ellipseGraphics.Left + ellipseGraphics.Width/2, ellipseGraphics.Top, imageUID, frameNumber, 0));

				//    ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate(
				//                                           ellipseGraphics.Left + ellipseGraphics.Width/2, ellipseGraphics.Bottom, imageUID, frameNumber, 1));

				//    // Horizontal minor axis
				//    ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate(
				//                                           ellipseGraphics.Left, ellipseGraphics.Top + ellipseGraphics.Height/2, imageUID, frameNumber, 2));

				//    ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate(
				//                                           ellipseGraphics.Right, ellipseGraphics.Top + ellipseGraphics.Height/2, imageUID, frameNumber, 3));
				//}

				geoShape = ellipseShape;
			}
			else if (roi is PolygonalRoi)
			{
				PolygonalRoi polygonalRoi = roi as PolygonalRoi;
				Platform.CheckForNullReference(polygonalRoi, "polygonalRoi");
				//if (!polygonalRoi.IsClosed)
				//{
				//    Platform.Log(LogLevel.Error, "Object state error: Given polygon is not closed");
				//    return null;
				//}

				aim_dotnet.Polyline polylineShape = new aim_dotnet.Polyline();
				polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
				polylineShape.IsIncludeFlag = true;
				for (int i = 0; i < polygonalRoi.Polygon.Vertices.Count; i++)
				{
					polylineShape.SpatialCoordinateCollection.Add(
						Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[i].X, polygonalRoi.Polygon.Vertices[i].Y, imageUID, frameNumber, i));
				}
				geoShape = polylineShape;
			}
			else if (roi is ProtractorRoiInfo)
			{
				ProtractorRoiInfo protractorRoi = roi as ProtractorRoiInfo;
				Platform.CheckForNullReference(protractorRoi, "protractorRoi");

				aim_dotnet.MultiPoint multipointShape = new aim_dotnet.MultiPoint();
				multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
				multipointShape.IsIncludeFlag = true;
				for (int i = 0; i < protractorRoi.Points.Count; i++)
				{
					multipointShape.SpatialCoordinateCollection.Add(
						Create2DSpatialCoordinate(protractorRoi.Points[i].X, protractorRoi.Points[i].Y, imageUID, frameNumber, i));
				}
				geoShape = multipointShape;
			}
			else if (roi is LinearRoi)
			{
				LinearRoi linearRoi = roi as LinearRoi;
				Platform.CheckForNullReference(linearRoi, "linearRoi");

				aim_dotnet.MultiPoint multipointShape = new aim_dotnet.MultiPoint();
				multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();
				multipointShape.IsIncludeFlag = true;
				for (int i = 0; i < linearRoi.Points.Count; i++)
				{
					multipointShape.SpatialCoordinateCollection.Add(
						Create2DSpatialCoordinate(linearRoi.Points[i].X, linearRoi.Points[i].Y, imageUID, frameNumber, i));
				}
				geoShape = multipointShape;
			}
				//else if (roi is PolygonalRoi)
				//{
				//    PolygonalRoi polylineGraphics = roi as PolygonalRoi;
				//    Platform.CheckForNullReference(polylineGraphics, "polylineGraphics");

				//    if (polylineGraphics.Polygon.CountVertices > 2 &&
				//        polylineGraphics.Polygon.Vertices[0] == polylineGraphics.Polygon.Vertices[polylineGraphics.Polygon.Vertices.Count - 1])
				//    {
				//        // Closed polyline graphics
				//        Polyline polylineShape = new Polyline();
				//        polylineShape.SpatialCoordinateCollection = new List<ISpatialCoordinate>();
				//        polylineShape.IsIncludeFlag = true;
				//        for (int i = 0; i < polylineGraphics.Polygon.CountVertices - 1; i++) // no need for the end point - we will have implicitly closed Polyline
				//        {
				//            polylineShape.SpatialCoordinateCollection.Add(
				//                Create2DSpatialCoordinate(polylineGraphics.Polygon.Vertices[i].X, polylineGraphics.Polygon.Vertices[i].Y, imageUID, frameNumber, i));
				//        }
				//        geoShape = polylineShape;
				//    }
				//    else
				//    {
				//        MultiPoint multipointShape = new MultiPoint();
				//        multipointShape.SpatialCoordinateCollection = new List<ISpatialCoordinate>();
				//        multipointShape.IsIncludeFlag = true;
				//        for (int i = 0; i < polylineGraphics.Polygon.CountVertices; i++)
				//        {
				//            multipointShape.SpatialCoordinateCollection.Add(
				//                Create2DSpatialCoordinate(polylineGraphics.Polygon.Vertices[i].X, polylineGraphics.Polygon.Vertices[i].Y, imageUID, frameNumber, i));
				//        }
				//        geoShape = multipointShape;
				//    }
				//}
			else if (roi is RectangularRoi)
			{
				RectangularRoi rectangularRoi = roi as RectangularRoi;
				Platform.CheckForNullReference(rectangularRoi, "rectangularRoi");

				aim_dotnet.Polyline polylineShape = new aim_dotnet.Polyline();
				polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>();

				// Top Left
				polylineShape.SpatialCoordinateCollection.Add(
					Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 0));

				// Top Right
				polylineShape.SpatialCoordinateCollection.Add(
					Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 1));

				// Buttom Right
				polylineShape.SpatialCoordinateCollection.Add(
					Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 2));

				// Buttom Left
				polylineShape.SpatialCoordinateCollection.Add(
					Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 3));

				geoShape = polylineShape;
			}
			else
				Console.WriteLine("AIMHelper.CreateGeoShape. Unhandled ROI type: " + roi.GetType().FullName);

			return geoShape;
		}
		// Helper method
		private static RoiGraphic CreateRoiGraphic(IGraphic interactiveGraphic, IAnnotationCalloutLocationStrategy strategy)
		{
			RoiGraphic roiGraphic;
			if (strategy == null)
				roiGraphic = new RoiGraphic(interactiveGraphic);
			else
				roiGraphic = new RoiGraphic(interactiveGraphic, strategy);

			roiGraphic.Name = "ROI"; // string.Empty;
			roiGraphic.State = roiGraphic.CreateInactiveState();

			return roiGraphic;
		}
Example #14
0
        /// <summary>
        /// Forces the callout to update, allowing all the analyzers to recompute and update the text content of the callout immediately.
        /// </summary>
        /// <param name="mode">A value indicating whether or not the current region of interest is in the state of changing, and therefore whether or not analyzers should skip expensive computations.</param>
        public void Update(RoiAnalysisMode mode)
        {
            RoiGraphic roiGraphic = this.ParentGraphic;

            this.Update(roiGraphic.GetRoi(), mode);
        }
Example #15
0
        /// <summary>
        /// Forces the callout to update, allowing all the analyzers to recompute and update the text content of the callout immediately.
        /// </summary>
        public void Update()
        {
            RoiGraphic roiGraphic = this.ParentGraphic;

            this.Update(roiGraphic.GetRoi(), RoiAnalysisMode.Normal);
        }
Example #16
0
 /// <summary>
 /// Cloning constructor.
 /// </summary>
 /// <param name="source">The source object from which to clone.</param>
 /// <param name="context">The cloning context object.</param>
 protected RoiGraphic(RoiGraphic source, ICloningContext context)
     : base(source, context)
 {
     context.CloneFields(source, this);
 }
Example #17
0
        protected RoiGraphic CreateRoiGraphic(bool initiallySelected)
		{
			//When you create a graphic from within a tool (particularly one that needs capture, like a multi-click graphic),
			//see it through to the end of creation.  It's just cleaner, not to mention that if this tool knows how to create it,
			//it should also know how to (and be responsible for) cancelling it and/or deleting it appropriately.
			IGraphic graphic = CreateGraphic();
			IAnnotationCalloutLocationStrategy strategy = CreateCalloutLocationStrategy();

			RoiGraphic roiGraphic;
			if (strategy == null)
				roiGraphic = new RoiGraphic(graphic);
			else
				roiGraphic = new RoiGraphic(graphic, strategy);

			if (Settings.Default.AutoNameMeasurements && !string.IsNullOrEmpty(this.RoiNameFormat))
				roiGraphic.Name = string.Format(this.RoiNameFormat, ++_serialNumber);
			else
				roiGraphic.Name = string.Empty;

			roiGraphic.State = initiallySelected ? roiGraphic.CreateSelectedState() : roiGraphic.CreateInactiveState();

			return roiGraphic;
		}
Example #18
0
		/// <summary>
		/// Convenience method to create a common polygonal, interactive region of interest.
		/// </summary>
		/// <returns>A new interactive region of interest graphic.</returns>
		public static RoiGraphic CreatePolygon()
		{
			RoiGraphic roiGraphic = new RoiGraphic(new PolygonControlGraphic(true, new MoveControlGraphic(new PolylineGraphic(true))));
			roiGraphic.State = roiGraphic.CreateInactiveState();
			return roiGraphic;
		}
Example #19
0
	    protected void AddRoiGraphic(IPresentationImage image, RoiGraphic roiGraphic, IOverlayGraphicsProvider provider)
        {
            _undoableCommand = new DrawableUndoableCommand(image);
            _undoableCommand.Enqueue(new AddGraphicUndoableCommand(roiGraphic, provider.OverlayGraphics));
            _undoableCommand.Name = CreationCommandName;
            _undoableCommand.Execute();

            OnRoiCreation(roiGraphic);
        }
        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;
        }
Example #21
0
		protected virtual void OnRoiCreation(RoiGraphic roiGraphic) {}