Esempio n. 1
0
        public static bool Save(string filename, DensityDef densityDef)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(false);
            }
            string dir = Path.GetDirectoryName(filename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            if (densityDef == null || densityDef.Ranges == null)
            {
                return(false);
            }
            XElement root = new XElement("ImageProcessQueue");

            root.SetElementValue("DensitySlice", "");
            if (!SetBaseInfo(root.Element("DensitySlice"), densityDef))
            {
                return(false);
            }
            if (!SetRangeInfo(root.Element("DensitySlice"), densityDef))
            {
                return(false);
            }
            root.Save(filename);
            return(true);
        }
Esempio n. 2
0
        private static void ReadBaseInfo(ref DensityDef densityDef, XElement node)
        {
            float max = float.MaxValue;

            if (float.TryParse(node.Element("MAX").Value, out max))
            {
                densityDef.MaxValue = max;
            }
            float min = float.MinValue;

            if (float.TryParse(node.Element("MIN").Value, out min))
            {
                densityDef.MinValue = min;
            }
            int rangeCount = 0;

            if (int.TryParse(node.Element("NUM").Value, out rangeCount))
            {
                densityDef.RangeCount = rangeCount;
            }
            float interval = 0;

            if (float.TryParse(node.Element("JIANGE").Value, out interval))
            {
                densityDef.Interval = interval;
            }
            bool applayInterval = false;

            if (bool.TryParse(node.Element("DoJIANGE").Value, out applayInterval))
            {
                densityDef.ApplayInterval = applayInterval;
            }
        }
Esempio n. 3
0
        public static ColorMapTable <double> GetColorMapTable(string filename)
        {
            if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                return(null);
            }
            DensityDef density = Read(filename);

            if (density.Ranges == null || density.Ranges.Length == 0)
            {
                return(null);
            }
            ColorMapTable <double> mapColor = new ColorMapTable <double>();
            int count = density.Ranges.Length;

            if (count > 1)
            {
                for (int i = 0; i < count - 1; i++)
                {
                    mapColor.Items.Add(new ColorMapItem <double>(density.Ranges[i].minValue, density.Ranges[i].maxValue,
                                                                 Color.FromArgb(255, density.Ranges[i].RGB_r, density.Ranges[i].RGB_g, density.Ranges[i].RGB_b)));
                }
            }
            int lastItemIndex = count - 1;

            mapColor.Items.Add(new ColorMapItem <double>(density.Ranges[lastItemIndex].minValue, density.Ranges[lastItemIndex].maxValue + 1,
                                                         Color.FromArgb(255, density.Ranges[lastItemIndex].RGB_r, density.Ranges[lastItemIndex].RGB_g, density.Ranges[lastItemIndex].RGB_b)));

            return(mapColor.Items == null || mapColor.Items.Count == 0 ? null : mapColor);
        }
Esempio n. 4
0
        public static DensityDef Read(string filename)
        {
            if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                return(null);
            }
            XElement node = XElement.Load(filename);

            if (node == null)
            {
                return(null);
            }
            node = node.Element("DensitySlice");
            if (node == null)
            {
                return(null);
            }
            DensityDef densityDef = new DensityDef();

            ReadBaseInfo(ref densityDef, node);
            if (densityDef == null)
            {
                return(null);
            }
            ReadRanges(ref densityDef, node);
            return(densityDef);
        }
Esempio n. 5
0
 private static bool SetBaseInfo(XElement pNode, DensityDef densityDef)
 {
     pNode.SetElementValue("MAX", densityDef.MaxValue.ToString());
     pNode.SetElementValue("MIN", densityDef.MinValue.ToString());
     pNode.SetElementValue("NUM", densityDef.RangeCount.ToString());
     pNode.SetElementValue("JIANGE", densityDef.Interval.ToString());
     pNode.SetElementValue("DoJIANGE", densityDef.ApplayInterval.ToString());
     return(true);
 }
Esempio n. 6
0
        private static void ReadRanges(ref DensityDef densityDef, XElement node)
        {
            XElement rangeNode = node.Element("RANGE");

            if (rangeNode == null)
            {
                return;
            }
            IEnumerable <XElement> rangeSubNodes = rangeNode.Elements();

            if (rangeSubNodes == null || rangeSubNodes.Count() == 0)
            {
                return;
            }
            List <DensityRange> ranges   = new List <DensityRange>();
            XElement            tempNode = null;

            foreach (XElement item in rangeSubNodes)
            {
                DensityRange temprange = new DensityRange(0, 0, 0, 0, 0);
                tempNode = item.Element("L");
                if (tempNode == null)
                {
                    continue;
                }
                temprange.minValue = float.Parse(tempNode.Value);
                tempNode           = item.Element("R");
                if (tempNode == null)
                {
                    continue;
                }
                temprange.maxValue = float.Parse(tempNode.Value);
                tempNode           = item.Element("RGB_R");
                if (tempNode == null)
                {
                    continue;
                }
                temprange.RGB_r = byte.Parse(tempNode.Value);
                tempNode        = item.Element("RGB_G");
                if (tempNode == null)
                {
                    continue;
                }
                temprange.RGB_g = byte.Parse(tempNode.Value);
                tempNode        = item.Element("RGB_B");
                if (tempNode == null)
                {
                    continue;
                }
                temprange.RGB_b = byte.Parse(tempNode.Value);
                ranges.Add(temprange);
            }
            densityDef.Ranges = ranges.Count == 0 ? null : ranges.ToArray();
        }
