public void ToStringTest() { var tag = new Tag("00020012"); var asString = tag.ToString(); var expected = string.Format("({0},{1}) : {2}", tag.Group, tag.Element, "ImplementationClassUID"); Assert.AreEqual(expected, tag.ToString()); }
private bool IsProtectedUID(Tag tag) { return tag.CompleteID == TagHelper.TRANSFER_SYNTAX_UID.CompleteID || tag.CompleteID == TagHelper.SOPCLASS_UID.CompleteID || tag.CompleteID == TagHelper.MEDIA_STORAGE_SOPCLASS_UID.CompleteID || tag.CompleteID == TagHelper.IMPLEMENTATION_CLASS_UID.CompleteID || tag.CompleteID == TagHelper.REFERENCED_SOPCLASS_UID.CompleteID; }
public void IsPrivateTest() { var tag = new Tag("00020012"); var isPrivate = tag.IsPrivate(); Assert.IsFalse(isPrivate); var privateTag = new Tag("30091047."); isPrivate = privateTag.IsPrivate(); Assert.IsTrue(isPrivate); }
public static IDICOMElement ToDICOMElement(this XElement xel) { if (xel.Name != "DICOMElement") { throw new ArgumentException("XML element must be of type DICOMElement <DICOMElement ..."); } var attr = xel.Attributes(); if (!attr.Any(a => a.Name == "VR")){ throw new ArgumentException("XML element must have attribute 'VR'."); } var vr = VRDictionary.GetVRFromAbbreviation(attr.First(a => a.Name == "VR").Value); if (!attr.Any(a => a.Name == "Tag")) { throw new ArgumentException("XML element must have attribute 'Tag'."); } var tag = new Tag(attr.First(a => a.Name == "Tag").Value); var data = xel.Elements("Data").Select(d => d.Value).ToArray(); return ElementFactory.GenerateElementFromStringData(tag, vr, data); }
/// <summary> /// This method helps read non-compliant files. Sometimes, an supposed implicit is encoded explicitly. We'll check here /// Returns true if element is actually encoded explicitly (VR is written as starting characters). /// </summary> /// <param name="tag">the read tag</param> /// <param name="dr">the binary reader which is reading the DICOM object</param> /// <param name="vr">the determined VR from the tag</param> /// <returns></returns> private static bool CheckForExplicitness(Tag tag, DICOMBinaryReader dr, ref VR vr) { if (VRReader.PeekVR(dr) != VR.Null) { vr = VRReader.ReadVR(dr); Logging.EvilLogger.Instance.Log($"{tag} was expectd to be implicit LE but is explicit LE. Attempting to read..."); return true; } //Implicilty encoded - All is well return false; }
public VR GetVRFromTag(Tag tag) { if (tag.Element == GROUP_HEADER) { return VR.UnsignedLong; } var found = Tags.FirstOrDefault(t => t.TagID == tag.CompleteID); if (found != null) { return found.VR; } else { return VR.Unknown; } }
public static byte[] WriteLittleEndian(Tag tag) { byte[] tagBytes = ByteHelper.HexStringToByteArray(tag.CompleteID); tagBytes = new byte[] { tagBytes[1], tagBytes[0], tagBytes[3], tagBytes[2] }; return tagBytes; }
public IntegerString(Tag tag, int[] data) : base(tag, data) { VR = VR.IntegerString; }
private IDICOMElement GenerateEmptyDICOMString(Tag tag) { var s = new LongString(); s.Tag = tag; s.Data = string.Empty; return s; }
/// <summary> /// Reads string data and creates the appropriate DICOM element /// </summary> /// <param name="data">the string data as an object (fresh from the DICOM reader)</param> /// <param name="vr">the VR of the element to be generated</param> /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns> private static IDICOMElement ReadString(VR vr, Tag tag, object data) { switch (vr) { case VR.AgeString: return new AgeString(tag, DICOMString.Read(data as byte[])); case VR.ApplicationEntity: return new ApplicationEntity(tag, DICOMString.Read(data as byte[])); case VR.CodeString: return new CodeString(tag, DICOMString.Read(data as byte[])); case VR.Date: return new Date(tag, DICOMString.Read(data as byte[])); case VR.DateTime: return new DateTime(tag, DICOMString.Read(data as byte[])); case VR.DecimalString: return new DecimalString(tag, DICOMString.Read(data as byte[])); case VR.IntegerString: return new IntegerString(tag, DICOMString.Read(data as byte[])); case VR.LongString: return new LongString(tag, DICOMString.Read(data as byte[])); case VR.LongText: return new LongText(tag, DICOMString.Read(data as byte[])); case VR.PersonName: return new PersonName(tag, DICOMString.Read(data as byte[])); case VR.ShortString: return new ShortString(tag, DICOMString.Read(data as byte[])); case VR.ShortText: return new ShortText(tag, DICOMString.Read(data as byte[])); case VR.Time: return new Time(tag, DICOMString.Read(data as byte[])); case VR.UnlimitedText: return new UnlimitedText(tag, DICOMString.Read(data as byte[])); case VR.UniqueIdentifier: return new UniqueIdentifier(tag, DICOMString.Read(data as byte[])); default: return new Unknown(tag, data as byte[]); } }
public static AttributeTag AttributeTag(Tag tag, byte[] data) { Tag aTag = TagReader.ReadBigEndian(data); return new AttributeTag(tag, aTag); }
/// <summary> /// Reads and returns the next DICOM element starting at the current location in the DICOM binary reader after the tag and VR have been read /// </summary> /// <param name="tag">the DICOM tag of the element</param> /// <param name="vr">the read VR of the element</param> /// <param name="dr">the binary reader which is reading the DICOM object</param> /// <returns></returns> private static IDICOMElement ReadElementExplicitLittleEndian(Tag tag, VR vr, DICOMBinaryReader dr) { int length = LengthReader.ReadLittleEndian(vr, dr); byte[] data = DataReader.ReadLittleEndian(length, dr, TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN); return ElementFactory.GenerateElement(tag, vr, data, TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN); }
public SignedLong(Tag tag, int[] data) : base(tag, data) { VR = Enums.VR.SignedLong; }
/// <summary> /// Generates a concrete element class from the VR, tag, data and syntax. Also directs the appropriate data /// interpretation. /// </summary> /// <param name="tag">the tag of the element to be generated</param> /// <param name="vr">the VR of the element to be generated</param> /// <param name="data">the raw data to be procesed (byte array)</param> /// <param name="syntax">the transfer syntax by which to interepret the data</param> /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns> public static IDICOMElement GenerateElement(Tag tag, VR vr, object data, TransferSyntax syntax, StringEncoding enc) { //HANDLE NUMBERS if (syntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN) { switch (vr) { case VR.AttributeTag: return(new AttributeTag(tag, BigEndianReader.ReadTag(data as byte[]))); case VR.FloatingPointDouble: return(new FloatingPointDouble(tag, BigEndianReader.ReadDoublePrecision(data as byte[]))); case VR.FloatingPointSingle: return(new FloatingPointSingle(tag, BigEndianReader.ReadSinglePrecision(data as byte[]))); case VR.SignedLong: return(new SignedLong(tag, BigEndianReader.ReadSignedLong(data as byte[]))); case VR.Signed64BitVeryLong: return(new Signed64bitVeryLong(tag, BigEndianReader.ReadSignedVeryLong(data as byte[]))); case VR.SignedShort: return(new SignedShort(tag, BigEndianReader.ReadSignedShort(data as byte[]))); case VR.UnsignedLong: return(new UnsignedLong(tag, BigEndianReader.ReadUnsignedLong(data as byte[]))); case VR.Unsigned64BitVeryLong: return(new Unsigned64bitVeryLong(tag, BigEndianReader.ReadUnsignedVeryLong(data as byte[]))); case VR.UnsignedShort: return(new UnsignedShort(tag, BigEndianReader.ReadUnsignedShort(data as byte[]))); } } else { switch (vr) { case VR.AttributeTag: return(new AttributeTag(tag, LittleEndianReader.ReadTag(data as byte[]))); case VR.FloatingPointDouble: return(new FloatingPointDouble(tag, LittleEndianReader.ReadDoublePrecision(data as byte[]))); case VR.FloatingPointSingle: return(new FloatingPointSingle(tag, LittleEndianReader.ReadSinglePrecision(data as byte[]))); case VR.SignedLong: return(new SignedLong(tag, LittleEndianReader.ReadSignedLong(data as byte[]))); case VR.Signed64BitVeryLong: return(new Signed64bitVeryLong(tag, LittleEndianReader.ReadSignedVeryLong(data as byte[]))); case VR.SignedShort: return(new SignedShort(tag, LittleEndianReader.ReadSignedShort(data as byte[]))); case VR.UnsignedLong: return(new UnsignedLong(tag, LittleEndianReader.ReadUnsignedLong(data as byte[]))); case VR.Unsigned64BitVeryLong: return(new Unsigned64bitVeryLong(tag, LittleEndianReader.ReadUnsignedVeryLong(data as byte[]))); case VR.UnsignedShort: return(new UnsignedShort(tag, LittleEndianReader.ReadUnsignedShort(data as byte[]))); } } //HANDLE ALL OTHERS switch (vr) { //HANDLE STRINGS case VR.AgeString: case VR.ApplicationEntity: case VR.CodeString: case VR.Date: case VR.DateTime: case VR.DecimalString: case VR.IntegerString: case VR.LongString: case VR.LongText: case VR.PersonName: case VR.ShortString: case VR.ShortText: case VR.Time: case VR.UnlimitedCharacter: case VR.UnlimitedText: case VR.UniversalResourceId: case VR.UniqueIdentifier: return(ReadString(vr, tag, data, enc)); //HANDLE BYTE DATA case VR.Sequence: return(new Sequence { Tag = tag, Items = SequenceReader.ReadItems(data as byte[], syntax, enc) }); case VR.OtherByteString: return(new OtherByteString(tag, data as byte[])); case VR.OtherFloatString: return(new OtherFloatString(tag, data as byte[])); case VR.OtherWordString: return(new OtherWordString(tag, data as byte[])); case VR.OtherDoubleString: return(new OtherDoubleString(tag, data as byte[])); case VR.OtherLongString: return(new OtherLongString(tag, data as byte[])); case VR.Other64BitVeryLongString: return(new Other64BitVeryLong(tag, data as byte[])); default: var unk = new Unknown(tag, data as byte[]); unk.TransferSyntax = syntax; return(unk); } }
/// <summary> /// Reads string data and creates the appropriate DICOM element /// </summary> /// <param name="data">the string data as an object (fresh from the DICOM reader)</param> /// <param name="vr">the VR of the element to be generated</param> /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns> private static IDICOMElement ReadString(VR vr, Tag tag, object data, StringEncoding enc) { switch (vr) { case VR.AgeString: return(new AgeString(tag, DICOMString.Read(data as byte[], enc))); case VR.ApplicationEntity: return(new ApplicationEntity(tag, DICOMString.Read(data as byte[], enc))); case VR.CodeString: return(new CodeString() { Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc) }); case VR.Date: return(new Date(tag, DICOMString.Read(data as byte[], enc))); case VR.DateTime: return(new DateTime(tag, DICOMString.Read(data as byte[], enc))); case VR.DecimalString: return(new DecimalString(tag, DICOMString.Read(data as byte[], enc))); case VR.IntegerString: return(new IntegerString(tag, DICOMString.Read(data as byte[], enc))); case VR.LongString: return(new LongString(tag, DICOMString.Read(data as byte[], enc))); case VR.LongText: return(new LongText() { Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc) }); case VR.PersonName: return(new PersonName() { Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc) }); case VR.ShortString: return(new ShortString() { Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc) }); case VR.ShortText: return(new ShortText(tag, DICOMString.Read(data as byte[], enc))); case VR.Time: return(new Time(tag, DICOMString.Read(data as byte[], enc))); case VR.UnlimitedCharacter: return(new UnlimitedCharacter() { Tag = tag, Data_ = DICOMString.ReadMultiple(data as byte[], enc) }); case VR.UnlimitedText: return(new UnlimitedText(tag, DICOMString.Read(data as byte[], enc))); case VR.UniqueIdentifier: return(new UniqueIdentifier(tag, DICOMString.Read(data as byte[], enc))); case VR.UniversalResourceId: return(new UniversalResourceId(tag, DICOMString.Read(data as byte[], enc))); default: return(new Unknown(tag, data as byte[])); } }
public Other64BitVeryLong(Tag tag, byte[] data) : base(tag, data) { VR = VR.Other64BitVeryLongString; }
public LongText(Tag tag, string data) : base() { Tag = tag; Data = data; VR = Enums.VR.LongText; }
public static byte[] WriteTag(Tag tag) { //TODO modify to make VM > 1 possible return MultiplicityComposer.ComposeMultipleBinary<Tag>(new Tag[]{tag}, WriteTagSingle); }
public UnsignedShort(Tag tag, int data) : base(tag, (ushort)data) { VR = VR.UnsignedShort; }
/// <summary> /// Generates a concrete element class from the VR, tag, data and string data (from XML). /// </summary> /// <param name="tag">the tag of the element to be generated</param> /// <param name="vr">the VR of the element to be generated</param> /// <param name="data">the string data of the element</param> /// <param name="syntax">the transfer syntax by which to interepret the data</param> /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns> public static IDICOMElement GenerateElementFromStringData(Tag tag, VR vr, string[] data) { switch (vr) { case VR.AttributeTag: return new AttributeTag(tag, new Tag(data.First())); case VR.FloatingPointDouble: return new FloatingPointDouble(tag, data.Select(d => double.Parse(d)).ToArray()); case VR.FloatingPointSingle: return new FloatingPointSingle(tag, data.Select(d => float.Parse(d)).ToArray()); case VR.SignedLong: return new SignedLong(tag, data.Select(d => int.Parse(d)).ToArray()); case VR.SignedShort: return new SignedShort(tag, data.Select(d => short.Parse(d)).ToArray()); case VR.UnsignedLong: return new UnsignedLong(tag, data.Select(d => uint.Parse(d)).ToArray()); case VR.UnsignedShort: return new UnsignedShort(tag, data.Select(d => ushort.Parse(d)).ToArray()); //HANDLE STRINGS case VR.AgeString: return new AgeString(tag, data.First()); case VR.ApplicationEntity: return new ApplicationEntity(tag, data.First()); case VR.CodeString: return new CodeString(tag, data.First()); case VR.DecimalString: return new DecimalString(tag, data.Select(d => double.Parse(d)).ToArray()); case VR.IntegerString: return new IntegerString(tag, data.Select(d => int.Parse(d)).ToArray()); case VR.LongString: return new LongString(tag, data.First()); case VR.LongText: return new LongText(tag, data.First()); case VR.PersonName: return new PersonName(tag, data.First()); case VR.ShortString: return new ShortString(tag, data.First()); case VR.ShortText: return new ShortText(tag, data.First()); case VR.UnlimitedText: return new UnlimitedText(tag, data.First()); case VR.UniqueIdentifier: return new UniqueIdentifier(tag, data.First()); //HANDLE DATES case VR.Date: return new Date(tag, StringDataParser.GetNullableDate(data.First())); case VR.DateTime: return new DateTime(tag, StringDataParser.GetNullableDate(data.First())); case VR.Time: return new Time(tag, StringDataParser.GetNullableDate(data.First())); //HANDLE BYTE DATA case VR.Sequence: return new Sequence { Tag = tag, Items = data.Select(d => DICOMObject.FromXML(d)).ToList()}; case VR.OtherByteString: return new OtherByteString(tag, ByteHelper.HexStringToByteArray(data.First())); case VR.OtherFloatString: return new OtherFloatString(tag, ByteHelper.HexStringToByteArray(data.First())); case VR.OtherWordString: return new OtherWordString(tag, ByteHelper.HexStringToByteArray(data.First())); default: return new Unknown(tag, ByteHelper.HexStringToByteArray(data.First())); } }
public UnsignedShort(Tag tag, ushort[] data) : base(tag, data) { VR = VR.UnsignedShort; }
/// <summary> /// Generates a concrete element class from the VR, tag, data and syntax. Also directs the appropriate data /// interpretation. /// </summary> /// <param name="tag">the tag of the element to be generated</param> /// <param name="vr">the VR of the element to be generated</param> /// <param name="data">the raw data to be procesed (byte array)</param> /// <param name="syntax">the transfer syntax by which to interepret the data</param> /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns> public static IDICOMElement GenerateElement(Tag tag, VR vr, object data, TransferSyntax syntax) { //HANDLE NUMBERS if (syntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN) { switch (vr) { case VR.AttributeTag: return new AttributeTag(tag, BigEndianReader.ReadTag(data as byte[])); case VR.FloatingPointDouble: return new FloatingPointDouble(tag, BigEndianReader.ReadDoublePrecision(data as byte[])); case VR.FloatingPointSingle: return new FloatingPointSingle(tag, BigEndianReader.ReadSinglePrecision(data as byte[])); case VR.SignedLong: return new SignedLong(tag, BigEndianReader.ReadSignedLong(data as byte[])); case VR.SignedShort: return new SignedShort(tag, BigEndianReader.ReadSignedShort(data as byte[])); case VR.UnsignedLong: return new UnsignedLong(tag, BigEndianReader.ReadUnsignedLong(data as byte[])); case VR.UnsignedShort: return new UnsignedShort(tag, BigEndianReader.ReadUnsignedShort(data as byte[])); } } else { switch (vr) { case VR.AttributeTag: return new AttributeTag(tag, LittleEndianReader.ReadTag(data as byte[])); case VR.FloatingPointDouble: return new FloatingPointDouble(tag, LittleEndianReader.ReadDoublePrecision(data as byte[])); case VR.FloatingPointSingle: return new FloatingPointSingle(tag, LittleEndianReader.ReadSinglePrecision(data as byte[])); case VR.SignedLong: return new SignedLong(tag, LittleEndianReader.ReadSignedLong(data as byte[])); case VR.SignedShort: return new SignedShort(tag, LittleEndianReader.ReadSignedShort(data as byte[])); case VR.UnsignedLong: return new UnsignedLong(tag, LittleEndianReader.ReadUnsignedLong(data as byte[])); case VR.UnsignedShort: return new UnsignedShort(tag, LittleEndianReader.ReadUnsignedShort(data as byte[])); } } //HANDLE ALL OTHERS switch (vr) { //HANDLE STRINGS case VR.AgeString: case VR.ApplicationEntity: case VR.CodeString: case VR.Date: case VR.DateTime: case VR.DecimalString: case VR.IntegerString: case VR.LongString: case VR.LongText: case VR.PersonName: case VR.ShortString: case VR.ShortText: case VR.Time: case VR.UnlimitedText: case VR.UniqueIdentifier: return ReadString(vr, tag, data); //HANDLE BYTE DATA case VR.Sequence: return new Sequence { Tag = tag, Items = SequenceReader.ReadItems(data as byte[], syntax) }; case VR.OtherByteString: return new OtherByteString(tag, data as byte[]); case VR.OtherFloatString: return new OtherFloatString(tag, data as byte[]); case VR.OtherWordString: return new OtherWordString(tag, data as byte[]); default: var unk = new Unknown(tag, data as byte[]); unk.TransferSyntax = syntax; return unk; } }
public static byte[] WriteTagSingle(Tag tag) { return DICOMTagWriter.WriteLittleEndian(tag); }
private IDICOMElement GenerateZeroDecimalString(Tag tag) { DecimalString ds = new DecimalString(tag, new double[] { 0.0 }); return ds; }
/// <summary> /// 获取String类型的属性值 /// </summary> /// <param name="dcm"></param> /// <param name="tag"></param> /// <returns></returns> public static string GetStringTypeTag(DICOMObject dcm, Tag tag) { string strReturn = string.Empty; try { DICOMData<String> data = dcm.TryGetPublicDataValue<String>(tag, String.Empty); strReturn = data.ToString(); } catch (System.Exception) { } return strReturn; }
public OtherByteString(Tag tag, byte[] data) : base(tag, data) { VR = Enums.VR.OtherByteString; }
public IntegerString(Tag tag, string data) : base(tag, StringDataParser.ParseIntegerString(data)) { VR = VR.IntegerString; }
/// <summary> /// 获取时间类型的属性值 /// </summary> /// <param name="dcm"></param> /// <param name="tag"></param> /// <returns></returns> public static string GetTimeTypeTag(DICOMObject dcm, Tag tag) { string strReturn = string.Empty; try { DICOMData<System.DateTime?> time = dcm.TryGetPublicDataValue<System.DateTime?>(tag, System.DateTime.MinValue); if (null != time && null != time.SingleValue) { strReturn = time.SingleValue.Value.ToString("HHmmss.ffffff"); } } catch (System.Exception) { } return strReturn; }
public AbstractElement(Tag tag, T[] dataArray) { DataContainer = new DICOMData <T>(); this.Tag = tag; this.DataContainer = DICOMData <T> .CreateFromArray(dataArray); }
public static byte[] WriteBigEndian(Tag tag) { return ByteHelper.HexStringToByteArray(tag.CompleteID); }
public AbstractElement(Tag tag, T data) { DataContainer = new DICOMData <T>(); this.Tag = tag; this.DataContainer.SingleValue = data; }
public static void WriteLittleEndian(DICOMBinaryWriter dw, Tag tag) { byte[] tagBytes = WriteLittleEndian(tag); dw.Write(tagBytes); }
/// <summary> /// To string override to visualize tag and vr of element /// </summary> /// <returns></returns> public override string ToString() { return(string.Format("{0}, {1}, {2}", Tag.ToString(), VR.ToString(), string.Join(" | ", DData_.ToArray()))); }