public void OnElement(IByteSource source, DicomTag tag, DicomVR vr, IByteBuffer data) {
			DicomElement element;
			switch (vr.Code) {
				case "AE": element = new DicomApplicationEntity(tag, data); break;
				case "AS": element = new DicomAgeString(tag, data); break;
				case "AT": element = new DicomAttributeTag(tag, data); break;
				case "CS": element = new DicomCodeString(tag, data); break;
				case "DA": element = new DicomDate(tag, data); break;
				case "DS": element = new DicomDecimalString(tag, data); break;
				case "DT": element = new DicomDateTime(tag, data); break;
				case "FD": element = new DicomFloatingPointDouble(tag, data); break;
				case "FL": element = new DicomFloatingPointSingle(tag, data); break;
				case "IS": element = new DicomIntegerString(tag, data); break;
				case "LO": element = new DicomLongString(tag, _encodings.Peek(), data); break;
				case "LT": element = new DicomLongText(tag, _encodings.Peek(), data); break;
				case "OB": element = new DicomOtherByte(tag, data); break;
				case "OD": element = new DicomOtherDouble(tag, data); break;
				case "OF": element = new DicomOtherFloat(tag, data); break;
				case "OW": element = new DicomOtherWord(tag, data); break;
				case "PN": element = new DicomPersonName(tag, _encodings.Peek(), data); break;
				case "SH": element = new DicomShortString(tag, _encodings.Peek(), data); break;
				case "SL": element = new DicomSignedLong(tag, data); break;
				case "SS": element = new DicomSignedShort(tag, data); break;
				case "ST": element = new DicomShortText(tag, _encodings.Peek(), data); break;
				case "TM": element = new DicomTime(tag, data); break;
				case "UC": element = new DicomUnlimitedCharacters(tag, _encodings.Peek(), data); break;
				case "UI": element = new DicomUniqueIdentifier(tag, data); break;
				case "UL": element = new DicomUnsignedLong(tag, data); break;
				case "UN": element = new DicomUnknown(tag, data); break;
				case "UR": element = new DicomUniversalResource(tag, _encodings.Peek(), data); break;
				case "US": element = new DicomUnsignedShort(tag, data); break;
				case "UT": element = new DicomUnlimitedText(tag, _encodings.Peek(), data); break;
				default:
					throw new DicomDataException("Unhandled VR in DICOM parser observer: {0}", vr.Code);
			}

			if (element.Tag == DicomTag.SpecificCharacterSet) {
				Encoding encoding = _encodings.Peek();
				if (element.Count > 0)
					encoding = DicomEncoding.GetEncoding(element.Get<string>(0));
				_encodings.Pop();
				_encodings.Push(encoding);
			}

			DicomDataset ds = _datasets.Peek();
			ds.Add(element);
		}
