/// <summary> /// Scans for the given tag in the di file /// </summary> /// <param name="searchTag">tag id to look for</param> /// <returns></returns> public DiDataElement Scan_for(uint searchTag) { var de = new DiDataElement(); var exceptionOccured = false; var inSequence = false; uint searchGroupId = (searchTag >> 16); do { try { de.ReadNext(this); if (de.GetGroupId() < searchGroupId && de.GetElementId() == 0) { Seek(de.GetInt(), SeekOrigin.Current); } } catch (Exception ex) { Debug.Log("DiFileInputStream::get_quick_info failed:" + ex); exceptionOccured = true; } if (searchTag == de.GetTag()) { return(de); } } while (!exceptionOccured && (inSequence || de.GetTag() < 0x00200013)); return(null); }
/// <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(); } }