コード例 #1
0
        /// <summary>
        /// Fills a QuickInfo objects and skips all information that is not necessary.
        /// </summary>
        /// <returns></returns>
        public QuickInfo Get_quick_info()
        {
            var de = new DiDataElement();
            var qi = new QuickInfo();

            VrFormat  = DiFile.VrExplicit;
            Endianess = DiFile.EndianLittle;

            //        // media stored sop
            //        de = scan_for(0x00020002);
            //        if (de!=null) {
            //            qi._media_stored_sop_class_uid = de.get_value_as_string();
            //        } else {
            //            return null;
            //        }

            // transfer syntax
            de = Scan_for(0x00020010);
            if (de != null)
            {
                var tsUid = de.GetValueAsString();
                VrFormat  = DiDictonary.get_ts_uid_vr_format(tsUid);
                Endianess = DiDictonary.get_ts_uid_endianess(tsUid);
                if (VrFormat == DiFile.EndianUnknown)
                {
                    Debug.Log("DiFileInputStream::get_quick_info Warning: Unknown Transfer Syntax UID \"" + tsUid + "\". Endianess & VR format will be guessed.");
                }
            }

            // image type
            de = Scan_for(0x00080008);
            if (de != null)
            {
                var imageType = de.GetValueAsString();
                var split     = imageType.Split(new [] { "\\\\" }, StringSplitOptions.None);
                if (split.Length > 2 && split[2].Equals("SCOUT"))
                {
                    qi.Scout = true;
                }
                else
                {
                    qi.Scout = false;
                }
            }

            // series uid
            de = Scan_for(0x0020000e);
            if (de != null)
            {
                qi.SeriesUid = de.GetValueAsString();
            }
            else
            {
                return(null);
            }

            // image number
            de             = Scan_for(0x00200013);
            qi.ImageNumber = de?.GetInt() ?? 0;

            return(qi);
        }
コード例 #2
0
        /// <summary>
        /// Initializes the DiFile from a file. Might throw an exception (unexpected
        /// end of file, wrong data etc).
        /// </summary>
        /// <param name="fileName">file_name a string containing the name of a valid dicom file</param>
        public void InitFromFile(string fileName)
        {
            _fileName = fileName;
            var file = new DiFileStream(_fileName);

            if (!file.SkipHeader())
            {
                return;
            }
            DiDataElement deOld = null, diDataElement;

            var i = 0;

            // read rest
            do
            {
                diDataElement = new DiDataElement();
                diDataElement.ReadNext(file);
                // System.out.println(de);
                // byte_sum += de._vl;

                if (diDataElement.GetTag() == 0xfffee000)
                {
                    // handle sequences ...
                    var seq   = new Dictionary <uint, DiDataElement>();
                    var seqDe = new DiDataElement();
                    while (seqDe.GetTag() != 0xfffee0dd)
                    {
                        seqDe = new DiDataElement();
                        seqDe.ReadNext(file);
                        seq[seqDe.GetTag()] = seqDe;
                    }

                    _sequences[deOld.GetTag()] = seq;
                }
                else if (diDataElement.GetTag() == 0x7fe00010 && diDataElement.GetVl() == 0)
                {
                    // encapsulated pixel format
                    var seq         = new Dictionary <uint, DiDataElement>();
                    var seqDe       = new DiDataElement();
                    var pixelDataDe = diDataElement;
                    var count       = 0;

                    while (seqDe.GetTag() != 0xfffee0dd)
                    {
                        Debug.Log(count + " -> " + seqDe);
                        seqDe = new DiDataElement();
                        seqDe.ReadNext(file);
                        if (seqDe.GetVl() > 4)
                        {
                            pixelDataDe = seqDe;
                        }

                        seq[seqDe.GetTag()] = seqDe;
                        count++;
                    }

                    _dataElements[diDataElement.GetTag()] = pixelDataDe;
                }
                else
                {
                    // handle all but sequences
                    _dataElements[diDataElement.GetTag()] = diDataElement;
                }

                i++;
                deOld = diDataElement;
            } while (diDataElement.GetTag() != 0x07fe0010 && file.CanRead && file.Position < file.Length);


            file.Close();

            // image number
            if (_dataElements.TryGetValue(0x00200013, out diDataElement))
            {
                _imageNumber = diDataElement.GetInt();
            }

            // image height
            if (_dataElements.TryGetValue(0x00280010, out diDataElement))
            {
                _height = diDataElement.GetInt();
            }

            // image width
            if (_dataElements.TryGetValue(0x00280011, out diDataElement))
            {
                _width = diDataElement.GetInt();
            }

            // Bits/Pixel allocated
            if (_dataElements.TryGetValue(0x00280100, out diDataElement))
            {
                _bitsAllocated = diDataElement.GetInt();
            }

            // Bits/Pixel stored
            if (_dataElements.TryGetValue(0x00280101, out diDataElement))
            {
                _bitsStored = diDataElement.GetInt();
            }

            // high bit
            if (_dataElements.TryGetValue(0x00280102, out diDataElement))
            {
                _highBit = diDataElement.GetInt();
            }
        }