当前位置: 首页>>代码示例>>C#>>正文


C# IByteSource.Rewind方法代码示例

本文整理汇总了C#中IByteSource.Rewind方法的典型用法代码示例。如果您正苦于以下问题:C# IByteSource.Rewind方法的具体用法?C# IByteSource.Rewind怎么用?C# IByteSource.Rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IByteSource的用法示例。


在下文中一共展示了IByteSource.Rewind方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsPrivateSequence

		private bool IsPrivateSequence(IByteSource source) {
			source.Mark();

			try {
				var group = source.GetUInt16();
				var element = source.GetUInt16();
				var tag = new DicomTag(group, element);

				if (tag == DicomTag.Item || tag == DicomTag.SequenceDelimitationItem)
					return true;
			} finally {
				source.Rewind();
			}

			return false;
		}
开发者ID:peerct,项目名称:fo-dicom,代码行数:16,代码来源:DicomReader.cs

示例2: IsPrivateSequenceBad

		private bool IsPrivateSequenceBad(IByteSource source) {
			source.Mark();

			try {
				var group = source.GetUInt16();
				var element = source.GetUInt16();
				var tag = new DicomTag(group, element);
				var length = source.GetUInt32();

				group = source.GetUInt16();
				element = source.GetUInt16();
				tag = new DicomTag(group, element);

				byte[] bytes = source.GetBytes(2);
				string vr = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
				try {
					DicomVR.Parse(vr);
					return !_explicit;
				} catch {
					// unable to parse VR
					if (_explicit)
						return true;
				}
			} finally {
				source.Rewind();
			}

			return false;
		}
开发者ID:peerct,项目名称:fo-dicom,代码行数:29,代码来源:DicomReader.cs

示例3: ParseItemSequenceTag

            private bool ParseItemSequenceTag(IByteSource source)
            {
                if (this.parseStage == ParseStage.Tag)
                {
                    source.Mark();

                    if (!source.Require(8))
                    {
                        this.result = DicomReaderResult.Suspended;
                        return false;
                    }

                    var group = source.GetUInt16();
                    var element = source.GetUInt16();

                    this._tag = new DicomTag(@group, element);

                    if (this._tag != DicomTag.Item && this._tag != DicomTag.SequenceDelimitationItem)
                    {
                        // assume invalid sequence
                        source.Rewind();
                        if (!this._implicit)
                        {
                            source.PopMilestone();
                        }
                        this.observer.OnEndSequence();
                        if (this.badPrivateSequence)
                        {
                            this.isExplicitVR = !this.isExplicitVR;
                            this.badPrivateSequence = false;
                        }
                        return false;
                    }

                    this.length = source.GetUInt32();

                    if (this._tag == DicomTag.SequenceDelimitationItem)
                    {
                        // #64, in case explicit length has been specified despite occurrence of Sequence Delimitation Item
                        if (source.HasReachedMilestone() && source.MilestonesCount > this.sequenceDepth)
                        {
                            this.ResetState();
                            return true;
                        }

                        // end of sequence
                        this.observer.OnEndSequence();
                        if (this.badPrivateSequence)
                        {
                            this.isExplicitVR = !this.isExplicitVR;
                            this.badPrivateSequence = false;
                        }
                        this.ResetState();
                        return false;
                    }

                    this.parseStage = ParseStage.Value;
                }
                return true;
            }
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:60,代码来源:DicomReader.cs

