Beispiel #1
0
        /// <summary>
        ///     Generates a concrete element class from the VR, tag, data and syntax. Also directs the appropriate data
        ///     interpretation.
        /// </summary>
        /// <param name="tag">the tag of the element to be generated</param>
        /// <param name="vr">the VR of the element to be generated</param>
        /// <param name="data">the raw data to be procesed (byte array)</param>
        /// <param name="syntax">the transfer syntax by which to interepret the data</param>
        /// <returns>a concrete DICOM element that uses the interface IDICOMElement</returns>
        public static IDICOMElement GenerateElement(Tag tag, VR vr, object data, TransferSyntax syntax, StringEncoding enc)
        {
            //HANDLE NUMBERS
            if (syntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN)
            {
                switch (vr)
                {
                case VR.AttributeTag:
                    return(new AttributeTag(tag, BigEndianReader.ReadTag(data as byte[])));

                case VR.FloatingPointDouble:
                    return(new FloatingPointDouble(tag, BigEndianReader.ReadDoublePrecision(data as byte[])));

                case VR.FloatingPointSingle:
                    return(new FloatingPointSingle(tag, BigEndianReader.ReadSinglePrecision(data as byte[])));

                case VR.SignedLong:
                    return(new SignedLong(tag, BigEndianReader.ReadSignedLong(data as byte[])));

                case VR.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.UnlimitedCharacter:
            case VR.UnlimitedText:
            case VR.UniversalResourceId:
            case VR.UniqueIdentifier:
                return(ReadString(vr, tag, data, enc));

            //HANDLE BYTE DATA
            case VR.Sequence:
                return(new Sequence {
                    Tag = tag, Items = SequenceReader.ReadItems(data as byte[], syntax, enc)
                });

            case VR.OtherByteString:
                return(new OtherByteString(tag, data as byte[]));

            case VR.OtherFloatString:
                return(new OtherFloatString(tag, data as byte[]));

            case VR.OtherWordString:
                return(new OtherWordString(tag, data as byte[]));

            case VR.OtherDoubleString:
                return(new OtherDoubleString(tag, data as byte[]));

            case VR.OtherLongString:
                return(new OtherLongString(tag, data as byte[]));

            default:
                var unk = new Unknown(tag, data as byte[]);
                unk.TransferSyntax = syntax;
                return(unk);
            }
        }