Esempio n. 7
0
        private void tsmiSaveFile_Click(object sender, EventArgs e)
        {
            if (_rangeList == null || _rangeList.Count == 0)
            {
                MessageBox.Show("请先设置密度分割范围,然后保存方案!", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string         filename       = null;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "XML文件|*.xml|所有文件|*.*";
            saveFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + @"\\SesitySliceForm\";
            if (!Directory.Exists(saveFileDialog.InitialDirectory))
            {
                Directory.CreateDirectory(saveFileDialog.InitialDirectory);
            }
            saveFileDialog.FileName = CreateFileName();
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                filename = saveFileDialog.FileName;
            }
            else
            {
                return;
            }
            DensityDef densityDef = new DensityDef();

            densityDef.MaxValue       = _maxValue;
            densityDef.MinValue       = _minValue;
            densityDef.Interval       = _interval;
            densityDef.RangeCount     = _rangeList.Count;
            densityDef.ApplayInterval = ckInterval.Checked;
            List <DensityRange> ranges = new List <DensityRange>();

            for (int i = 0; i < _rangeList.Count; i++)
            {
                DensityRange tempRange = new DensityRange();
                tempRange.minValue = _rangeList[i].minValue;
                tempRange.maxValue = _rangeList[i].maxValue;
                tempRange.RGB_r    = _rangeList[i].RGB_r;
                tempRange.RGB_g    = _rangeList[i].RGB_g;
                tempRange.RGB_b    = _rangeList[i].RGB_b;
                ranges.Add(tempRange);
            }
            densityDef.Ranges = ranges.ToArray();
            DensitySolution.Save(filename, densityDef);
        }
Esempio n. 8
0
        private static bool SetRangeInfo(XElement pNode, DensityDef densityDef)
        {
            if (densityDef.Ranges == null || densityDef.Ranges.Length == 0)
            {
                return(false);
            }
            pNode.SetElementValue("RANGE", "");
            XElement rangeRoot = pNode.Element("RANGE");
            string   tempNodename;
            int      length = densityDef.Ranges.Length;

            for (int i = 0; i < length; i++)
            {
                tempNodename = "R" + i.ToString() + "_RANGE";
                rangeRoot.SetElementValue(tempNodename, "");
                SetSubRangeInfo(rangeRoot.Element(tempNodename), densityDef.Ranges[i]);
            }
            return(true);
        }
Esempio n. 9
0
        private void tsmiOpenFile_Click(object sender, EventArgs e)
        {
            lstDensityRange.Items.Clear();
            if (_rangeList != null)
            {
                _rangeList.Clear();
            }
            else
            {
                _rangeList = new List <DensityRange>();
            }
            string filename = null;

            if (e != null)
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "密度分割方案(*.xml)|*.xml";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    filename = dlg.FileName;
                }
                else
                {
                    return;
                }
            }
            else
            {
                filename = _densityXML;
            }
            DensityDef densityDef = DensitySolution.Read(filename);

            if (densityDef == null)
            {
                return;
            }
            txtMax.Text        = densityDef.MaxValue.ToString();
            txtMin.Text        = densityDef.MinValue.ToString();
            _isOpenXML         = true;
            txtInterval.Text   = densityDef.Interval.ToString();
            _isOpenXML         = false;
            ckInterval.Checked = Convert.ToBoolean(densityDef.ApplayInterval.ToString());
            int          length = densityDef.Ranges == null || densityDef.Ranges.Length == 0 ? 0 : densityDef.Ranges.Length;
            DensityRange temprange;

            for (int i = 0; i < length; i++)
            {
                if (e != null)
                {
                    temprange.minValue = densityDef.Ranges[i].minValue;
                    temprange.maxValue = densityDef.Ranges[i].maxValue;
                }
                else
                {
                    temprange.minValue = i == 0 ? _min_value : (_lwMinValue == 0 ? _min_value : _lwMinValue) + _lwInterval * (i - 1);
                    temprange.maxValue = i + 1 == length ? _max_value : (_lwMinValue == 0 ? _min_value : _lwMinValue) + _lwInterval * i;
                }
                temprange.RGB_r = densityDef.Ranges[i].RGB_r;
                temprange.RGB_g = densityDef.Ranges[i].RGB_g;
                temprange.RGB_b = densityDef.Ranges[i].RGB_b;
                _rangeList.Add(temprange);
            }

            for (int i = 0; i < _rangeList.Count; i++)
            {
                lstDensityRange.Items.Add(_rangeList[i].ToString());
            }
        }