Пример #1
0
        public static DicomVM Parse(string s)
        {
            try
            {
                DicomVM vm = null;
                if (_vm.TryGetValue(s, out vm))
                {
                    return(vm);
                }

                string[] parts = s.Split(new[] { "-", " ", "or" }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length == 1)
                {
                    vm              = new DicomVM();
                    vm.Minimum      = int.Parse(parts[0]);
                    vm.Maximum      = vm.Minimum;
                    vm.Multiplicity = vm.Minimum;
                }
                else
                {
                    vm = new DicomVM
                    {
                        Minimum      = int.Parse(parts[0]),
                        Multiplicity = 1
                    };

                    if (parts[1].IndexOf("n", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        vm.Maximum = int.MaxValue;
                        parts[1]   = parts[1].TrimEnd('n', 'N');

                        if (parts[1].Length > 0)
                        {
                            vm.Multiplicity = int.Parse(parts[1]);
                        }
                    }
                    else
                    {
                        vm.Maximum = int.Parse(parts[1]);
                    }
                }

                _vm.Add(s, vm);

                return(vm);
            }
            catch (Exception e)
            {
                throw new DicomDataException("Error parsing value multiplicty ['" + s + "']", e);
            }
        }
Пример #2
0
        private void ReadDictionaryXML()
        {
            DicomDictionary dict = _dict;

            var 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.");
                }

                var 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;
                    }

                    var        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);
                    }

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

                    bool       retired  = false;
                    XAttribute xretired = xentry.Attribute("retired");
                    if (xretired != null && !string.IsNullOrEmpty(xretired.Value) && bool.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"))
                    {
                        var tag = DicomMaskedTag.Parse(group, element);
                        tag.Tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                    else
                    {
                        var tag = DicomTag.Parse(group + "," + element);
                        tag.PrivateCreator = dict.PrivateCreator;
                        dict.Add(new DicomDictionaryEntry(tag, name, keyword, vm, retired, vrs.ToArray()));
                    }
                }
            }
        }