Exemplo n.º 1
0
        protected static void Parse(string tagPath, out List<DicomTag> parentTags, out DicomTag tag)
        {
            Platform.CheckForNullReference(tagPath, "tagPath");

            parentTags = null;
            tag = null;

            string[] tagPathComponents = tagPath.Split(',');
            if (tagPathComponents != null)
            {
                uint tagValue;
                if (tagPathComponents.Length > 1)
                {
                    parentTags = new List<DicomTag>();

                    for (int i = 0; i < tagPathComponents.Length - 1; i++)
                    {
                        tagValue = uint.Parse(tagPathComponents[i], NumberStyles.HexNumber);
                        DicomTag parent = DicomTagDictionary.GetDicomTag(tagValue);
                        if (parent == null)
                            throw new Exception(String.Format("Specified tag {0} is not in the dictionary", parent));
                        parentTags.Add(parent);
                    }
                }

                tagValue = uint.Parse(tagPathComponents[tagPathComponents.Length - 1], NumberStyles.HexNumber);
                tag = DicomTagDictionary.GetDicomTag(tagValue);
                if (tag == null)
                    throw new Exception(String.Format("Specified tag {0} is not in the dictionary", tag));

            }
        }
Exemplo n.º 2
0
		public DicomFieldAttribute(uint tag, uint parentTag)
			: this(tag)
		{
			_parentTag = DicomTagDictionary.GetDicomTag(parentTag);
			if (_parentTag == null)
				_parentTag = new DicomTag(parentTag, "Unknown Tag", "UnknownTag", DicomVr.UNvr, false, 1, uint.MaxValue, false);
		}
		public DicomAttribute this[DicomTag tag]
		{
			get
			{
				if (_attributes.ContainsKey(tag))
					return _attributes[tag];

				if (!_fieldMap.ContainsKey(tag))
				{
					return null;
				}

				DicomAttribute attr = tag.CreateDicomAttribute();
				object value = _fieldMap[tag].GetValue(_entity, null);
				if (value!=null)
					attr.SetStringValue(value.ToString());
				_attributes.Add(tag, attr);
				return attr;
			}
			set
			{
				if (_fieldMap[tag]!=null)
				{
					_fieldMap[tag].SetValue(_entity, value.ToString(), null);
				}
			}
		}
        internal DicomAttributeMultiValueText(DicomTag tag, ByteBuffer item)
            : base(tag)
        {
            string valueArray;

            valueArray = item.GetString();

            // store the length before removing pad chars
            StreamLength = (uint) valueArray.Length;

            // Saw some Osirix images that had padding on SH attributes with a null character, just
            // pull them out here.
			// Leading and trailing space characters are non-significant in all multi-valued VRs,
			// so pull them out here as well since some devices seem to pad UI attributes with spaces too.
            valueArray = valueArray.Trim(new [] {tag.VR.PadChar, '\0', ' '});

            if (valueArray.Length == 0)
            {
                _values = new string[0];
                Count = 1;
                StreamLength = 0;
            }
            else
            {
                _values = valueArray.Split(new char[] {'\\'});

                Count = (long) _values.Length;
                StreamLength = (uint) valueArray.Length;
            }
        }
Exemplo n.º 5
0
 public DicomAttributeSQ(DicomTag tag)
     : base(tag)
 {
     if (!tag.VR.Equals(DicomVr.SQvr)
      && !tag.MultiVR)
         throw new DicomException(SR.InvalidVR);
 }
		public override bool TryGetAttribute(DicomTag tag, out DicomAttribute attribute)
		{
			lock (SyncLock)
			{
				// the instance dataset should always override the prototype values from the sliceset
				return DataSet.TryGetAttribute(tag, out attribute) || Slice.TryGetAttribute(tag, out attribute);
			}
		}
Exemplo n.º 7
0
		public override DicomAttribute this[DicomTag tag]
		{
			get
			{
				DicomAttribute dicomAttribute;
				return _fusionHeaders.TryGetAttribute(tag, out dicomAttribute) ? dicomAttribute : _realSopDataSource[tag];
			}
		}
Exemplo n.º 8
0
        public DicomFieldAttribute(uint tag)
        {
            _tag = DicomTagDictionary.GetDicomTag(tag);
            if (_tag == null)
                _tag = new DicomTag(tag, "Unknown Tag", "UnknownTag", DicomVr.UNvr, false, 1, uint.MaxValue, false);

            _default = DicomFieldDefault.None;
            _defltOnZL = false;
            _createEmpty = false;
        }
