コード例 #1
0
        public DicomDictionaryEntry(DicomMaskedTag tag, string name, string keyword, DicomVM vm, bool retired, params DicomVR[] vrs)
        {
            Tag     = tag.Tag;
            MaskTag = tag;

            if (String.IsNullOrWhiteSpace(name))
            {
                Name = Tag.ToString();
            }
            else
            {
                Name = name;
            }

            if (String.IsNullOrWhiteSpace(keyword))
            {
                Keyword = Name.Replace(" ", "");
            }
            else
            {
                Keyword = keyword;
            }

            ValueMultiplicity    = vm;
            ValueRepresentations = vrs;
            IsRetired            = retired;
        }
コード例 #2
0
        public DicomDictionaryEntry(
            DicomMaskedTag tag,
            string name,
            string keyword,
            DicomVM vm,
            bool retired,
            params DicomVR[] vrs)
        {
            Tag     = tag.Tag;
            MaskTag = tag;

            if (string.IsNullOrEmpty(name?.Trim()))
            {
                Name = Tag.ToString();
            }
            else
            {
                Name = name;
            }

            if (string.IsNullOrEmpty(keyword?.Trim()))
            {
                Keyword = Name;
            }
            else
            {
                Keyword = keyword;
            }

            ValueMultiplicity    = vm;
            ValueRepresentations = vrs;
            IsRetired            = retired;
        }
コード例 #3
0
 private static void LoadInternalDictionaries()
 {
     lock (_lock) {
         if (_default == null)
         {
             _default = new DicomDictionary();
             _default.Add(new DicomDictionaryEntry(DicomMaskedTag.Parse("xxxx", "0000"), "Group Length", "GroupLength", DicomVM.VM_1, false, DicomVR.UL));
             try {
                 var assembly = Assembly.GetExecutingAssembly();
                 var stream   = assembly.GetManifestResourceStream("Dicom.Dictionaries.DICOM Dictionary.xml.gz");
                 var gzip     = new GZipStream(stream, CompressionMode.Decompress);
                 var reader   = new DicomDictionaryReader(_default, DicomDictionaryFormat.XML, gzip);
                 reader.Process();
             } catch (Exception e) {
                 throw new DicomDataException("Unable to load DICOM dictionary from resources.\n\n" + e.Message, e);
             }
             try {
                 var assembly = Assembly.GetExecutingAssembly();
                 var stream   = assembly.GetManifestResourceStream("Dicom.Dictionaries.Private Dictionary.xml.gz");
                 var gzip     = new GZipStream(stream, CompressionMode.Decompress);
                 var reader   = new DicomDictionaryReader(_default, DicomDictionaryFormat.XML, gzip);
                 reader.Process();
             } catch (Exception e) {
                 throw new DicomDataException("Unable to load private dictionary from resources.\n\n" + e.Message, e);
             }
         }
     }
 }
コード例 #4
0
        public void Add_PrivateTag_GetsCorrectVR()
        {
            var privCreatorDictEntry = new DicomDictionaryEntry(
                new DicomTag(0x0011, 0x0010),
                "Private Creator",
                "PrivateCreator",
                DicomVM.VM_1,
                false,
                DicomVR.LO);

            DicomDictionary.Default.Add(privCreatorDictEntry);

            DicomPrivateCreator privateCreator1 = DicomDictionary.Default.GetPrivateCreator("TESTCREATOR1");
            DicomDictionary     privDict1       = DicomDictionary.Default[privateCreator1];

            var dictEntry = new DicomDictionaryEntry(
                DicomMaskedTag.Parse("0011", "xx10"),
                "TestPrivTagName",
                "TestPrivTagKeyword",
                DicomVM.VM_1,
                false,
                DicomVR.CS);

            privDict1.Add(dictEntry);

            var ds = new DicomDataset
            {
                { dictEntry.Tag, "VAL1" }
            };

            Assert.Equal(DicomVR.CS, ds.Get <DicomVR>(ds.GetPrivateTag(dictEntry.Tag)));
        }
コード例 #5
0
 /// <summary>
 /// Copies tags matching mask to the destination dataset.
 /// </summary>
 /// <param name="destination">Destination Dataset</param>
 /// <param name="mask">Tags to copy</param>
 /// <returns>Current Dataset</returns>
 public DicomDataset CopyTo(DicomDataset destination, DicomMaskedTag mask)
 {
     if (destination != null)
     {
         destination.Add(_items.Values.Where(x => mask.IsMatch(x.Tag)));
     }
     return(this);
 }
