public DicomDatasetWalkerTest()
        {
            var dataset = new DicomDataset(
                new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.RTDoseStorage),
                new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3"),
                new DicomDate(DicomTag.AcquisitionDate, DateTime.Today),
                new DicomPersonName(DicomTag.ConsultingPhysicianName, "Doe", "John"),
                new DicomDecimalString(DicomTag.GridFrameOffsetVector, 1.0m, 2.0m, 3.0m, 4.0m, 5.0m, 6.0m),
                new DicomSequence(
                    DicomTag.BeamSequence,
                    new DicomDataset(
                        new DicomIntegerString(DicomTag.BeamNumber, 1),
                        new DicomDecimalString(DicomTag.FinalCumulativeMetersetWeight, 1.0m),
                        new DicomLongString(DicomTag.BeamName, "Ant")),
                    new DicomDataset(
                        new DicomIntegerString(DicomTag.BeamNumber, 2),
                        new DicomDecimalString(DicomTag.FinalCumulativeMetersetWeight, 100.0m),
                        new DicomLongString(DicomTag.BeamName, "Post")),
                    new DicomDataset(
                        new DicomIntegerString(DicomTag.BeamNumber, 3),
                        new DicomDecimalString(DicomTag.FinalCumulativeMetersetWeight, 2.0m),
                        new DicomLongString(DicomTag.BeamName, "Left"))),
                new DicomIntegerString(DicomTag.NumberOfContourPoints, 120));

            _walker     = new DicomDatasetWalker(dataset);
            _walkerImpl = new DatasetWalkerImpl();
        }
Beispiel #2
0
        private void OnCompletePreamble(IByteTarget target, object state)
        {
            DicomWriter        writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
            DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);

            walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
        }
Beispiel #3
0
		private void OnCompletePreamble(IByteTarget target, object state) {
			// recalculate FMI group length as required by standard
			_fileMetaInfo.RecalculateGroupLengths();

			DicomWriter writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
			DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);
			walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
		}
Beispiel #4
0
        private void OnCompletePreamble(IByteTarget target, object state)
        {
            // recalculate FMI group length as required by standard
            _fileMetaInfo.RecalculateGroupLengths();

            DicomWriter        writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
            DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);

            walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
        }
Beispiel #5
0
        private static Task WalkDatasetAsync(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            var writer = new DicomWriter(syntax, options, target);
            var walker = new DicomDatasetWalker(dataset);

            return(walker.WalkAsync(writer));
        }
Beispiel #6
0
        private static void WalkDataset(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            var writer = new DicomWriter(syntax, options, target);
            var walker = new DicomDatasetWalker(dataset);

            walker.Walk(writer);
        }
Beispiel #7
0
 private void OnCompleteDataset(IAsyncResult result)
 {
     try {
         DicomDatasetWalker walker = result.AsyncState as DicomDatasetWalker;
         walker.EndWalk(result);
     } catch (Exception e) {
         _exception = e;
     } finally {
         _async.Set();
     }
 }
Beispiel #8
0
        public string Get(string patientid)
        {
            var dataset = m_WorklistRepository.WorklistItems.FirstOrDefault(i => i.Get <string>(DicomTag.PatientID) == patientid);

            var log = new StringBuilder();
            IDicomDatasetWalker walkerTexasRanger = new DicomDatasetDumper(log);
            var a = new DicomDatasetWalker(dataset);

            a.Walk(walkerTexasRanger);


            return(log.ToString());
        }
        ////不支持.net4
        ///// <summary>
        ///// Write DICOM file preamble.
        ///// </summary>
        ///// <param name="target">Byte target subject to writing.</param>
        //private static Task WritePreambleAsync(IByteTarget target)
        //{
        //    var preamble = new byte[132];
        //    preamble[128] = (byte)'D';
        //    preamble[129] = (byte)'I';
        //    preamble[130] = (byte)'C';
        //    preamble[131] = (byte)'M';

        //    return target.WriteAsync(preamble, 0, 132);
        //}

        /// <summary>
        /// Write DICOM file meta information.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="fileMetaInfo">File meta information.</param>
        /// <param name="options">Writer options.</param>
        private static void WriteFileMetaInfo(
            IByteTarget target,
            DicomDataset fileMetaInfo,
            DicomWriteOptions options)
        {
            // recalculate FMI group length as required by standard
            fileMetaInfo.RecalculateGroupLengths();

            var writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, options, target);
            var walker = new DicomDatasetWalker(fileMetaInfo);

            walker.Walk(writer);
        }