Exemplo n.º 9
0
        public override bool TryGetAttribute(DicomTag tag, out DicomAttribute attribute)
        {
            lock (SyncLock)
            {
                if (NeedFullHeader(tag.TagValue))
                    GetFullHeader();

                return base.TryGetAttribute(tag, out attribute);
            }
        }
		internal DicomAttributeSingleValueText(DicomTag tag, ByteBuffer item)
			: base(tag)
		{
			_value = item.GetString();

			// Saw some Osirix images that had padding on SH attributes with a null character, just
			// pull them out here.
			_value = _value.Trim(new char[] {tag.VR.PadChar, '\0'});

			Count = 1;
			StreamLength = (uint) _value.Length;
		}
Exemplo n.º 11
0
        public override DicomAttribute this[DicomTag tag]
        {
            get
            {
                lock (SyncLock)
                {
                    if (NeedFullHeader(tag.TagValue))
						LoadFullHeader();

                    return base[tag];
                }
            }
        }
Exemplo n.º 12
0
        public override DicomAttribute this[DicomTag tag]
        {
            get
            {
                //the _sop indexer is not thread-safe.
                lock (SyncLock)
                {
                    if (_sop.IsStoredTag(tag))
                        return _sop[tag];

                    return base[tag];
                }
            }
        }
Exemplo n.º 13
0
        public override bool TryGetAttribute(DicomTag tag, out DicomAttribute attribute)
        {
            lock (SyncLock)
            {
                if (_sop.IsStoredTag(tag))
                {
                    attribute = _sop[tag];
                    if (!attribute.IsEmpty)
                        return true;
                }

                return base.TryGetAttribute(tag, out attribute);
            }
        }
Exemplo n.º 14
0
        public override DicomAttribute this[DicomTag tag]
        {
            get
            {
                lock (SyncLock)
                {
                    DicomAttribute attribute;
                    if (TryGetXmlAttribute(tag.TagValue, out attribute))
                        return attribute;

                    return base[tag];
                }
            }
        }
		public override DicomAttribute this[DicomTag tag]
		{
			get
			{
				lock (SyncLock)
				{
					// the instance dataset should always override the prototype values from the sliceset
					// if the operation results in a new attribute being inserted, do it in the instance dataset
					DicomAttribute attribute;
					if (DataSet.TryGetAttribute(tag, out attribute) || Slice.TryGetAttribute(tag, out attribute))
						return attribute;
					return DataSet[tag];
				}
			}
		}
		/// <summary>
		/// Contructor from a <see cref="DicomCompressedPixelData"/> instance.
		/// </summary>
		/// <param name="compressedPixelData"></param>
		public DicomUncompressedPixelData(DicomCompressedPixelData compressedPixelData)
			: base(compressedPixelData)
		{
			if (BitsAllocated > 8)
			{
				_pd = new DicomAttributeOW(DicomTags.PixelData);
			}
			else
			{
				var pdTag = DicomTagDictionary.GetDicomTag(DicomTags.PixelData);
				var obTag = new DicomTag(DicomTags.PixelData, pdTag.Name, pdTag.VariableName, DicomVr.OBvr, pdTag.MultiVR, pdTag.VMLow, pdTag.VMHigh, pdTag.Retired);
				_pd = new DicomAttributeOB(obTag);
			}
			InitializeFrameData(this, _pd);
		}
Exemplo n.º 17
0
		public DicomAttributeSQ(DicomTag tag, ByteBuffer bb)
			: base(tag)
		{
			if (!tag.VR.Equals(DicomVr.SQvr)
			 && !tag.MultiVR)
				throw new DicomException(SR.InvalidVR);

/* This doesn't work yet.  Need to implement a different way.
			DicomStreamReader reader = new DicomStreamReader(bb.Stream);
			reader.Dataset = ds;
			reader.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
			DicomReadStatus stat = reader.Read(new DicomTag(0xffffffff, "Test", "Test", DicomVr.UNvr, false, 1, 1, true), DicomReadOptions.Default);
			if (stat != DicomReadStatus.Success)
			{
				Platform.Log(LogLevel.Error, "Unexpected parsing error ({0}) when reading sequence attribute.", stat);
				throw new DicomDataException("Unexpected error parsing SQ attribute");
			}
*/
		}