Exemplo n.º 2
0
        private static DicomItem CreateDicomItem(DicomTag tag, string vr, object data)
        {
            DicomItem item;

            switch (vr)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, (string[])data);
                break;

            case "AS":
                item = new DicomAgeString(tag, (string[])data);
                break;

            case "AT":
                item = new DicomAttributeTag(tag, ((string[])data).Select(ParseTag).ToArray());
                break;

            case "CS":
                item = new DicomCodeString(tag, (string[])data);
                break;

            case "DA":
                item = new DicomDate(tag, (string[])data);
                break;

            case "DS":
                item = new DicomDecimalString(tag, (string[])data);
                break;

            case "DT":
                item = new DicomDateTime(tag, (string[])data);
                break;

            case "FD":
                item = new DicomFloatingPointDouble(tag, (double[])data);
                break;

            case "FL":
                item = new DicomFloatingPointSingle(tag, (float[])data);
                break;

            case "IS":
                item = new DicomIntegerString(tag, (int[])data);
                break;

            case "LO":
                item = new DicomLongString(tag, (string[])data);
                break;

            case "LT":
                item = new DicomLongText(tag, ((string[])data).Single());
                break;

            case "OB":
                item = new DicomOtherByte(tag, (IByteBuffer)data);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (IByteBuffer)data);
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (IByteBuffer)data);
                break;

            case "OL":
                item = new DicomOtherLong(tag, (IByteBuffer)data);
                break;

            case "OW":
                item = new DicomOtherWord(tag, (IByteBuffer)data);
                break;

            case "PN":
                item = new DicomPersonName(tag, (string[])data);
                break;

            case "SH":
                item = new DicomShortString(tag, (string[])data);
                break;

            case "SL":
                item = new DicomSignedLong(tag, (int[])data);
                break;

            case "SS":
                item = new DicomSignedShort(tag, (short[])data);
                break;

            case "ST":
                item = new DicomShortText(tag, ((string[])data)[0]);
                break;

            case "SQ":
                item = new DicomSequence(tag, ((DicomDataset[])data));
                break;

            case "TM":
                item = new DicomTime(tag, (string[])data);
                break;

            case "UC":
                item = new DicomUnlimitedCharacters(tag, ((string[])data).SingleOrDefault());
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, (string[])data);
                break;

            case "UL":
                item = new DicomUnsignedLong(tag, (uint[])data);
                break;

            case "UN":
                item = new DicomUnknown(tag, (IByteBuffer)data);
                break;

            case "UR":
                item = new DicomUniversalResource(tag, ((string[])data).Single());
                break;

            case "US":
                item = new DicomUnsignedShort(tag, (ushort[])data);
                break;

            case "UT":
                item = new DicomUnlimitedText(tag, ((string[])data).Single());
                break;

            default:
                throw new NotSupportedException("Unsupported value representation");
            }
            return(item);
        }
        public void OnElement(IByteSource source, DicomTag tag, DicomVR vr, IByteBuffer data)
        {
            DicomElement element;

            switch (vr.Code)
            {
            case "AE":
                element = new DicomApplicationEntity(tag, data);
                break;

            case "AS":
                element = new DicomAgeString(tag, data);
                break;

            case "AT":
                element = new DicomAttributeTag(tag, data);
                break;

            case "CS":
                element = new DicomCodeString(tag, data);
                break;

            case "DA":
                element = new DicomDate(tag, data);
                break;

            case "DS":
                element = new DicomDecimalString(tag, data);
                break;

            case "DT":
                element = new DicomDateTime(tag, data);
                break;

            case "FD":
                element = new DicomFloatingPointDouble(tag, data);
                break;

            case "FL":
                element = new DicomFloatingPointSingle(tag, data);
                break;

            case "IS":
                element = new DicomIntegerString(tag, data);
                break;

            case "LO":
                element = new DicomLongString(tag, _encodings.Peek(), data);
                break;

            case "LT":
                element = new DicomLongText(tag, _encodings.Peek(), data);
                break;

            case "OB":
                element = new DicomOtherByte(tag, data);
                break;

            case "OD":
                element = new DicomOtherDouble(tag, data);
                break;

            case "OF":
                element = new DicomOtherFloat(tag, data);
                break;

            case "OL":
                element = new DicomOtherLong(tag, data);
                break;

            case "OW":
                element = new DicomOtherWord(tag, data);
                break;

            case "PN":
                element = new DicomPersonName(tag, _encodings.Peek(), data);
                break;

            case "SH":
                element = new DicomShortString(tag, _encodings.Peek(), data);
                break;

            case "SL":
                element = new DicomSignedLong(tag, data);
                break;

            case "SS":
                element = new DicomSignedShort(tag, data);
                break;

            case "ST":
                element = new DicomShortText(tag, _encodings.Peek(), data);
                break;

            case "TM":
                element = new DicomTime(tag, data);
                break;

            case "UC":
                element = new DicomUnlimitedCharacters(tag, _encodings.Peek(), data);
                break;

            case "UI":
                element = new DicomUniqueIdentifier(tag, data);
                break;

            case "UL":
                element = new DicomUnsignedLong(tag, data);
                break;

            case "UN":
                element = new DicomUnknown(tag, data);
                break;

            case "UR":
                element = new DicomUniversalResource(tag, _encodings.Peek(), data);
                break;

            case "US":
                element = new DicomUnsignedShort(tag, data);
                break;

            case "UT":
                element = new DicomUnlimitedText(tag, _encodings.Peek(), data);
                break;

            default:
                throw new DicomDataException("Unhandled VR in DICOM parser observer: {0}", vr.Code);
            }

            if (element.Tag == DicomTag.SpecificCharacterSet)
            {
                Encoding encoding = _encodings.Peek();
                if (element.Count > 0)
                {
                    encoding = DicomEncoding.GetEncoding(element.Get <string>(0));
                }

                _encodings.Pop();
                _encodings.Push(encoding);
            }

            DicomDataset ds = _datasets.Peek();

            ds.AddOrUpdate(element);
        }