コード例 #6
0
		public DicomDictionaryEntry(DicomMaskedTag tag, string name, string keyword, DicomVM vm, bool retired, params DicomVR[] vrs) {
			Tag = tag.Tag;
			MaskTag = tag;

			if (String.IsNullOrWhiteSpace(name))
				Name = Tag.ToString();
			else
				Name = name;

			if (String.IsNullOrWhiteSpace(keyword))
				Keyword = Name;
			else
				Keyword = keyword;

			ValueMultiplicity = vm;
			ValueRepresentations = vrs;
			IsRetired = retired;
		}
コード例 #7
0
        public void Add_PrivateTag_ShouldBeAddedWithCorrectVR()
        {
            var privCreatorDictEntry = new DicomDictionaryEntry(new DicomTag(0x0011, 0x0010), "Private Creator", "PrivateCreator", DicomVM.VM_1, false, DicomVR.LO);

            DicomDictionary.Default.Add(privCreatorDictEntry);

            DicomPrivateCreator privateCreator1 = DicomDictionary.Default.GetPrivateCreator("TESTCREATOR1");
            DicomDictionary     privDict1       = DicomDictionary.Default[privateCreator1];

            var dictEntry = new DicomDictionaryEntry(DicomMaskedTag.Parse("0011", "xx10"), "TestPrivTagName", "TestPrivTagKeyword", DicomVM.VM_1, false, DicomVR.CS);

            privDict1.Add(dictEntry);

            var ds = new DicomDataset();

            ds.Add(dictEntry.Tag, "VAL1");
            Assert.Equal(DicomVR.CS, ds.GetDicomItem <DicomItem>(dictEntry.Tag).ValueRepresentation);
        }
コード例 #8
0
ファイル: DicomMaskedTag.cs プロジェクト: zinan/fo-dicom
        public static DicomMaskedTag Parse(string group, string element)
        {
            try
            {
                DicomMaskedTag tag = new DicomMaskedTag();

                ushort g = ushort.Parse(group.ToLower().Replace('x', '0'), NumberStyles.HexNumber);
                ushort e = ushort.Parse(element.ToLower().Replace('x', '0'), NumberStyles.HexNumber);
                tag.Tag = new DicomTag(g, e);

                string mask = (group + element).ToLowerInvariant();
                mask =
                    mask.Replace('0', 'f')
                    .Replace('1', 'f')
                    .Replace('2', 'f')
                    .Replace('3', 'f')
                    .Replace('4', 'f')
                    .Replace('5', 'f')
                    .Replace('6', 'f')
                    .Replace('7', 'f')
                    .Replace('8', 'f')
                    .Replace('9', 'f')
                    .Replace('a', 'f')
                    .Replace('b', 'f')
                    .Replace('c', 'f')
                    .Replace('d', 'f')
                    .Replace('e', 'f')
                    .Replace('f', 'f')
                    .Replace('x', '0');
                tag.Mask = uint.Parse(mask, NumberStyles.HexNumber);

                return(tag);
            }
            catch (Exception e)
            {
                throw new DicomDataException(
                          "Error parsing masked DICOM tag [group:'" + group + "', element:'" + element + "']",
                          e);
            }
        }
コード例 #9
0
        public void Enumerate_DictionaryEntriesWithPrivateTags_ContainsAllExpectedEntries()
        {
            var dict = new DicomDictionary();

            var tag1       = new DicomTag(0x0010, 0x0020);
            var dictEntry1 = new DicomDictionaryEntry(
                tag1,
                "TestPublicTagName",
                "TestPublicTagKeyword",
                DicomVM.VM_1,
                false,
                DicomVR.DT);
            var privCreatorDictEntry = new DicomDictionaryEntry(
                new DicomTag(0x0011, 0x0010),
                "Private Creator",
                "PrivateCreator",
                DicomVM.VM_1,
                false,
                DicomVR.LO);

            dict.Add(privCreatorDictEntry);

            DicomPrivateCreator privateCreator = dict.GetPrivateCreator("TESTCREATOR");
            DicomDictionary     privDict       = dict[privateCreator];

            var dictEntry2 = new DicomDictionaryEntry(
                DicomMaskedTag.Parse("0011", "xx10"),
                "TestPrivTagName",
                "TestPrivTagKeyword",
                DicomVM.VM_1,
                false,
                DicomVR.DT);

            privDict.Add(dictEntry2);
            dict.Add(dictEntry1);

            Assert.Contains(dictEntry1, dict);
            Assert.Contains(privCreatorDictEntry, dict);
            Assert.Contains(dictEntry2, dict[dictEntry2.Tag.PrivateCreator]);
        }
コード例 #10
0
 /// <summary>
 /// Copies tags matching mask to the destination dataset.
 /// </summary>
 /// <param name="destination">Destination Dataset</param>
 /// <param name="mask">Tags to copy</param>
 /// <returns>Current Dataset</returns>
 public DicomDataset CopyTo(DicomDataset destination, DicomMaskedTag mask)
 {
     destination?.AddOrUpdate(_items.Values.Where(x => mask.IsMatch(x.Tag)));
     return(this);
 }
