Reads a DICOM dataset from a stream
コード例 #1
0
ファイル: DicomStreamReader.cs プロジェクト: evrimulgen/mdcm
        private DicomReadStatus ParseSequenceItemDataset(DicomTransferSyntax syntax, long len, out DcmDataset dataset, DicomReadOptions options)
        {
            long pos = _stream.Position;

            dataset = new DcmDataset(pos, (uint)len, syntax);

            Stream stream = (len != UndefinedLength) ? new SegmentStream(_stream, _stream.Position, _len) : _stream;

            DicomStreamReader idsr = new DicomStreamReader(stream);

            idsr.Dataset  = dataset;
            idsr.Encoding = _encoding;
            if (len != UndefinedLength)
            {
                idsr.PositionOffset = dataset.StreamPosition;
            }

            DicomReadStatus status = idsr.Read(null, options);

            if (status != DicomReadStatus.Success)
            {
                _stream.Seek(pos, SeekOrigin.Begin);
                dataset = null;
            }
            else
            {
                if (len == UndefinedLength)
                {
                    // rewind delimitation item tag
                    _stream.Seek(-4, SeekOrigin.Current);

                    len = _stream.Position - pos;
                }

                _remain -= len;
                _bytes  += len;
                _read   += len;
            }

            return(status);
        }
コード例 #2
0
ファイル: DcmNetworkBase.cs プロジェクト: JeanLedesma/mdcm
 public void CloseDataset()
 {
     DatasetStream = null;
     DatasetData = null;
     DatasetReader = null;
     if (DatasetFileStream != null) {
         DatasetFileStream.Dispose();
         DatasetFileStream = null;
     }
 }
コード例 #3
0
ファイル: DcmNetworkBase.cs プロジェクト: JeanLedesma/mdcm
 public void CloseCommand()
 {
     CommandData = null;
     CommandReader = null;
 }
コード例 #4
0
ファイル: DicomStreamReader.cs プロジェクト: JeanLedesma/mdcm
        private DicomReadStatus ParseSequenceItemDataset(DicomTransferSyntax syntax, long len, out DcmDataset dataset, DicomReadOptions options)
        {
            long pos = _stream.Position;

            dataset = new DcmDataset(pos, (uint)len, syntax);

            Stream stream = (len != UndefinedLength) ? new SegmentStream(_stream, _stream.Position, _len) : _stream;

            DicomStreamReader idsr = new DicomStreamReader(stream);
            idsr.Dataset = dataset;
            idsr.Encoding = _encoding;
            if (len != UndefinedLength)
                idsr.PositionOffset = dataset.StreamPosition;

            DicomReadStatus status = idsr.Read(null, options);

            if (status != DicomReadStatus.Success) {
                _stream.Seek(pos, SeekOrigin.Begin);
                dataset = null;
            }
            else {
                if (len == UndefinedLength) {
                    // rewind delimitation item tag
                    _stream.Seek(-4, SeekOrigin.Current);

                    len = _stream.Position - pos;
                }

                _remain -= len;
                _bytes += len;
                _read += len;
            }

            return status;
        }
コード例 #5
0
		/// <summary>
		/// Gets file stream starting at DICOM dataset
		/// </summary>
		/// <param name="file">Filename</param>
		/// <returns>File stream</returns>
		public static FileStream GetDatasetStream(String file) {
			FileStream fs = File.OpenRead(file);
			fs.Seek(128, SeekOrigin.Begin);
			CheckFileHeader(fs);
			DicomStreamReader dsr = new DicomStreamReader(fs);
			DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
			dsr.Dataset = metainfo;
			if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) {
				return fs;
			}
			fs.Close();
			return null;
		}
コード例 #6
0
		/// <summary>
		/// Gets the file meta information from a DICOM file
		/// </summary>
		/// <param name="file">Filename</param>
		/// <returns>File meta information</returns>
		public static DcmFileMetaInfo LoadFileMetaInfo(String file) {
			using (FileStream fs = File.OpenRead(file)) {
				fs.Seek(128, SeekOrigin.Begin);
				CheckFileHeader(fs);
				DicomStreamReader dsr = new DicomStreamReader(fs);
				DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
				dsr.Dataset = metainfo;
				dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly);
				fs.Close();
				return metainfo;
			}
		}
コード例 #7
0
		/// <summary>
		/// Loads a dicom file, stopping at a certain tag
		/// </summary>
		/// <param name="file">Filename</param>
		/// <param name="stopTag">Tag to stop parsing at</param>
		/// <param name="options">DICOM read options</param>
		public DicomReadStatus Load(String file, DicomTag stopTag, DicomReadOptions options) {
			using (FileStream fs = File.OpenRead(file)) {
				fs.Seek(128, SeekOrigin.Begin);
				CheckFileHeader(fs);
				DicomStreamReader dsr = new DicomStreamReader(fs);

				_metainfo = new DcmFileMetaInfo();
				dsr.Dataset = _metainfo;
				dsr.Read(DcmFileMetaInfo.StopTag, options | DicomReadOptions.FileMetaInfoOnly);

				if (_metainfo.TransferSyntax.IsDeflate) {
					MemoryStream ms = StreamUtility.Deflate(fs, false);
					dsr = new DicomStreamReader(ms);
				}

				_dataset = new DcmDataset(_metainfo.TransferSyntax);
				dsr.Dataset = _dataset;
				DicomReadStatus status = dsr.Read(stopTag, options);

				fs.Close();

				return status;
			}
		}