Exemplo n.º 4
0
        private static DicomItem CreateDicomItem(DicomTag tag, BsonValue data, DicomVR vr = null)
        {
            // Ok to throw an exception here - we should always be writing the VR into the Bson document if it's ambiguous
            if (vr == null)
            {
                vr = tag.DictionaryEntry.ValueRepresentations.Single();
            }

            DicomItem item;

            switch (vr.Code)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, GetString(data));
                break;

            case "AS":
                item = new DicomAgeString(tag, GetString(data));
                break;

            case "AT":
                item = ParseAttributeTag(tag, data);
                break;

            case "CS":
                item = new DicomCodeString(tag, GetString(data));
                break;

            case "DA":
                item = new DicomDate(tag, GetString(data));
                break;

            case "DS":
                item = new DicomDecimalString(tag, GetString(data));
                break;

            case "DT":
                item = new DicomDateTime(tag, GetString(data));
                break;

            case "FD":
                item = new DicomFloatingPointDouble(tag, (double[])GetTypedArray <double>(data));
                break;

            case "FL":
                item = new DicomFloatingPointSingle(tag, (float[])GetTypedArray <float>(data));
                break;

            case "IS":
                item = new DicomIntegerString(tag, GetString(data));
                break;

            case "LO":
                item = new DicomLongString(tag, Encoding.UTF8, GetString(data));
                break;

            case "LT":
                item = new DicomLongText(tag, Encoding.UTF8, GetString(data));
                break;

            case "OB":
                item = data.IsBsonNull
                        ? new DicomOtherByte(tag)
                        : new DicomOtherByte(tag, data.AsByteArray);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (double[])GetTypedArray <double>(data));
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (float[])GetTypedArray <float>(data));
                break;

            case "OL":
                item = new DicomOtherLong(tag, (uint[])GetTypedArray <uint>(data));
                break;

            case "OW":
                item = data.IsBsonNull
                        ? new DicomOtherWord(tag)
                        : new DicomOtherWord(tag, (ushort[])GetTypedArray <ushort>(data));
                break;

            case "PN":
                item = new DicomPersonName(tag, Encoding.UTF8, GetString(data));
                break;

            case "SH":
                item = new DicomShortString(tag, Encoding.UTF8, GetString(data));
                break;

            case "SL":
                item = new DicomSignedLong(tag, (int[])GetTypedArray <int>(data));
                break;

            case "SS":
                item = new DicomSignedShort(tag, (short[])GetTypedArray <short>(data));
                break;

            case "ST":
                item = new DicomShortText(tag, Encoding.UTF8, GetString(data));
                break;

            case "SQ":
                item = GetDicomSequence(tag, data);
                break;

            case "TM":
                item = new DicomTime(tag, GetString(data));
                break;

            case "UC":
                item = new DicomUnlimitedCharacters(tag, Encoding.UTF8, GetString(data));
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, GetString(data));
                break;

            case "UL":
                item = new DicomUnsignedLong(tag, (uint[])GetTypedArray <uint>(data));
                break;

            case "UN":
                item = data.IsBsonNull
                        ? new DicomUnknown(tag)
                        : new DicomUnknown(tag, (byte[])GetTypedArray <byte>(data));
                break;

            case "UR":
                item = new DicomUniversalResource(tag, Encoding.UTF8, GetString(data));
                break;

            case "US":
                item = new DicomUnsignedShort(tag, (ushort[])GetTypedArray <ushort>(data));
                break;

            case "UT":
                item = new DicomUnlimitedText(tag, Encoding.UTF8, GetString(data));
                break;

            default:
                throw new NotSupportedException($"Unsupported value representation {vr}");
            }

            return(item);
        }
