LAUREL BRIDGE

LaurelBridge.DCFExamples.ReadDataSetFlat Namespace

DICOM Connectivity Framework V3.4
The ReadDataSetFlat example demonstrates how to use DCF and the ReadDataSetFlat method to diagnose problems with sequence encoding.
Classes

  ClassDescription
Public classOptions
Command line options class for parsing user options for ReadDataSetFlat.
Public classProgram
A program to demonstrate how to use readDataSetFlat on a SR dataset.
Remarks

Supported OS Platforms:

  • Windows - .Net Framework 4.7.2 64-bit and 32-bit
  • Windows - .Net Core 2.1 64-bit and 32-bit
  • Linux - .Net Core 2.1 64-bit

Examples

ReadDataSetFlat Sample Code
public class Program
{
    /// <summary>
    /// Main entry point for ReadDataSetFlat.
    /// </summary>
    /// <param name="args">command line arguments</param>
    [STAThread]
    public static void Main(string[] args)
    {
        try
        {
            Options options;
            if (!Options.TryParse(args, out options))
            {
                throw new ArgumentException("bad command line parameters");
            }

            using (DicomFileInput dfi = new DicomFileInput(options.FileName))
            {
                dfi.TrackElementOffsets = true;
                DicomDataSet dds = dfi.ReadDataSetFlat();
                Console.WriteLine("DataSet.IsFlat = {0}", dds.IsFlat);
                dds.DumperOptions = new DataSetDumperOptions { ShowElementOffsets = true };
                Console.WriteLine(dds);
                List<IDicomElement> elementList = new List<IDicomElement>(dds);
                IList<AttributeTag> tagsToDump = new AttributeTag[]
                {
                    Tags.SOPClassUID,
                    Tags.SOPInstanceUID,
                    Tags.StudyDate,
                    Tags.StudyTime,
                    Tags.SeriesTime,
                    Tags.CodeMeaning,
                    Tags.NumericValue,
                    Tags.TextValue,
                    Tags.ConceptNameCodeSequence,
                    Tags.ContentSequence,
                    Tags.ContentTemplateSequence,
                    //Tags.Item,
                    //Tags.ItemDelimitationItem,
                    //Tags.SequenceDelimitationItem,
                };
                Console.WriteLine("{0}Printing interesting elements in dataset:", Environment.NewLine);
                int indent = 0;
                foreach (IDicomElement el in elementList)
                {
                    // this relies on undefined length sequences and items
                    // (defined length sequences would have to calculate the end of the sequence or item based on the
                    // length of each element, which is also dependent on explicit or implicit transfer syntax;
                    // see DicomDeviceInput CalcHeaderLength and is left as an exercise for the reader ;-).
                    if (el.Tag.Equals(Tags.Item) && el.Length == (-1))
                        indent++;
                    else if (el.Tag.Equals(Tags.ItemDelimitationItem))
                        indent--;
                    if (tagsToDump.Contains(el.Tag))
                    {

                        Console.WriteLine("{0}{1}", GetIndent(indent), el);
                    }
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught during execution: {0}", e);
            Environment.ExitCode = 1;
        }
        finally
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey();
            }
        }
    }

    private static readonly Dictionary<int, string> _indent = new Dictionary<int, string>();

    private static string GetIndent(int indent)
    {
        if (indent <= 0)
            return string.Empty;
        if (!_indent.ContainsKey(indent))
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < indent; i++)
                sb.Append("> ");
            _indent[indent] = sb.ToString();
        }
        return _indent[indent];
    }
}