ClearCanvas.ImageViewer.RoiGraphics.Roi.ConvertFromSquarePixels C# (CSharp) Method

ConvertFromSquarePixels() protected static method

Converts an area in pixels into the given units given some particular pixel spacing.
Thrown if is a physical unit of measurement and is not calibrated.
protected static ConvertFromSquarePixels ( double area, ClearCanvas.Dicom.Iod.Units units, PixelSpacing pixelSpacing ) : double
area double The area of pixels to be converted.
units ClearCanvas.Dicom.Iod.Units The units into which the area should be converted.
pixelSpacing PixelSpacing The pixel spacing information available.
return double
		protected static double ConvertFromSquarePixels(double area, Units units, PixelSpacing pixelSpacing)
		{
			if (!ValidateUnits(units, pixelSpacing))
			{
				const string msg = "Pixel spacing must be calibrated in order to compute physical units.";
				throw new ArgumentException(msg, "units");
			}

			double factor;

			switch (units)
			{
				case Units.Pixels:
					factor = 1;
					break;
				case Units.Centimeters:
					factor = pixelSpacing.Column*pixelSpacing.Row/100;
					break;
				case Units.Millimeters:
				default:
					factor = pixelSpacing.Column*pixelSpacing.Row;
					break;
			}

			return area*factor;
		}