public static XDocument ToXML(DcmDataset dataset, XDicomOptions options) { XDocument document = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); XElement root = new XElement("dicom"); LoadSequence(root, dataset.Elements, options); document.Add(root); return document; }
public static XDocument ToXML(DcmDataset dataset, XDicomOptions options) { XDocument document = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); XElement root = new XElement("dicom"); LoadSequence(root, dataset.Elements, options); document.Add(root); return(document); }
private static void LoadSequence(XElement parent, IList <DcmItem> items, XDicomOptions options) { foreach (DcmItem item in items) { if (!Flags.IsSet(options, XDicomOptions.IncludePixelData) && item.Tag == DicomTags.PixelData) { continue; } XElement attr = new XElement("attr"); attr.SetAttributeValue("tag", item.Tag.Card.ToString("x8")); attr.SetAttributeValue("vr", item.VR.VR); if (item is DcmItemSequence) { DcmItemSequence seq = (DcmItemSequence)item; attr.SetAttributeValue("len", -1); foreach (DcmItemSequenceItem si in seq.SequenceItems) { XElement itm = new XElement("item"); LoadSequence(itm, si.Dataset.Elements, options); attr.Add(itm); } } else if (item is DcmFragmentSequence) { DcmFragmentSequence seq = (DcmFragmentSequence)item; attr.SetAttributeValue("len", -1); LoadFragmentOffsetTable(attr, seq); foreach (ByteBuffer fi in seq.Fragments) { LoadFragmentItem(attr, seq.VR, fi); } } else { DcmElement element = (DcmElement)item; attr.SetAttributeValue("len", element.Length); attr.Add(element.GetValueString()); } if (Flags.IsSet(options, XDicomOptions.Comments)) { parent.Add(new XComment(item.Tag.Entry.Name)); } parent.Add(attr); } }
private static void LoadSequence(XElement parent, IList<DcmItem> items, XDicomOptions options) { foreach (DcmItem item in items) { if (!Flags.IsSet(options, XDicomOptions.IncludePixelData) && item.Tag == DicomTags.PixelData) continue; XElement attr = new XElement("attr"); attr.SetAttributeValue("tag", item.Tag.Card.ToString("x8")); attr.SetAttributeValue("vr", item.VR.VR); if (item is DcmItemSequence) { DcmItemSequence seq = (DcmItemSequence)item; attr.SetAttributeValue("len", -1); foreach (DcmItemSequenceItem si in seq.SequenceItems) { XElement itm = new XElement("item"); LoadSequence(itm, si.Dataset.Elements, options); attr.Add(itm); } } else if (item is DcmFragmentSequence) { DcmFragmentSequence seq = (DcmFragmentSequence)item; attr.SetAttributeValue("len", -1); LoadFragmentOffsetTable(attr, seq); foreach (ByteBuffer fi in seq.Fragments) { LoadFragmentItem(attr, seq.VR, fi); } } else { DcmElement element = (DcmElement)item; attr.SetAttributeValue("len", element.Length); attr.Add(element.GetValueString()); } if (Flags.IsSet(options, XDicomOptions.Comments)) parent.Add(new XComment(item.Tag.Entry.Name)); parent.Add(attr); } }
public static bool IsSet(XDicomOptions options, XDicomOptions flag) { return (options & flag) == flag; }
private static void LoadSequence(XElement parent, IList<DcmItem> items, XDicomOptions options) { foreach (DcmItem item in items) { if (!Flags.IsSet(options, XDicomOptions.IncludePixelData) && item.Tag == DicomTags.PixelData) continue; XElement attr = new XElement("attr"); attr.SetAttributeValue("tag", item.Tag.Card.ToString("x8")); attr.SetAttributeValue("vr", item.VR.VR); if (item is DcmItemSequence) { DcmItemSequence seq = (DcmItemSequence)item; attr.SetAttributeValue("len", -1); foreach (DcmItemSequenceItem si in seq.SequenceItems) { XElement itm = new XElement("item"); LoadSequence(itm, si.Dataset.Elements, options); attr.Add(itm); } } else if (item is DcmFragmentSequence) { DcmFragmentSequence seq = (DcmFragmentSequence)item; attr.SetAttributeValue("len", -1); LoadFragmentOffsetTable(attr, seq); foreach (ByteBuffer fi in seq.Fragments) { LoadFragmentItem(attr, seq.VR, fi); } } else { DcmElement element = (DcmElement)item; attr.SetAttributeValue("len", element.Length); { //Bug: '.', hexadecimal value 0x00, is an invalid character //See: http://forums.asp.net/t/1216196.aspx for given workaround. var elementValue = element.GetValueString(); elementValue = System.Text.RegularExpressions.Regex.Replace(elementValue, "\\p{C}+", ""); attr.Add(elementValue); } } if (Flags.IsSet(options, XDicomOptions.Comments)) parent.Add(new XComment(item.Tag.Entry.Name)); parent.Add(attr); } }
public static bool IsSet(XDicomOptions options, XDicomOptions flag) { return((options & flag) == flag); }