コード例 #8
0
ファイル: DicomFileFormat.cs プロジェクト: fo-dicom/mdcm
 /// <summary>
 /// Gets the file meta information from a DICOM file
 /// </summary>
 /// <param name="file">Filename</param>
 /// <param name="useIsoStore">Load file from isolated storage</param>
 /// <returns>File meta information</returns>
 public static DcmFileMetaInfo LoadFileMetaInfo(String file, bool useIsoStore = false)
 {
     if (useIsoStore)
     {
         using (var store = IsolatedStorageFile.GetUserStoreForApplication())
         {
             using (var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read))
             {
                 fs.Seek(128, SeekOrigin.Begin);
                 if (!CheckFileHeader(fs)) return null;
                 DicomStreamReader dsr = new DicomStreamReader(fs);
                 DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
                 dsr.Dataset = metainfo;
                 dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly);
                 fs.Close();
                 return metainfo;
             }
         }
     }
     else
     {
         using (var fs = File.OpenRead(file))
         {
             fs.Seek(128, SeekOrigin.Begin);
             CheckFileHeader(fs);
             DicomStreamReader dsr = new DicomStreamReader(fs);
             DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
             dsr.Dataset = metainfo;
             dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly);
             fs.Close();
             return metainfo;
         }
     }
 }
コード例 #9
0
ファイル: DicomFileFormat.cs プロジェクト: fo-dicom/mdcm
 /// <summary>
 /// Gets file stream starting at DICOM dataset
 /// </summary>
 /// <param name="file">Filename</param>
 /// <param name="useIsoStore">Get dataset from isolated store</param>
 /// <returns>File stream</returns>
 public static FileStream GetDatasetStream(String file, bool useIsoStore = false)
 {
     if (useIsoStore)
     {
         using (var store = IsolatedStorageFile.GetUserStoreForApplication())
         {
             var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read);
             fs.Seek(128, SeekOrigin.Begin);
             CheckFileHeader(fs);
             DicomStreamReader dsr = new DicomStreamReader(fs);
             DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
             dsr.Dataset = metainfo;
             if (
                 dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) ==
                 DicomReadStatus.Success && fs.Position < fs.Length)
             {
                 return fs;
             }
             fs.Close();
             return null;
         }
     }
     else
     {
         FileStream fs = File.OpenRead(file);
         fs.Seek(128, SeekOrigin.Begin);
         CheckFileHeader(fs);
         DicomStreamReader dsr = new DicomStreamReader(fs);
         DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
         dsr.Dataset = metainfo;
         if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length)
         {
             return fs;
         }
         fs.Close();
         return null;
     }
 }
コード例 #10
0
        /// <summary>
        /// Loads a dicom file from a stream, stopping at a certain tag
        /// </summary>
        /// <param name="stream">Stream containing DICOM file</param>
        /// <param name="stopTag">Tag to stop parsing at</param>
        /// <param name="options">DICOM read options</param>
        public DicomReadStatus Load(Stream stream, DicomTag stopTag, DicomReadOptions options)
        {
            stream.Seek(128, SeekOrigin.Begin);
            CheckFileHeader(stream);
            DicomStreamReader dsr = new DicomStreamReader(stream);

            _metainfo = new DcmFileMetaInfo();
            dsr.Dataset = _metainfo;
            dsr.Read(DcmFileMetaInfo.StopTag, options | DicomReadOptions.FileMetaInfoOnly);

            if (_metainfo.TransferSyntax.IsDeflate)
            {
                MemoryStream ms = StreamUtility.Deflate(stream, false);
                dsr = new DicomStreamReader(ms);
            }

            _dataset = new DcmDataset(_metainfo.TransferSyntax);
            dsr.Dataset = _dataset;
            DicomReadStatus status = dsr.Read(stopTag, options);
            return status;
        }
コード例 #11
0
 /// <summary>
 /// Loads the meta information from a DICOM file in a stream.
 /// Note that the caller is expected to dispose of the stream after usage.
 /// </summary>
 /// <param name="stream">The stream fontaining the DICOM file</param>
 /// <returns>File meta information</returns>
 public static DcmFileMetaInfo LoadFileMetaInfo(Stream stream)
 {
     stream.Seek(128, SeekOrigin.Begin);
     CheckFileHeader(stream);
     DicomStreamReader dsr = new DicomStreamReader(stream);
     DcmFileMetaInfo metainfo = new DcmFileMetaInfo();
     dsr.Dataset = metainfo;
     dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly);
     return metainfo;
 }