/// <summary>
        /// Analyzes the given ROI.
        /// </summary>
        /// <param name="roi">The ROI being analyzed.</param>
        /// <param name="mode">The analysis mode.</param>
        /// <returns>A string containing the analysis results, which can be appended to the analysis
        /// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
        public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
        {
            if (!SupportsRoi(roi))
            {
                return(null);
            }

            IRoiLengthProvider lengthProvider = (IRoiLengthProvider)roi;

            Units oldUnits = lengthProvider.Units;

            lengthProvider.Units = lengthProvider.IsCalibrated ? _units : Units.Pixels;

            IRoiAnalyzerResult result;

            if (!lengthProvider.IsCalibrated || _units == Units.Pixels)
            {
                result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthPixels, lengthProvider.Length,
                                                          String.Format(SR.FormatLengthPixels, lengthProvider.Length));
            }
            else if (_units == Units.Millimeters)
            {
                result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthMm, lengthProvider.Length,
                                                          String.Format(SR.FormatLengthMm, lengthProvider.Length));
            }
            else
            {
                result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthCm, lengthProvider.Length,
                                                          String.Format(SR.FormatLengthCm, lengthProvider.Length));
            }

            lengthProvider.Units = oldUnits;

            return(result);
        }
		/// <summary>
		/// Analyzes the given ROI.
		/// </summary>
		/// <param name="roi">The ROI being analyzed.</param>
		/// <param name="mode">The analysis mode.</param>
		/// <returns>A string containing the analysis results, which can be appended to the analysis
		/// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
		public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
		{
			if (!SupportsRoi(roi))
				return null;

			IRoiLengthProvider lengthProvider = (IRoiLengthProvider) roi;

			Units oldUnits = lengthProvider.Units;
			lengthProvider.Units = lengthProvider.IsCalibrated ? _units : Units.Pixels;

			IRoiAnalyzerResult result;

			if (!lengthProvider.IsCalibrated || _units == Units.Pixels)
			{
				result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthPixels, lengthProvider.Length,
				                                          String.Format(SR.FormatLengthPixels, lengthProvider.Length));
			}
			else if (_units == Units.Millimeters)
			{
				result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthMm, lengthProvider.Length,
				                                          String.Format(SR.FormatLengthMm, lengthProvider.Length));
			}
			else
			{
				result = new SingleValueRoiAnalyzerResult("Length", SR.FormatLengthCm, lengthProvider.Length,
				                                          String.Format(SR.FormatLengthCm, lengthProvider.Length));
			}

			lengthProvider.Units = oldUnits;

			return result;
		}
