private List <string> GetDicomDirectoryImages
        (
            string dicomFile,
            DicomDataSet dataset
        )
        {
            try
            {
                DicomElement  refernceFileElement;
                List <string> dicomImages;
                string        baseDirectory;


                refernceFileElement = null;
                dicomImages         = new List <string> ( );
                baseDirectory       = Path.GetDirectoryName(dicomFile);

                refernceFileElement = dataset.FindFirstElement(null,
                                                               DicomTag.ReferencedFileID,
                                                               false);

                if (null != refernceFileElement)
                {
                    dicomImages.Add(Path.Combine(baseDirectory, dataset.GetConvertValue(refernceFileElement)));
                }

                while (null != (refernceFileElement = dataset.FindNextElement(refernceFileElement, false)))
                {
                    dicomImages.Add(Path.Combine(baseDirectory, dataset.GetConvertValue(refernceFileElement)));
                }

                return(dicomImages);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.Assert(false, exception.Message);

                throw exception;
            }
        }
Exemple #2
0
        private void LoadDicomDir(string filename)
        {
            if (_cancel)
            {
                return;
            }

            string       pathname    = string.Empty;
            string       refFilename = string.Empty;
            DicomElement element     = null;
            int          count       = 0;
            int          totalCount  = 0;
            int          nMod        = 1;
            string       sMsg        = string.Empty;


            if (!filename.ToUpper().Contains("DICOMDIR"))
            {
                return;
            }

            pathname = Path.GetDirectoryName(filename) + "\\";
            using (DicomDataSet ds = new DicomDataSet())
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    LogText("Loading DICOMDIR...");
                    ds.Load(filename, DicomDataSetLoadFlags.None);

                    // Get the total count
                    LogText("Getting total count...");
                    element = ds.FindFirstElement(null, DicomTag.ReferencedFileID, false);
                    while (element != null)
                    {
                        totalCount++;
                        element = ds.FindNextElement(element, false);
                    }

                    if (totalCount >= 20)
                    {
                        nMod = 10;
                    }

                    // now get the datasets
                    element = ds.FindFirstElement(null, DicomTag.ReferencedFileID, false);
                    if (element != null && ds.GetElementValueCount(element) > 0)
                    {
                        if (!_cancel)
                        {
                            refFilename = ds.GetConvertValue(element);
                            if (LoadDicomFile(pathname + refFilename))
                            {
                                count++;
                            }
                            Application.DoEvents();
                        }
                    }

                    while ((refFilename.Length > 0) && (!_cancel))
                    {
                        element = ds.FindNextElement(element, false);
                        if (element != null && ds.GetElementValueCount(element) > 0)
                        {
                            refFilename = ds.GetConvertValue(element);
                            if (LoadDicomFile(pathname + refFilename))
                            {
                                count++;
                            }
                            Application.DoEvents();
                        }
                        else
                        {
                            refFilename = "";
                        }
                        if (count % nMod == 0)
                        {
                            sMsg = string.Format("Loaded {0} of {1} files...", count.ToString(), totalCount.ToString());
                            LogText(sMsg);
                        }
                    }
                }
                catch (DicomException de)
                {
                    LogText("Dicom error: " + de.Code.ToString() + ": " + filename);
                }
            }
            sMsg = string.Format("Loaded {0} of {1} total files", count.ToString(), totalCount.ToString());
            LogText(sMsg);
            RefreshList();
            this.Cursor = Cursors.Default;
        }