public DicomDictonaryEntry GetEntry(ushort gtag, ushort etag) { string newtag = '"' + "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")" + '"'; dde = dict.Find(dde => dde.tag == newtag); return(dde); }
public virtual DCMAbstractType Decode(byte[] data, ref uint idx) { DCMDataElement element = new DCMDataElement(); //读取TAG element.gtag = vrdecoder.GetGroupTag(data, ref idx); element.etag = vrdecoder.GetElementTag(data, ref idx); //处理SQ 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); DicomDictonaryEntry entry = dicomDictionary.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子类对象 element.vrparser = vrfactory.GetVR(element.vr); //读取值长度 element.length = element.vrparser.GetLength(data, ref idx); //读取值 element.value = element.vrparser.GetValue(data, ref idx, element.length); element.idx = idx; return(element); }
private string encodeVR(ushort gtag, ushort etag) { DicomDictonaryEntry dd = new DicomDictonaryEntry(); DicomDictionary dde = new DicomDictionary(); dd = dde.GetEntry(gtag, etag); string vr = dd.VR; return(vr); }
public DicomDictionary() { StreamReader sr = new StreamReader("dicom.txt", Encoding.Default); String line; while ((line = sr.ReadLine()) != null) { DicomDictonaryEntry dde = new DicomDictonaryEntry(); string[] a = line.Split('\t'); dde.tag = a[0]; dde.Name = a[1]; dde.Keyword = a[2]; dde.VR = a[3]; dde.VM = a[4]; dict.Add(dde); } }
public virtual DCMAbstractType Decode(byte[] data, ref uint idx) { DCMDataElement element = new DCMDataElement(); //读取TAG element.gtag = vrdecoder.GetGroupTag(data, ref idx); element.etag = vrdecoder.GetElementTag(data, ref idx); //这一项仅仅只用于测试容易看出,Reference==0; string tag = "(" + element.gtag.ToString("X4") + "," + element.etag.ToString("X4") + ")"; if (element.gtag == 0xfffe && element.etag == 0xe000) { DCMDataItem sqitem = new DCMDataItem(this); sqitem.gtag = element.gtag; sqitem.etag = element.etag; uint length = vrdecoder.GetUInt32(data, ref idx); sqitem.length = length; uint offset = idx; //idx小于value长度时,不断地调用Decode方法来解锁; while (idx - offset < length) { //递归,不断地解码 //解出Tag不为DataElemt类型时,重复的递归 DCMAbstractType sqelem = Decode(data, ref idx); if (sqelem.gtag == 0xfffe && sqelem.etag == 0xe00d) { break; } sqitem[0] = sqelem; } return(sqitem); } else if (element.gtag == 0xfffe && element.etag == 0xe00d) //序列结束标记 { element.vr = "UL"; //回归初始状态 element.length = vrdecoder.GetUInt32(data, ref idx); //不能用GetLength //且不用解出Value return(element); } else if (element.gtag == 0xfffe && element.etag == 0xe0dd) { element.vr = "UL";//回归初始状态 element.length = vrdecoder.GetUInt32(data, ref idx); //不能用GetLength //不用解出Value类了; return(element); } //查数据字典得到VR,Name,VM element.vr = vrdecoder.GetVR(data, ref idx); //0002系类文件头并没有在DicomDirationay内有定义 DicomDictonaryEntry entry = dictionary.GetEntry(element.gtag, element.etag); if (entry != null) { element.vr = entry.VR; element.name = entry.Keyword; element.vm = entry.VM; } else if (element.vr == "" && element.etag == 0) { element.vr = "US"; } if (element.vr == "OB or OW") { //在上一层找items[DicomTags.BitsAllocated];但是上层对下层是完全不透明的;怎么办 element.vr = "OW"; } try { vrdecoder = vrfactory.GetVR(element.vr); element.vrparser = vrdecoder; //读取值长度 element.length = vrdecoder.GetLength(data, ref idx, element.vr); //读取值 element.value = vrdecoder.GetValue(data, ref idx, element.length); return(element); } catch { throw; } }