示例4: ParseItemSequence

		private void ParseItemSequence(IByteSource source, object state) {
			try {
				_result = DicomReaderResult.Processing;

				while (!source.IsEOF && !source.HasReachedMilestone()) {
					if (_state == ParseState.Tag) {
						source.Mark();

						if (!source.Require(8, ParseItemSequence, state)) {
							_result = DicomReaderResult.Suspended;
							return;
						}

						ushort group = source.GetUInt16();
						ushort element = source.GetUInt16();

						_tag = new DicomTag(group, element);

						if (_tag != DicomTag.Item && _tag != DicomTag.SequenceDelimitationItem) {
							// assume invalid sequence
							source.Rewind();
							if (!_implicit)
								source.PopMilestone();
							_observer.OnEndSequence();
							if (_badPrivateSequence) {
								_explicit = !_explicit;
								_badPrivateSequence = false;
							}
							return;
						}

						_length = source.GetUInt32();

						if (_tag == DicomTag.SequenceDelimitationItem) {
							// end of sequence
							_observer.OnEndSequence();
							if (_badPrivateSequence) {
								_explicit = !_explicit;
								_badPrivateSequence = false;
							}
							ResetState();
							return;
						}

						_state = ParseState.Value;
					}

					if (_state == ParseState.Value) {
						if (_length != UndefinedLength) {
							if (!source.Require(_length, ParseItemSequence, state)) {
								_result = DicomReaderResult.Suspended;
								return;
							}

							source.PushMilestone(_length);
						}

						_observer.OnBeginSequenceItem(source, _length);

						ResetState();
						ParseDataset(source, state);
						ResetState();

						_observer.OnEndSequenceItem();
						continue;
					}
				}

				// end of explicit length sequence
				if (source.HasReachedMilestone())
					source.PopMilestone();

				_observer.OnEndSequence();
				if (_badPrivateSequence) {
					_explicit = !_explicit;
					_badPrivateSequence = false;
				}
			} catch (Exception e) {
				_exception = e;
				_result = DicomReaderResult.Error;
			} finally {
				if (_result != DicomReaderResult.Processing && _result != DicomReaderResult.Suspended) {
					_async.Set();
				}
			}
		}
开发者ID:peerct,项目名称:fo-dicom,代码行数:86,代码来源:DicomReader.cs

示例5: IsPrivateSequenceBad

            private static bool IsPrivateSequenceBad(IByteSource source, bool isExplicitVR)
            {
                source.Mark();

                try
                {
                    source.GetUInt16(); // group
                    source.GetUInt16(); // element
                    source.GetUInt32(); // length

                    source.GetUInt16(); // group
                    source.GetUInt16(); // element

                    var bytes = source.GetBytes(2);
                    var vr = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                    DicomVR dummy;
                    if (DicomVR.TryParse(vr, out dummy)) return !isExplicitVR;
                    // unable to parse VR
                    if (isExplicitVR) return true;
                }
                finally
                {
                    source.Rewind();
                }

                return false;
            }
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:27,代码来源:DicomReader.cs

示例6: ParseVR

            private bool ParseVR(IByteSource source)
            {
                while (this.parseStage == ParseStage.VR)
                {
                    if (this._tag == DicomTag.Item || this._tag == DicomTag.ItemDelimitationItem
                        || this._tag == DicomTag.SequenceDelimitationItem)
                    {
                        this._vr = DicomVR.NONE;
                        this.parseStage = ParseStage.Length;
                        break;
                    }

                    if (this.isExplicitVR)
                    {
                        if (!source.Require(2))
                        {
                            this.result = DicomReaderResult.Suspended;
                            return false;
                        }

                        source.Mark();
                        var bytes = source.GetBytes(2);
                        var vr = Encoding.UTF8.GetString(bytes, 0, bytes.Length);

                        if (string.IsNullOrWhiteSpace(vr))
                        {
                            if (this._entry != null)
                            {
                                this._vr = this._entry.ValueRepresentations.FirstOrDefault();
                            }
                        }
                        else if (!DicomVR.TryParse(vr, out this._vr))
                        {
                            // unable to parse VR; rewind VR bytes for continued attempt to interpret the data.
                            this._vr = DicomVR.Implicit;
                            source.Rewind();
                        }
                    }
                    else
                    {
                        if (this._entry != null)
                        {
                            if (this._entry == DicomDictionary.UnknownTag)
                            {
                                this._vr = DicomVR.UN;
                            }
                            else if (this._entry.ValueRepresentations.Contains(DicomVR.OB)
                                     && this._entry.ValueRepresentations.Contains(DicomVR.OW))
                            {
                                this._vr = DicomVR.OW; // ???
                            }
                            else
                            {
                                this._vr = this._entry.ValueRepresentations.FirstOrDefault();
                            }
                        }
                    }

                    if (this._vr == null)
                    {
                        this._vr = DicomVR.UN;
                    }

                    this.parseStage = ParseStage.Length;

                    if (this._vr == DicomVR.UN)
                    {
                        if (this._tag.Element == 0x0000)
                        {
                            // Group Length to UL
                            this._vr = DicomVR.UL;
                            break;
                        }
                        if (this.isExplicitVR)
                        {
                            break;
                        }
                    }

                    if (this._tag.IsPrivate)
                    {
                        if (this._tag.Element != 0x0000 && this._tag.Element <= 0x00ff && this._vr == DicomVR.UN)
                        {
                            this._vr = DicomVR.LO; // force private creator to LO
                        }
                    }
                }
                return true;
            }
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:89,代码来源:DicomReader.cs