コード例 #11
0
        /// <summary>
        /// Ensures the default DICOM dictionaries are loaded
        /// Safe to call multiple times but will throw an exception if inconsistent values for loadPrivateDictionary are provided over multiple calls
        /// </summary>
        /// <param name="loadPrivateDictionary">Leave null (default value) if unconcerned.  Set true to search for resource streams named "Dicom.Dictionaries.Private Dictionary.xml.gz" in referenced assemblies</param>
        /// <returns></returns>
        public static DicomDictionary EnsureDefaultDictionariesLoaded(bool?loadPrivateDictionary = null)
        {
            // short-circuit if already initialised (#151).
            if (_default != null)
            {
                if (loadPrivateDictionary.HasValue && _defaultIncludesPrivate != loadPrivateDictionary.Value)
                {
                    throw new DicomDataException("Default DICOM dictionary already loaded " +
                                                 (_defaultIncludesPrivate ? "with" : "without") +
                                                 "private dictionary and the current request to ensure the default dictionary is loaded requests that private dictionary " +
                                                 (loadPrivateDictionary.Value ? "is" : "is not") + " loaded");
                }
                return(_default);
            }

            lock (_lock)
            {
                if (_default == null)
                {
                    var dict = new DicomDictionary();
                    dict.Add(
                        new DicomDictionaryEntry(
                            DicomMaskedTag.Parse("xxxx", "0000"),
                            "Group Length",
                            "GroupLength",
                            DicomVM.VM_1,
                            false,
                            DicomVR.UL));
                    try
                    {
#if NET35 || HOLOLENS
                        using (
                            var stream =
                                new MemoryStream(
                                    UnityEngine.Resources.Load <UnityEngine.TextAsset>("DICOM Dictionary").bytes))
                        {
                            var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, stream);
                            reader.Process();
                        }
#else
                        var assembly = typeof(DicomDictionary).GetTypeInfo().Assembly;
                        using (
                            var stream = assembly.GetManifestResourceStream(
                                "Dicom.Dictionaries.DICOMDictionary.xml.gz"))
                        {
                            var gzip   = new GZipStream(stream, CompressionMode.Decompress);
                            var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, gzip);
                            reader.Process();
                        }
#endif
                    }
                    catch (Exception e)
                    {
                        throw new DicomDataException(
                                  "Unable to load DICOM dictionary from resources.\n\n" + e.Message,
                                  e);
                    }
                    if (loadPrivateDictionary.GetValueOrDefault(true))
                    {
                        try
                        {
#if NET35 || HOLOLENS
                            using (
                                var stream =
                                    new MemoryStream(
                                        UnityEngine.Resources.Load <UnityEngine.TextAsset>("Private Dictionary").bytes))
                            {
                                var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, stream);
                                reader.Process();
                            }
#else
                            var assembly = typeof(DicomDictionary).GetTypeInfo().Assembly;
                            using (
                                var stream =
                                    assembly.GetManifestResourceStream("Dicom.Dictionaries.PrivateDictionary.xml.gz"))
                            {
                                var gzip   = new GZipStream(stream, CompressionMode.Decompress);
                                var reader = new DicomDictionaryReader(dict, DicomDictionaryFormat.XML, gzip);
                                reader.Process();
                            }
#endif
                        }
                        catch (Exception e)
                        {
                            throw new DicomDataException(
                                      "Unable to load private dictionary from resources.\n\n" + e.Message,
                                      e);
                        }
                    }

                    _defaultIncludesPrivate = loadPrivateDictionary.GetValueOrDefault(true);
                    _default = dict;
                }
                else
                {
                    //ensure the race wasn't for two different "load private dictionary" states
                    if (loadPrivateDictionary.HasValue && _defaultIncludesPrivate != loadPrivateDictionary)
                    {
                        throw new DicomDataException("Default DICOM dictionary already loaded " +
                                                     (_defaultIncludesPrivate ? "with" : "without") +
                                                     "private dictionary and the current request to ensure the default dictionary is loaded requests that private dictionary " +
                                                     (loadPrivateDictionary.Value ? "is" : "is not") + " loaded");
                    }
                    return(_default);
                }

                //race is complete
                return(_default);
            }
        }
