public static byte[] GetDataLittleEndian(IDICOMElement el) { VR vr = VRDictionary.GetVRFromType(el); switch (vr) { case VR.AttributeTag: AttributeTag at = el as AttributeTag; return(LittleEndianWriter.WriteTag(at.DataContainer)); case VR.FloatingPointDouble: FloatingPointDouble fpd = el as FloatingPointDouble; return(LittleEndianWriter.WriteDoublePrecision(fpd.DataContainer)); case VR.FloatingPointSingle: FloatingPointSingle fps = el as FloatingPointSingle; return(LittleEndianWriter.WriteSinglePrecision(fps.DataContainer)); case VR.OtherByteString: OtherByteString obs = el as OtherByteString; return(DataRestriction.EnforceEvenLength(obs.DataContainer.MultipicityValue.ToArray(), vr)); case VR.OtherFloatString: OtherFloatString ofs = el as OtherFloatString; return(ofs.DataContainer.MultipicityValue.ToArray()); case VR.OtherWordString: OtherWordString ows = el as OtherWordString; return(ows.DataContainer.MultipicityValue.ToArray()); case VR.SignedLong: SignedLong sl = el as SignedLong; return(LittleEndianWriter.WriteSignedLong(sl.DataContainer)); case VR.SignedShort: SignedShort sis = el as SignedShort; return(LittleEndianWriter.WriteSignedShort(sis.DataContainer)); case VR.Unknown: Unknown uk = el as Unknown; return(DataRestriction.EnforceEvenLength(uk.DataContainer.MultipicityValue.ToArray(), vr)); case VR.UnsignedLong: UnsignedLong ul = el as UnsignedLong; return(LittleEndianWriter.WriteUnsignedLong(ul.DataContainer)); case VR.UnsignedShort: UnsignedShort ush = el as UnsignedShort; return(LittleEndianWriter.WriteUnsignedShort(ush.DataContainer)); default: return(GetStringBytes(vr, el)); } }
/// <summary> /// This static function returns the Re-Construted value of the particular Dicom attribute. /// </summary> /// <param name="attribute">Dicom attribute contains tag vr and value</param> /// <returns>Returns the value of the Dicom attribute</returns> public static String GetDicomValue(DvtkData.Dimse.Attribute attribute) { String dumpString = ""; if (attribute != null && attribute.Length != 0) { switch (attribute.ValueRepresentation) { case VR.AE: { ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(applicationEntity.Values)); break; } case VR.AS: { AgeString ageString = (AgeString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(ageString.Values)); break; } case VR.AT: { AttributeTag attributeTag = (AttributeTag)attribute.DicomValue; Console.WriteLine("{0}", GetValues(attributeTag.Values)); break; } case VR.CS: { CodeString codeString = (CodeString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(codeString.Values)); break; } case VR.DA: { Date date = (Date)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(date.Values)); break; } case VR.DS: { DecimalString decimalString = (DecimalString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(decimalString.Values)); break; } case VR.DT: { DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(dateTime.Values)); break; } case VR.FD: { FloatingPointDouble floatingPointDouble = (FloatingPointDouble)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(floatingPointDouble.Values)); break; } case VR.FL: { FloatingPointSingle floatingPointSingle = (FloatingPointSingle)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(floatingPointSingle.Values)); break; } case VR.IS: { IntegerString integerString = (IntegerString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(integerString.Values)); break; } case VR.LO: { LongString longString = (LongString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(longString.Values)); break; } case VR.LT: { LongText longText = (LongText)attribute.DicomValue; dumpString += String.Format("{0}", longText.Value); break; } case VR.OB: { OtherByteString otherByteString = (OtherByteString)attribute.DicomValue; dumpString += String.Format("{0}", otherByteString.FileName); break; } case VR.OF: { OtherFloatString otherFloatString = (OtherFloatString)attribute.DicomValue; dumpString += String.Format("{0}", otherFloatString.FileName); break; } case VR.OW: { OtherWordString otherWordString = (OtherWordString)attribute.DicomValue; dumpString += String.Format("{0}", otherWordString.FileName); break; } case VR.OV: { OtherVeryLongString otherVeryLongString = (OtherVeryLongString)attribute.DicomValue; dumpString += String.Format("{0}", otherVeryLongString.FileName); break; } case VR.PN: { PersonName personName = (PersonName)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(personName.Values)); break; } case VR.SH: { ShortString shortString = (ShortString)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(shortString.Values)); break; } case VR.SL: { SignedLong signedLong = (SignedLong)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(signedLong.Values)); break; } case VR.SQ: { //SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue; //int itemNumber = 1; //dumpString += "\r\n"; //foreach (SequenceItem item in sequenceOfItems.Sequence) //{ // dumpString += String.Format("> Begin Item: {0}\r\n", itemNumber); // dumpString += item.Dump(prefix); // dumpString += prefix + String.Format("> End Item: {0}\r\n", itemNumber++); //} break; } case VR.SS: { SignedShort signedShort = (SignedShort)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(signedShort.Values)); break; } case VR.ST: { ShortText shortText = (ShortText)attribute.DicomValue; dumpString += String.Format("{0}", shortText.Value); break; } case VR.TM: { Time time = (Time)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(time.Values)); break; } case VR.UI: { UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(uniqueIdentifier.Values)); break; } case VR.UL: { UnsignedLong unsignedLong = (UnsignedLong)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(unsignedLong.Values)); break; } case VR.UN: { break; } case VR.US: { UnsignedShort unsignedShort = (UnsignedShort)attribute.DicomValue; dumpString += String.Format("{0}", GetValues(unsignedShort.Values)); break; } case VR.UT: { break; } case VR.UR: { break; } case VR.UC: { break; } default: dumpString += String.Format("\' \'"); break; } } else { dumpString += String.Format("\' \'"); } return(dumpString); }
private static DICOMElement CreateVRObject(string vr, Constants.EncodeType encType, byte[] data, Tag t, bool isLittleEndian, bool isIndefinite) { switch (vr) { case "CS": CodeString cs = new CodeString(); cs.ByteData = data; cs.EncodeType = encType; cs.IsLittleEndian = isLittleEndian; cs.Tag = t; return cs; case "SH": ShortString sh = new ShortString(); sh.ByteData = data; sh.EncodeType = encType; sh.IsLittleEndian = isLittleEndian; sh.Tag = t; return sh; case "LO": LongString lo = new LongString(); lo.ByteData = data; lo.EncodeType = encType; lo.IsLittleEndian = isLittleEndian; lo.Tag = t; return lo; case "ST": ShortText st = new ShortText(); st.ByteData = data; st.EncodeType = encType; st.IsLittleEndian = isLittleEndian; st.Tag = t; return st; case "LT": LongText lt = new LongText(); lt.ByteData = data; lt.EncodeType = encType; lt.IsLittleEndian = isLittleEndian; lt.Tag = t; return lt; case "UT": UnlimitedText ut = new UnlimitedText(); ut.ByteData = data; ut.EncodeType = encType; ut.IsLittleEndian = isLittleEndian; ut.Tag = t; return ut; case "AE": ApplicationEntity ae = new ApplicationEntity(); ae.ByteData = data; ae.EncodeType = encType; ae.IsLittleEndian = isLittleEndian; ae.Tag = t; return ae; case "PN": PersonsName pn = new PersonsName(); pn.ByteData = data; pn.EncodeType = encType; pn.IsLittleEndian = isLittleEndian; pn.Tag = t; return pn; case "UI": UniqueIdentifier ui = new UniqueIdentifier(); ui.ByteData = data; ui.EncodeType = encType; ui.IsLittleEndian = isLittleEndian; ui.Tag = t; return ui; case "DA": DateVR da = new DateVR(); da.ByteData = data; da.EncodeType = encType; da.IsLittleEndian = isLittleEndian; da.Tag = t; return da; case "TM": TimeVR tm = new TimeVR(); tm.ByteData = data; tm.EncodeType = encType; tm.IsLittleEndian = isLittleEndian; tm.Tag = t; return tm; case "DT": DateTimeVR dt = new DateTimeVR(); dt.ByteData = data; dt.EncodeType = encType; dt.IsLittleEndian = isLittleEndian; dt.Tag = t; return dt; case "AS": AgeString aSt = new AgeString(); aSt.ByteData = data; aSt.EncodeType = encType; aSt.IsLittleEndian = isLittleEndian; aSt.Tag = t; return aSt; case "IS": IntegerString iSt = new IntegerString(); iSt.ByteData = data; iSt.EncodeType = encType; iSt.IsLittleEndian = isLittleEndian; iSt.Tag = t; return iSt; case "DS": DecimalString ds = new DecimalString(); ds.ByteData = data; ds.EncodeType = encType; ds.IsLittleEndian = isLittleEndian; ds.Tag = t; return ds; case "SS": SignedShort ss = new SignedShort(); ss.ByteData = data; ss.EncodeType = encType; ss.IsLittleEndian = isLittleEndian; ss.Tag = t; return ss; case "US": UnsignedShort us = new UnsignedShort(); us.ByteData = data; us.EncodeType = encType; us.IsLittleEndian = isLittleEndian; us.Tag = t; return us; case "SL": SignedLong sl = new SignedLong(); sl.ByteData = data; sl.EncodeType = encType; sl.IsLittleEndian = isLittleEndian; sl.Tag = t; return sl; case "UL": UnsignedLong ul = new UnsignedLong(); ul.ByteData = data; ul.EncodeType = encType; ul.IsLittleEndian = isLittleEndian; ul.Tag = t; return ul; case "AT": AttributeTag at = new AttributeTag(); at.ByteData = data; at.EncodeType = encType; at.IsLittleEndian = isLittleEndian; at.Tag = t; return at; case "FL": FloatingPointSingle fl = new FloatingPointSingle(); fl.ByteData = data; fl.EncodeType = encType; fl.IsLittleEndian = isLittleEndian; fl.Tag = t; return fl; case "FD": FloatingPointDouble fd = new FloatingPointDouble(); fd.ByteData = data; fd.EncodeType = encType; fd.IsLittleEndian = isLittleEndian; fd.Tag = t; return fd; case "OB": if (t.Id == TagHelper.PIXEL_DATA) { PixelData fd1 = new PixelData(data, encType, isLittleEndian, "OB", isIndefinite); fd1.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE; fd1.EncodeType = encType; fd1.IsLittleEndian = isLittleEndian; fd1.Tag = t; return fd1; } else { OtherByteString ob = new OtherByteString(); ob.ByteData = data; ob.EncodeType = encType; ob.IsLittleEndian = isLittleEndian; ob.Tag = t; return ob; } case "OW": if (t.Id == TagHelper.PIXEL_DATA) { PixelData fd2 = new PixelData(data, encType, isLittleEndian, "OW", isIndefinite); fd2.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE; fd2.EncodeType = encType; fd2.IsLittleEndian = isLittleEndian; fd2.Tag = t; return fd2; } else { OtherWordString ow = new OtherWordString(); ow.ByteData = data; ow.EncodeType = encType; ow.IsLittleEndian = isLittleEndian; ow.Tag = t; return ow; } case "OF": OtherFloatString of = new OtherFloatString(); of.ByteData = data; of.EncodeType = encType; of.IsLittleEndian = isLittleEndian; of.Tag = t; return of; case "SQ": Sequence s = new Sequence(); s.ByteData = data; s.EncodeType = encType; s.IsLittleEndian = isLittleEndian; s.Tag = t; s.ReadChildren(); return s; default: //Case for unknown VR DICOMElement dOb = new DICOMElement(); dOb.ByteData = data; dOb.EncodeType = encType; dOb.IsLittleEndian = isLittleEndian; dOb.Tag = t; return dOb; } }