public static void Write(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length) { var lengthBytes = BitConverter.GetBytes(length); if (settings.TransferSyntax != TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN) { //Length byte size depends on VR Encoding switch (VRDictionary.GetEncodingFromVR(vr)) { case VREncoding.ExplicitLong: dw.WriteNullBytes(2); lengthBytes = BitConverter.GetBytes(length); break; case VREncoding.ExplicitShort: lengthBytes = BitConverter.GetBytes((ushort) length); break; case VREncoding.Implicit: lengthBytes = BitConverter.GetBytes(length); break; } } if (settings.TransferSyntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN) { Array.Reverse(lengthBytes); } dw.Write(lengthBytes); }
public static void WriteLittleEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, IDICOMElement toWrite) { byte[] data = DataComposer.GetDataLittleEndian(toWrite); LengthWriter.Write(dw, vr, settings, data != null ? data.Length : 0); dw.Write(data != null ? data : new byte[0]); }
/// <summary> /// Creates the DICOM two letter abbreviation from a VR type. /// </summary> /// <param name="vr">the VR type</param> /// <returns>the DICOM two letter abbreviation</returns> public static string GetAbbreviationFromVR(VR vr) { switch (vr) { case VR.CodeString: return "CS"; case VR.ShortString: return "SH"; case VR.LongString: return "LO"; case VR.ShortText: return "ST"; case VR.LongText: return "LT"; case VR.UnlimitedText: return "UT"; case VR.ApplicationEntity: return "AE"; case VR.PersonName: return "PN"; case VR.UniqueIdentifier: return "UI"; case VR.Date: return "DA"; case VR.Time: return "TM"; case VR.DateTime: return "DT"; case VR.AgeString: return "AS"; case VR.IntegerString: return "IS"; case VR.DecimalString: return "DS"; case VR.SignedShort: return "SS"; case VR.UnsignedShort: return "US"; case VR.SignedLong: return "SL"; case VR.UnsignedLong: return "UL"; case VR.AttributeTag: return "AT"; case VR.FloatingPointSingle: return "FL"; case VR.FloatingPointDouble: return "FD"; case VR.OtherByteString: return "OB"; case VR.OtherWordString: return "OW"; case VR.OtherFloatString: return "OF"; case VR.Sequence: return "SQ"; case VR.Unknown: return "UN"; default: return string.Empty; } }
public static void Write(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length) { var lengthBytes = BitConverter.GetBytes(length); if (settings.TransferSyntax != TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN) { //Length byte size depends on VR Encoding switch (VRDictionary.GetEncodingFromVR(vr)) { case VREncoding.ExplicitLong: dw.WriteNullBytes(2); lengthBytes = BitConverter.GetBytes(length); break; case VREncoding.ExplicitShort: lengthBytes = BitConverter.GetBytes((ushort) length); if (length > 65536) { throw new ArgumentOutOfRangeException("Length is greater than allowed for explicit VR syntax. Try using implicit VR"); } break; case VREncoding.Implicit: lengthBytes = BitConverter.GetBytes(length); break; } } if (settings.TransferSyntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN) { Array.Reverse(lengthBytes); } dw.Write(lengthBytes); }
public static void WriteLittleEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length) { byte[] lengthBytes = new byte[0]; if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)) { switch (VRDictionary.GetEncodingFromVR(vr)) { case VREncoding.ExplicitLong: dw.WriteNullBytes(2); lengthBytes = BitConverter.GetBytes(length); break; case VREncoding.ExplicitShort: lengthBytes = BitConverter.GetBytes((short)length); break; case VREncoding.Implicit: lengthBytes = BitConverter.GetBytes(length); break; } } else { lengthBytes =BitConverter.GetBytes(length); } dw.Write(lengthBytes); }
public static byte[] EnforceEvenLength(byte[] data, VR vr) { switch (vr) { case VR.UniqueIdentifier: case VR.OtherByteString: case VR.Unknown: return DataPadder.PadNull(data); 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: return DataPadder.PadSpace(data); default: return data; } }
/// <summary> /// Constructor. /// </summary> /// <param name="tag">The Tag of this instance.</param> /// <param name="vR">The Value Representation(s) of this instance.</param> /// <param name="name">The name of this instance.</param> /// <param name="parent">The parent of this instance.</param> public Attribute(Tag tag, VR valueRepresentations, string name, AttributesAndMacros parent) { this.tag = tag; this.valueRepresentations = valueRepresentations; this.name = name; this.parent = parent; }
/// <summary> /// Constructor. /// </summary> /// <param name="tag">The tag of this instance.</param> /// <param name="vr">The VR of this instance.</param> /// <param name="parent">The parent of this instance.</param> public Attribute(Tag tag, VR vr, AttributeSet parent) { this.tag = tag; this.vr = vr; this.parent = parent; this.parent.Add(this); }
public static void WriteVR(DICOMBinaryWriter dw, DICOMWriteSettings settings, VR vr) { if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)) { string abbreviation = VRDictionary.GetAbbreviationFromVR(vr); dw.Write(abbreviation); } }
/// <summary> /// Reads the length from a series of bytes in a stream. The number of bytes is automatically determined from /// VR. /// </summary> /// <param name="vr">the value representation of the element</param> /// <param name="dr">the binary stream with a current position on the length parameter</param> /// <param name="syntax">the transfer syntax of this element</param> /// <returns></returns> public static int Read(VR vr, DICOMBinaryReader dr, TransferSyntax syntax) { switch (syntax) { case TransferSyntax.EXPLICIT_VR_BIG_ENDIAN: return ReadBigEndian(vr, dr); default: return ReadLittleEndian(vr, dr); } }
/// <summary> /// Class constructor. /// </summary> /// <param name="parentSequenceTag">Parent Sequence Tag</param> /// <param name="tag">Comparison Tag</param> /// <param name="vr">Tag VR</param> /// <param name="commonDataFormat">Data Format for Tag</param> public DicomComparisonTag(DvtkData.Dimse.Tag parentSequenceTag, DvtkData.Dimse.Tag tag, VR vr, BaseCommonDataFormat commonDataFormat) { _parentSequenceTag = parentSequenceTag; _tag = tag; _vr = vr; _commonDataFormat = commonDataFormat; }
/// <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; }
/// <summary> /// Determines the encoding, meaning how many bytes to write the VR and length parameters, from a VR type. /// Options are explicit long (8 bytes), explicit short (4 bytes), or implicit (4 bytes). In Evil DICOM, the null /// VR is used to represent an unknown VR (before dictionary lookup) that is implicitly encoded. /// </summary> /// <param name="vr">the VR type</param> /// <returns>the encoding method for this type</returns> public static VREncoding GetEncodingFromVR(VR vr) { switch (vr) { case VR.OtherByteString: case VR.OtherWordString: case VR.OtherFloatString: case VR.Sequence: case VR.Unknown: return VREncoding.ExplicitLong; case VR.Null: return VREncoding.Implicit; default: return VREncoding.ExplicitShort; } }
/// <summary> /// Reads the length in little endian byte format from a series of bytes in a stream. The number of bytes is /// automatically determined from /// VR. /// </summary> /// <param name="vr">the value representation of the element</param> /// <param name="dr">the binary stream with a current position on the length parameter</param> /// <returns></returns> public static int ReadLittleEndian(VR vr, DICOMBinaryReader dr) { int length = 0; switch (VRDictionary.GetEncodingFromVR(vr)) { case VREncoding.Implicit: byte[] byteLength = dr.ReadBytes(4); length = BitConverter.ToInt32(byteLength, 0); break; case VREncoding.ExplicitLong: byteLength = dr.Skip(2).ReadBytes(4); length = BitConverter.ToInt32(byteLength, 0); break; case VREncoding.ExplicitShort: byteLength = dr.ReadBytes(2); length = BitConverter.ToUInt16(byteLength, 0); break; } return length; }
bool CompareSeqence(VR vr,DicomValueType thisAttribValue,DicomValueType matchAttribValue ) { bool isFound = true; switch (vr) { case VR.AE: { ApplicationEntity thisApplicationEntity = (ApplicationEntity)thisAttribValue; ApplicationEntity matchApplicationEntity = (ApplicationEntity)matchAttribValue; if (thisApplicationEntity.Values.Count != matchApplicationEntity.Values.Count) { isFound = false; } else { for (int i = 0; i < thisApplicationEntity.Values.Count; i++) { if (!WildCardMatchString(matchApplicationEntity.Values[i], thisApplicationEntity.Values[i], IsCaseSensitiveAE)) { isFound = false; break; } } } break; } case VR.AS: { AgeString thisAgeString = (AgeString)thisAttribValue; AgeString matchAgeString = (AgeString)matchAttribValue; if (thisAgeString.Values.Count != matchAgeString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisAgeString.Values.Count; i++) { if (!MatchString(matchAgeString.Values[i], thisAgeString.Values[i])) { isFound = false; break; } } } break; } case VR.AT: { AttributeTag thisAttributeTag = (AttributeTag)thisAttribValue; AttributeTag matchAttributeTag = (AttributeTag)matchAttribValue; if (thisAttributeTag.Values.Count != matchAttributeTag.Values.Count) { isFound = false; } else { for (int i = 0; i < thisAttributeTag.Values.Count; i++) { if (matchAttributeTag.Values[i] != thisAttributeTag.Values[i]) { isFound = false; break; } } } break; } case VR.CS: { CodeString thisCodeString = (CodeString)thisAttribValue; CodeString matchCodeString = (CodeString)matchAttribValue; //if (thisCodeString.Values.Count != matchCodeString.Values.Count) //{ // isFound = false; //} //else //{ // for (int i = 0; i < thisCodeString.Values.Count; i++) // { // if (!WildCardMatchString(matchCodeString.Values[i], thisCodeString.Values[i], IsCaseSensitiveCS)) // { // isFound = false; // break; // } // } //} isFound = false; for (int i = 0; i < thisCodeString.Values.Count; i++) { for (int j = 0; j < matchCodeString.Values.Count; j++) { if (WildCardMatchString(matchCodeString.Values[j], thisCodeString.Values[i], IsCaseSensitiveCS)) { isFound = true; break; } } } break; } case VR.DA: { Date thisDate = (Date)thisAttribValue; Date matchDate = (Date)matchAttribValue; if (thisDate.Values.Count != matchDate.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDate.Values.Count; i++) { System.String thisDateString = thisDate.Values[i].Trim(); System.String matchDateString = matchDate.Values[i].Trim(); switch (matchDateString.Length) { case 9: // ToDate = -YYYYMMDD // FromDate = YYYYMMDD- if (matchDateString.StartsWith("-")) { System.String date = matchDateString.Substring(1, 8); int comparison = thisDateString.CompareTo(date); if (comparison > 0) { isFound = false; } } else if (matchDateString.EndsWith("-")) { System.String date = matchDateString.Substring(0, 8); int comparison = thisDateString.CompareTo(date); if (comparison < 0) { isFound = false; } } break; case 17: // DateRange = YYYYMMDD-YYYYMMDD System.String[] dates = matchDateString.Split('-'); int comparison1 = thisDateString.CompareTo(dates[0]); int comparison2 = thisDateString.CompareTo(dates[1]); if ((comparison1 < 0) || (comparison2 > 0)) { isFound = false; } break; case 8: // Date = YYYYMMDD default: if (!MatchString(matchDateString, thisDateString)) { isFound = false; } break; } if (isFound == false) { break; } } } break; } case VR.DS: { DecimalString thisDecimalString = (DecimalString)thisAttribValue; DecimalString matchDecimalString = (DecimalString)matchAttribValue; if (thisDecimalString.Values.Count != matchDecimalString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDecimalString.Values.Count; i++) { if (!MatchString(matchDecimalString.Values[i], thisDecimalString.Values[i])) { isFound = false; break; } } } break; } case VR.DT: { DvtkData.Dimse.DateTime thisDateTime = (DvtkData.Dimse.DateTime)thisAttribValue; DvtkData.Dimse.DateTime matchDateTime = (DvtkData.Dimse.DateTime)matchAttribValue; if (thisDateTime.Values.Count != matchDateTime.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDateTime.Values.Count; i++) { if (!MatchString(matchDateTime.Values[i], thisDateTime.Values[i])) { isFound = false; break; } } } break; } case VR.FD: { FloatingPointDouble thisFloatingPointDouble = (FloatingPointDouble)thisAttribValue; FloatingPointDouble matchFloatingPointDouble = (FloatingPointDouble)matchAttribValue; if (thisFloatingPointDouble.Values.Count != matchFloatingPointDouble.Values.Count) { isFound = false; } else { for (int i = 0; i < thisFloatingPointDouble.Values.Count; i++) { if (matchFloatingPointDouble.Values[i] != thisFloatingPointDouble.Values[i]) { isFound = false; break; } } } break; } case VR.FL: { FloatingPointSingle thisFloatingPointSingle = (FloatingPointSingle)thisAttribValue; FloatingPointSingle matchFloatingPointSingle = (FloatingPointSingle)matchAttribValue; if (thisFloatingPointSingle.Values.Count != matchFloatingPointSingle.Values.Count) { isFound = false; } else { for (int i = 0; i < thisFloatingPointSingle.Values.Count; i++) { if (matchFloatingPointSingle.Values[i] != thisFloatingPointSingle.Values[i]) { isFound = false; break; } } } break; } case VR.IS: { IntegerString thisIntegerString = (IntegerString)thisAttribValue; IntegerString matchIntegerString = (IntegerString)matchAttribValue; if (thisIntegerString.Values.Count != matchIntegerString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisIntegerString.Values.Count; i++) { if (!MatchString(matchIntegerString.Values[i], thisIntegerString.Values[i])) { isFound = false; break; } } } break; } case VR.LO: { LongString thisLongString = (LongString)thisAttribValue; LongString matchLongString = (LongString)matchAttribValue; if (thisLongString.Values.Count != matchLongString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisLongString.Values.Count; i++) { if (!WildCardMatchString(matchLongString.Values[i], thisLongString.Values[i], IsCaseSensitiveLO)) { isFound = false; break; } } } break; } case VR.LT: { break; } case VR.OB: { break; } case VR.OF: { break; } case VR.OW: { break; } case VR.PN: { PersonName thisPersonName = (PersonName)thisAttribValue; PersonName matchPersonName = (PersonName)matchAttribValue; if (thisPersonName.Values.Count != matchPersonName.Values.Count) { isFound = false; } else { for (int i = 0; i < thisPersonName.Values.Count; i++) { if (!WildCardMatchString(matchPersonName.Values[i], thisPersonName.Values[i], IsCaseSensitivePN)) { isFound = false; break; } } } break; } case VR.SH: { ShortString thisShortString = (ShortString)thisAttribValue; ShortString matchShortString = (ShortString)matchAttribValue; if (thisShortString.Values.Count != matchShortString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisShortString.Values.Count; i++) { if (!WildCardMatchString(matchShortString.Values[i], thisShortString.Values[i], IsCaseSensitiveSH)) { isFound = false; break; } } } break; } case VR.SL: { SignedLong thisSignedLong = (SignedLong)thisAttribValue; SignedLong matchSignedLong = (SignedLong)matchAttribValue; if (thisSignedLong.Values.Count != matchSignedLong.Values.Count) { isFound = false; } else { for (int i = 0; i < thisSignedLong.Values.Count; i++) { if (matchSignedLong.Values[i] != thisSignedLong.Values[i]) { isFound = false; break; } } } break; } case VR.SQ: { // SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue; // foreach (SequenceItem item in sequenceOfItems.Sequence) // { // } break; } case VR.SS: { SignedShort thisSignedShort = (SignedShort)thisAttribValue; SignedShort matchSignedShort = (SignedShort)matchAttribValue; if (thisSignedShort.Values.Count != matchSignedShort.Values.Count) { isFound = false; } else { for (int i = 0; i < thisSignedShort.Values.Count; i++) { if (matchSignedShort.Values[i] != thisSignedShort.Values[i]) { isFound = false; break; } } } break; } case VR.ST: { break; } case VR.TM: { isFound = false; Time thisTime = (Time)thisAttribValue; Time matchTime = (Time)matchAttribValue; for (int i = 0; i < thisTime.Values.Count; i++) { if (TMMatching.Matches(thisTime.Values[i], matchTime.Values[0])) { isFound = true; break; } } break; } case VR.UI: { UniqueIdentifier thisUniqueIdentifier = (UniqueIdentifier)thisAttribValue; UniqueIdentifier matchUniqueIdentifier = (UniqueIdentifier)matchAttribValue; // check for list of UID matching if ((thisUniqueIdentifier.Values.Count == 1) && (matchUniqueIdentifier.Values.Count > 1)) { isFound = false; // iterate over all the possible matches for (int i = 0; i < matchUniqueIdentifier.Values.Count; i++) { if (MatchString(matchUniqueIdentifier.Values[i], thisUniqueIdentifier.Values[0])) { isFound = true; break; } } } else if (thisUniqueIdentifier.Values.Count == matchUniqueIdentifier.Values.Count) { for (int i = 0; i < thisUniqueIdentifier.Values.Count; i++) { if (!MatchString(matchUniqueIdentifier.Values[i], thisUniqueIdentifier.Values[i])) { isFound = false; break; } } } else { isFound = false; } break; } case VR.UL: { UnsignedLong thisUnsignedLong = (UnsignedLong)thisAttribValue; UnsignedLong matchUnsignedLong = (UnsignedLong)matchAttribValue; if (thisUnsignedLong.Values.Count != matchUnsignedLong.Values.Count) { isFound = false; } else { for (int i = 0; i < thisUnsignedLong.Values.Count; i++) { if (matchUnsignedLong.Values[i] != thisUnsignedLong.Values[i]) { isFound = false; break; } } } break; } case VR.UN: { break; } case VR.US: { UnsignedShort thisUnsignedShort = (UnsignedShort)thisAttribValue; UnsignedShort matchUnsignedShort = (UnsignedShort)matchAttribValue; if (thisUnsignedShort.Values.Count != matchUnsignedShort.Values.Count) { isFound = false; } else { for (int i = 0; i < thisUnsignedShort.Values.Count; i++) { if (matchUnsignedShort.Values[i] != thisUnsignedShort.Values[i]) { isFound = false; break; } } } break; } case VR.UT: { break; } default: isFound = false; break; } return isFound; }
/// <summary> /// Checks to see if a certain IDICOMElement is of a given VR type /// </summary> /// <param name="elem">the DICOM element in question</param> /// <param name="vr">the VR type to test the DICOM element</param> /// <returns>a boolean indicating whether or not the DICOM element is of a given VR type</returns> public static bool IsVR(this IDICOMElement elem, VR vr) { switch (vr) { case VR.CodeString: return(elem is CodeString); case VR.ShortString: return(elem is ShortString); case VR.LongString: return(elem is LongString); case VR.ShortText: return(elem is ShortText); case VR.LongText: return(elem is LongText); case VR.UnlimitedText: return(elem is UnlimitedText); case VR.ApplicationEntity: return(elem is ApplicationEntity); case VR.PersonName: return(elem is PersonName); case VR.UniqueIdentifier: return(elem is UniqueIdentifier); case VR.Date: return(elem is Date); case VR.Time: return(elem is Time); case VR.DateTime: return(elem is DateTime); case VR.AgeString: return(elem is AgeString); case VR.IntegerString: return(elem is IntegerString); case VR.DecimalString: return(elem is DecimalString); case VR.SignedShort: return(elem is SignedShort); case VR.UnsignedShort: return(elem is UnsignedShort); case VR.SignedLong: return(elem is SignedLong); case VR.UnsignedLong: return(elem is UnsignedLong); case VR.AttributeTag: return(elem is AttributeTag); case VR.FloatingPointSingle: return(elem is FloatingPointSingle); case VR.FloatingPointDouble: return(elem is FloatingPointDouble); case VR.OtherByteString: return(elem is OtherByteString); case VR.OtherWordString: return(elem is OtherWordString); case VR.OtherFloatString: return(elem is OtherFloatString); case VR.Sequence: return(elem is Sequence); case VR.Unknown: return(elem is Unknown); default: return(elem is AbstractElement <object>); } }
/// <summary> /// Creates the DICOM two letter abbreviation from a VR type. /// </summary> /// <param name="vr">the VR type</param> /// <returns>the DICOM two letter abbreviation</returns> public static string GetAbbreviationFromVR(VR vr) { switch (vr) { case VR.CodeString: return("CS"); case VR.ShortString: return("SH"); case VR.LongString: return("LO"); case VR.ShortText: return("ST"); case VR.LongText: return("LT"); case VR.UnlimitedCharacter: return("UC"); case VR.UniversalResourceId: return("UR"); case VR.UnlimitedText: return("UT"); case VR.ApplicationEntity: return("AE"); case VR.PersonName: return("PN"); case VR.UniqueIdentifier: return("UI"); case VR.Date: return("DA"); case VR.Time: return("TM"); case VR.DateTime: return("DT"); case VR.AgeString: return("AS"); case VR.IntegerString: return("IS"); case VR.DecimalString: return("DS"); case VR.SignedShort: return("SS"); case VR.UnsignedShort: return("US"); case VR.SignedLong: return("SL"); case VR.UnsignedLong: return("UL"); case VR.AttributeTag: return("AT"); case VR.FloatingPointSingle: return("FL"); case VR.FloatingPointDouble: return("FD"); case VR.OtherByteString: return("OB"); case VR.OtherWordString: return("OW"); case VR.OtherFloatString: return("OF"); case VR.OtherDoubleString: return("OD"); case VR.OtherLongString: return("OL"); case VR.Sequence: return("SQ"); case VR.Unknown: return("UN"); default: return(string.Empty); } }
/// <summary> /// Adds an <see cref="Attribute"/> to the <see cref="AttributeSet"/>. /// </summary> /// <param name="groupNumberString">The group number for the newly created <see cref="Attribute"/> in hex string format</param> /// <param name="elementNumberString">The element number for the newly created <see cref="Attribute"/> in hex string format</param> /// <param name="vr">The value representation for the newly created <see cref="Attribute"/></param> /// <param name="list"></param> /// <returns>The position into which the new <see cref="Attribute"/> was inserted.</returns> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> /// <example>This sample shows how to call the AddAttribute method. /// <code> /// AttributeSet attributeSet = new DataSet(); /// Attribute attribute = new Attribute("0x12345678", VR.AE, "String0", "String1", "String2"); /// attributeSet.AddAttribute(attribute); /// </code> /// </example> public int AddAttribute( string groupNumberString, string elementNumberString, VR vr, params object[] list) { GROUP_NUMBER groupNumber = GROUP_NUMBER.Parse(groupNumberString, System.Globalization.NumberStyles.HexNumber); ELEMENT_NUMBER elementNumber = ELEMENT_NUMBER.Parse(elementNumberString, System.Globalization.NumberStyles.HexNumber); return base.Add(new Attribute(groupNumber, elementNumber, vr, list)); }
public DicomTagVr(Tag tag, VR vr) { _tag = tag; _vr = vr; }
/// <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; } }
/// <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 DicomTagVr(Tag tag, VR vr) { _tag = tag; _vr = vr; }
public static byte[] GetStringBytes(VR vr, IDICOMElement el) { string data; byte[] unpadded; switch (vr) { case VR.AgeString: var age = el as AgeString; data = age.DataContainer.SingleValue; unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ApplicationEntity: var ae = el as ApplicationEntity; unpadded = GetASCIIBytes(ae.DataContainer.SingleValue); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.CodeString: var cs = el as CodeString; unpadded = GetASCIIBytes(cs.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.Date: var d = el as Date; data = StringDataComposer.ComposeDate(d.Data); unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.DateTime: var dt = el as DateTime; data = StringDataComposer.ComposeDateTime(dt.DataContainer.SingleValue); unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.DecimalString: var ds = el as DecimalString; data = StringDataComposer.ComposeDecimalString(ds.DataContainer.MultipicityValue.ToArray()); unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.IntegerString: var iSt = el as IntegerString; data = StringDataComposer.ComposeIntegerString(iSt.DataContainer.MultipicityValue.ToArray()); unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.LongString: var ls = el as LongString; unpadded = GetASCIIBytes(ls.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.LongText: var lt = el as LongText; unpadded = GetASCIIBytes(lt.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.PersonName: var pn = el as PersonName; unpadded = GetASCIIBytes(pn.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ShortString: var ss = el as ShortString; unpadded = GetASCIIBytes(ss.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ShortText: var st = el as ShortText; unpadded = GetASCIIBytes(st.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.Time: var t = el as Time; data = StringDataComposer.ComposeTime(t.Data); unpadded = GetASCIIBytes(data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UnlimitedText: var ut = el as UnlimitedText; unpadded = GetASCIIBytes(ut.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UniqueIdentifier: var ui = el as UniqueIdentifier; unpadded = GetASCIIBytes(ui.Data); return(DataRestriction.EnforceEvenLength(unpadded, vr)); default: return(null); } }
public static void WriteBigEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, IDICOMElement toWrite) { byte[] data = DataComposer.GetDataBigEndian(toWrite); LengthWriter.Write(dw, vr, settings, data != null ? data.Length : 0); dw.Write(data != null ? data : new byte[0]); }
public Tag(UInt32 id, VR vr, string description) { ID = id; VR = vr; Description = description; }
public Tag(UInt16 group, UInt16 element, VR vr, string description) : this((UInt32)((group << 16) + element), vr, description) { }
/// <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.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()))); case VR.OtherLongString: return(new OtherLongString(tag, ByteHelper.HexStringToByteArray(data.First()))); case VR.OtherDoubleString: return(new OtherDoubleString(tag, ByteHelper.HexStringToByteArray(data.First()))); default: return(new Unknown(tag, ByteHelper.HexStringToByteArray(data.First()))); } }
public static void WriteBigEndian(DICOMBinaryWriter dw, VR vr, int length) { }
/// <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: return(new Unknown(tag, data as byte[])); } }
/// <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[])); } }
/// <summary> /// Checks to see if a certain IDICOMElement is of a given VR type /// </summary> /// <param name="elem">the DICOM element in question</param> /// <param name="vr">the VR type to test the DICOM element</param> /// <returns>a boolean indicating whether or not the DICOM element is of a given VR type</returns> public static bool IsVR(this IDICOMElement elem, VR vr) { switch (vr) { case VR.CodeString: return elem is CodeString; case VR.ShortString: return elem is ShortString; case VR.LongString: return elem is LongString; case VR.ShortText: return elem is ShortText; case VR.LongText: return elem is LongText; case VR.UnlimitedText: return elem is UnlimitedText; case VR.ApplicationEntity: return elem is ApplicationEntity; case VR.PersonName: return elem is PersonName; case VR.UniqueIdentifier: return elem is UniqueIdentifier; case VR.Date: return elem is Date; case VR.Time: return elem is Time; case VR.DateTime: return elem is DateTime; case VR.AgeString: return elem is AgeString; case VR.IntegerString: return elem is IntegerString; case VR.DecimalString: return elem is DecimalString; case VR.SignedShort: return elem is SignedShort; case VR.UnsignedShort: return elem is UnsignedShort; case VR.SignedLong: return elem is SignedLong; case VR.UnsignedLong: return elem is UnsignedLong; case VR.AttributeTag: return elem is AttributeTag; case VR.FloatingPointSingle: return elem is FloatingPointSingle; case VR.FloatingPointDouble: return elem is FloatingPointDouble; case VR.OtherByteString: return elem is OtherByteString; case VR.OtherWordString: return elem is OtherWordString; case VR.OtherFloatString: return elem is OtherFloatString; case VR.Sequence: return elem is Sequence; case VR.Unknown: return elem is Unknown; default: return elem is AbstractElement<object>; } }
/// <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[]); } }
/// <summary> /// Adds an <see cref="Attribute"/> to the <see cref="AttributeSet"/>. /// </summary> /// <param name="groupElementString">The group element hex number for the newly created <see cref="Attribute"/> in hex string format</param> /// <param name="vr">The value representation for the newly created <see cref="Attribute"/></param> /// <param name="list">The list of values for the newly create <see cref="Attribute"/></param> /// <returns>The position into which the new <see cref="Attribute"/> was inserted.</returns> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> /// <example>This sample shows how to call the AddAttribute method. /// <code> /// AttributeSet attributeSet = new DataSet(); /// attributeSet.AddAttribute("0x12345678", VR.AE, "String0", "String1", "String2"); /// </code> /// </example> public int AddAttribute( string groupElementString, VR vr, params object[] list) { GROUP_ELEMENT groupElement = GROUP_ELEMENT.Parse(groupElementString, System.Globalization.NumberStyles.HexNumber); return base.Add(new Attribute(groupElement, vr, list)); }
public static void WriteBigEndian(DICOMBinaryWriter dw, VR vr, int length) { }
/// <summary> /// Creates an <see cref="Attribute"/> /// </summary> /// <param name="groupNumber">The group number.</param> /// <param name="elementNumber">The element number.</param> /// <param name="vr">The value representation.</param> /// <param name="list">The list of values.</param> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> // resolve call ambiguity by making this call internal internal Attribute( GROUP_NUMBER groupNumber, ELEMENT_NUMBER elementNumber, VR vr, params object[] list) { _InitializeAttribute(groupNumber, elementNumber, vr, list); }
/// <summary> /// Adds an <see cref="Attribute"/> to the <see cref="AttributeSet"/>. /// </summary> /// <param name="groupNumber">The group number for the newly created <see cref="Attribute"/>.</param> /// <param name="elementNumber">The element number for the newly created <see cref="Attribute"/>.</param> /// <param name="vr">The value representation for the newly created <see cref="Attribute"/>.</param> /// <param name="list">The list of values for the newly create <see cref="Attribute"/></param> /// <returns>The position into which the new <see cref="Attribute"/> was inserted.</returns> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> /// <example>This sample shows how to call the AddAttribute method. /// <code> /// AttributeSet attributeSet = new DataSet(); /// Attribute attribute = new Attribute(0x12345678, VR.AE, "String0", "String1", "String2"); /// attributeSet.AddAttribute(attribute); /// </code> /// </example> public int AddAttribute( GROUP_NUMBER groupNumber, ELEMENT_NUMBER elementNumber, VR vr, params object[] list) { return base.Add(new Attribute(groupNumber, elementNumber, vr, list)); }
/// <summary> /// Class constructor. /// </summary> /// <param name="tag">Comparison Tag</param> /// <param name="vr">Tag VR.</param> /// <param name="commonDataFormat">Data Format for Tag</param> public DicomComparisonTag(DvtkData.Dimse.Tag tag, VR vr, BaseCommonDataFormat commonDataFormat) { _tag = tag; _vr = vr; _commonDataFormat = commonDataFormat; }
/// <summary> /// Adds an <see cref="Attribute"/> to the <see cref="AttributeSet"/>. /// </summary> /// <param name="groupElement">The group element hex number for the newly created <see cref="Attribute"/>.</param> /// <param name="vr">The value representation for the newly created <see cref="Attribute"/>.</param> /// <param name="list">The list of values for the newly create <see cref="Attribute"/></param> /// <returns>The position into which the new <see cref="Attribute"/> was inserted.</returns> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> /// <example>This sample shows how to call the AddAttribute method. /// <code> /// AttributeSet attributeSet = new DataSet(); /// attributeSet.AddAttribute(0x12345678, VR.AE, "String0", "String1", "String2"); /// </code> /// </example> public int AddAttribute( GROUP_ELEMENT groupElement, VR vr, params object[] list) { return base.Add(new Attribute(groupElement, vr, list)); }
public static Type GetDataTypeFromVR(VR vr) { switch (vr) { case VR.CodeString: case VR.ShortString: case VR.LongString: case VR.ShortText: case VR.LongText: case VR.UnlimitedCharacter: case VR.UniversalResourceId: case VR.UnlimitedText: case VR.ApplicationEntity: case VR.PersonName: case VR.UniqueIdentifier: case VR.AgeString: return(typeof(string)); case VR.Date: case VR.Time: case VR.DateTime: return(typeof(System.DateTime?)); case VR.IntegerString: return(typeof(int)); case VR.DecimalString: return(typeof(double)); case VR.SignedShort: return(typeof(short)); case VR.UnsignedShort: return(typeof(ushort)); case VR.SignedLong: return(typeof(int)); case VR.UnsignedLong: return(typeof(uint)); case VR.AttributeTag: return(typeof(Tag)); case VR.FloatingPointSingle: return(typeof(float)); case VR.FloatingPointDouble: return(typeof(double)); case VR.OtherByteString: case VR.OtherWordString: case VR.OtherFloatString: case VR.OtherDoubleString: case VR.Other64BitVeryLongString: case VR.OtherLongString: return(typeof(byte)); case VR.Sequence: return(typeof(DICOMObject)); case VR.Signed64BitVeryLong: return(typeof(long)); case VR.Unsigned64BitVeryLong: return(typeof(ulong)); default: return(typeof(object)); } }
/// <summary> /// Creates an <see cref="Attribute"/> /// </summary> /// <param name="groupElement">The group element hex number.</param> /// <param name="vr">The value representation.</param> /// <param name="list">The list of values.</param> /// <exception cref="System.InvalidCastException"> /// The <c>list</c> is an <see cref="object"/> array. /// The items in this <c>list</c> are converted to the underlying <c>vr</c> as much as possible. /// However <see cref="System.InvalidCastException"/> may occur during these run-time conversions. /// </exception> public Attribute( GROUP_ELEMENT groupElement, VR vr, params object[] list) { Tag tag = groupElement; _InitializeAttribute(tag.GroupNumber, tag.ElementNumber, vr, list); }
public static void WriteVR(DICOMBinaryWriter dw, DICOMWriteSettings settings, VR vr) { if (settings.TransferSyntax != TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN) { var abbreviation = VRDictionary.GetAbbreviationFromVR(vr); dw.Write(abbreviation); } }
private void _InitializeAttribute( GROUP_NUMBER groupNumber, ELEMENT_NUMBER elementNumber, VR vr, params object[] list) { this.Tag.GroupNumber = groupNumber; this.Tag.ElementNumber = elementNumber; DicomValueType dicomValue = null; if(list!= null) { switch (vr) { case VR.AE: { System.String[] stringArray = _CastToStringArray(list); ApplicationEntity applicationEntity = new ApplicationEntity(); applicationEntity.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = applicationEntity; // compute attribute value length Length = 0; if (applicationEntity.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in applicationEntity.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)applicationEntity.Values.Count - 1; } break; } case VR.AS: { System.String[] stringArray = _CastToStringArray(list); AgeString ageString = new AgeString(); ageString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = ageString; // compute attribute value length Length = (System.UInt32)ageString.Values.Count * 4; break; } case VR.AT: { Tag[] tagArray = _CastToTagArray(list); AttributeTag attributeTag = new AttributeTag(); attributeTag.Values = new DvtkData.Collections.TagCollection(tagArray); dicomValue = attributeTag; // compute attribute value length Length = (System.UInt32)attributeTag.Values.Count * 4; break; } case VR.CS: { System.String[] stringArray = _CastToStringArray(list); CodeString codeString = new CodeString(); codeString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = codeString; // compute attribute value length Length = 0; if (codeString.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in codeString.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)codeString.Values.Count - 1; } break; } case VR.DA: { System.String[] stringArray = _CastToDateStringArray(list); Date date = new Date(); date.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = date; // compute attribute value length Length = 0; if (date.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in date.Values) { length += (System.UInt32)data.Length; } Length = length; } break; } case VR.DS: { System.String[] stringArray = _CastToStringArray(list); DecimalString decimalString = new DecimalString(); decimalString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = decimalString; // compute attribute value length Length = 0; if (decimalString.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in decimalString.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)decimalString.Values.Count - 1; } break; } case VR.DT: { System.String[] stringArray = _CastToDateTimeStringArray(list); DateTime dateTime = new DateTime(); dateTime.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = dateTime; // compute attribute value length Length = 0; if (dateTime.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in dateTime.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)dateTime.Values.Count - 1; } break; } case VR.FD: { System.Double[] floatingPointDoubleArray = _CastToFloatingPointDoubleArray(list); FloatingPointDouble floatingPointDouble = new FloatingPointDouble(); floatingPointDouble.Values = new DvtkData.Collections.DoubleCollection(floatingPointDoubleArray); dicomValue = floatingPointDouble; // compute attribute value length Length = (System.UInt32)floatingPointDouble.Values.Count * 8; break; } case VR.FL: { System.Single[] floatingPointSingleArray = _CastToFloatingPointSingleArray(list); FloatingPointSingle floatingPointSingle = new FloatingPointSingle(); floatingPointSingle.Values = new DvtkData.Collections.SingleCollection(floatingPointSingleArray); dicomValue = floatingPointSingle; // compute attribute value length Length = (System.UInt32)floatingPointSingle.Values.Count * 4; break; } case VR.IS: { System.String[] stringArray = _CastToStringArray(list); IntegerString integerString = new IntegerString(); integerString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = integerString; // compute attribute value length Length = 0; if (integerString.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in integerString.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)integerString.Values.Count - 1; } break; } case VR.LO: { System.String[] stringArray = _CastToStringArray(list); LongString longString = new LongString(); longString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = longString; // compute attribute value length Length = 0; if (longString.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in longString.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)longString.Values.Count - 1; } break; } case VR.LT: { if (list.Length > 1) throw new System.ArgumentException(); LongText longText = new LongText(); Length = 0; if (list.Length == 1) { System.String stringValue = System.Convert.ToString(list[0]); longText.Value = stringValue; Length = (System.UInt32)stringValue.Length; } dicomValue = longText; break; } case VR.OB: { OtherByteString otherByteString = new OtherByteString(); if (list.Length > 0) { if (list.Length == 1 && list[0] is System.String) { otherByteString.FileName = (System.String)list[0]; Length = (System.UInt32)otherByteString.FileName.Length; } else if (list.Length == 1 && list[0] is BitmapPatternParameters) { otherByteString.BitmapPattern = (BitmapPatternParameters)list[0]; } else if (list.Length > 0 && list.Length <= 7) { BitmapPatternParameters pattern = new BitmapPatternParameters(); try { int listLength = list.Length; if (listLength > 0) { pattern.NumberOfRows = System.Convert.ToUInt16(list[0]); if (listLength == 1) pattern.NumberOfColumns = pattern.NumberOfRows; } if (listLength > 1) pattern.NumberOfColumns = System.Convert.ToUInt16(list[1]); if (listLength > 2) pattern.StartValue = System.Convert.ToInt16(list[2]); if (listLength > 3) pattern.ValueIncrementPerRowBlock = System.Convert.ToInt16(list[3]); if (listLength > 4) pattern.ValueIncrementPerColumnBlock = System.Convert.ToInt16(list[4]); if (listLength > 5) pattern.NumberOfIdenticalValueRows = System.Convert.ToUInt16(list[5]); if (listLength > 6) pattern.NumberOfIdenticalValueColumns = System.Convert.ToUInt16(list[6]); } catch { throw new System.ArgumentException(); } otherByteString.BitmapPattern = pattern; } else throw new System.ArgumentException(); } dicomValue = otherByteString; break; } case VR.OF: { OtherFloatString otherFloatString = new OtherFloatString(); if (list.Length > 0) { if (list.Length == 1 && list[0] is System.String) { otherFloatString.FileName = (System.String)list[0]; Length = (System.UInt32)otherFloatString.FileName.Length; } else if (list.Length == 1 && list[0] is BitmapPatternParameters) { otherFloatString.BitmapPattern = (BitmapPatternParameters)list[0]; } else if (list.Length > 0 && list.Length <= 7) { BitmapPatternParameters pattern = new BitmapPatternParameters(); try { int listLength = list.Length; if (listLength > 0) { pattern.NumberOfRows = System.Convert.ToUInt16(list[0]); if (listLength == 1) pattern.NumberOfColumns = pattern.NumberOfRows; } if (listLength > 1) pattern.NumberOfColumns = System.Convert.ToUInt16(list[1]); if (listLength > 2) pattern.StartValue = System.Convert.ToInt16(list[2]); if (listLength > 3) pattern.ValueIncrementPerRowBlock = System.Convert.ToInt16(list[3]); if (listLength > 4) pattern.ValueIncrementPerColumnBlock = System.Convert.ToInt16(list[4]); if (listLength > 5) pattern.NumberOfIdenticalValueRows = System.Convert.ToUInt16(list[5]); if (listLength > 6) pattern.NumberOfIdenticalValueColumns = System.Convert.ToUInt16(list[6]); } catch { throw new System.ArgumentException(); } otherFloatString.BitmapPattern = pattern; } else throw new System.ArgumentException(); } dicomValue = otherFloatString; break; } case VR.OW: { OtherWordString otherWordString = new OtherWordString(); if (list.Length > 0) { if (list.Length == 1 && list[0] is System.String) { otherWordString.FileName = (System.String)list[0]; Length = (System.UInt32)otherWordString.FileName.Length; } else if (list.Length == 1 && list[0] is BitmapPatternParameters) { otherWordString.BitmapPattern = (BitmapPatternParameters)list[0]; } else if (list.Length > 0 && list.Length <= 7) { BitmapPatternParameters pattern = new BitmapPatternParameters(); try { int listLength = list.Length; if (listLength > 0) { pattern.NumberOfRows = System.Convert.ToUInt16(list[0]); if (listLength == 1) pattern.NumberOfColumns = pattern.NumberOfRows; } if (listLength > 1) pattern.NumberOfColumns = System.Convert.ToUInt16(list[1]); if (listLength > 2) pattern.StartValue = System.Convert.ToInt16(list[2]); if (listLength > 3) pattern.ValueIncrementPerRowBlock = System.Convert.ToInt16(list[3]); if (listLength > 4) pattern.ValueIncrementPerColumnBlock = System.Convert.ToInt16(list[4]); if (listLength > 5) pattern.NumberOfIdenticalValueRows = System.Convert.ToUInt16(list[5]); if (listLength > 6) pattern.NumberOfIdenticalValueColumns = System.Convert.ToUInt16(list[6]); } catch { throw new System.ArgumentException(); } otherWordString.BitmapPattern = pattern; } else throw new System.ArgumentException(); } dicomValue = otherWordString; break; } case VR.PN: { System.String[] stringArray = _CastToStringArray(list); PersonName personName = new PersonName(); personName.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = personName; // compute attribute value length Length = 0; if (personName.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in personName.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)personName.Values.Count - 1; } break; } case VR.SH: { System.String[] stringArray = _CastToStringArray(list); ShortString shortString = new ShortString(); shortString.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = shortString; // compute attribute value length Length = 0; if (shortString.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in shortString.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)shortString.Values.Count - 1; } break; } case VR.SL: { System.Int32[] signedLongArray = _CastToSignedLongArray(list); SignedLong signedLong = new SignedLong(); signedLong.Values = new DvtkData.Collections.Int32Collection(signedLongArray); dicomValue = signedLong; // compute attribute value length Length = (System.UInt32)signedLong.Values.Count * 4; break; } case VR.SQ: { SequenceItem[] sequenceItemArray = _CastToSequenceItemArray(list); SequenceOfItems sequenceOfItems = new SequenceOfItems(); sequenceOfItems.Sequence = new Sequence(); foreach (SequenceItem item in sequenceItemArray) { sequenceOfItems.Sequence.Add(item); } dicomValue = sequenceOfItems; // set length to Undefined Length = 0xFFFFFFFF; break; } case VR.SS: { System.Int16[] signedShortArray = _CastToSignedShortArray(list); SignedShort signedShort = new SignedShort(); signedShort.Values = new DvtkData.Collections.Int16Collection(signedShortArray); dicomValue = signedShort; // compute attribute value length Length = (System.UInt32)signedShort.Values.Count * 2; break; } case VR.ST: { if (list.Length > 1) throw new System.ArgumentException(); ShortText shortText = new ShortText(); Length = 0; if (list.Length == 1) { System.String stringValue = System.Convert.ToString(list[0]); shortText.Value = stringValue; Length = (System.UInt32)shortText.Value.Length; } dicomValue = shortText; break; } case VR.TM: { System.String[] stringArray = _CastToTimeStringArray(list); Time time = new Time(); time.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = time; // compute attribute value length Length = 0; if (time.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in time.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)time.Values.Count - 1; } break; } case VR.UI: { System.String[] stringArray = _CastUniqueIdentifierStringArray(list); UniqueIdentifier uniqueIdentifier = new UniqueIdentifier(); uniqueIdentifier.Values = new DvtkData.Collections.StringCollection(stringArray); dicomValue = uniqueIdentifier; // compute attribute value length Length = 0; if (uniqueIdentifier.Values.Count > 0) { System.UInt32 length = 0; foreach(String data in uniqueIdentifier.Values) { length += (System.UInt32)data.Length; } Length = length + (System.UInt32)uniqueIdentifier.Values.Count - 1; } break; } case VR.UL: { System.UInt32[] unsignedLongArray = _CastToUnsignedLongArray(list); UnsignedLong unsignedLong = new UnsignedLong(); unsignedLong.Values = new DvtkData.Collections.UInt32Collection(unsignedLongArray); dicomValue = unsignedLong; // compute attribute value length Length = (System.UInt32)unsignedLong.Values.Count * 4; break; } case VR.UN: { Unknown unknown = new Unknown(); Length = 0; if (list.Length == 0 || list[0] is System.Byte) { System.Byte[] byteArray = _CastToByteArray(list); unknown.ByteArray = byteArray; Length = (System.UInt32)unknown.ByteArray.Length; } else throw new System.ArgumentException(); dicomValue = unknown; break; } case VR.US: { System.UInt16[] unsignedShortArray = _CastToUnsignedShortArray(list); UnsignedShort unsignedShort = new UnsignedShort(); unsignedShort.Values = new DvtkData.Collections.UInt16Collection(unsignedShortArray); dicomValue = unsignedShort; // compute attribute value length Length = (System.UInt32)unsignedShort.Values.Count * 2; break; } case VR.UT: { if (list.Length > 1) throw new System.ArgumentException(); UnlimitedText unlimitedText = new UnlimitedText(); Length = 0; if (list.Length == 1) { System.String stringValue = System.Convert.ToString(list[0]); unlimitedText.Value = stringValue; Length = (System.UInt32)unlimitedText.Value.Length; } dicomValue = unlimitedText; break; } default: dicomValue = null; break; } } else { dicomValue = null; } this._ValueField = dicomValue; }
// ----------------------------- // - Begin constructors region - // ----------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="tag">The tag of this instance.</param> /// <param name="vr">The VR of this instance.</param> /// <param name="parent">The parent of this instance.</param> public SingleAttribute(Tag tag, VR vr, AttributeSet parent) : base(tag, vr, parent) { // Do nothing. }
public static string ToString(VR valueRepresentations, string seperator) { string stringRepresentation = string.Empty; foreach(VR vr in Enum.GetValues(typeof (VR))) { if (vr != VR.None) { if ((valueRepresentations & vr) == vr) { if (stringRepresentation.Length == 0) { stringRepresentation = vr.ToString(); } else { stringRepresentation += seperator + vr.ToString(); } } } } return(stringRepresentation); }
public static byte[] GetStringBytes(VR vr, IDICOMElement el, StringEncoding enc) { string data; byte[] unpadded; switch (vr) { case VR.AgeString: var age = el as AgeString; data = StringDataComposer.ComposeMultipleString(age.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ApplicationEntity: var ae = el as ApplicationEntity; data = StringDataComposer.ComposeMultipleString(ae.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.CodeString: var cs = el as CodeString; data = StringDataComposer.ComposeMultipleString(cs.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.Date: var d = el as Date; data = StringDataComposer.ComposeDates(d.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.DateTime: var dt = el as DateTime; data = StringDataComposer.ComposeDateTimes(dt.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.DecimalString: var ds = el as DecimalString; data = StringDataComposer.ComposeDecimalString(ds.DataContainer.MultipicityValue.ToArray()); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.IntegerString: var iSt = el as IntegerString; data = StringDataComposer.ComposeIntegerString(iSt.DataContainer.MultipicityValue.ToArray()); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.LongString: var ls = el as LongString; data = StringDataComposer.ComposeMultipleString(ls.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.LongText: var lt = el as LongText; data = StringDataComposer.ComposeMultipleString(lt.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.PersonName: var pn = el as PersonName; data = StringDataComposer.ComposeMultipleString(pn.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ShortString: var ss = el as ShortString; data = StringDataComposer.ComposeMultipleString(ss.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.ShortText: var st = el as ShortText; // VM=1 ALWAYS unpadded = GetEncodedBytes(st.Data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.Time: var t = el as Time; data = StringDataComposer.ComposeTimes(t.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UnlimitedText: var ut = el as UnlimitedText; // VM=1 ALWAYS unpadded = GetEncodedBytes(ut.Data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UnlimitedCharacter: var uc = el as UnlimitedCharacter; data = StringDataComposer.ComposeMultipleString(uc.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UniqueIdentifier: var ui = el as UniqueIdentifier; data = StringDataComposer.ComposeMultipleString(ui.Data_); unpadded = GetEncodedBytes(data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); case VR.UniversalResourceId: var uid = el as UniversalResourceId; // VM=1 ALWAYS unpadded = GetEncodedBytes(uid.Data, enc); return(DataRestriction.EnforceEvenLength(unpadded, vr)); default: return(null); } }
// Start is called before the first frame update void Start() { if (VR.GetPlatform() == VR.Platform.None) { this.enabled = false; return; } RightControllerButton0 = TransformUtils.FindTransform("AButton"); RightControllerButton1 = TransformUtils.FindTransform("BButton"); RightControllerJoystick = TransformUtils.FindTransform("RightJoystickCenter"); RightControllerTrigger = TransformUtils.FindTransform("RightTriggerCenter"); RightControllerGrip = TransformUtils.FindTransform("RightGripCenter"); LeftControllerButton0 = TransformUtils.FindTransform("XButton"); LeftControllerButton1 = TransformUtils.FindTransform("YButton"); LeftControllerJoystick = TransformUtils.FindTransform("LeftJoystickCenter"); LeftControllerTrigger = TransformUtils.FindTransform("LeftTriggerCenter"); LeftControllerGrip = TransformUtils.FindTransform("LeftGripCenter"); MenuButton = TransformUtils.FindTransform("MenuButton"); HomeButton = TransformUtils.FindTransform("HomeButton"); leftController = TransformUtils.FindTransform("LeftControllerAnchor"); rightController = TransformUtils.FindTransform("RightControllerAnchor"); transform.parent = rightController; transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; rightVRInputToTransform = new Hashtable(); rightVRInputToTransform.Add(VRInput.Button0, RightControllerButton0); rightVRInputToTransform.Add(VRInput.Button1, RightControllerButton1); rightVRInputToTransform.Add(VRInput.JoystickClick, RightControllerJoystick); rightVRInputToTransform.Add(VRInput.JoystickHorizontal, RightControllerJoystick); rightVRInputToTransform.Add(VRInput.JoystickVertical, RightControllerJoystick); rightVRInputToTransform.Add(VRInput.Trigger, RightControllerTrigger); rightVRInputToTransform.Add(VRInput.Grip, RightControllerGrip); rightVRInputToTransform.Add(VRInput.MenuButton, HomeButton); leftVRInputToTransform = new Hashtable(); leftVRInputToTransform.Add(VRInput.Button0, LeftControllerButton0); leftVRInputToTransform.Add(VRInput.Button1, LeftControllerButton1); leftVRInputToTransform.Add(VRInput.JoystickClick, LeftControllerJoystick); leftVRInputToTransform.Add(VRInput.JoystickHorizontal, LeftControllerJoystick); leftVRInputToTransform.Add(VRInput.JoystickVertical, LeftControllerJoystick); leftVRInputToTransform.Add(VRInput.Trigger, LeftControllerTrigger); leftVRInputToTransform.Add(VRInput.Grip, LeftControllerGrip); leftVRInputToTransform.Add(VRInput.MenuButton, MenuButton); //Create hashtable linking generic vrinputs to OVRInputs VRInputToOVRButton = new Hashtable(); VRInputToOVRButton.Add(VRInput.Button0, OVRInput.Button.One); VRInputToOVRButton.Add(VRInput.Button1, OVRInput.Button.Two); VRInputToOVRButton.Add(VRInput.JoystickClick, OVRInput.Button.PrimaryThumbstick); VRInputToOVRButton.Add(VRInput.JoystickHorizontal, OVRInput.Button.PrimaryThumbstickRight); VRInputToOVRButton.Add(VRInput.JoystickVertical, OVRInput.Button.PrimaryThumbstickUp); VRInputToOVRButton.Add(VRInput.Trigger, OVRInput.Button.PrimaryIndexTrigger); VRInputToOVRButton.Add(VRInput.Grip, OVRInput.Button.PrimaryHandTrigger); VRInputToOVRButton.Add(VRInput.MenuButton, OVRInput.Button.Start); VRInputToOVRButtonAlternate = new Hashtable(); VRInputToOVRButtonAlternate.Add(VRInput.Button0, OVRInput.Button.One); VRInputToOVRButtonAlternate.Add(VRInput.Button1, OVRInput.Button.Two); VRInputToOVRButtonAlternate.Add(VRInput.JoystickClick, OVRInput.Button.PrimaryThumbstick); VRInputToOVRButtonAlternate.Add(VRInput.JoystickHorizontal, OVRInput.Button.PrimaryThumbstickLeft); VRInputToOVRButtonAlternate.Add(VRInput.JoystickVertical, OVRInput.Button.PrimaryThumbstickDown); VRInputToOVRButtonAlternate.Add(VRInput.Trigger, OVRInput.Button.PrimaryIndexTrigger); VRInputToOVRButtonAlternate.Add(VRInput.Grip, OVRInput.Button.PrimaryHandTrigger); VRInputToOVRButtonAlternate.Add(VRInput.MenuButton, OVRInput.Button.Start); }
/// <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> public 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: var dateData = DICOMString.Read(data as byte[], enc); if (dateData.Any(b => b == '-')) // Range ('-') { var parts = dateData.Split('-'); var dates = parts.Select(p => StringDataParser.ParseDate(p)).OrderBy(p => p).ToArray(); return(new Date(tag, dates) { IsRange = true }); } else { return(new Date(tag, dateData)); } case VR.DateTime: var dateTimeData = DICOMString.Read(data as byte[], enc); if (dateTimeData.Any(b => b == '-')) // Range ('-') { var parts = dateTimeData.Split('-'); var dates = parts.Select(p => StringDataParser.ParseDateTime(p)).OrderBy(p => p).ToArray(); return(new DateTime(tag, dates) { IsRange = true }); } else { return(new DateTime(tag, dateTimeData)); } 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: var timeData = DICOMString.Read(data as byte[], enc); if (timeData.Any(b => b == '-')) // Range ('-') { var parts = timeData.Split('-'); var dates = parts.Select(p => StringDataParser.ParseTime(p)).OrderBy(p => p).ToArray(); return(new Time(tag, dates) { IsRange = true }); } else { return(new Time(tag, timeData)); } 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[])); } }
/// <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()))); }
/// <summary> /// Finds all DICOM elements that match a VR type /// </summary> /// <param name="vrToFind">the VR type to find</param> /// <returns>a list of all elements that meet the search criteria</returns> public List <IDICOMElement> FindAll(VR vrToFind) { return(AllElements.Where(el => el.IsVR(vrToFind)).ToList()); }