Exemple #3
0
        /// <summary>
        /// Analyzes the given ROI.
        /// </summary>
        /// <param name="roi">The ROI being analyzed.</param>
        /// <param name="mode">The analysis mode.</param>
        /// <returns>A string containing the analysis results, which can be appended to the analysis
        /// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
        //public string Analyze(Roi roi, RoiAnalysisMode mode)
        //{
        //    if (!SupportsRoi(roi))
        //        return null;

        //    // performance enhancement to restrict excessive computation of polygon area.
        //    if (mode == RoiAnalysisMode.Responsive)
        //    {
        //        if (_units == Units.Pixels)
        //            return String.Format(SR.FormatAreaPixels, SR.StringNoValue);
        //        else if (_units == Units.Millimeters)
        //            return String.Format(SR.FormatAreaSquareMm, SR.StringNoValue);
        //        else
        //            return String.Format(SR.FormatAreaSquareCm, SR.StringNoValue);
        //    }

        //    IRoiAreaProvider areaProvider = (IRoiAreaProvider) roi;

        //    string text;

        //    Units oldUnits = areaProvider.Units;
        //    areaProvider.Units = areaProvider.IsCalibrated ? _units : Units.Pixels;

        //    if (!areaProvider.IsCalibrated || _units == Units.Pixels)
        //        text = String.Format(SR.FormatAreaPixels, areaProvider.Area);
        //    else if (_units == Units.Millimeters)
        //        text = String.Format(SR.FormatAreaSquareMm, areaProvider.Area);
        //    else
        //        text = String.Format(SR.FormatAreaSquareCm, areaProvider.Area);

        //    areaProvider.Units = oldUnits;

        //    return text;
        //}

        /// <summary>
        /// Analyzes the given ROI.
        /// </summary>
        /// <param name="roi">The ROI being analyzed.</param>
        /// <param name="mode">The analysis mode.</param>
        /// <returns>A string containing the analysis results, which can be appended to the analysis
        /// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
        public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
        {
            if (!SupportsRoi(roi))
            {
                return(null);
            }

            // performance enhancement to restrict excessive computation of polygon area.
            if (mode == RoiAnalysisMode.Responsive)
            {
                if (_units == Units.Pixels)
                {
                    return(new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsPixels, SR.StringNoValue)));
                }
                if (_units == Units.Millimeters)
                {
                    return(new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsMm2, SR.StringNoValue)));
                }
                return
                    (new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsCm2, SR.StringNoValue)));
            }

            IRoiAreaProvider areaProvider = (IRoiAreaProvider)roi;


            IRoiAnalyzerResult result;

            Units oldUnits = areaProvider.Units;

            areaProvider.Units = areaProvider.IsCalibrated ? _units : Units.Pixels;

            if (!areaProvider.IsCalibrated || _units == Units.Pixels)
            {
                result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsPixels, areaProvider.Area,
                                                          String.Format(SR.FormatAreaPixels, areaProvider.Area));
            }

            else if (_units == Units.Millimeters)
            {
                result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsMm2, areaProvider.Area,
                                                          String.Format(SR.FormatAreaSquareMm, areaProvider.Area));
            }

            else
            {
                result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsCm2, areaProvider.Area,
                                                          String.Format(SR.FormatAreaSquareCm, areaProvider.Area));
            }


            areaProvider.Units = oldUnits;


            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Analyzes the given ROI.
        /// </summary>
        /// <param name="roi">The ROI being analyzed.</param>
        /// <param name="mode">The analysis mode.</param>
        /// <returns>A string containing the analysis results, which can be appended to the analysis
        /// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
        //public string Analyze(Roi roi, RoiAnalysisMode mode)
        //{
        //    if (!SupportsRoi(roi))
        //        return null;

        //    IRoiStatisticsProvider statisticsProvider = (IRoiStatisticsProvider) roi;

        //    StringBuilder sb = new StringBuilder();

        //    bool isGrayscale = roi.PixelData is GrayscalePixelData;

        //    var meanValue = SR.StringNotApplicable;
        //    var stdDevValue = SR.StringNotApplicable;

        //    if (isGrayscale && roi.ContainsPixelData)
        //    {
        //        if (mode == RoiAnalysisMode.Responsive)
        //        {
        //            meanValue = stdDevValue = SR.StringNoValue;
        //        }
        //        else
        //        {
        //            double mean = statisticsProvider.Mean;
        //            double stdDev = statisticsProvider.StandardDeviation;

        //            var units = roi.ModalityLutUnits.Label;
        //            var displayFormat = @"{0:" + (roi.SubnormalModalityLut ? @"G3" : @"F1") + "}" + (!string.IsNullOrEmpty(units) ? ' ' + units : string.Empty);

        //            meanValue = string.Format(displayFormat, mean);
        //            stdDevValue = string.Format(displayFormat, stdDev);
        //        }
        //    }

        //    sb.AppendFormat(SR.FormatMean, meanValue);
        //    sb.AppendLine();
        //    sb.AppendFormat(SR.FormatStdDev, stdDevValue);
        //    return sb.ToString();
        //}

        public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
        {
            if (!SupportsRoi(roi))
            {
                return(null);
            }

            IRoiStatisticsProvider statisticsProvider = (IRoiStatisticsProvider)roi;

            MultiValueRoiAnalyzerResult result = new MultiValueRoiAnalyzerResult("Statistics")
            {
                ShowHeader = false
            };

            bool isGrayscale = roi.PixelData is GrayscalePixelData;

            var meanValue   = SR.StringNotApplicable;
            var stdDevValue = SR.StringNotApplicable;

            if (isGrayscale && roi.ContainsPixelData)
            {
                if (mode == RoiAnalysisMode.Responsive)
                {
                    meanValue = stdDevValue = SR.StringNoValue;
                    result.Add(new RoiAnalyzerResultNoValue("Mean", String.Format(SR.FormatMean, meanValue)));
                    result.Add(new RoiAnalyzerResultNoValue("StdDev", String.Format(SR.FormatStdDev, stdDevValue)));
                }
                else
                {
                    double mean   = statisticsProvider.Mean;
                    double stdDev = statisticsProvider.StandardDeviation;

                    var units         = roi.ModalityLutUnits.Label;
                    var displayFormat = @"{0:" + (roi.SubnormalModalityLut ? @"G3" : @"F1") + "}" + (!string.IsNullOrEmpty(units) ? ' ' + units : string.Empty);

                    meanValue   = string.Format(displayFormat, mean);
                    stdDevValue = string.Format(displayFormat, stdDev);

                    result.Add(new SingleValueRoiAnalyzerResult("Mean", units, mean,
                                                                String.Format(SR.FormatMean, meanValue)));
                    result.Add(new SingleValueRoiAnalyzerResult("StdDev", units, stdDevValue,
                                                                String.Format(SR.FormatStdDev, stdDevValue)));
                }
            }
            else
            {
                result.Add(new RoiAnalyzerResultNoValue("Mean", String.Format(SR.FormatMean, meanValue)));
                result.Add(new RoiAnalyzerResultNoValue("StdDev", String.Format(SR.FormatStdDev, stdDevValue)));
            }

            return(result);
        }
        private IRoiAnalyzerResult Analyze(ProtractorRoi roi, RoiAnalysisMode mode)
        {
            // Don't show the callout until the second ray is drawn
            if (roi.Points.Count < 3)
            {
                return(new RoiAnalyzerResultNoValue("Protactor", SR.StringNoValue));
            }

            List <PointF> normalizedPoints = NormalizePoints(roi);

            double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

            return(new SingleValueRoiAnalyzerResult("Protactor", SR.FormatAngleDegrees, Math.Abs(angle), String.Format(SR.FormatAngleDegrees, Math.Abs(angle))));
        }
		private IRoiAnalyzerResult Analyze(ProtractorRoi roi, RoiAnalysisMode mode)
		{
			// Don't show the callout until the second ray is drawn
			if (roi.Points.Count < 3)
			{
				return new RoiAnalyzerResultNoValue("Protactor", SR.StringNoValue);
			}

			List<PointF> normalizedPoints = NormalizePoints(roi);

			double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

			return new SingleValueRoiAnalyzerResult("Protactor", SR.FormatAngleDegrees, Math.Abs(angle), String.Format(SR.FormatAngleDegrees, Math.Abs(angle)));
		}
