Dicom.Data.DcmDataset.GetDouble C# (CSharp) Method

GetDouble() public method

public GetDouble ( Dicom.Data.DicomTag tag, double deflt ) : double
tag Dicom.Data.DicomTag
deflt double
return double
        public double GetDouble(DicomTag tag, double deflt)
        {
            DcmElement elem = GetElement(tag);
            if (elem != null && elem.Length > 0) {
                if (elem.VR == DicomVR.FD)
                    return (elem as DcmFloatingPointDouble).GetValue();
                else if (elem.VR == DicomVR.DS)
                    return (elem as DcmDecimalString).GetDouble();
                else if (elem.VR == DicomVR.OB || elem.VR == DicomVR.UN) {
                    var bytes = elem.ByteBuffer.ToBytes();
                    return BitConverter.ToDouble(bytes, 0);
                } else
                    throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR");
            }
            return deflt;
        }

Usage Example

Example #1
0
		public DcmPixelData(DcmDataset dataset) {
			_transferSyntax = dataset.InternalTransferSyntax;
			_lossy = dataset.GetString(DicomTags.LossyImageCompression, "00") != "00";
			_lossyMethod = dataset.GetString(DicomTags.LossyImageCompressionMethod, String.Empty);
			_lossyRatio = dataset.GetString(DicomTags.LossyImageCompressionRatio, String.Empty);
			_frames = dataset.GetInt32(DicomTags.NumberOfFrames, 1);
			_width = dataset.GetUInt16(DicomTags.Columns, 0);
			_height = dataset.GetUInt16(DicomTags.Rows, 0);
			_bitsStored = dataset.GetUInt16(DicomTags.BitsStored, 0);
			_bitsAllocated = dataset.GetUInt16(DicomTags.BitsAllocated, 0);
			_highBit = dataset.GetUInt16(DicomTags.HighBit, (ushort)(_bitsStored - 1));
			_samplesPerPixel = dataset.GetUInt16(DicomTags.SamplesPerPixel, 0);
			_pixelRepresentation = dataset.GetUInt16(DicomTags.PixelRepresentation, 0);
			_planarConfiguration = dataset.GetUInt16(DicomTags.PlanarConfiguration, 0);
			_photometricInterpretation = dataset.GetString(DicomTags.PhotometricInterpretation, String.Empty);
			_rescaleSlope = dataset.GetDouble(DicomTags.RescaleSlope, 1.0);
			_rescaleIntercept = dataset.GetDouble(DicomTags.RescaleIntercept, 0.0);
			_pixelDataItem = dataset.GetItem(DicomTags.PixelData);

			_hasPixelPadding = dataset.Contains(DicomTags.PixelPaddingValue);
			if (_hasPixelPadding) {
				DcmElement elem = dataset.GetElement(DicomTags.PixelPaddingValue);
				if (elem is DcmUnsignedShort)
					_pixelPaddingValue = (elem as DcmUnsignedShort).GetValue();
				else if (elem is DcmSignedShort) {
					_pixelPaddingValue = (elem as DcmSignedShort).GetValue();
				} else
					_pixelPaddingValue = MinimumDataValue;
			}
		}