示例7: DoParseAsync

        private static async Task<Tuple<DicomReaderResult, DicomFileFormat, DicomTransferSyntax>> DoParseAsync(
            IByteSource source,
            IDicomReaderObserver fileMetasetInfoObserver,
            IDicomReaderObserver datasetObserver,
            Func<ParseState, bool> stop,
            DicomTransferSyntax syntax,
            DicomFileFormat fileFormat)
        {
            string code = null, uid = null;
            var obs = new DicomReaderCallbackObserver();
            if (fileFormat != DicomFileFormat.DICOM3)
            {
                obs.Add(
                    DicomTag.RecognitionCodeRETIRED,
                    (sender, ea) =>
                        {
                            try
                            {
                                code = Encoding.UTF8.GetString(ea.Data.Data, 0, ea.Data.Data.Length);
                            }
                            catch
                            {
                            }
                        });
            }
            obs.Add(
                DicomTag.TransferSyntaxUID,
                (sender, ea) =>
                    {
                        try
                        {
                            uid = Encoding.UTF8.GetString(ea.Data.Data, 0, ea.Data.Data.Length);
                        }
                        catch
                        {
                        }
                    });

            var reader = new DicomReader { IsExplicitVR = syntax.IsExplicitVR, IsDeflated = false };

            DicomReaderResult result;
            if (fileFormat == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                result =
                    await
                    reader.ReadAsync(source, new DicomReaderMultiObserver(obs, datasetObserver), stop).ConfigureAwait(false);
                UpdateFileFormatAndSyntax(code, uid, ref fileFormat, ref syntax);
            }
            else
            {
                if (
                    await
                    reader.ReadAsync(
                        source,
                        new DicomReaderMultiObserver(obs, fileMetasetInfoObserver),
                        FileMetaInfoStopCriterion).ConfigureAwait(false) != DicomReaderResult.Stopped)
                {
                    throw new DicomReaderException("DICOM File Meta Info ended prematurely");
                }

                UpdateFileFormatAndSyntax(code, uid, ref fileFormat, ref syntax);

                // rewind to last marker (start of previous tag)... ugly because 
                // it requires knowledge of how the parser is implemented
                source.Rewind();

                source.Endian = syntax.Endian;
                reader.IsExplicitVR = syntax.IsExplicitVR;
                reader.IsDeflated = syntax.IsDeflate;
                result = await reader.ReadAsync(source, datasetObserver, stop).ConfigureAwait(false);
            }

            return Tuple.Create(result, fileFormat, syntax);
        }
开发者ID:aerik,项目名称:fo-dicom,代码行数:74,代码来源:DicomFileReader.cs

