コード例 #1
0
        public override List <DCMAbstractType> Decode(byte[] data, ref uint idx)
        {
            uint temp_idx = 0;

            while (idx < data.Length)
            {
                DCMAbstractType item = null;
                try
                {
                    item = syntax.Decode(data, ref idx);
                    if (item != null && item.gtag == 0x0002)
                    {
                        items.Add(item);
                        temp_idx = idx;
                    }
                    else
                    {
                        //但要注意最后那条数据元素必须通过修改idx退回到缓冲区
                        idx = temp_idx;
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (e.GetType() == typeof(NullReferenceException))
                    {
                        idx = temp_idx;
                        break;
                    }
                }
            }
            return(items);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 /// <summary>
 /// 当中调用传输语法类对象从data[idx]开始解码一条数据元素,添加到items, 循环将整个数据集解码,返回items, 同时变化后的idx通过引用(ref)返回。
 /// </summary>
 public virtual List <DCMAbstractType> Decode(byte[] data, ref uint idx)
 {
     while (idx < data.Length)
     {
         DCMAbstractType item = null;
         item = syntax.Decode(data, ref idx);
         items.Add(item);
     }
     return(items);
 }
コード例 #4
0
        public override List <DCMAbstractType> Decode(byte[] data, ref uint idx)
        {
            filemete = new DCMFileMeta(new ExplicitVRLittleEndian());
            DCMAbstractType uid  = filemete.Decode(data, ref idx).Find((DCMAbstractType type) => type.etag == 0x0010 && type.gtag == 0x0002);
            string          uid1 = uid.GetValue <string>();
            TransferSyntax  syn  = TransferSyntaxs.All[uid1];

            Data = new DCMDataSet(syn);
            Data.Decode(data, ref idx);

            return(items);
        }
コード例 #5
0
        public override List <DCMAbstractType> Decode(byte[] data, ref uint idx)
        {
            DCMAbstractType item = TransferSyntax.Decode(data, ref idx);

            if (item.gtag == 0xfffe && item.etag == 0xe000)  //item start
            {
                uint   ulidx = 0;
                byte[] val   = (byte[])item.value;
                base.Decode(val, ref ulidx);
                //tudo:修正idx位置
                if (item.length == 0xffffffff)  //修正idx位置
                {
                    idx -= (uint)(item.length - ulidx);
                }
            }
            return(items);
        }
コード例 #6
0
 public override List <DCMAbstractType> Decode(byte[] data, ref uint idx)
 {
     while (idx < data.Length)
     {
         DCMAbstractType item = null;
         //此处调用传输语法对象解码一条数据元素
         item = TransferSyntax.Decode(data, ref idx);
         if (item.gtag == 0x0002)
         {
             items.Add(item);
         }
         else
         {
             idx -= item.length;
             idx -= 8;
             break;
         }
     }
     return(items);
 }
コード例 #7
0
 public override List <DCMAbstractType> Decode(byte[] data, ref uint idx)
 {
     while (idx < data.Length)
     {
         DCMAbstractType metaitem = null;
         uint            i        = idx;//保存原始idx
         //此处调用传输语法对象解码一条数据元素
         metaitem = syntax.Decode(data, ref idx);
         if (metaitem.gtag == 0x0002)//将文件头元素存入容器
         {
             items.Add(metaitem);
         }
         else//修改idx退回到缓冲区
         {
             idx = items[items.Count - 1].idx;
             break;
         }
     }
     return(items);
 }
コード例 #8
0
ファイル: LongVR.cs プロジェクト: alittlehorse/DCMLIB
        /// <summary>
        /// SQ必须重写GetValue方法,因为传进来的参数length是由前边的Getlength方法获取的
        /// 而SQ可能取值FFFF
        /// </summary>
        /// <param name="data"></param>
        /// <param name="idx"></param>
        /// <param name="length">传入长度数值</param>
        /// <returns></returns>
        public override byte[] GetValue(byte[] data, ref uint idx, uint length)
        {
            uint            offset = idx;
            DCMDataSequence sq     = new DCMDataSequence(syntax);

            while (idx - offset < length)
            {
                DCMAbstractType item = syntax.Decode(data, ref idx);
                if (item.gtag == 0xfffe && item.etag == 0xe0dd)
                {
                    break;
                }
                else
                {
                    sq[0] = (DCMDataItem)item;
                }
            }
            GCHandle handle = GCHandle.Alloc(sq);
            IntPtr   ptr    = GCHandle.ToIntPtr(handle);

            return(BitConverter.GetBytes(ptr.ToInt64()));
        }
コード例 #9
0
 //DCMDataSet索引成员
 public virtual DCMAbstractType this[uint idx]
 {
     get
     {
         //拉姆达表达式(匿名函数)比较tag与索引idx是否相等,返回索引结果
         DCMAbstractType item = items.Find(elem => (uint)(elem.gtag << 16) + (elem.etag) == idx);
         return(item);
     }
     set
     {
         DCMAbstractType val  = (DCMAbstractType)value;
         DCMAbstractType item = items.Find(elem => (uint)(elem.gtag << 16 + (elem.etag)) == idx);
         if (item == null)  //not exists
         {
             items.Add(val);
         }
         else
         {
             item.length = val.length;
             item.value  = val.value;
         }
     }
 }
コード例 #10
0
        public virtual List <DCMAbstractType> Decode(byte[] data, ref uint idx)
        {
            while (idx < data.Length)
            {
                //此处调用传输语法对象解码一条数据元素
                //DCMAbstractType item = TransferSyntax.Decode(data, ref idx);
                DCMAbstractType item = TransferSyntax.Decode(data, ref idx);
                //判断特殊标记
                if (item.gtag == 0xfffe && item.etag == 0xe0dd)
                {
                    break;
                }
                if (item.gtag == 0xfffe && item.etag == 0xe00d)
                {
                    break;
                }


                if (item.vr == "SQ")
                {
                    DCMDataSequnce sq    = new DCMDataSequnce(TransferSyntax);
                    uint           ulidx = 0;
                    byte[]         val   = (byte[])item.value;
                    sq.Decode(val, ref ulidx);
                    item.value = sq;
                    //todo:修正idx位置
                    if (item.length == 0xffffffff)  //修正idx位置
                    {
                        idx -= (uint)(item.length - ulidx);
                    }
                }

                items.Add(item);
            }
            return(items);
        }
コード例 #11
0
ファイル: TransferSyntax.cs プロジェクト: alittlehorse/DCMLIB
        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;
            }
        }