Exemple #7
0
        private IRoiAnalyzerResult Analyze(ProtractorRoiInfo roiInfo, RoiAnalysisMode mode)
        {
            // Don't show the callout until the second ray is drawn
            if (roiInfo.Points.Count < 3)
            {
                //return SR.ToolsMeasurementSetVertex;
                return new RoiAnalyzerResultNoValue("Protactor", SR.ToolsMeasurementSetVertex);
            }

            List<PointF> normalizedPoints = NormalizePoints(roiInfo);

            double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

            //return String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle));
            return new SingleValueRoiAnalyzerResult("Protactor", SR.ToolsMeasurementFormatDegrees, Math.Abs(angle),String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle)));
        }
        private IRoiAnalyzerResult Analyze(ProtractorRoiInfo roiInfo, RoiAnalysisMode mode)
        {
            // Don't show the callout until the second ray is drawn
            if (roiInfo.Points.Count < 3)
            {
                //return SR.ToolsMeasurementSetVertex;
                return(new RoiAnalyzerResultNoValue("Protactor", SR.ToolsMeasurementSetVertex));
            }

            List <PointF> normalizedPoints = NormalizePoints(roiInfo);

            double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

            //return String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle));
            return(new SingleValueRoiAnalyzerResult("Protactor", SR.ToolsMeasurementFormatDegrees, Math.Abs(angle), String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle))));
        }
		/// <summary>
		/// Analyzes the given ROI.
		/// </summary>
		/// <param name="roi">The ROI being analyzed.</param>
		/// <param name="mode">The analysis mode.</param>
		/// <returns>A string containing the analysis results, which can be appended to the analysis
		/// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
		public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
		{
			if (!SupportsRoi(roi))
				return null;

			IRoiStatisticsProvider statisticsProvider = (IRoiStatisticsProvider) roi;

			MultiValueRoiAnalyzerResult result = new MultiValueRoiAnalyzerResult("Statistics") {ShowHeader = false};

			bool isGrayscale = roi.PixelData is GrayscalePixelData;

			var meanValue = SR.StringNotApplicable;
			var stdDevValue = SR.StringNotApplicable;

			if (isGrayscale && roi.ContainsPixelData)
			{
				if (mode == RoiAnalysisMode.Responsive)
				{
					meanValue = stdDevValue = SR.StringNoValue;
					result.Add(new RoiAnalyzerResultNoValue("Mean", String.Format(SR.FormatMean, meanValue)));
					result.Add(new RoiAnalyzerResultNoValue("StdDev", String.Format(SR.FormatStdDev, stdDevValue)));
				}
				else
				{
					double mean = statisticsProvider.Mean;
					double stdDev = statisticsProvider.StandardDeviation;

					var units = roi.ModalityLutUnits.Label;
					var displayFormat = @"{0:" + (roi.SubnormalModalityLut ? @"G3" : @"F1") + "}" + (!string.IsNullOrEmpty(units) ? ' ' + units : string.Empty);

					meanValue = string.Format(displayFormat, mean);
					stdDevValue = string.Format(displayFormat, stdDev);

					result.Add(new SingleValueRoiAnalyzerResult("Mean", units, mean,
					                                            String.Format(SR.FormatMean, meanValue)));
					result.Add(new SingleValueRoiAnalyzerResult("StdDev", units, stdDevValue,
					                                            String.Format(SR.FormatStdDev, stdDevValue)));
				}
			}
			else
			{
				result.Add(new RoiAnalyzerResultNoValue("Mean", String.Format(SR.FormatMean, meanValue)));
				result.Add(new RoiAnalyzerResultNoValue("StdDev", String.Format(SR.FormatStdDev, stdDevValue)));
			}

			return result;
		}