示例8: Preprocess

        private static void Preprocess(
            IByteSource source,
            ref DicomFileFormat fileFormat,
            ref DicomTransferSyntax syntax)
        {
            // mark file origin
            source.Mark();

            // test for DICM preamble
            source.Skip(128);
            if (source.GetUInt8() == 'D' && source.GetUInt8() == 'I' && source.GetUInt8() == 'C'
                && source.GetUInt8() == 'M')
            {
                fileFormat = DicomFileFormat.DICOM3;
            }

            // test for incorrect syntax in file meta info
            do
            {
                if (fileFormat == DicomFileFormat.DICOM3)
                {
                    // move milestone to after preamble
                    source.Mark();
                }
                else
                {
                    // rewind to origin milestone
                    source.Rewind();
                }

                // test for file meta info
                var group = source.GetUInt16();

                if (@group > 0x00ff)
                {
                    source.Endian = Endian.Big;
                    syntax = DicomTransferSyntax.ExplicitVRBigEndian;

                    @group = Endian.Swap(@group);
                }

                if (@group > 0x00ff)
                {
                    // invalid starting tag
                    fileFormat = DicomFileFormat.Unknown;
                    source.Rewind();
                    break;
                }

                if (fileFormat == DicomFileFormat.Unknown)
                {
                    fileFormat = @group == 0x0002
                                     ? DicomFileFormat.DICOM3NoPreamble
                                     : DicomFileFormat.DICOM3NoFileMetaInfo;
                }

                var element = source.GetUInt16();
                var tag = new DicomTag(@group, element);

                // test for explicit VR
                var vrt = Encoding.UTF8.GetBytes(tag.DictionaryEntry.ValueRepresentations[0].Code);
                var vrs = source.GetBytes(2);

                if (vrt[0] != vrs[0] || vrt[1] != vrs[1])
                {
                    // implicit VR
                    syntax = syntax.Endian == Endian.Little
                                 ? DicomTransferSyntax.ImplicitVRLittleEndian
                                 : DicomTransferSyntax.ImplicitVRBigEndian;
                }

                source.Rewind();
            }
            while (fileFormat == DicomFileFormat.Unknown);

            if (fileFormat == DicomFileFormat.Unknown)
            {
                throw new DicomReaderException("Attempted to read invalid DICOM file");
            }

            // Adopt transfer syntax endianess to byte source.
            source.Endian = syntax.Endian;
        }
开发者ID:aerik,项目名称:fo-dicom,代码行数:83,代码来源:DicomFileReader.cs

