/// <summary> /// Gets an enumeration of <see cref="VoiWindow"/>s defined in the specified data source. /// </summary> /// <param name="dataset">A DICOM data source.</param> /// <returns>An enumeration of <see cref="VoiWindow"/>s.</returns> public static IEnumerable <VoiWindow> GetWindows(IDicomAttributeProvider dataset) { string windowCenterValues = dataset[DicomTags.WindowCenter].ToString(); if (string.IsNullOrEmpty(windowCenterValues)) { yield break; } string windowWidthValues = dataset[DicomTags.WindowWidth].ToString(); if (string.IsNullOrEmpty(windowWidthValues)) { yield break; } string windowExplanationValues = dataset[DicomTags.WindowCenterWidthExplanation].ToString(); double[] windowCenters; DicomStringHelper.TryGetDoubleArray(windowCenterValues, out windowCenters); double[] windowWidths; DicomStringHelper.TryGetDoubleArray(windowWidthValues, out windowWidths); string[] windowExplanations = DicomStringHelper.GetStringArray(windowExplanationValues); foreach (VoiWindow window in GetWindows(windowCenters, windowWidths, windowExplanations)) { yield return(window); } }
/// <summary> /// Creates an <see cref="ImagePositionPatient"/> object from a dicom multi-valued string. /// </summary> /// <returns> /// Null if there are not exactly 3 parsed values in the input string. /// </returns> public static ImagePositionPatient FromString(string multiValuedString) { double[] values; if (DicomStringHelper.TryGetDoubleArray(multiValuedString, out values) && values.Length == 3) { return(new ImagePositionPatient(values[0], values[1], values[2])); } return(null); }
public static PixelSpacing FromString(string multiValuedString) { double[] values; if (DicomStringHelper.TryGetDoubleArray(multiValuedString, out values) && values.Length == 2) { return(new PixelSpacing(values[0], values[1])); } return(null); }
/// <summary> /// Parses a <see cref="PixelSpacing"/> from a DICOM multi-valued string. /// </summary> /// <param name="multiValuedString">Pixel spacing, defined in row spacing and column spacing, separated by a backslash.</param> /// <returns> /// NULL if there are not exactly 2 parsed values in the input string. /// </returns> public static PixelSpacing FromString(string multiValuedString) { if (string.IsNullOrEmpty(multiValuedString)) { return(null); } double[] values; return(DicomStringHelper.TryGetDoubleArray(multiValuedString, out values) && values.Length == 2 ? new PixelSpacing(values[0], values[1]) : null); }
/// <summary> /// Returns a delegate that will get the value of <paramref name="dicomTag"/> (all positions), /// from an <see cref="ImageSop"/> as an array of <see cref="double"/>s. /// </summary> public static FrameDataRetrieverDelegate<double[]> GetDoubleArrayRetriever(uint dicomTag) { return delegate(Frame frame) { string value; value = frame[dicomTag].ToString(); double[] values; if (!DicomStringHelper.TryGetDoubleArray(value ?? "", out values)) values = new double[] { }; return values; }; }
/// <summary> /// Creates an <see cref="ImageOrientationPatient"/> object from a DICOM multi-valued string. /// </summary> /// <param name="multiValuedString">A DICOM multi-valued string containing the 6 components of the row and column cosine vectors.</param> /// <returns> /// Returns NULL if there are not exactly six parseable values in the input string. /// </returns> public static ImageOrientationPatient FromString(string multiValuedString) { if (string.IsNullOrEmpty(multiValuedString)) { return(null); } double[] values; if (DicomStringHelper.TryGetDoubleArray(multiValuedString, out values) && values.Length == 6) { return(new ImageOrientationPatient(values[0], values[1], values[2], values[3], values[4], values[5])); } return(null); }
/// <summary> /// Parses a <see cref="GradientDirection"/> from a DICOM multi-valued string. /// </summary> /// <param name="multiValuedString">Gradient direction, defined as X Y and Z, separated by a backslash.</param> /// <returns> /// NULL if there are not exactly 2 parsed values in the input string. /// </returns> public static GradientDirection FromString(string multiValuedString) { if (string.IsNullOrEmpty(multiValuedString)) { return(null); } double[] values; if (DicomStringHelper.TryGetDoubleArray(multiValuedString, out values) && values.Length == 3) { new GradientDirection(values[0], values[1], values[2]); } return(null); }
public void TestDoubleArrayConverter() { string input = null; double[] output; DicomStringHelper.TryGetDoubleArray(input, out output); Assert.AreEqual(output.Length, 0); input = ""; DicomStringHelper.TryGetDoubleArray(input, out output); Assert.AreEqual(output.Length, 0); input = @"0\1.2\2.3"; DicomStringHelper.TryGetDoubleArray(input, out output); Assert.AreEqual(output[0], 0); Assert.AreEqual(output[1], 1.2); Assert.AreEqual(output[2], 2.3); }