예제 #1
0
        public ucTagAndImage()
        {
            InitializeComponent();

            var testFile = @"D:\Documents\Dose Report\1.2.840.113564.10001.2016033015344433716-dose report-CBCT.dcm";
            var stream   = new FileStream(testFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);

            var dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();

            dicom.Read(stream);

            foreach (Element element in dicom)
            {
                // do not show group length tags
                if (element.element == 0)
                {
                    continue;
                }



                var node = new TreeListNode {
                    Text = element.GetPath()
                };
                node.SubItems.Add(element.Description);

                tagTreeList.Nodes.Add(node);
                FillElement(element, node);
            }
        }
예제 #2
0
        private bool SendStorageCommit(string path, ApplicationEntity host, int status)
        {
            bool result = true;

            try
            {
                StorageCommitServiceSCU commit = new StorageCommitServiceSCU();
                commit.Syntaxes.Add(Syntax.ImplicitVrLittleEndian);
                commit.Role = Role.Scp;

                Association association = new Association();
                association.AddService(commit);

                if (association.Open(host))
                {
                    if (commit.Active)
                    {
                        try
                        {
                            EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                            dicom.Read(path);

                            if (status != 0)
                            {
                                dicom.Add(t.RetrieveAETitle, host.Title);
                                // add the FailedSOPSequence
                                Sequence sequence = new Sequence(t.FailedSOPSequence);
                                dicom.Add(sequence);
                                Elements item = sequence.NewItem();
                                item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPClassUID]);
                                item.Add(dicom[t.ReferencedSOPSequence + t.ReferencedSOPInstanceUID]);
                                item.Add(t.FailureReason, 274);
                                // remove the ReferencedSOPSequence
                                dicom.Remove(t.ReferencedSOPSequence);
                            }

                            result = commit.Report(dicom);
                            Debug.WriteLine("commit done!");
                        }
                        catch (Exception ex)
                        {
                            result = false;
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    result = false;
                    Debug.WriteLine("\ncan't Open.");
                }
                association.Close();
            }
            catch
            {
            }
            RefreshControls();
            return(result);
        }
예제 #3
0
 private void Browser_Load(object sender, EventArgs e)
 {
     try
     {
         if (dicom == null)
         {
             if (filename != null && filename.Length > 0)
             {
                 try
                 {
                     if (filename != null && filename.Length > 0)
                     {
                         stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
                         dicom  = new EK.Capture.Dicom.DicomToolKit.DataSet();
                         dicom.Read(stream);
                     }
                 }
                 catch (Exception ex)
                 {
                     if (!dicom.Part10Header)
                     {
                         System.Windows.Forms.MessageBox.Show("Unable to parse dicom fragment, " + ex.Message);
                     }
                     else
                     {
                         System.Windows.Forms.MessageBox.Show("Valid Dicom header found. Unable to parse dicom file, " + ex.Message);
                     }
                 }
                 finally
                 {
                     if (stream != null)
                     {
                         stream.Close();
                         stream.Dispose();
                         stream = null;
                     }
                 }
             }
             else
             {
                 dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                 dicom.Part10Header = true;
             }
         }
         FillTreeView();
     }
     catch (Exception ex)
     {
         MessageBox.Show(Logging.Log(ex));
     }
 }
예제 #4
0
        private Elements GetCachedDataSet(string name)
        {
            // create a stream on the file
            FileStream input = new FileStream(Path.Combine(info.FullName, name), FileMode.Open, FileAccess.Read, FileShare.Read);

            // and read the contents
            DataSet dicom = new DataSet();

            dicom.Read(input, 0x7000);

            input.Close();
            input.Dispose();

            return(dicom.Elements);
        }
