public void AddSequenceItem(DcmDataset itemDataset) { DcmItemSequenceItem item = new DcmItemSequenceItem(); item.Dataset = itemDataset; AddSequenceItem(item); }
public override DcmItem Clone() { DcmItemSequenceItem si = new DcmItemSequenceItem(StreamPosition, StreamLength); si.Dataset = Dataset.Clone(); return(si); }
private static void Save(XElement parent, DcmDataset dataset) { foreach (XElement attr in parent.Elements("attr")) { DicomTag tag = DicomTag.Parse(attr.Attribute("tag").Value); DicomVR vr = DicomVR.Lookup(attr.Attribute("vr").Value); int len = int.Parse(attr.Attribute("len").Value, CultureInfo.InvariantCulture); if (vr == DicomVR.SQ) { DcmItemSequence seq = new DcmItemSequence(tag); foreach (XElement itm in attr.Elements("item")) { DcmItemSequenceItem item = new DcmItemSequenceItem(); Save(itm, item.Dataset); seq.AddSequenceItem(item); } dataset.AddItem(seq); } else if (len == -1) { DcmFragmentSequence seq = new DcmFragmentSequence(tag, vr); bool first = true; foreach (XElement itm in attr.Elements("item")) { if (first) { SaveFragmentOffsetTable(itm, seq); first = false; } else { SaveFragmentItem(itm, seq); } } dataset.AddItem(seq); } else { DcmElement element = DcmElement.Create(tag, vr); element.SetValueString(attr.FirstText()); dataset.AddItem(element); } } }
/// <summary> /// Original Attributes Sequence (0400,0561) /// Sequence of Items containing all attributes that were /// removed or replaced by other values in the main dataset. /// One or more Items may be permitted in this sequence. /// </summary> /// <param name="originalAttributesSource"> /// Source of Previous Values (0400,0564) /// The source that provided the SOP Instance prior to the /// removal or replacement of the values. For example, this /// might be the Institution from which imported SOP Instances /// were received. /// </param> /// <param name="modifyingSystem"> /// Modifying System (0400,0563) /// Identification of the system which removed and/or replaced /// the attributes. /// </param> /// <param name="reasonForModification"> /// Reason for the Attribute Modification (0400,0565) /// Reason for the attribute modification. Defined terms are: /// COERCE = Replace values of attributes such as Patient /// Name, ID, Accession Number, for example, during import /// of media from an external institution, or reconciliation /// against a master patient index. /// CORRECT = Replace incorrect values, such as Patient /// Name or ID, for example, when incorrect worklist item /// was chosen or operator input error. /// </param> /// <param name="tagsToModify"> /// Tags from this dataset to be removed or modified. /// </param> public void CreateOriginalAttributesSequence(string originalAttributesSource, string modifyingSystem, string reasonForModification, IEnumerable<DicomTag> tagsToModify) { DcmItemSequenceItem item = new DcmItemSequenceItem(); item.Dataset.AddElementWithValue(DicomTags.SourceOfPreviousValues, originalAttributesSource); item.Dataset.AddElementWithValue(DicomTags.AttributeModificationDateTime, DateTime.Now); item.Dataset.AddElementWithValue(DicomTags.ModifyingSystem, modifyingSystem); item.Dataset.AddElementWithValue(DicomTags.ReasonForTheAttributeModification, reasonForModification); DcmItemSequence sq = new DcmItemSequence(DicomTags.ModifiedAttributesSequence); item.Dataset.AddItem(sq); DcmItemSequenceItem modified = new DcmItemSequenceItem(); sq.AddSequenceItem(modified); foreach (DicomTag tag in tagsToModify) { DcmItem modifiedItem = GetItem(tag); if (modifiedItem == null) modified.Dataset.AddItem(modifiedItem.Clone()); } DcmItemSequence oasq = GetSQ(DicomTags.OriginalAttributesSequence); if (oasq == null) { oasq = new DcmItemSequence(DicomTags.OriginalAttributesSequence); AddItem(oasq); } oasq.AddSequenceItem(item); }
public void AddReferenceSequenceItem(DicomTag tag, DicomUID classUid, DicomUID instUid) { DcmItemSequence sq = GetSQ(tag); if (sq == null) { sq = new DcmItemSequence(tag); AddItem(sq); } DcmItemSequenceItem item = new DcmItemSequenceItem(); item.Dataset.AddElementWithValue(DicomTags.ReferencedSOPClassUID, classUid); item.Dataset.AddElementWithValue(DicomTags.ReferencedSOPInstanceUID, instUid); sq.AddSequenceItem(item); }
private DicomReadStatus InsertSequenceItem(DicomReadOptions options) { if (_tag.Equals(DicomTags.Item)) { if (_len != UndefinedLength && _len > _remain) return NeedMoreData(_len); if (_sds.Count > _sqs.Count) _sds.Pop(); DcmItemSequenceItem si = new DcmItemSequenceItem(_pos, _len); if (_len != UndefinedLength || (_stream.CanSeek && Flags.IsSet(options, DicomReadOptions.AllowSeekingForContext))) { if (_len == UndefinedLength) options |= DicomReadOptions.SequenceItemOnly; DcmDataset ds = null; DicomReadStatus status = ParseSequenceItemDataset(TransferSyntax, _len, out ds, options); if (status != DicomReadStatus.Success) { Dicom.Debug.Log.Warn("Unknown error while attempting to read sequence item. Trying again with alternate encodings."); DicomTransferSyntax[] syntaxes = null; if (TransferSyntax == DicomTransferSyntax.ExplicitVRBigEndian) syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRLittleEndian }; else if (TransferSyntax.IsExplicitVR) syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian }; else syntaxes = new DicomTransferSyntax[] { DicomTransferSyntax.ExplicitVRLittleEndian, DicomTransferSyntax.ExplicitVRBigEndian }; foreach (DicomTransferSyntax tx in syntaxes) { status = ParseSequenceItemDataset(tx, _len, out ds, options); if (status == DicomReadStatus.Success) break; } } if (status != DicomReadStatus.Success) return DicomReadStatus.UnknownError; si.Dataset = ds; if (_len == UndefinedLength) { if (8 > _remain) { // need more data? _sds.Push(ds); } else { // skip delimitation item _stream.Seek(8, SeekOrigin.Current); _remain -= 8; _bytes += 8; _read += 8; } } } else { DcmDataset ds = new DcmDataset(_pos + 8, _len, TransferSyntax); _sds.Push(ds); } _sqs.Peek().AddSequenceItem(si); } else if (_tag == DicomTags.ItemDelimitationItem) { if (_sds.Count == _sqs.Count) _sds.Pop(); } else if (_tag == DicomTags.SequenceDelimitationItem) { if (_sds.Count == _sqs.Count) _sds.Pop(); _sqs.Pop(); } return DicomReadStatus.Success; }
private void UpdateImageBox(DcmImageBox imageBox, String filename, int index) { try { DicomFileFormat ff = new DicomFileFormat(); ff.Load(filename, DicomReadOptions.DefaultWithoutDeferredLoading); if (ff.Dataset != null) { ff.Dataset.ChangeTransferSyntax(DicomTransferSyntax.ImplicitVRLittleEndian, null); DcmPixelData pixelData = new DcmPixelData(ff.Dataset); PhotometricInterpretation pi = PhotometricInterpretation.Lookup(pixelData.PhotometricInterpretation); // Grayscale only printer? if (pi.IsColor == true && _supportsColorPrinting == false) { pixelData.Unload(); return; } // Color only printer? if (pi.IsColor == false && _supportsGrayscalePrinting == false) { pixelData.Unload(); return; } DicomUID imageBoxSOPClassUID = null; DcmItemSequence seq = null; DcmItemSequenceItem item = new DcmItemSequenceItem(); pixelData.UpdateDataset(item.Dataset); if (pi.IsColor == true) { imageBoxSOPClassUID = DicomUID.BasicColorImageBoxSOPClass; seq = new DcmItemSequence(DicomTags.BasicColorImageSequence); } else { imageBoxSOPClassUID = DicomUID.BasicGrayscaleImageBoxSOPClass; seq = new DcmItemSequence(DicomTags.BasicGrayscaleImageSequence); } seq.AddSequenceItem(item); imageBox.Dataset.AddItem(seq); pixelData.Unload(); imageBox.UpdateImageBox(imageBoxSOPClassUID); imageBox.ImageBoxPosition = (ushort)index; } } catch (Exception) { } }
public void AddSequenceItem(DcmItemSequenceItem item) { _items.Add(item); }
public override DcmItem Clone() { DcmItemSequenceItem si = new DcmItemSequenceItem(StreamPosition, StreamLength); si.Dataset = Dataset.Clone(); return si; }