本文整理汇总了C#中DicomReadOptions类的典型用法代码示例。如果您正苦于以下问题:C# DicomReadOptions类的具体用法?C# DicomReadOptions怎么用?C# DicomReadOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DicomReadOptions类属于命名空间,在下文中一共展示了DicomReadOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ButtonLoadFile_Click
private void ButtonLoadFile_Click(object sender, EventArgs e)
{
openFileDialog.DefaultExt = "dcm";
openFileDialog.ShowDialog();
DicomFile dicomFile = new DicomFile(openFileDialog.FileName);
DicomReadOptions options = new DicomReadOptions();
dicomFile.Load(options);
_theStream.AddFile(dicomFile);
}
示例2: LoadFiles
private void LoadFiles(DirectoryInfo dir)
{
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
DicomFile dicomFile = new DicomFile(file.FullName);
try
{
DicomReadOptions options = new DicomReadOptions();
dicomFile.Load(options);
_theStream.AddFile(dicomFile);
/*
if (true == dicomFile.Load())
{
_theStream.AddFile(dicomFile);
}
* */
}
catch (DicomException)
{
// TODO: Add some logging for failed files
}
}
String[] subdirectories = Directory.GetDirectories(dir.FullName);
foreach (String subPath in subdirectories)
{
DirectoryInfo subDir = new DirectoryInfo(subPath);
LoadFiles(subDir);
continue;
}
}
示例3: CreateFrom
/// <summary>
/// Creates an instance of <see cref="DicomPixelData"/> from specified image path
/// </summary>
/// <param name="path"></param>
/// <param name="readOptions"></param>
/// <returns>
/// </returns>
public static DicomPixelData CreateFrom(string path, DicomReadOptions readOptions)
{
var file = new DicomFile(path);
file.Load(readOptions);
return CreateFrom(file);
}
示例4: Load
/// <summary>
/// Load a DICOM file (as set by the <see cref="Filename"/> property).
/// </summary>
/// <remarks>
/// Note: If the file does not contain DICM encoded in it, the routine will assume
/// the file is not a Part 10 format file, and is instead encoded as just a DataSet
/// with the transfer syntax set to Implicit VR Little Endian.
/// </remarks>
/// <param name="stopTag"></param>
/// <param name="options">The options to use when reading the file.</param>
public void Load(DicomTag stopTag, DicomReadOptions options)
{
using (FileStream fs = File.OpenRead(Filename))
{
Load(fs, stopTag, options);
fs.Close();
}
}
示例5: LoadCore
private void LoadCore(Stream stream, DicomStreamOpener streamOpener, DicomTag stopTag, DicomReadOptions options)
{
// TODO CR (24 Jan 2014): DICOM stream read only uses tag value, so the real implementation should be the uint overload!
if (stopTag == null)
stopTag = new DicomTag(0xFFFFFFFF, "Bogus Tag", "BogusTag", DicomVr.NONE, false, 1, 1, false);
DicomStreamReader dsr;
var iStream = stream ?? streamOpener.Open();
if (iStream.CanSeek)
{
iStream.Seek(128, SeekOrigin.Begin);
if (!FileHasPart10Header(iStream))
{
if (!Flags.IsSet(options, DicomReadOptions.ReadNonPart10Files))
throw new DicomException(String.Format("File is not part 10 format file: {0}", Filename));
iStream.Seek(0, SeekOrigin.Begin);
dsr = new DicomStreamReader(iStream)
{
StreamOpener = streamOpener,
TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
Dataset = DataSet
};
DicomReadStatus stat = dsr.Read(stopTag, options);
if (stat != DicomReadStatus.Success)
{
Platform.Log(LogLevel.Error, "Unexpected error when reading file: {0}", Filename);
throw new DicomException("Unexpected read error with file: " + Filename);
}
TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
if (DataSet.Contains(DicomTags.SopClassUid))
MediaStorageSopClassUid = DataSet[DicomTags.SopClassUid].ToString();
if (DataSet.Contains(DicomTags.SopInstanceUid))
MediaStorageSopInstanceUid = DataSet[DicomTags.SopInstanceUid].ToString();
Loaded = true;
return;
}
}
else
{
// TODO CR (04 Apr 2014): this code here is almost identical to the seekable stream above, except that we use the 4CC wrapper
// we can combine these two when we trust that the wrapper works in all cases
iStream = FourCcReadStream.Create(iStream);
// Read the 128 byte header first, then check for DICM
iStream.SeekEx(128, SeekOrigin.Begin);
if (!FileHasPart10Header(iStream))
{
if (!Flags.IsSet(options, DicomReadOptions.ReadNonPart10Files))
throw new DicomException(String.Format("File is not part 10 format file: {0}", Filename));
iStream.Seek(0, SeekOrigin.Begin);
dsr = new DicomStreamReader(iStream)
{
StreamOpener = streamOpener,
TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
Dataset = DataSet
};
DicomReadStatus stat = dsr.Read(stopTag, options);
if (stat != DicomReadStatus.Success)
{
Platform.Log(LogLevel.Error, "Unexpected error when reading file: {0}", Filename);
throw new DicomException("Unexpected read error with file: " + Filename);
}
TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
if (DataSet.Contains(DicomTags.SopClassUid))
MediaStorageSopClassUid = DataSet[DicomTags.SopClassUid].ToString();
if (DataSet.Contains(DicomTags.SopInstanceUid))
MediaStorageSopInstanceUid = DataSet[DicomTags.SopInstanceUid].ToString();
Loaded = true;
return;
}
}
dsr = new DicomStreamReader(iStream)
{
TransferSyntax = TransferSyntax.ExplicitVrLittleEndian,
StreamOpener = streamOpener,
Dataset = MetaInfo
};
DicomReadStatus readStat =
dsr.Read(new DicomTag(0x0002FFFF, "Bogus Tag", "BogusTag", DicomVr.UNvr, false, 1, 1, false), options);
if (readStat != DicomReadStatus.Success)
{
Platform.Log(LogLevel.Error, "Unexpected error when reading file Meta info for file: {0}", Filename);
throw new DicomException("Unexpected failure reading file Meta info for file: " + Filename);
}
MetaInfoFileLength = dsr.EndGroupTwo + 128 + 4;
dsr.Dataset = DataSet;
dsr.TransferSyntax = TransferSyntax;
readStat = dsr.Read(stopTag, options);
//.........这里部分代码省略.........
示例6: Load
/// <summary>
/// Load a DICOM file from an input stream, given a delegate to open the stream.
/// </summary>
/// <remarks>
/// Note: If the file does not contain DICM encoded in it, and
/// <see cref="Stream.CanSeek"/> is true for the stream returned by <paramref name="streamOpener"/>,
/// the routine will assume the file is not a Part 10 format file, and is
/// instead encoded as just a DataSet with the transfer syntax set to
/// Implicit VR Little Endian.
///
/// Also, if you are using the <see cref="DicomReadOptions.StorePixelDataReferences"/> option with
/// a <see cref="Stream"/> as opposed to simply a file name, you must use this method so that the
/// stream can be reopenened internally whenever pixel data is accessed.
/// </remarks>
/// <param name="streamOpener">A delegate that opens the stream to read from.</param>
/// <param name="stopTag">The dicom tag to stop the reading at.</param>
/// <param name="options">The dicom read options to consider.</param>
public void Load(DicomStreamOpener streamOpener, DicomTag stopTag, DicomReadOptions options)
{
Platform.CheckForNullReference(streamOpener, "streamOpener");
StreamOpener = streamOpener;
using (var stream = streamOpener.Open())
{
LoadCore(stream, streamOpener, stopTag, options);
stream.Close();
}
}
示例7: ParseVR
private DicomReadStatus ParseVR(DicomReadOptions options)
{
if (_vr == null) {
if (_syntax.IsExplicitVR) {
if (_remain >= 2) {
_vr = DicomVR.Lookup(_reader.ReadChars(2));
_remain -= 2;
_bytes += 2;
_read += 2;
}
else {
return NeedMoreData(2);
}
}
else {
if (_tag.Element == 0x0000)
_vr = DicomVR.UL;
else if (Flags.IsSet(options, DicomReadOptions.ForcePrivateCreatorToLO) &&
_tag.IsPrivate && _tag.Element > 0x0000 && _tag.Element <= 0x00ff)
_vr = DicomVR.UN;
else
_vr = _tag.Entry.DefaultVR;
}
if (_vr == DicomVR.UN) {
if (_tag.Element == 0x0000)
_vr = DicomVR.UL; // is this needed?
else if (_tag.IsPrivate) {
if (_tag.Element <= 0x00ff) {
// private creator id
} else if (_stream.CanSeek && Flags.IsSet(options, DicomReadOptions.AllowSeekingForContext)) {
// attempt to identify private sequence
long pos = _stream.Position;
if (_syntax.IsExplicitVR) {
if (_remain >= 2)
_reader.ReadUInt16();
else {
_vr = null;
_stream.Position = pos;
return NeedMoreData(2);
}
}
uint l = 0;
if (_remain >= 4) {
l = _reader.ReadUInt32();
if (l == UndefinedLength)
_vr = DicomVR.SQ;
} else {
_vr = null;
_stream.Position = pos;
return NeedMoreData(4);
}
//if (l != 0 && _vr == DicomVR.UN) {
// if (_remain >= 4) {
// ushort g = _reader.ReadUInt16();
// ushort e = _reader.ReadUInt16();
// DicomTag tag = new DicomTag(g, e);
// if (tag == DicomTags.Item || tag == DicomTags.SequenceDelimitationItem)
// _vr = DicomVR.SQ;
// } else {
// _vr = null;
// _stream.Position = pos;
// return NeedMoreData(4);
// }
//}
_stream.Position = pos;
}
}
}
}
return DicomReadStatus.Success;
}
示例8: Load
/// <summary>
/// Loads a dicom file
/// </summary>
/// <param name="file">Filename</param>
/// <param name="options">DICOM read options</param>
public DicomReadStatus Load(String file, DicomReadOptions options) {
return Load(file, null, options);
}
示例9: Load
/// <summary>
/// Loads a dicom file
/// </summary>
/// <param name="fs">File stream to read</param>
/// <param name="options">DICOM read options</param>
public DicomReadStatus Load(Stream fs, DicomReadOptions options)
{
return Load(fs, null, options);
}
示例10: IsSet
public static bool IsSet(DicomReadOptions options, DicomReadOptions flag)
{
return (options & flag) == flag;
}
示例11: Read
public DicomReadStatus Read(DicomTag stopAtTag, DicomReadOptions options)
{
if (stopAtTag == null)
stopAtTag = new DicomTag(0xFFFFFFFF, "Bogus Tag", "BogusTag", DicomVr.UNvr, false, 1, 1, false);
// Counters:
// _remain - bytes remaining in stream
// _bytes - estimates bytes to end of dataset
// _read - number of bytes read from stream
try
{
BytesNeeded = 0;
_remain = _stream.Length - _stream.Position;
while (_remain > 0)
{
if (_inGroup2 && BytesRead >= _endGroup2)
{
_inGroup2 = false;
// Only change if we're still reading the meta info
if (Dataset.StartTagValue < DicomTags.TransferSyntaxUid)
{
TransferSyntax group2Syntax =
TransferSyntax.GetTransferSyntax(
Dataset[DicomTags.TransferSyntaxUid].GetString(0, String.Empty));
if (group2Syntax == null)
throw new DicomException("Unsupported transfer syntax in group 2 elements");
TransferSyntax = group2Syntax;
}
}
uint tagValue;
if (LastTagRead == null)
{
if (_remain < 4)
return NeedMoreData(4);
_pos = _stream.Position;
ushort g = _reader.ReadUInt16();
ushort e = _reader.ReadUInt16();
tagValue = DicomTag.GetTagValue(g, e);
if (DicomTag.IsPrivateGroup(g) && e > 0x00ff)
{
SaveTagRead = LastTagRead = DicomTagDictionary.GetDicomTag(g, e) ??
new DicomTag((uint) g << 16 | e, "Private Tag", "PrivateTag", DicomVr.UNvr, false, 1, uint.MaxValue, false);
}
else
{
if (e == 0x0000)
SaveTagRead = LastTagRead = new DicomTag((uint)g << 16 | e, "Group Length", "GroupLength", DicomVr.ULvr, false, 1, 1, false);
else
{
SaveTagRead = LastTagRead = DicomTagDictionary.GetDicomTag(g, e) ??
new DicomTag((uint) g << 16 | e, "Private Tag", "PrivateTag", DicomVr.UNvr, false, 1, uint.MaxValue, false);
}
}
_remain -= 4;
BytesEstimated += 4;
BytesRead += 4;
}
else
tagValue = LastTagRead.TagValue;
if ((tagValue >= stopAtTag.TagValue)
&& (_sqrs.Count == 0)) // only exit in root message when after stop tag
return DicomReadStatus.Success;
bool twoByteLength;
if (_vr == null)
{
if (_syntax.ExplicitVr)
{
if (LastTagRead == DicomTag.Item ||
LastTagRead == DicomTag.ItemDelimitationItem ||
LastTagRead == DicomTag.SequenceDelimitationItem)
{
_vr = DicomVr.NONE;
twoByteLength = _vr.Is16BitLengthField;
}
else
{
if (_remain < 2)
return NeedMoreData(2);
string vr = new string(_reader.ReadChars(2));
_vr = DicomVr.GetVR(vr);
twoByteLength = _vr.Is16BitLengthField;
_remain -= 2;
BytesEstimated += 2;
BytesRead += 2;
if (LastTagRead.VR.Equals(DicomVr.UNvr))
{
LastTagRead = new DicomTag(LastTagRead.TagValue, "Private Tag", "PrivateTag", _vr, false, 1, uint.MaxValue, false);
if (vr.Equals("??"))
twoByteLength = true;
}
else if (!LastTagRead.VR.Equals(_vr))
{
if (!vr.Equals(" "))
{
DicomTag tag =
//.........这里部分代码省略.........
示例12: ParseSequenceItemDataset
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;
}
示例13: ParseTag
private DicomReadStatus ParseTag(DicomTag stopAtTag, DicomReadOptions options)
{
if (_tag == null) {
if (_remain >= 4) {
_pos = _stream.Position + _offset;
ushort g = _reader.ReadUInt16();
if (Flags.IsSet(options, DicomReadOptions.FileMetaInfoOnly) && g != 0x0002) {
_stream.Seek(-2, SeekOrigin.Current);
return DicomReadStatus.SuccessEndRead;
}
ushort e = _reader.ReadUInt16();
if (DicomTag.IsPrivateGroup(g) && e > 0x00ff) {
uint card = DicomTag.GetCard(g, e);
if ((card & 0xffffff00) != _privateCreatorCard) {
_privateCreatorCard = card & 0xffffff00;
DicomTag pct = DicomTag.GetPrivateCreatorTag(g, e);
DcmDataset ds = _dataset;
if (_sds.Count > 0 && _sds.Count == _sqs.Count) {
ds = _sds.Peek();
if (!ds.Contains(pct))
ds = _dataset;
}
_privateCreatorId = ds.GetString(pct, String.Empty);
}
_tag = new DicomTag(g, e, _privateCreatorId);
}
else {
_tag = new DicomTag(g, e);
if (g == 0xfffe) {
if (_tag == DicomTags.Item ||
_tag == DicomTags.ItemDelimitationItem ||
_tag == DicomTags.SequenceDelimitationItem)
_vr = DicomVR.NONE;
}
}
_remain -= 4;
_bytes += 4;
_read += 4;
}
else {
return NeedMoreData(4);
}
}
if (_tag == DicomTags.ItemDelimitationItem && Flags.IsSet(options, DicomReadOptions.SequenceItemOnly))
return DicomReadStatus.SuccessEndRead;
if (_tag >= stopAtTag)
return DicomReadStatus.SuccessEndRead;
return DicomReadStatus.Success;
}
示例14: ReadOptionsTest
public void ReadOptionsTest(DicomFile sourceFile, DicomReadOptions options, bool areEqual)
{
bool result = sourceFile.Save(DicomWriteOptions.Default);
Assert.AreEqual(result, true);
DicomFile newFile = new DicomFile(sourceFile.Filename);
newFile.Load(options);
if (areEqual)
Assert.AreEqual(sourceFile.DataSet.Equals(newFile.DataSet), true);
else
Assert.AreNotEqual(sourceFile.DataSet.Equals(newFile.DataSet), true);
}
示例15: Read
/// <summary>
/// Read dataset from stream
/// </summary>
/// <param name="stopAtTag">End parsing at this tag</param>
/// <param name="options">DICOM read options</param>
/// <returns>Status code</returns>
public DicomReadStatus Read(DicomTag stopAtTag, DicomReadOptions options)
{
// Counters:
// _remain - bytes remaining in stream
// _bytes - estimates bytes to end of dataset
// _read - number of bytes read from stream
try {
_need = 0;
_remain = _stream.Length - _stream.Position;
while (_remain > 0) {
DicomReadStatus status = ParseTag(stopAtTag, options);
if (status == DicomReadStatus.SuccessEndRead)
return DicomReadStatus.Success;
if (status != DicomReadStatus.Success)
return status;
status = ParseVR(options);
if (status != DicomReadStatus.Success)
return status;
status = ParseLength(options);
if (status != DicomReadStatus.Success)
return status;
if (_tag.IsPrivate) {
if (_tag.Element != 0x0000 && _tag.Element <= 0x00ff) {
// handle UN private creator id
if (_vr != DicomVR.LO && Flags.IsSet(options, DicomReadOptions.ForcePrivateCreatorToLO)) {
Dicom.Debug.Log.Warn("Converting Private Creator VR from '{0}' to 'LO'", _vr.VR);
_vr = DicomVR.LO;
}
}
}
if (_vr == DicomVR.UN && _syntax.IsExplicitVR && Flags.IsSet(options, DicomReadOptions.UseDictionaryForExplicitUN)) {
_vr = _tag.Entry.DefaultVR;
}
if (_fragment != null) {
status = InsertFragmentItem(options);
if (status != DicomReadStatus.Success)
return status;
}
else if (_sqs.Count > 0 &&
(_tag == DicomTags.Item ||
_tag == DicomTags.ItemDelimitationItem ||
_tag == DicomTags.SequenceDelimitationItem)) {
status = InsertSequenceItem(options);
if (status != DicomReadStatus.Success)
return status;
}
else {
if (_sqs.Count > 0) {
DcmItemSequence sq = _sqs.Peek();
if (sq.StreamLength != UndefinedLength) {
long end = sq.StreamPosition + 8 + sq.StreamLength;
if (_syntax.IsExplicitVR)
end += 2 + 2;
if ((_stream.Position - _offset) >= end) {
if (_sds.Count == _sqs.Count)
_sds.Pop();
_sqs.Pop();
}
}
}
if (_len == UndefinedLength) {
if (_vr == DicomVR.SQ) {
DcmItemSequence sq = new DcmItemSequence(_tag, _pos, _len, _endian);
InsertDatasetItem(sq, options);
_sqs.Push(sq);
}
else {
_fragment = new DcmFragmentSequence(_tag, _vr, _pos, _endian);
InsertDatasetItem(_fragment, options);
}
}
else {
if (_vr == DicomVR.SQ) {
DcmItemSequence sq = new DcmItemSequence(_tag, _pos, _len, _endian);
InsertDatasetItem(sq, options);
_sqs.Push(sq);
}
else {
if (_len > _remain)
return NeedMoreData(_len);
DcmElement elem = DcmElement.Create(_tag, _vr, _pos, _endian, CurrentBuffer(options));
_remain -= _len;
_read += _len;
InsertDatasetItem(elem, options);
}
//.........这里部分代码省略.........