public string[] GetStringArray(DicomTag tag, string[] deflt) { DcmElement elem = GetElement(tag); if (elem is DcmMultiStringElement) return (elem as DcmMultiStringElement).GetValues(); if (elem is DcmStringElement) return new string[] { (elem as DcmStringElement).GetValue() }; if (elem != null) throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); return deflt; }
public int GetInt32(DicomTag tag, int deflt) { DcmElement elem = GetElement(tag); if (elem != null && elem.Length > 0) { if (elem.VR == DicomVR.IS) return (elem as DcmIntegerString).GetInt32(); else if (elem.VR == DicomVR.SL) return (elem as DcmSignedLong).GetValue(); else throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); } return deflt; }
public string GetString(DicomTag tag, int index, string deflt) { DcmElement elem = GetElement(tag); if (elem is DcmStringElement) return (elem as DcmStringElement).GetValue(index); if (elem is DcmMultiStringElement) return (elem as DcmMultiStringElement).GetValue(index); if (elem != null) throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); return deflt; }
public float GetFloat(DicomTag tag, float deflt) { DcmElement elem = GetElement(tag); if (elem != null && elem.Length > 0) { if (elem.VR == DicomVR.FL) return (elem as DcmFloatingPointSingle).GetValue(); else if (elem.VR == DicomVR.DS) return (elem as DcmDecimalString).GetFloat(); else throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); } return deflt; }
public DateTime GetDateTime(DicomTag tag, int index, DateTime deflt) { DcmElement elem = GetElement(tag); if (elem is DcmDate || elem is DcmTime || elem is DcmDateTime) { try { if (elem is DcmDate) return (elem as DcmDate).GetDateTime(index); if (elem is DcmTime) return (elem as DcmTime).GetDateTime(index); if (elem is DcmDateTime) return (elem as DcmDateTime).GetDateTime(index); } catch { return deflt; } } if (elem != null) throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); return deflt; }
public void SetStringArray(DicomTag tag, string[] values) { DcmElement elem = GetElement(tag); if (elem is DcmMultiStringElement) { (elem as DcmMultiStringElement).SetValues(values); return; } if (elem != null) throw new DicomDataException("Tried to access element " + tag.ToString() + " with incorrect VR"); throw new DicomDataException("Element " + tag.ToString() + " does not exist in Dataset"); }
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; }
public void ToString() { var t = new DicomTag(0x0028, 0x9145); Assert.AreEqual("(0028,9145)", t.ToString()); }