Exemplo n.º 5
0
        private static DicomItem CreateDicomItem(DicomTag tag, string vr, object data)
        {
            DicomItem item;

            switch (vr)
            {
            case "AE":
                item = new DicomApplicationEntity(tag, (string[])data);
                break;

            case "AS":
                item = new DicomAgeString(tag, (string[])data);
                break;

            case "AT":
                item = new DicomAttributeTag(tag, ((string[])data).Select(ParseTag).ToArray());
                break;

            case "CS":
                item = new DicomCodeString(tag, (string[])data);
                break;

            case "DA":
                item = new DicomDate(tag, (string[])data);
                break;

            case "DS":
                if (data is IByteBuffer dataBufferDS)
                {
                    item = new DicomDecimalString(tag, dataBufferDS);
                }
                else if (data is decimal[] dataAsNumbers)
                {
                    item = new DicomDecimalString(tag, dataAsNumbers);
                }
                else
                {
                    item = new DicomDecimalString(tag, (string[])data);
                }
                break;

            case "DT":
                item = new DicomDateTime(tag, (string[])data);
                break;

            case "FD":
                if (data is IByteBuffer dataBufferFD)
                {
                    item = new DicomFloatingPointDouble(tag, dataBufferFD);
                }
                else
                {
                    item = new DicomFloatingPointDouble(tag, (double[])data);
                }
                break;

            case "FL":
                if (data is IByteBuffer dataBufferFL)
                {
                    item = new DicomFloatingPointSingle(tag, dataBufferFL);
                }
                else
                {
                    item = new DicomFloatingPointSingle(tag, (float[])data);
                }
                break;

            case "IS":
                if (data is IByteBuffer dataBufferIS)
                {
                    item = new DicomIntegerString(tag, dataBufferIS);
                }
                else if (data is string[] dataAsStrings)
                {
                    item = new DicomIntegerString(tag, dataAsStrings);
                }
                else
                {
                    item = new DicomIntegerString(tag, (int[])data);
                }
                break;

            case "LO":
                item = new DicomLongString(tag, (string[])data);
                break;

            case "LT":
                if (data is IByteBuffer dataBufferLT)
                {
                    item = new DicomLongText(tag, _jsonTextEncodings, dataBufferLT);
                }
                else
                {
                    item = new DicomLongText(tag, data.AsStringArray().SingleOrEmpty());
                }
                break;

            case "OB":
                item = new DicomOtherByte(tag, (IByteBuffer)data);
                break;

            case "OD":
                item = new DicomOtherDouble(tag, (IByteBuffer)data);
                break;

            case "OF":
                item = new DicomOtherFloat(tag, (IByteBuffer)data);
                break;

            case "OL":
                item = new DicomOtherLong(tag, (IByteBuffer)data);
                break;

            case "OW":
                item = new DicomOtherWord(tag, (IByteBuffer)data);
                break;

            case "OV":
                item = new DicomOtherVeryLong(tag, (IByteBuffer)data);
                break;

            case "PN":
                item = new DicomPersonName(tag, (string[])data);
                break;

            case "SH":
                item = new DicomShortString(tag, (string[])data);
                break;

            case "SL":
                if (data is IByteBuffer dataBufferSL)
                {
                    item = new DicomSignedLong(tag, dataBufferSL);
                }
                else
                {
                    item = new DicomSignedLong(tag, (int[])data);
                }
                break;

            case "SQ":
                item = new DicomSequence(tag, ((DicomDataset[])data));
                break;

            case "SS":
                if (data is IByteBuffer dataBufferSS)
                {
                    item = new DicomSignedShort(tag, dataBufferSS);
                }
                else
                {
                    item = new DicomSignedShort(tag, (short[])data);
                }
                break;

            case "ST":
                if (data is IByteBuffer dataBufferST)
                {
                    item = new DicomShortText(tag, _jsonTextEncodings, dataBufferST);
                }
                else
                {
                    item = new DicomShortText(tag, data.AsStringArray().FirstOrEmpty());
                }
                break;

            case "SV":
                if (data is IByteBuffer dataBufferSV)
                {
                    item = new DicomSignedVeryLong(tag, dataBufferSV);
                }
                else if (data is string[] dataAsStrings)
                {
                    var dataAsLongs = dataAsStrings.Select(s => long.Parse(s)).ToArray();
                    item = new DicomSignedVeryLong(tag, dataAsLongs);
                }
                else
                {
                    item = new DicomSignedVeryLong(tag, (long[])data);
                }
                break;

            case "TM":
                item = new DicomTime(tag, (string[])data);
                break;

            case "UC":
                if (data is IByteBuffer dataBufferUC)
                {
                    item = new DicomUnlimitedCharacters(tag, _jsonTextEncodings, dataBufferUC);
                }
                else
                {
                    item = new DicomUnlimitedCharacters(tag, data.AsStringArray().SingleOrDefault());
                }
                break;

            case "UI":
                item = new DicomUniqueIdentifier(tag, (string[])data);
                break;

            case "UL":
                if (data is IByteBuffer dataBufferUL)
                {
                    item = new DicomUnsignedLong(tag, dataBufferUL);
                }
                else
                {
                    item = new DicomUnsignedLong(tag, (uint[])data);
                }
                break;

            case "UN":
                item = new DicomUnknown(tag, (IByteBuffer)data);
                break;

            case "UR":
                item = new DicomUniversalResource(tag, data.AsStringArray().SingleOrEmpty());
                break;

            case "US":
                if (data is IByteBuffer dataBufferUS)
                {
                    item = new DicomUnsignedShort(tag, dataBufferUS);
                }
                else
                {
                    item = new DicomUnsignedShort(tag, (ushort[])data);
                }
                break;

            case "UT":
                if (data is IByteBuffer dataBufferUT)
                {
                    item = new DicomUnlimitedText(tag, _jsonTextEncodings, dataBufferUT);
                }
                else
                {
                    item = new DicomUnlimitedText(tag, data.AsStringArray().SingleOrEmpty());
                }
                break;

            case "UV":
                if (data is IByteBuffer dataBufferUV)
                {
                    item = new DicomUnsignedVeryLong(tag, dataBufferUV);
                }
                else if (data is string[] dataAsStrings)
                {
                    var dataAsULongs = dataAsStrings.Select(s => ulong.Parse(s)).ToArray();
                    item = new DicomUnsignedVeryLong(tag, dataAsULongs);
                }
                else
                {
                    item = new DicomUnsignedVeryLong(tag, (ulong[])data);
                }
                break;

            default:
                throw new NotSupportedException("Unsupported value representation");
            }
            return(item);
        }