예제 #5
0
        private void Export(string path)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(path))
                {
                    // header
                    writer.Write("\"Filename\"");
                    foreach (String text in mapping)
                    {
                        string[] strings = text.Split(":".ToCharArray());
                        writer.Write(",\"" + ((strings.Length > 1) ? strings[1] : Dictionary.Instance[strings[0]].Description) + "\"");
                    }
                    writer.WriteLine();

                    // rows
                    foreach (FileInfo file in files)
                    {
                        EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                        dicom.Read(file.FullName, 0x7F00);

                        writer.Write("\"" + file.FullName + "\"");

                        foreach (String text in mapping)
                        {
                            string[] strings = text.Split(":".ToCharArray());
                            string   value   = String.Empty;
                            try
                            {
                                value = (dicom.ValueExists(strings[0])) ? ToString(dicom[strings[0]]) : String.Empty;
                            }
                            catch (Exception ex)
                            {
                                Logging.Log(LogLevel.Error, String.Format("Export Value: {0}", ex.Message));
                            }
                            writer.Write(",\"" + value + "\"");
                        }
                        writer.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Log(LogLevel.Error, String.Format("Export: {0}", ex.Message));
            }
        }
예제 #6
0
        private void Shift(string filename)
        {
            using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
            {
                EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                dicom.Read(stream);

                stream.Close();

                // apply the shift to the image pixels
                ushort[] pixels = (ushort[])dicom[t.PixelData].Value;
                for (int n = 0; n < pixels.Length; n++)
                {
                    pixels[n] = lut[pixels[n]];
                }

                if (AddPixelValuesCheckBox.Checked)
                {
                    pixels[0] = 0;
                    pixels[1] = (ushort)(maxvalue - 1);
                }

                dicom.Set(t.BitsStored, N);
                dicom.Set(t.HighBit, N - 1);
                if (AddPixelValuesCheckBox.Checked)
                {
                    pixels[0] = 0;
                    pixels[1] = (ushort)(maxvalue - 1);
                    dicom.Set(t.SmallestImagePixelValue, (ushort)0);
                    dicom.Set(t.LargestImagePixelValue, (ushort)(maxvalue - 1));
                }
                else
                {
                    dicom.Set(t.SmallestImagePixelValue, (ushort)(maxvalue / 4));
                    dicom.Set(t.LargestImagePixelValue, maxvalue - maxvalue / 4);
                }
                dicom.Set(t.WindowWidth, maxvalue / 2);
                dicom.Set(t.WindowCenter, maxvalue / 2);

                FileInfo info = new FileInfo(filename);
                String   text = filename.Replace(info.Extension, "");
                text += "a" + info.Extension;

                dicom.Write(text);
            }
        }
예제 #7
0
        private string ReadDicom(FileInfo file)
        {
            string        error = "\uFFFD";
            StringBuilder line  = new StringBuilder();

            try
            {
                EK.Capture.Dicom.DicomToolKit.DataSet dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();
                dicom.Read(file.FullName, 0x5000);
                for (int n = 0; n < mapping.Count; n++)
                {
                    String   text    = mapping[n];
                    string[] strings = text.Split(":".ToCharArray());
                    string   value   = String.Empty;
                    try
                    {
                        value = (dicom.ValueExists(strings[0])) ? ToString(dicom[strings[0]]) : String.Empty;
                    }
                    catch (Exception ex)
                    {
                        value = error;
                        Logging.Log(LogLevel.Error, String.Format("ReadDicom Value: {0}", ex.Message));
                    }
                    if (n > 0)
                    {
                        line.Append("|");
                    }
                    line.Append(value);
                }
            }
            catch (Exception ex)
            {
                line = new StringBuilder("");
                for (int n = 0; n < mapping.Count; n++)
                {
                    if (n > 0)
                    {
                        line.Append("|");
                    }
                    line.Append(error);
                }
                Logging.Log(LogLevel.Error, String.Format("ReadDicom: {0}", ex.Message));
            }
            return(line.ToString());
        }