Exemplo n.º 18
0
        private InstanceXml GetInstanceXml(StudyXmlOutputSettings outputSettings, out DicomFile real)
        {
            var xml = new StudyXml();
            real = new DicomFile();
            SetupMR(real.DataSet);
            real.MediaStorageSopClassUid = real.DataSet[DicomTags.SopClassUid].ToString();
            real.MetaInfo[DicomTags.SopClassUid].SetString(0, real.DataSet[DicomTags.SopClassUid].ToString());
            
            var bytes = new Byte[2048];
            real.DataSet[DicomTags.RedPaletteColorLookupTableData].Values = bytes;

            var privateTag = new DicomTag(0x00111301, "Private Tag", "PrivateTag", DicomVr.CSvr, false, 1, 1, false);
            real.DataSet[privateTag].SetString(0, "Private");

            var sequences = (DicomSequenceItem[])real.DataSet[DicomTags.RequestAttributesSequence].Values;
            var firstItem = sequences.First();
            firstItem[DicomTags.RedPaletteColorLookupTableData].Values = bytes;

            var attr = real.DataSet[DicomTags.ReferencedStudySequence];
            var sequenceItem = new DicomSequenceItem();
            attr.AddSequenceItem(sequenceItem);
            sequenceItem[privateTag].SetString(0, "Private");

            xml.AddFile(real);
            
            var memento = xml.GetMemento(outputSettings ?? new StudyXmlOutputSettings
            {
                IncludeLargeTags = StudyXmlTagInclusion.IncludeTagExclusion,
                IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag,
                MaxTagLength = 1024
            });

            xml = new StudyXml();
            xml.SetMemento(memento);
            return xml.First().First();
        }
Exemplo n.º 19
0
		public DicomFragmentSequence(DicomTag tag) : base(tag) {}
Exemplo n.º 20
0
			public BinaryDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 21
0
			public AttributeTagDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 22
0
			public TextDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 23
0
			public DateTimeDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 24
0
			public AgeDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 25
0
 /// <summary>
 /// Load a DICOM file (as set by the <see cref="Filename"/> property).
 /// </summary>
 /// <remarks>
 /// Note:  If the file does not contain DICM encoded in it, the routine will assume
 /// the file is not a Part 10 format file, and is instead encoded as just a DataSet
 /// with the transfer syntax set to Implicit VR Little Endian.
 /// </remarks>
 /// <param name="stopTag"></param>
 /// <param name="options">The options to use when reading the file.</param>
 /// <param name="filename">The path of the file to load.</param>
 public void Load(DicomTag stopTag, DicomReadOptions options, string filename)
 {
     Platform.CheckForEmptyString(filename, "filename");
     Filename = filename;
     Load(stopTag, options);
 }
Exemplo n.º 26
0
			public UnsignedDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 27
0
			public IntegerDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 28