Beispiel #10
0
        public string Get()
        {
            var datasets = m_WorklistRepository.WorklistItems.ToList();

            var log = new StringBuilder();

            foreach (var dataset in datasets)
            {
                log.AppendLine("-------------------------------------------------------------------------------------------------");
                IDicomDatasetWalker walkerTexasRanger = new DicomDatasetDumper(log);

                var a = new DicomDatasetWalker(dataset);
                a.Walk(walkerTexasRanger);
            }

            return(log.ToString());
        }
Beispiel #11
0
        private DicomDataset DeepClone_(DicomDataset dataset)
        {
            var ms     = new MemoryStream();
            var target = new StreamByteTarget(ms);
            var writer = new DicomWriter(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default, target);
            var walker = new DicomDatasetWalker(dataset);

            walker.Walk(writer);

            var clone  = new DicomDataset();
            var reader = new DicomReader {
                IsExplicitVR = false
            };
            var byteSource = new ByteBufferByteSource(
                new MemoryByteBuffer(ms.ToArray()));

            reader.Read(byteSource, new DicomDatasetReaderObserver(clone));
            return(clone);
        }
Beispiel #12
0
        public void DicomDatasetDumper_ShallNotThrow_OnLongPrivateTags()
        {
            var dataSet = new DicomDataset(new List <DicomItem>
            {
                new DicomUniqueIdentifier(
                    new DicomTag(0x0029, 0x1009, "A VERY LONG PRIVATE CREATOR THAT SHOULD WORK BUT IT DOESN'T"),
                    "123456789.123456789.123456789")
            });

            var stringBuilder = new StringBuilder();
            var dumper        = new DicomDatasetDumper(stringBuilder, 128, 64);
            var walker        = new DicomDatasetWalker(dataSet);

            walker.Walk(dumper);

            var expected = "(0029,1009:A VERY LONG PRIVATE CREATOR THAT SHOULD WORK BUT IT DOESN'T) UI [123456789.123456789.123456789]#    30, Unknown" + Environment.NewLine;
            var actual   = stringBuilder.ToString();

            Assert.Equal(expected, actual);
        }
Beispiel #13
0
        private void OnCompleteFileMetaInfo(IAsyncResult result)
        {
            try {
                DicomDatasetWalker walker;

                if (result != null)
                {
                    walker = result.AsyncState as DicomDatasetWalker;
                    walker.EndWalk(result);
                }

                DicomTransferSyntax syntax = _fileMetaInfo.TransferSyntax;

                DicomWriter writer = new DicomWriter(syntax, _options, _target);
                walker = new DicomDatasetWalker(_dataset);
                walker.BeginWalk(writer, OnCompleteDataset, walker);
            } catch (Exception e) {
                _exception = e;
                _async.Set();
            }
        }
Beispiel #14
0
        private void OnCompleteFileMetaInfo(IAsyncResult result)
        {
            try {
                DicomDatasetWalker walker;

                if (result != null)
                {
                    walker = result.AsyncState as DicomDatasetWalker;
                    walker.EndWalk(result);
                }

                //DicomTransferSyntax syntax = _fileMetaInfo.TransferSyntax;
                DicomTransferSyntax syntax = _fileMetaInfo.InternalTransferSyntax;
                if (_options.KeepGroupLengths)
                {
                    // update transfer syntax and recalculate existing group lengths
                    _dataset.InternalTransferSyntax = syntax;
                    _dataset.RecalculateGroupLengths(false);
                }
                else
                {
                    // remove group lengths as suggested in PS 3.5 7.2
                    //
                    //	2. It is recommended that Group Length elements be removed during storage or transfer
                    //	   in order to avoid the risk of inconsistencies arising during coercion of data
                    //	   element values and changes in transfer syntax.
                    _dataset.RemoveGroupLengths();
                }

                DicomWriter writer = new DicomWriter(syntax, _options, _target);
                walker = new DicomDatasetWalker(_dataset);
                walker.BeginWalk(writer, OnCompleteDataset, walker);
            } catch (Exception e) {
                _exception = e;
                _async.Set();
            }
        }
