Ejemplo n.º 1
0
        bool LoadDicomFile(string filename)
        {
            //if (_cancel)
            //   return false;

            using (DicomDataSet ds = new DicomDataSet())
            {
                ListViewItem item = null;
                DicomElement element;
                string       strTransferSyntax = "";
                bool         succeeded         = true;

                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    ds.Load(filename, DicomDataSetLoadFlags.None);
                    item = listViewImages.Items.Add(ds.GetValue <string>(DicomTag.PatientName, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.PatientID, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.StudyID, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.Modality, string.Empty));

                    strTransferSyntax = "Implicit VR - Little Endian";

                    element = ds.FindFirstElement(null, DicomTag.TransferSyntaxUID, false);
                    if (element != null && ds.GetElementValueCount(element) > 0)
                    {
                        string   uidString;
                        DicomUid uid;

                        uidString = ds.GetValue <string>(element, string.Empty);
                        uid       = DicomUidTable.Instance.Find(uidString);
                        if (uid != null)
                        {
                            strTransferSyntax = uid.Name;
                        }
                    }
                }
                catch (DicomException de)
                {
                    LogText("Dicom error: " + de.Code.ToString(), filename);
                    succeeded = false;
                }

                if (succeeded)
                {
                    // Mark item read if we have a basic directory
                    if (ds.InformationClass == DicomClassType.BasicDirectory)
                    {
                        item.Font = new Font(listViewImages.Font, FontStyle.Bold);
                    }

                    item.SubItems.Add(strTransferSyntax);
                    item.SubItems.Add(filename);

                    item.Checked = true;
                }
                this.Cursor = Cursors.Default;
                return(succeeded);
            }
        }
