Example #1
0
		/// <summary>
		/// Checks whether or not this defined term is the same as <paramref name="other"/>.
		/// </summary>
		public bool Equals(Units other)
		{
			return Code == other.Code;
		}
Example #2
0
File: Roi.cs Project: nhannd/Xian
		/// <summary>
		/// Checks if operations in the given <paramref name="units"/> are possible with the <paramref name="pixelSpacing"/> information available.
		/// </summary>
		/// <returns>True if such operations are valid; False if no such operation is possible.</returns>
		protected static bool ValidateUnits(Units units, PixelSpacing pixelSpacing)
		{
			return (units == Units.Pixels || !pixelSpacing.IsNull);
		}
Example #3
0
File: Roi.cs Project: nhannd/Xian
		/// <summary>
		/// Converts an area in pixels into the given units given some particular pixel spacing.
		/// </summary>
		/// <param name="area">The area of pixels to be converted.</param>
		/// <param name="units">The units into which the area should be converted.</param>
		/// <param name="pixelSpacing">The pixel spacing information available.</param>
		/// <returns>The equivalent area in the units of <paramref name="units"/>.</returns>
		/// <exception cref="ArgumentException">Thrown if <paramref name="units"/> is a physical unit of measurement and <paramref name="pixelSpacing"/> is not calibrated.</exception>
		protected static double ConvertFromSquarePixels(double area, Units units, PixelSpacing pixelSpacing)
		{
			if (!ValidateUnits(units, pixelSpacing))
				throw new ArgumentException("Pixel spacing must be calibrated in order to compute physical units.", "units");

			double factor = 1;

			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;
		}
Example #4
0
		/// <summary>
		/// Helper method to compute the physical distance between two pixels.
		/// </summary>
		/// <param name="point1">The first point.</param>
		/// <param name="point2">The second point.</param>
		/// <param name="normalizedPixelSpacing">The normalized pixel spacing of the image.</param>
		/// <param name="units">The units in which the resultant distance is given, passed by reference. If <paramref name="normalizedPixelSpacing"/> is not calibrated, then the passed variable will change to <see cref="RoiGraphics.Units.Pixels"/>.</param>
		/// <returns>The distance between the two points, in units of <paramref name="units"/>.</returns>
		public static double CalculateLength(
			PointF point1,
			PointF point2,
			PixelSpacing normalizedPixelSpacing,
			ref Units units)
		{
			if (normalizedPixelSpacing.IsNull)
				units = Units.Pixels;

			double widthInPixels = point2.X - point1.X;
			double heightInPixels = point2.Y - point1.Y;

			double length;

			if (units == Units.Pixels)
			{
				length = Math.Sqrt(widthInPixels*widthInPixels + heightInPixels*heightInPixels);
			}
			else
			{
				double widthInMm = widthInPixels*normalizedPixelSpacing.Column;
				double heightInMm = heightInPixels*normalizedPixelSpacing.Row;
				double lengthInMm = Math.Sqrt(widthInMm*widthInMm + heightInMm*heightInMm);

				if (units == Units.Millimeters)
					length = lengthInMm;
				else
					length = lengthInMm/10;
			}

			return length;
		}