コード例 #12
0
        private void ReadDictionaryXML()
        {
            DicomDictionary dict = _dict;

            XDocument xdoc = XDocument.Load(_stream);

            IEnumerable <XElement> xdicts;

            if (xdoc.Root.Name == "dictionaries")
            {
                xdicts = xdoc.Root.Elements("dictionary");
            }
            else
            {
                XElement xdict = xdoc.Element("dictionary");
                if (xdict == null)
                {
                    throw new DicomDataException("Expected <dictionary> root node in DICOM dictionary.");
                }

                List <XElement> dicts = new List <XElement>();
                dicts.Add(xdict);
                xdicts = dicts;
            }

            foreach (var xdict in xdicts)
            {
                XAttribute creator = xdict.Attribute("creator");
                if (creator != null && !String.IsNullOrEmpty(creator.Value))
                {
                    dict = _dict[_dict.GetPrivateCreator(creator.Value)];
                }
                else
                {
                    dict = _dict;
                }

                foreach (XElement xentry in xdict.Elements("tag"))
                {
                    string name = xentry.Value ?? "Unknown";

                    string keyword = String.Empty;
                    if (xentry.Attribute("keyword") != null)
                    {
                        keyword = xentry.Attribute("keyword").Value;
                    }

                    List <DicomVR> vrs = new List <DicomVR>();
                    XAttribute     xvr = xentry.Attribute("vr");
                    if (xvr != null && !String.IsNullOrEmpty(xvr.Value))
                    {
                        string[] vra = xvr.Value.Split('_', '/', '\\', ',', '|');
                        foreach (string vr in vra)
                        {
                            vrs.Add(DicomVR.Parse(vr));
                        }
                    }
                    else
                    {
                        vrs.Add(DicomVR.NONE);
                    }

                    DicomVM vm = DicomVM.Parse(xentry.Attribute("vm").Value);

                    bool       retired  = false;
                    XAttribute xretired = xentry.Attribute("retired");
                    if (xretired != null && !String.IsNullOrEmpty(xretired.Value) && Boolean.Parse(xretired.Value))
                    {
                        retired = true;
                    }

                    string group   = xentry.Attribute("group").Value;
                    string element = xentry.Attribute("element").Value;
                    if (group.ToLower().Contains("x") || element.ToLower().Contains("x"))
                    {
                        DicomMaskedTag tag = DicomMaskedTag.Parse(group, element);
                        tag.Tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                    else
                    {
                        DicomTag tag = DicomTag.Parse(group + "," + element);
                        tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                }
            }
        }
コード例 #13
0
 /// <summary>
 /// Enumerates DICOM items matching mask.
 /// </summary>
 /// <param name="dataset">Dataset from which masked items should be retrieved.</param>
 /// <param name="mask">Requested mask.</param>
 /// <returns>Enumeration of masked DICOM items.</returns>
 public static IEnumerable <DicomItem> EnumerateMasked(this DicomDataset dataset, DicomMaskedTag mask)
 {
     return(dataset.Where(x => mask.IsMatch(x.Tag)));
 }
コード例 #14
0
ファイル: DicomMaskedTag.cs プロジェクト: ZeryZhang/fo-dicom
		public static DicomMaskedTag Parse(string group, string element) {
			try {
				DicomMaskedTag tag = new DicomMaskedTag();

				ushort g = ushort.Parse(group.ToLower().Replace('x', '0'), NumberStyles.HexNumber);
				ushort e = ushort.Parse(element.ToLower().Replace('x', '0'), NumberStyles.HexNumber);
				tag.Tag = new DicomTag(g, e);

				string mask = group + element;
				mask = mask.Replace('0', 'f').Replace('1', 'f').Replace('2', 'f')
							.Replace('3', 'f').Replace('4', 'f').Replace('5', 'f')
							.Replace('6', 'f').Replace('7', 'f').Replace('8', 'f')
							.Replace('9', 'f').Replace('a', 'f').Replace('b', 'f')
							.Replace('c', 'f').Replace('d', 'f').Replace('e', 'f')
							.Replace('f', 'f').Replace('x', '0');
				tag.Mask = uint.Parse(mask, NumberStyles.HexNumber);

				return tag;
			} catch (Exception e) {
				throw new DicomDataException("Error parsing masked DICOM tag [group:'" + group + "', element:'" + element +"']", e);
			}
		}
コード例 #15
0
		public RemoveElementDicomTransformRule(DicomMaskedTag mask) {
			_mask = mask;
		}
コード例 #16
0
 public RemoveElementDicomTransformRule(DicomMaskedTag mask)
 {
     _mask = mask;
 }
コード例 #17
0
		/// <summary>
		/// Enumerates DICOM items matching mask.
		/// </summary>
		/// <param name="mask">Mask</param>
		/// <returns>Enumeration of DICOM items</returns>
		public static IEnumerable<DicomItem> EnumerateMasked(this DicomDataset dataset, DicomMaskedTag mask) {
			return dataset.Where(x => mask.IsMatch(x.Tag));
		}