예제 #8
0
        private bool SendImage(ApplicationEntity host, string path)
        {
            bool result = true;

            try
            {
                DataSet dicom = new DataSet();
                dicom.Read(path);

                string            uid     = (string)dicom[t.SOPClassUID].Value;
                StorageServiceSCU storage = new StorageServiceSCU(uid);
                storage.Syntaxes.Add(Syntax.ImplicitVrLittleEndian);

                Association association = new Association();
                association.AddService(storage);

                if (association.Open(host))
                {
                    if (storage.Active)
                    {
                        try
                        {
                            storage.Store(dicom);
                        }
                        catch (Exception ex)
                        {
                            result = false;
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    result = false;
                    //Debug.WriteLine("\ncan't Open.");
                }

                association.Close();
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
예제 #9
0
파일: Form1.cs 프로젝트: 1059444127/Dicom-4
        private void Form1_Load(object sender, EventArgs e)
        {
            var testFile = @"D:\Documents\Dose Report\1.2.840.113564.10001.2016033015344433716-dose report-CBCT.dcm";
            var stream   = new FileStream(testFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);

            var dicom = new EK.Capture.Dicom.DicomToolKit.DataSet();

            dicom.Read(stream);

            foreach (Element element in dicom)
            {
                // do not show group length tags
                if (element.element == 0)
                {
                    continue;
                }
                //TreeNode node = root.Nodes.Add(element.GetPath() + " tag", Title(element));
                //FillElement(element, node);
            }
        }
예제 #10
0
        private void PduDataReceived(byte[] pdu)
        {
            //Logging.Log("PduDataReceived {0}", pdu);
            //Dump("<< P-DATA-TF", pdu);

            // TODO this must be able to handle multiple pdvs

            string       syntax  = Syntax.ImplicitVrLittleEndian;
            ServiceClass service = FindServiceClass(pdu[10]);

            if (service != null)
            {
                syntax = service.Syntaxes[0];
            }

            // TODO currently assuming that a Command comes in a single pdu
            // TODO all DataSet fragments are combined into a single Message

            if (MessageControl.IsDataSet((MessageType)pdu[11]))
            {
                //Logging.Log("dataset");
                if (MessageControl.IsNotLast((MessageType)pdu[11]))
                {
                    //Logging.Log("not last fragment");
                    if (file == null)
                    {
                        file = new FileStream(Guid.NewGuid().ToString() + ".tmp", FileMode.Create, FileAccess.ReadWrite);
                        //Dump("PduDataReceived1 ...", pdu);
                    }
                    else
                    {
                        //Logging.Log("Receiving {0} bytes", pdu.Length - 12);
                    }
                    file.Write(pdu, 12, pdu.Length - 12);
                    return;
                }
                else
                {
                    //Logging.Log("last fragment");
                    if (file != null)
                    {
                        Dump("PduDataReceived2 ...", pdu);

                        file.Write(pdu, 12, pdu.Length - 12);
                        file.Flush();

                        DataSet dicom = new DataSet();
                        dicom.TransferSyntaxUID = syntax;

                        file.Seek(0, SeekOrigin.Begin);
                        dicom.Read(file);

                        if (service != null)
                        {
                            try
                            {
                                service.LastMessage = new Message(dicom);
                                ((IPresentationDataSink)service).OnData(MessageType.LastDataSet, service.LastMessage);
                            }
                            catch (Exception ex)
                            {
                                Logging.Log(LogLevel.Error, "Exception in OnData for SOPClassUId={0}, {1}", service.SOPClassUId, ex.Message);
                            }
                        }

                        file.Close();
                        File.Delete(file.Name);
                        file = null;
                        return;
                    }
                }
            }

            // parse response
            MemoryStream        memory   = new MemoryStream(pdu, 0, pdu.Length);
            PresentationDataPdu response = new PresentationDataPdu(syntax);

            response.Read(memory);

            response.Dump();

            foreach (PresentationDataValue pdv in response.Values)
            {
                service = FindServiceClass(pdv.context);
                if (service != null && service is IPresentationDataSink)
                {
                    service.LastMessage = new Message(pdv.Dicom);
                    ((IPresentationDataSink)service).OnData(pdv.control, service.LastMessage);
                }
            }
        }