Exemplo n.º 1
0
        public void WriteMultipleFl()
        {
            var vssd = DICOMForge.VirtualSourceAxisDistances();

            vssd.Data_ = new System.Collections.Generic.List <float>()
            {
                2538.4199f, 2541.00f
            };
            byte[] elBytes = null;
            using (var stream = new MemoryStream())
            {
                using (var dw = new DICOMBinaryWriter(stream))
                {
                    DICOMElementWriter.Write(dw, DICOMWriteSettings.DefaultExplicit(), vssd);
                    elBytes = stream.ToArray();
                }
            }

            AbstractElement <float> readVssd = null;

            using (var dr = new DICOMBinaryReader(elBytes))
            {
                readVssd = DICOMElementReader.ReadElementExplicitLittleEndian(dr) as AbstractElement <float>;
            }

            Assert.AreEqual(readVssd.Data_.Count, 2);
            Assert.AreEqual(readVssd.Data_[0], 2538.4199f);
            Assert.AreEqual(readVssd.Data_[1], 2541.00f);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a clone of this DICOM object
        /// </summary>
        /// <returns>a new copied DICOM object</returns>
        public DICOMObject Clone()
        {
            List <IDICOMElement> copy = new List <IDICOMElement>();

            foreach (var el in Elements)
            {
                using (var ms = new MemoryStream())
                {
                    using (var dw = new DICOMBinaryWriter(ms))
                    {
                        DICOMElementWriter.Write(dw, DICOMIOSettings.Default(), el);
                    }
                    using (var dr = new DICOMBinaryReader(ms.ToArray()))
                    {
                        copy.Add(DICOMElementReader.ReadElementImplicitLittleEndian(dr));
                    }
                }
            }

            return(new DICOMObject(copy));
        }
Exemplo n.º 3
0
        public static (string Value, PreambleStatus Status) Read(string filePath, string group, string element)
        {
            TransferSyntax syntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN;
            PreambleStatus preambleStatus;
            DICOMObject    dicomObject = null;

            using (var dicomBinaryReader = new DICOMBinaryReader(filePath))
            {
                preambleStatus = Read(dicomBinaryReader);
                if (preambleStatus == PreambleStatus.Ok || preambleStatus == PreambleStatus.MismatchPreamble128)
                {
                    List <IDICOMElement> metaElements = DICOMFileReader.ReadFileMetadata(dicomBinaryReader, ref syntax);
                    List <IDICOMElement> elements     = metaElements.Concat(DICOMElementReader.ReadAllElements(dicomBinaryReader, syntax)).ToList();
                    dicomObject = new DICOMObject(elements);
                }
            }

            IDICOMElement value = dicomObject?.Elements.FirstOrDefault(d => d.Tag.Group == group && d.Tag.Element == element);

            return(value?.DData.ToString(), preambleStatus);
        }
Exemplo n.º 4
0
        public void WriteDecimalString()
        {
            var ds = new DecimalString();

            ds.DData_ = Enumerable.Range(1, 15000).Select(i => ((double)i) + 0.005).ToList();
            ds.Tag    = new Tag("00082130");
            byte[] written;
            var    settings = DICOMIOSettings.Default();

            using (var ms = new MemoryStream())
            {
                using (var dw = new DICOMBinaryWriter(ms))
                {
                    DICOMElementWriter.Write(dw, DICOMIOSettings.Default(), ds);
                }
                written = ms.ToArray();
            }

            using (var dr = new DICOMBinaryReader(written))
            {
                var read = DICOMElementReader.ReadElementImplicitLittleEndian(dr) as DecimalString;
                CollectionAssert.AreEqual(ds.DData_, read.Data_);
            }
        }