0
        private void LoadCore(Stream stream, DicomStreamOpener streamOpener, DicomTag stopTag, DicomReadOptions options)
        {
            // TODO CR (24 Jan 2014): DICOM stream read only uses tag value, so the real implementation should be the uint overload!
            if (stopTag == null)
            {
                stopTag = new DicomTag(0xFFFFFFFF, "Bogus Tag", "BogusTag", DicomVr.NONE, false, 1, 1, false);
            }

            DicomStreamReader dsr;

            var iStream = stream ?? streamOpener.Open();

            if (iStream.CanSeek)
            {
                iStream.Seek(128, SeekOrigin.Begin);
                if (!FileHasPart10Header(iStream))
                {
                    if (!Flags.IsSet(options, DicomReadOptions.ReadNonPart10Files))
                    {
                        throw new DicomException(String.Format("File is not part 10 format file: {0}", Filename));
                    }

                    iStream.Seek(0, SeekOrigin.Begin);
                    dsr = new DicomStreamReader(iStream)
                    {
                        StreamOpener   = streamOpener,
                        TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
                        Dataset        = DataSet
                    };
                    DicomReadStatus stat = dsr.Read(stopTag, options);
                    if (stat != DicomReadStatus.Success)
                    {
                        Platform.Log(LogLevel.Error, "Unexpected error when reading file: {0}", Filename);
                        throw new DicomException("Unexpected read error with file: " + Filename);
                    }

                    TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
                    if (DataSet.Contains(DicomTags.SopClassUid))
                    {
                        MediaStorageSopClassUid = DataSet[DicomTags.SopClassUid].ToString();
                    }
                    if (DataSet.Contains(DicomTags.SopInstanceUid))
                    {
                        MediaStorageSopInstanceUid = DataSet[DicomTags.SopInstanceUid].ToString();
                    }

                    Loaded = true;
                    return;
                }
            }
            else
            {
                // TODO CR (04 Apr 2014): this code here is almost identical to the seekable stream above, except that we use the 4CC wrapper
                // we can combine these two when we trust that the wrapper works in all cases
                iStream = FourCcReadStream.Create(iStream);

                // Read the 128 byte header first, then check for DICM
                iStream.SeekEx(128, SeekOrigin.Begin);

                if (!FileHasPart10Header(iStream))
                {
                    if (!Flags.IsSet(options, DicomReadOptions.ReadNonPart10Files))
                    {
                        throw new DicomException(String.Format("File is not part 10 format file: {0}", Filename));
                    }

                    iStream.Seek(0, SeekOrigin.Begin);
                    dsr = new DicomStreamReader(iStream)
                    {
                        StreamOpener   = streamOpener,
                        TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
                        Dataset        = DataSet
                    };
                    DicomReadStatus stat = dsr.Read(stopTag, options);
                    if (stat != DicomReadStatus.Success)
                    {
                        Platform.Log(LogLevel.Error, "Unexpected error when reading file: {0}", Filename);
                        throw new DicomException("Unexpected read error with file: " + Filename);
                    }

                    TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
                    if (DataSet.Contains(DicomTags.SopClassUid))
                    {
                        MediaStorageSopClassUid = DataSet[DicomTags.SopClassUid].ToString();
                    }
                    if (DataSet.Contains(DicomTags.SopInstanceUid))
                    {
                        MediaStorageSopInstanceUid = DataSet[DicomTags.SopInstanceUid].ToString();
                    }

                    Loaded = true;
                    return;
                }
            }

            dsr = new DicomStreamReader(iStream)
            {
                TransferSyntax = TransferSyntax.ExplicitVrLittleEndian,
                StreamOpener   = streamOpener,
                Dataset        = MetaInfo
            };

            DicomReadStatus readStat =
                dsr.Read(new DicomTag(0x0002FFFF, "Bogus Tag", "BogusTag", DicomVr.UNvr, false, 1, 1, false), options);

            if (readStat != DicomReadStatus.Success)
            {
                Platform.Log(LogLevel.Error, "Unexpected error when reading file Meta info for file: {0}", Filename);
                throw new DicomException("Unexpected failure reading file Meta info for file: " + Filename);
            }

            MetaInfoFileLength = dsr.EndGroupTwo + 128 + 4;

            dsr.Dataset        = DataSet;
            dsr.TransferSyntax = TransferSyntax;
            readStat           = dsr.Read(stopTag, options);
            if (readStat != DicomReadStatus.Success)
            {
                Platform.Log(LogLevel.Error, "Unexpected error ({0}) when reading file at offset {2}: {1}", readStat, Filename, dsr.BytesRead);
                throw new DicomException("Unexpected failure (" + readStat + ") reading file at offset " + dsr.BytesRead + ": " + Filename);
            }

            Loaded = true;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Load a DICOM file from an input stream.
        /// </summary>
        /// <remarks>
        /// Note:  If the file does not contain DICM encoded in it, and
        /// <see cref="Stream.CanSeek"/> is true for <paramref name="iStream"/>,
        /// the routine will assume the file is not a Part 10 format file, and is
        /// instead encoded as just a DataSet with the transfer syntax set to
        /// Implicit VR Little Endian.
        /// </remarks>
        /// <param name="iStream">The input stream to read from.</param>
        /// <param name="stopTag">The dicom tag to stop the reading at.</param>
        /// <param name="options">The dicom read options to consider.</param>
        public void Load(Stream iStream, DicomTag stopTag, DicomReadOptions options)
        {
            if (iStream == null)
            {
                throw new ArgumentNullException("iStream");
            }

            if (stopTag == null)
            {
                stopTag = new DicomTag(0xFFFFFFFF, "Bogus Tag", "BogusTag", DicomVr.NONE, false, 1, 1, false);
            }

            DicomStreamReader dsr;

            if (iStream.CanSeek)
            {
                iStream.Seek(128, SeekOrigin.Begin);
                if (!FileHasPart10Header(iStream))
                {
                    if (!Flags.IsSet(options, DicomReadOptions.ReadNonPart10Files))
                    {
                        throw new DicomException(String.Format("File is not part 10 format file: {0}", Filename));
                    }

                    iStream.Seek(0, SeekOrigin.Begin);
                    dsr = new DicomStreamReader(iStream)
                    {
                        Filename       = Filename,
                        TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
                        Dataset        = DataSet
                    };
                    DicomReadStatus stat = dsr.Read(stopTag, options);
                    if (stat != DicomReadStatus.Success)
                    {
                        Platform.Log(LogLevel.Error, "Unexpected error when reading file: {0}", Filename);
                        throw new DicomException("Unexpected read error with file: " + Filename);
                    }

                    TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
                    if (DataSet.Contains(DicomTags.SopClassUid))
                    {
                        MediaStorageSopClassUid = DataSet[DicomTags.SopClassUid].ToString();
                    }
                    if (DataSet.Contains(DicomTags.SopInstanceUid))
                    {
                        MediaStorageSopInstanceUid = DataSet[DicomTags.SopInstanceUid].ToString();
                    }
                    return;
                }
            }
            else
            {
                // Read the 128 byte header first, then check for DICM
                iStream.Read(new byte[128], 0, 128);

                if (!FileHasPart10Header(iStream))
                {
                    Platform.Log(LogLevel.Error, "Reading DICOM file from stream, file does not have part 10 format header.");
                    throw new DicomException("File being read from stream is not a part 10 format file");
                }
            }

            dsr = new DicomStreamReader(iStream)
            {
                TransferSyntax = TransferSyntax.ExplicitVrLittleEndian,
                //TransferSyntax = TransferSyntax.ImplicitVrLittleEndian,
                Filename = Filename,
                Dataset  = MetaInfo
            };

            DicomReadStatus readStat =
                dsr.Read(new DicomTag(0x0002FFFF, "Bogus Tag", "BogusTag", DicomVr.UNvr, false, 1, 1, false), options);

            if (readStat != DicomReadStatus.Success)
            {
                Platform.Log(LogLevel.Error, "Unexpected error when reading file Meta info for file: {0}", Filename);
                throw new DicomException("Unexpected failure reading file Meta info for file: " + Filename);
            }

            MetaInfoFileLength = dsr.EndGroupTwo + 128 + 4;

            dsr.Dataset        = DataSet;
            dsr.TransferSyntax = TransferSyntax;
            readStat           = dsr.Read(stopTag, options);
            if (readStat != DicomReadStatus.Success)
            {
                Platform.Log(LogLevel.Error, "Unexpected error ({0}) when reading file at offset {2}: {1}", readStat, Filename, dsr.BytesRead);
                //throw new DicomException("Unexpected failure (" + readStat + ") reading file at offset " + dsr.BytesRead + ": " + Filename);
            }

            Loaded = true;
        }
Exemplo n.º 30
0
 /// <summary>
 /// Internal method for creating a new <see cref="DicomAttribute"/> derived class for the VR.
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 internal DicomAttribute CreateDicomAttribute(DicomTag tag)
 {
     return(_createDelegate(tag, null));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Internal method for creating a new <see cref="DicomAttribute"/> derived class for the VR.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="bb"></param>
 /// <returns></returns>
 internal DicomAttribute CreateDicomAttribute(DicomTag tag, ByteBuffer bb)
 {
     return(_createDelegate(tag, bb));
 }
Exemplo n.º 32
0
 /// <summary>
 /// Load a DICOM file from an input stream.
 /// </summary>
 /// <remarks>
 /// Note:  If the file does not contain DICM encoded in it, and
 /// <see cref="Stream.CanSeek"/> is true for <paramref name="stream"/>,
 /// the routine will assume the file is not a Part 10 format file, and is
 /// instead encoded as just a DataSet with the transfer syntax set to
 /// Implicit VR Little Endian.
 ///
 /// Also, this overload cannot be used directly with <see cref="DicomReadOptions.StorePixelDataReferences"/>,
 /// as there must be a way to re-open the same stream at a later time. If the option is required,
 /// use the <see cref="Load(Func{Stream}, DicomTag, DicomReadOptions)">overload</see> that accepts a delegate for opening the stream.
 /// </remarks>
 /// <param name="stream">The input stream to read from.</param>
 /// <param name="stopTag">The dicom tag to stop the reading at.</param>
 /// <param name="options">The dicom read options to consider.</param>
 public void Load(Stream stream, DicomTag stopTag, DicomReadOptions options)
 {
     Platform.CheckForNullReference(stream, "stream");
     LoadCore(stream, null, stopTag, options);
 }
Exemplo n.º 33
0
			public FloatingPointDicomColumnDefintion(DicomTag tag) : base(tag) {}
Exemplo n.º 34
0
		public override bool TryGetAttribute(DicomTag tag, out DicomAttribute attribute)
		{
			return _fusionHeaders.TryGetAttribute(tag, out attribute) || _realSopDataSource.TryGetAttribute(tag, out attribute);
		}
Exemplo n.º 35
0
			public override DicomAttribute this[DicomTag tag]
			{
				get { return _sopDataSource[tag]; }
			}
Exemplo n.º 36
0
			public override bool TryGetAttribute(DicomTag tag, out DicomAttribute attribute)
			{
				return _sopDataSource.TryGetAttribute(tag, out attribute);
			}
Exemplo n.º 37
0
 public DicomFragmentSequence(DicomTag tag) : base(tag)
 {
 }