Exemple #1
0
        public virtual DCMAbstractType Decode(byte[] data, ref uint idx)
        {
            DCMDataElement element = new DCMDataElement();

            //vrdecoder = new US(this);
            //读取TAG
            element.gtag = vrdecoder.GetUShort(data, ref idx);
            element.etag = vrdecoder.GetUShort(data, ref idx);

            if (element.gtag == 0xfffe && element.etag == 0xe000) //处理SQ的三个特殊标记
            {
                DCMDataItem sqitem = new DCMDataItem(this);
                uint        length = vrdecoder.GetUInt(data, ref idx); //不能用GetLength
                uint        offset = idx;
                while (idx - offset < length)
                {
                    DCMAbstractType sqelem = Decode(data, ref idx);                             //递归
                    if (length == 0xffffffff && sqelem.gtag == 0xfffe && sqelem.etag == 0xe00d) //条目结束标记
                    {
                        break;
                    }
                    sqitem.items.Add(sqelem);
                }
                return(sqitem);
            }
            else if (element.gtag == 0xfffe && element.etag == 0xe0dd)  //序列结束标记
            {
                element.vr     = "UL";
                element.length = vrdecoder.GetUInt(data, ref idx);  //不能用GetLength
                return(element);
            }


            //查数据字典得到VR,Name,VM
            element.vr = vrdecoder.GetVR(data, ref idx);

            DicomDictionaryEntry entry = dictionary.GetEntry(element.gtag, element.etag);

            if (entry != null)
            {
                if (element.vr == "")
                {
                    element.vr = entry.VR;
                }
                element.name = entry.Keyword;
                element.vm   = entry.VM;
            }
            else if (element.vr == "" && element.etag == 0)
            {
                element.vr = "US";
            }
            //根据得到的VR实例化具体vr类,此处暂时用vrdecode(即US类对象)
            element.vrparser = vrfactory.GetVR(element.vr);
            vrdecoder        = element.vrparser;
            //读取值长度
            element.length = vrdecoder.GetLength(data, ref idx);
            //读取值
            element.value = vrdecoder.GetValue(data, ref idx, element.length);
            return(element);
        }
Exemple #2
0
 public DicomDictionary()
 {
     string[] line = File.ReadAllLines(@"D:\learning\医用软件设计\实验\实验1\dicom.txt");
     for (int i = 0; i < line.Length; i++)
     {
         DicomDictionaryEntry myEntry = new DicomDictionaryEntry();
         string[]             oneline;
         oneline         = line[i].Split('\t');
         myEntry.Tag     = oneline[0];
         myEntry.Name    = oneline[1];
         myEntry.Keyword = oneline[2];
         myEntry.VR      = oneline[3];
         myEntry.VM      = oneline[4];
         dicomlist.Add(myEntry);
     }
 }
Exemple #3
0
        public DicomDictionaryEntry GetEntry(ushort gtag, ushort etag)
        {
            DicomDictionaryEntry entry = new DicomDictionaryEntry();

            string str = null;

            str = "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")";
            string tag = "\"" + str + "\"";

            for (int i = 0; i < dicomlist.Count; i++)
            {
                if (dicomlist[i].Tag == tag)
                {
                    entry = dicomlist[i];
                    break;
                }
            }
            return(entry);
        }