示例9: ParseDataset

        private void ParseDataset(IByteSource source, object state)
        {
            try
            {
                _result = DicomReaderResult.Processing;

                while (!source.IsEOF && !source.HasReachedMilestone() && _result == DicomReaderResult.Processing)
                {
                    if (_state == ParseState.Tag)
                    {
                        source.Mark();

                        if (!source.Require(4, ParseDataset, state))
                        {
                            _result = DicomReaderResult.Suspended;
                            return;
                        }

                        ushort group = source.GetUInt16();
                        ushort element = source.GetUInt16();
                        DicomPrivateCreator creator = null;

                        if (group.IsOdd() && element > 0x00ff)
                        {
                            string pvt = null;
                            uint card = (uint)(group << 16) + (uint)(element >> 8);
                            if (_private.TryGetValue(card, out pvt)) creator = Dictionary.GetPrivateCreator(pvt);
                        }

                        _tag = new DicomTag(group, element, creator);
                        _entry = Dictionary[_tag];

                        if (!_tag.IsPrivate && _entry != null && _entry.MaskTag == null) _tag = _entry.Tag; // Use dictionary tag

                        if (_stop != null && _tag.CompareTo(_stop) >= 0)
                        {
                            _result = DicomReaderResult.Stopped;
                            return;
                        }

                        _state = ParseState.VR;
                    }

                    while (_state == ParseState.VR)
                    {
                        if (_tag == DicomTag.Item || _tag == DicomTag.ItemDelimitationItem
                            || _tag == DicomTag.SequenceDelimitationItem)
                        {
                            _vr = DicomVR.NONE;
                            _state = ParseState.Length;
                            break;
                        }

                        if (IsExplicitVR)
                        {
                            if (!source.Require(2, ParseDataset, state))
                            {
                                _result = DicomReaderResult.Suspended;
                                return;
                            }

                            source.Mark();
                            byte[] bytes = source.GetBytes(2);
                            string vr = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                            if (!DicomVR.TryParse(vr, out _vr))
                            {
                                // unable to parse VR; rewind VR bytes for continued attempt to interpret the data.
                                _vr = DicomVR.Implicit;
                                source.Rewind();
                            }
                        }
                        else
                        {
                            if (_entry != null)
                            {
                                if (_entry == DicomDictionary.UnknownTag) _vr = DicomVR.UN;
                                else if (_entry.ValueRepresentations.Contains(DicomVR.OB)
                                         && _entry.ValueRepresentations.Contains(DicomVR.OW)) _vr = DicomVR.OW; // ???
                                else _vr = _entry.ValueRepresentations.FirstOrDefault();
                            }
                        }

                        if (_vr == null) _vr = DicomVR.UN;

                        _state = ParseState.Length;

                        if (_vr == DicomVR.UN)
                        {
                            if (_tag.Element == 0x0000)
                            {
                                // Group Length to UL
                                _vr = DicomVR.UL;
                                break;
                            }
                            else if (IsExplicitVR)
                            {
                                break;
                            }
                        }

//.........这里部分代码省略.........
开发者ID:GMZ,项目名称:fo-dicom,代码行数:101,代码来源:DicomReader.cs

示例10: IsPrivateSequenceBad

            private static bool IsPrivateSequenceBad(IByteSource source, bool isExplicitVR)
            {
                source.Mark();

                try
                {
                    // Skip "item" tags; continue skipping until length is non-zero (#223)
                    while (new DicomTag(source.GetUInt16(), source.GetUInt16()) == DicomTag.Item    // group, element
                           & source.GetUInt32() == 0)   // length (using & instead of && enforces RHS to be evaluated regardless of LHS)
                    {
                    }

                    source.GetUInt16(); // group
                    source.GetUInt16(); // element

                    var bytes = source.GetBytes(2);
                    var vr = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
                    DicomVR dummy;
                    if (DicomVR.TryParse(vr, out dummy)) return !isExplicitVR;
                    // unable to parse VR
                    if (isExplicitVR) return true;
                }
                finally
                {
                    source.Rewind();
                }

                return false;
            }
开发者ID:aerik,项目名称:fo-dicom,代码行数:29,代码来源:DicomReader.cs

示例11: autoCheckTransferSyntax

        private void autoCheckTransferSyntax(IByteSource source, ushort group, ushort element, object state)
        {
            //start checking Transfer Syntax after reading premable bytes
            if (group > 0x0002 && !bAutoDetectVRType)
            {
                bAutoDetectVRType = true;//just check once
                source.Mark();//mark the original position of pointer
                //try to parse VR
                uint tmpLength = 0;
                source.Skip(2);
                if (!source.Require(2, ParseDataset, state))
                {
                    _result = DicomReaderResult.Suspended;
                    source.Rewind();
                    return;
                }
                tmpLength = source.GetUInt16();
                try
                {
                    if (!source.Require(tmpLength, ParseDataset, state))
                    {
                        _result = DicomReaderResult.Suspended;
                        source.Rewind();
                        return;
                    }
                    source.Skip((int)tmpLength);
                    if (!source.Require(4, ParseDataset, state))
                    {
                        _result = DicomReaderResult.Suspended;
                        source.Rewind();
                        return;
                    }
                    ushort group2 = source.GetUInt16();
                    ushort element2 = source.GetUInt16();
                    DicomPrivateCreator creator2 = null;
                    if (group2.IsOdd() && element2 > 0x00ff)
                    {
                        string pvt2 = null;
                        uint card2 = (uint)(group2 << 16) + (uint)(element2 >> 8);
                        if (_private.TryGetValue(card2, out pvt2))
                            creator2 = Dictionary.GetPrivateCreator(pvt2);
                    }
                    var tmpTag = new DicomTag(group2, element2, creator2);
                    var tmpEntry = Dictionary[tmpTag];

                    if (!tmpTag.IsPrivate && tmpEntry != null && tmpEntry.MaskTag == null)
                    {
                        tmpTag = tmpEntry.Tag; // Use dictionary tag
                        IsExplicitVR = true;
                    }
                    else
                    {
                        IsExplicitVR = false;
                    }
                    source.Rewind();
                }
                catch (Exception exin)
                {
                    source.Rewind();
                    //说明有错误,直接抛出异常
                    throw new DicomIoException("Auto Check Transfer Syntax Exception by zssure,Details:{0}", exin.StackTrace);

                }


            }

        }
开发者ID:ZeryZhang,项目名称:fo-dicom,代码行数:68,代码来源:DicomReader.cs


注:本文中的IByteSource.Rewind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。