Exemple #10
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();
            var           parent  = 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();
        }
		/// <summary>
		/// Analyzes the given ROI.
		/// </summary>
		/// <param name="roi">The ROI being analyzed.</param>
		/// <param name="mode">The analysis mode.</param>
		/// <returns>A string containing the analysis results, which can be appended to the analysis
		/// callout of the associated <see cref="RoiGraphic"/>, if one exists.</returns>
		public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
		{
			if (!SupportsRoi(roi))
				return null;

			// performance enhancement to restrict excessive computation of polygon area.
			if (mode == RoiAnalysisMode.Responsive)
			{
				if (_units == Units.Pixels)
					return new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsPixels, SR.StringNoValue));
				if (_units == Units.Millimeters)
					return new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsMm2, SR.StringNoValue));
				return
					new RoiAnalyzerResultNoValue("Area", String.Format(SR.LabelUnitsCm2, SR.StringNoValue));
			}

			IRoiAreaProvider areaProvider = (IRoiAreaProvider) roi;

			IRoiAnalyzerResult result;

			Units oldUnits = areaProvider.Units;
			areaProvider.Units = areaProvider.IsCalibrated ? _units : Units.Pixels;

			if (!areaProvider.IsCalibrated || _units == Units.Pixels)
				result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsPixels, areaProvider.Area,
				                                          String.Format(SR.FormatAreaPixels, areaProvider.Area));

			else if (_units == Units.Millimeters)
				result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsMm2, areaProvider.Area,
				                                          String.Format(SR.FormatAreaSquareMm, areaProvider.Area));

			else
				result = new SingleValueRoiAnalyzerResult("Area", SR.LabelUnitsCm2, areaProvider.Area,
				                                          String.Format(SR.FormatAreaSquareCm, areaProvider.Area));

			areaProvider.Units = oldUnits;

			return result;
		}
Exemple #12
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();
		}
Exemple #13
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);
		}
Exemple #14
0
        ////TODO (cr Feb 2010): All the analysis should really be done in the ProtractorRoiInfo.
        //public string Analyze(ProtractorRoiInfo roiInfo, RoiAnalysisMode mode)
        //{
        //    // Don't show the callout until the second ray is drawn
        //    if (roiInfo.Points.Count < 3)
        //        return SR.ToolsMeasurementSetVertex;

        //    List<PointF> normalizedPoints = NormalizePoints(roiInfo);

        //    double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

        //    return String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle));
        //}

        //TODO (cr Feb 2010): All the analysis should really be done in the ProtractorRoiInfo.
        public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
        {
            return Analyze((ProtractorRoiInfo) roi, mode);
        }
        ////TODO (cr Feb 2010): All the analysis should really be done in the ProtractorRoiInfo.
        //public string Analyze(ProtractorRoiInfo roiInfo, RoiAnalysisMode mode)
        //{
        //    // Don't show the callout until the second ray is drawn
        //    if (roiInfo.Points.Count < 3)
        //        return SR.ToolsMeasurementSetVertex;

        //    List<PointF> normalizedPoints = NormalizePoints(roiInfo);

        //    double angle = Vector.SubtendedAngle(normalizedPoints[0], normalizedPoints[1], normalizedPoints[2]);

        //    return String.Format(SR.ToolsMeasurementFormatDegrees, Math.Abs(angle));
        //}

        //TODO (cr Feb 2010): All the analysis should really be done in the ProtractorRoiInfo.
        public IRoiAnalyzerResult Analyze(Roi roi, RoiAnalysisMode mode)
        {
            return(Analyze((ProtractorRoiInfo)roi, mode));
        }
Exemple #16
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)
        {
            var roiGraphic = ParentGraphic;

            this.Update(roiGraphic.GetRoi(), mode);
        }