Exemplo n.º 1
0
        public static void WriteBigEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, IDICOMElement toWrite)
        {
            DICOMTagWriter.WriteBigEndian(dw, toWrite.Tag);
            VR vr = VRDictionary.GetVRFromType(toWrite);

            VRWriter.WriteVR(dw, settings, vr);
        }
Exemplo n.º 2
0
 public static void WriteVR(DICOMBinaryWriter dw, DICOMWriteSettings settings, IDICOMElement toWrite)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         VR     vr           = VRDictionary.GetVRFromType(toWrite);
         string abbreviation = VRDictionary.GetAbbreviationFromVR(vr);
         dw.Write(abbreviation);
     }
 }
Exemplo n.º 3
0
        public static byte[] GetDataLittleEndian(IDICOMElement el, StringEncoding enc)
        {
            var vr = VRDictionary.GetVRFromType(el);

            switch (vr)
            {
            case VR.AttributeTag:
                var at = el as AttributeTag;
                return(LittleEndianWriter.WriteTag(at.DataContainer));

            case VR.FloatingPointDouble:
                var fpd = el as FloatingPointDouble;
                return(LittleEndianWriter.WriteDoublePrecision(fpd.DataContainer));

            case VR.FloatingPointSingle:
                var fps = el as FloatingPointSingle;
                return(LittleEndianWriter.WriteSinglePrecision(fps.DataContainer));

            case VR.OtherByteString:
                var obs = el as OtherByteString;
                return(DataRestriction.EnforceEvenLength(obs.DataContainer.MultipicityValue.ToArray(), vr));

            case VR.OtherFloatString:
                var ofs = el as OtherFloatString;
                return(ofs.DataContainer.MultipicityValue.ToArray());

            case VR.OtherWordString:
                var ows = el as OtherWordString;
                return(ows.DataContainer.MultipicityValue.ToArray());

            case VR.SignedLong:
                var sl = el as SignedLong;
                return(LittleEndianWriter.WriteSignedLong(sl.DataContainer));

            case VR.SignedShort:
                var sis = el as SignedShort;
                return(LittleEndianWriter.WriteSignedShort(sis.DataContainer));

            case VR.Unknown:
                var uk = el as Unknown;
                return(DataRestriction.EnforceEvenLength(uk.DataContainer.MultipicityValue.ToArray(), vr));

            case VR.UnsignedLong:
                var ul = el as UnsignedLong;
                return(LittleEndianWriter.WriteUnsignedLong(ul.DataContainer));

            case VR.UnsignedShort:
                var ush = el as UnsignedShort;
                return(LittleEndianWriter.WriteUnsignedShort(ush.DataContainer));

            default:
                return(GetStringBytes(vr, el, enc));
            }
        }
Exemplo n.º 4
0
        public static void WriteLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, IDICOMElement toWrite)
        {
            VR vr = VRDictionary.GetVRFromType(toWrite);

            if (vr == VR.Sequence)
            {
                SequenceWriter.WriteLittleEndian(dw, settings, toWrite);
            }
            else
            {
                DICOMTagWriter.WriteLittleEndian(dw, toWrite.Tag);
                VRWriter.WriteVR(dw, settings, vr);
                DataWriter.WriteLittleEndian(dw, vr, settings, toWrite);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Method used to read out unknown VR types (not in the dictionary).
        /// </summary>
        /// <typeparam name="T">the type of value to try to read out</typeparam>
        /// <param name="outValue">the value read</param>
        /// <param name="tx">the transfer syntax to try (default is Implicit little endian)</param>
        /// <returns>whether or not the read was successfull</returns>
        public bool TryReadAs <T>(out T outValue) where T : IDICOMElement
        {
            VR vr = VRDictionary.GetVRFromType(typeof(T));

            try
            {
                IDICOMElement el = ElementFactory.GenerateElement(Tag, vr, Data_.ToArray(), TransferSyntax);
                outValue = (T)el;
                return(true);
            }
            catch (Exception e)
            {
                EvilLogger.Instance.Log("Couldn't cast unknown type as type {0} for {1}", LogPriority.ERROR, typeof(T),
                                        Tag);
                outValue = default(T);
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Method used to read out unknown VR types (not in the dictionary).
        /// </summary>
        /// <typeparam name="T">the type of value to try to read out</typeparam>
        /// <param name="outValue">the value read</param>
        /// <param name="tx">the transfer syntax to try (default is Implicit little endian)</param>
        /// <returns>whether or not the read was successfull</returns>
        public bool TryReadAs <T>(out T outValue) where T : IDICOMElement
        {
            var vr = VRDictionary.GetVRFromType(typeof(T));

            try
            {
                var el = ElementFactory.GenerateElement(Tag, vr, Data_.ToArray(), TransferSyntax, StringEncoding.ISO_IR_192);
                outValue = (T)el;
                return(true);
            }
            catch (Exception e)
            {
                _logger.LogInformation("Couldn't cast unknown type as type {0} for {1}", LogPriority.ERROR, typeof(T),
                                       Tag);
                outValue = default(T);
                return(false);
            }
        }