Beispiel #15
0
        private void OnCompleteFileMetaInfo(IAsyncResult result)
        {
            try
            {
                DicomDatasetWalker walker;

                if (result != null)
                {
                    walker = result.AsyncState as DicomDatasetWalker;
                    walker.EndWalk(result);
                }

                DicomTransferSyntax syntax = _fileMetaInfo.TransferSyntax;

                if (_options.KeepGroupLengths)
                {
                    // update transfer syntax and recalculate existing group lengths
                    _dataset.InternalTransferSyntax = syntax;
                    _dataset.RecalculateGroupLengths(false);
                }
                else
                {
                    // remove group lengths as suggested in PS 3.5 7.2
                    //
                    //	2. It is recommended that Group Length elements be removed during storage or transfer
                    //	   in order to avoid the risk of inconsistencies arising during coercion of data
                    //	   element values and changes in transfer syntax.
                    _dataset.RemoveGroupLengths();
                }

                DicomWriter writer = new DicomWriter(syntax, _options, _target);
                walker = new DicomDatasetWalker(_dataset);
                walker.BeginWalk(writer, OnCompleteDataset, walker);
            }
            catch (Exception e)
            {
                _exception = e;
                _async.Set();
            }
        }
Beispiel #16
0
 public void OnBeginWalk(DicomDatasetWalker walker, DicomDatasetWalkerCallback callback)
 {
     _target.Endian = _syntax.Endian;
     _callback = callback;
     _sequences = new Stack<DicomSequence>();
 }
Beispiel #17
0
 private void OnCompletePreamble(IByteTarget target, object state)
 {
     DicomWriter writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, _options, _target);
     DicomDatasetWalker walker = new DicomDatasetWalker(_fileMetaInfo);
     walker.BeginWalk(writer, OnCompleteFileMetaInfo, walker);
 }
Beispiel #18
0
        private void OnCompleteFileMetaInfo(IAsyncResult result)
        {
            try {
                DicomDatasetWalker walker;

                if (result != null) {
                    walker = result.AsyncState as DicomDatasetWalker;
                    walker.EndWalk(result);
                }

                DicomTransferSyntax syntax = _fileMetaInfo.TransferSyntax;

                DicomWriter writer = new DicomWriter(syntax, _options, _target);
                walker = new DicomDatasetWalker(_dataset);
                walker.BeginWalk(writer, OnCompleteDataset, walker);
            } catch (Exception e) {
                _exception = e;
                _async.Set();
            }
        }
 public void OnBeginWalk(DicomDatasetWalker walker, DicomDatasetWalkerCallback callback)
 {
 }
        /// <summary>
        /// Write DICOM dataset.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="syntax">Transfer syntax applicable to dataset.</param>
        /// <param name="dataset">Dataset.</param>
        /// <param name="options">Writer options.</param>
        private static Task WriteDatasetAsync(
            IByteTarget target,
            DicomTransferSyntax syntax,
            DicomDataset dataset,
            DicomWriteOptions options)
        {
            UpdateDatasetGroupLengths(syntax, dataset, options);

            var writer = new DicomWriter(syntax, options, target);
            var walker = new DicomDatasetWalker(dataset);
            return walker.WalkAsync(writer);
        }
		public void OnBeginWalk(DicomDatasetWalker walker, DicomDatasetWalkerCallback callback) {
		}
        /// <summary>
        /// Write DICOM file meta information.
        /// </summary>
        /// <param name="target">Byte target subject to writing.</param>
        /// <param name="fileMetaInfo">File meta information.</param>
        /// <param name="options">Writer options.</param>
        private static void WriteFileMetaInfo(
            IByteTarget target,
            DicomDataset fileMetaInfo,
            DicomWriteOptions options)
        {
            // recalculate FMI group length as required by standard
            fileMetaInfo.RecalculateGroupLengths();

            var writer = new DicomWriter(DicomTransferSyntax.ExplicitVRLittleEndian, options, target);
            var walker = new DicomDatasetWalker(fileMetaInfo);
            walker.Walk(writer);
        }
Beispiel #23
0
 public void OnBeginWalk(DicomDatasetWalker walker, DicomDatasetWalkerCallback callback)
 {
     _target.Endian = _syntax.Endian;
     _callback      = callback;
     _sequences     = new Stack <DicomSequence>();
 }
Beispiel #24
0
 private static void WalkDataset(
     IByteTarget target,
     DicomTransferSyntax syntax,
     DicomDataset dataset,
     DicomWriteOptions options)
 {
     var writer = new DicomWriter(syntax, options, target);
     var walker = new DicomDatasetWalker(dataset);
     walker.Walk(writer);
 }