Ejemplo n.º 2
0
        public static int GetCount(this DicomDataSet ds, long tag)
        {
            DicomElement element = ds.FindFirstElement(null, tag, false);

            if (element != null)
            {
                return(ds.GetElementValueCount(element));
            }

            return(0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper method to get string value from a DICOM dataset.
        /// </summary>
        /// <param name="dcm">The DICOM dataset.</param>
        /// <param name="tag">Dicom tag.</param>
        /// <returns>String value of the specified DICOM tag.</returns>
        public static string GetStringValue(DicomDataSet dcm, long tag, bool tree)
        {
            DicomElement element;

            element = dcm.FindFirstElement(null, tag, tree);
            if (element != null)
            {
                if (dcm.GetElementValueCount(element) > 0)
                {
                    return(dcm.GetConvertValue(element));
                }
            }

            return("");
        }
Ejemplo n.º 4
0
        public static StringCollection GetStringValues(DicomDataSet dcm, long tag)
        {
            DicomElement     element;
            StringCollection sc = new StringCollection();

            element = dcm.FindFirstElement(null, tag, true);
            if (element != null)
            {
                if (dcm.GetElementValueCount(element) > 0)
                {
                    string   s     = dcm.GetConvertValue(element);
                    string[] items = s.Split('\\');

                    foreach (string value in items)
                    {
                        sc.Add(value);
                    }
                }
            }

            return(sc);
        }
Ejemplo n.º 5
0
        /*
         * Builds a SQL condition for a list of UIDs.
         */

        private string GetUIDCondition(long Tag, string strFieldName)
        {
            string strRetCondition = "";

            try
            {
                DicomElement element = ds.FindFirstElement(null, Tag, false);
                if (element != null)
                {
                    string strUID;
                    int    nUIDsCount = ds.GetElementValueCount(element);

                    if (nUIDsCount > 0)
                    {
                        strRetCondition += " AND (";

                        for (int i = 0; i < nUIDsCount; i++)
                        {
                            strUID           = ds.GetStringValue(element, i);
                            strRetCondition += strFieldName + "='" + strUID + "'";

                            if (i != nUIDsCount - 1)
                            {
                                strRetCondition += " OR ";
                            }
                        }

                        strRetCondition += ")";
                    }
                }
            }
            catch (Exception ex)
            {
                server.mf.Log("Error creating UID condition:\r\n\r\n" + ex.ToString());
                strRetCondition = "";
            }

            return(strRetCondition);
        }
Ejemplo n.º 6
0
      public static StringCollection GetStringValues(DicomDataSet dcm, long tag)
      {
         DicomElement element;
         StringCollection sc = new StringCollection();

         element = dcm.FindFirstElement(null, tag, true);
         if(element != null)
         {
            if(dcm.GetElementValueCount(element) > 0)
            {
               string s = dcm.GetConvertValue(element);
               string[] items = s.Split('\\');

               foreach(string value in items)
               {
                  sc.Add(value);
               }
            }
         }

         return sc;
      }
Ejemplo n.º 7
0
      /// <summary>
      /// Helper method to get string value from a DICOM dataset.
      /// </summary>
      /// <param name="dcm">The DICOM dataset.</param>
      /// <param name="tag">Dicom tag.</param>
      /// <returns>String value of the specified DICOM tag.</returns>
      public static string GetStringValue(DicomDataSet dcm, long tag, bool tree)
      {
         DicomElement element;

         element = dcm.FindFirstElement(null, tag, tree);
         if(element != null)
         {
            if(dcm.GetElementValueCount(element) > 0)
            {
               return dcm.GetConvertValue(element);
            }
         }

         return "";
      }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Lấy giá trị của một Tag từ DicomDataset của ảnh
 /// </summary>
 /// <param name="ds"></param>
 /// <param name="tag"></param>
 /// <returns></returns>
 string GetStringValue(DicomDataSet ds, long tag)
 {
     try
     {
         if (ds == null) return "";
         DicomElement element;
         element = ds.FindFirstElement(null, tag, false);
         if (element != null)
         {
             if (ds.GetElementValueCount(element) > 0)
             {
                 return ds.GetConvertValue(element);
             }
         }
         return "";
     }
     catch
     {
         return "";
     }
 }
Ejemplo n.º 10
0
        static void fillOutputWithDicomDataSet(MedicalViewerPageInfo output, DicomDataSet ds)
        {
            DicomElement elemImagePatientOrientation   = ds.FindFirstElement(null, DicomTag.PatientOrientation, true);
            DicomElement elemImagePositionPatient      = ds.FindFirstElement(null, DicomTag.ImagePositionPatient, true);
            DicomElement elemImageOrientationPatient   = ds.FindFirstElement(null, DicomTag.ImageOrientationPatient, true);
            DicomElement elemImagerPixelSpacing        = ds.FindFirstElement(null, DicomTag.ImagerPixelSpacing, true);
            DicomElement elemPixelSpacing              = ds.FindFirstElement(null, DicomTag.PixelSpacing, true);
            DicomElement elemPhotometricInterpretation = ds.FindFirstElement(null, DicomTag.PhotometricInterpretation, true);


            if (null != elemPhotometricInterpretation)
            {
                string photometricInterpretation = ds.GetStringValue(elemPhotometricInterpretation, 0);
                output.SupportWindowLevel = photometricInterpretation == "MONOCHROME2" || photometricInterpretation == "MONOCHROME1";
            }

            if (null != elemImagePatientOrientation)
            {
                int count = ds.GetElementValueCount(elemImagePatientOrientation);
                if (count > 0)
                {
                    output.PatientOrientation = new string[count];
                    for (int index = 0; index < count; index++)
                    {
                        output.PatientOrientation[index] = ds.GetStringValue(elemImagePatientOrientation, index);
                    }
                }
            }
            if (null != elemImagePositionPatient)
            {
                output.ImagePositionPatientArray = ds.GetDoubleValue(elemImagePositionPatient, 0, 3);
                if (output.ImagePositionPatientArray.Length == 0)
                {
                    output.ImagePositionPatientArray = null;
                }
            }
            if (null != elemImageOrientationPatient)
            {
                output.ImageOrientationPatientArray = ds.GetDoubleValue(elemImageOrientationPatient, 0, 6);
                if (output.ImageOrientationPatientArray.Length == 0)
                {
                    output.ImageOrientationPatientArray = null;
                }
            }
            if (null != elemPixelSpacing)
            {
                output.PixelSpacingPatientArray = ds.GetDoubleValue(elemPixelSpacing, 0, 2);
                if (output.PixelSpacingPatientArray.Length == 0)
                {
                    output.PixelSpacingPatientArray = null;
                }
            }
            else if (null != elemImagerPixelSpacing)
            {
                output.PixelSpacingPatientArray = ds.GetDoubleValue(elemImagerPixelSpacing, 0, 2);
                if (output.PixelSpacingPatientArray.Length == 0)
                {
                    output.PixelSpacingPatientArray = null;
                }
            }
        }