本文整理汇总了C#中DicomDataset.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# DicomDataset.FirstOrDefault方法的具体用法?C# DicomDataset.FirstOrDefault怎么用?C# DicomDataset.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DicomDataset
的用法示例。
在下文中一共展示了DicomDataset.FirstOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
private void Load(DicomDataset ds) {
_rows = ds.Get<ushort>(OverlayTag(DicomTag.OverlayRows));
_columns = ds.Get<ushort>(OverlayTag(DicomTag.OverlayColumns));
var type = ds.Get<string>(OverlayTag(DicomTag.OverlayType), "Unknown");
if (type.StartsWith("R"))
_type = DicomOverlayType.ROI;
else
_type = DicomOverlayType.Graphics;
DicomTag tag = OverlayTag(DicomTag.OverlayOrigin);
if (ds.Contains(tag)) {
_originX = ds.Get<short>(tag, 0, 1);
_originY = ds.Get<short>(tag, 1, 1);
}
_bitsAllocated = ds.Get<ushort>(OverlayTag(DicomTag.OverlayBitsAllocated), 0, 1);
_bitPosition = ds.Get<ushort>(OverlayTag(DicomTag.OverlayBitPosition), 0, 0);
tag = OverlayTag(DicomTag.OverlayData);
if (ds.Contains(tag)) {
var elem = ds.FirstOrDefault(x => x.Tag == tag) as DicomElement;
_data = elem.Buffer;
} else {
// overlay embedded in high bits of pixel data
if (ds.InternalTransferSyntax.IsEncapsulated)
throw new DicomImagingException("Attempted to extract embedded overlay from compressed pixel data. Decompress pixel data before attempting this operation.");
var pixels = DicomPixelData.Create(ds);
// (1,1) indicates top left pixel of image
int ox = Math.Max(0, _originX - 1);
int oy = Math.Max(0, _originY - 1);
int ow = Math.Min(_rows, pixels.Width - _rows - ox);
int oh = Math.Min(_columns, pixels.Height - _columns - oy);
var frame = pixels.GetFrame(0);
// calculate length of output buffer
var count = (_rows * _columns) / 8;
if (((_rows * _columns) % 8) != 0)
count++;
if ((count & 1) != 0)
count++;
var bytes = new byte[count];
var bits = new BitArray(bytes);
int mask = 1 << _bitPosition;
if (pixels.BitsAllocated == 8) {
var data = ByteBufferEnumerator<byte>.Create(frame).ToArray();
for (int y = oy; y < oh; y++) {
int n = (y * pixels.Width) + ox;
int i = (y - oy) * _columns;
for (int x = ox; x < ow; x++) {
if ((data[n] & mask) != 0)
bits[i] = true;
n++;
i++;
}
}
} else if (pixels.BitsAllocated == 16) {
// we don't really care if the pixel data is signed or not
var data = ByteBufferEnumerator<ushort>.Create(frame).ToArray();
for (int y = oy; y < oh; y++) {
int n = (y * pixels.Width) + ox;
int i = (y - oy) * _columns;
for (int x = ox; x < ow; x++) {
if ((data[n] & mask) != 0)
bits[i] = true;
n++;
i++;
}
}
} else {
throw new DicomImagingException("Unable to extract embedded overlay from pixel data with bits stored greater than 16.");
}
_data = new MemoryByteBuffer(bytes);
}
_description = ds.Get<string>(OverlayTag(DicomTag.OverlayDescription), String.Empty);
_subtype = ds.Get<string>(OverlayTag(DicomTag.OverlaySubtype), String.Empty);
_label = ds.Get<string>(OverlayTag(DicomTag.OverlayLabel), String.Empty);
_frames = ds.Get<int>(OverlayTag(DicomTag.NumberOfFramesInOverlay), 0, 1);
_frameOrigin = ds.Get<ushort>(OverlayTag(DicomTag.ImageFrameOrigin), 0, 1);
//TODO: include ROI
}
示例2: CreateRecordSequenceItem
private DicomDirectoryRecord CreateRecordSequenceItem(DicomDirectoryRecordType recordType, DicomDataset dataset) {
if (recordType == null)
throw new ArgumentNullException("recordType");
if (dataset == null)
throw new ArgumentNullException("dataset");
var sequenceItem = new DicomDirectoryRecord();
//add record item attributes
sequenceItem.Add<uint>(DicomTag.OffsetOfTheNextDirectoryRecord, 0);
sequenceItem.Add<ushort>(DicomTag.RecordInUseFlag, 0xFFFF);
sequenceItem.Add<uint>(DicomTag.OffsetOfReferencedLowerLevelDirectoryEntity, 0);
sequenceItem.Add<string>(DicomTag.DirectoryRecordType, recordType.ToString());
//copy the current dataset character set
sequenceItem.Add(dataset.FirstOrDefault(d => d.Tag == DicomTag.SpecificCharacterSet));
foreach (var tag in recordType.Tags) {
if (dataset.Contains(tag)) {
sequenceItem.Add(dataset.Get<DicomItem>(tag));
} else {
System.Diagnostics.Debug.WriteLine("Cannot find tag {0} for record type {1}", tag, recordType);
}
}
return sequenceItem;
}
示例3: Load
private void Load(DicomDataset ds)
{
_rows = ds.Get<ushort>(OverlayTag(DicomTag.OverlayRows));
_columns = ds.Get<ushort>(OverlayTag(DicomTag.OverlayColumns));
_type = ds.Get<string>(OverlayTag(DicomTag.OverlayType), "Unknown");
DicomTag tag = OverlayTag(DicomTag.OverlayOrigin);
if (ds.Contains(tag)) {
short[] xy = ds.Get<short[]>(tag);
if (xy != null && xy.Length == 2) {
_originX = xy[0];
_originY = xy[1];
}
}
_bitsAllocated = ds.Get<ushort>(OverlayTag(DicomTag.OverlayBitsAllocated), 0, 1);
_bitPosition = ds.Get<ushort>(OverlayTag(DicomTag.OverlayBitPosition), 0, 0);
tag = OverlayTag(DicomTag.OverlayData);
if (ds.Contains(tag)) {
var elem = ds.FirstOrDefault(x => x.Tag == tag) as DicomElement;
_data = elem.Buffer;
}
_description = ds.Get<string>(OverlayTag(DicomTag.OverlayDescription), String.Empty);
_subtype = ds.Get<string>(OverlayTag(DicomTag.OverlaySubtype), String.Empty);
_label = ds.Get<string>(OverlayTag(DicomTag.OverlayLabel), String.Empty);
_frames = ds.Get<int>(OverlayTag(DicomTag.NumberOfFramesInOverlay), 0, 1);
_frameOrigin = ds.Get<ushort>(OverlayTag(DicomTag.ImageFrameOrigin), 0, 1);
//TODO: include ROI
}