Exemplo n.º 1
0
        public static MWNumericArray Process(IList <IFilter> filters, MWNumericArray m)
        {
            var  d        = (MWNumericArray)m.Clone();
            bool splitadd = false;
            var  tlst     = new List <MWNumericArray>();

            foreach (var f in filters)
            {
                if (f is Spliter)
                {
                    if (splitadd)
                    {
                        tlst.Add(d);
                    }
                    splitadd = false;
                    d        = (MWNumericArray)m.Clone();
                }
                else
                {
                    splitadd = true;
                }
                d = f.Process(d);
            }
            if (splitadd)
            {
                tlst.Add(d);
            }
            //合并
            if (tlst.Count > 0)
            {
                d = tlst[0];
                for (int i = 1; i < tlst.Count; i++)
                {
                    var it = Tools.InsertRow(d, tlst[i], d.Dimensions[0] + 1);
                    d.Dispose();
                    tlst[i].Dispose();
                    d = it;
                }
            }
            return(d);
        }
Exemplo n.º 2
0
        private void btnCompute_Click(object sender, EventArgs e)
        {
            if (spec1 == null || spec2 == null)
            {
                MessageBox.Show(string.Format("第{0}条光谱为空,请先选择。",
                                              spec1 == null ? 1 : 2), "信息提示");
                return;
            }
            int mwin = 0;

            if (!int.TryParse(txbmwin.Text, out mwin))
            {
                MessageBox.Show("移动窗口大小必须为整数", "信息提示");
                return;
            }
            IList <IFilter> filters = new List <IFilter>();

            if (this._model != null)
            {
                if (this._model is IdentifyModel)
                {
                    filters = ((IdentifyModel)this._model).Filters;
                }
                else if (this._model is FittingModel)
                {
                    filters = ((FittingModel)this._model).Filters;
                }
            }

            var s1 = spec1.Clone();
            var s2 = spec2.Clone();

            //对光谱预处理
            if (filters != null)
            {
                var  ya       = new MWNumericArray(s1.Data.Lenght, 1, s1.Data.Y);
                var  yb       = new MWNumericArray(s2.Data.Lenght, 1, s2.Data.Y);
                bool splitadd = false;
                var  y1       = (MWNumericArray)ya.Clone();
                var  y2       = (MWNumericArray)yb.Clone();
                var  x1       = Serialize.DeepClone <double[]>(s1.Data.X);
                var  x2       = Serialize.DeepClone <double[]>(s2.Data.X);
                var  y1lst    = new List <MWNumericArray>();
                var  x1lst    = new List <double[]>();
                var  y2lst    = new List <MWNumericArray>();
                var  x2lst    = new List <double[]>();

                foreach (var tf in filters)
                {
                    var f = RIPP.Lib.Serialize.DeepClone <RIPP.NIR.Data.Filter.IFilter>(tf);
                    if (f is Spliter)
                    {
                        if (splitadd)
                        {
                            x1lst.Add(x1);
                            y1lst.Add(y1);
                            x2lst.Add(x2);
                            y2lst.Add(y2);
                        }
                        splitadd = false;
                        y1       = (MWNumericArray)ya.Clone();
                        y2       = (MWNumericArray)yb.Clone();
                        x1       = Serialize.DeepClone <double[]>(s1.Data.X);
                        x2       = Serialize.DeepClone <double[]>(s2.Data.X);
                    }
                    else
                    {
                        splitadd = true;
                    }
                    y1 = f.Process(y1);
                    y2 = f.Process(y2);
                    if (f.FType == FilterType.VarFilter)
                    {
                        x1 = f.VarProcess(x1);
                        x2 = f.VarProcess(x2);
                    }
                }
                if (splitadd)
                {
                    x1lst.Add(x1);
                    y1lst.Add(y1);
                    x2lst.Add(x2);
                    y2lst.Add(y2);
                }
                //合并
                if (x1lst.Count > 0)
                {
                    s1.Data.X = x1lst[0];
                    s1.Data.Y = (double[])y1lst[0].ToVector(MWArrayComponent.Real);
                    s2.Data.X = x2lst[0];
                    s2.Data.Y = (double[])y2lst[0].ToVector(MWArrayComponent.Real);
                    for (int i = 1; i < x1lst.Count; i++)
                    {
                        s1.Data.X = RIPP.NIR.Data.Tools.InsertColumn(s1.Data.X, x1lst[i], s1.Data.X.Length + 1);
                        s1.Data.Y = RIPP.NIR.Data.Tools.InsertColumn(s1.Data.Y, (double[])y1lst[i].ToVector(MWArrayComponent.Real), s1.Data.Y.Length + 1);

                        s2.Data.X = RIPP.NIR.Data.Tools.InsertColumn(s2.Data.X, x2lst[i], s2.Data.X.Length + 1);
                        s2.Data.Y = RIPP.NIR.Data.Tools.InsertColumn(s2.Data.Y, (double[])y2lst[i].ToVector(MWArrayComponent.Real), s2.Data.Y.Length + 1);
                    }
                }
                else
                {
                    s1.Data.X = x1;
                    s1.Data.Y = (double[])y1.ToVector(MWArrayComponent.Real);
                    s2.Data.X = x2;
                    s2.Data.Y = (double[])y2.ToVector(MWArrayComponent.Real);
                }

                //s1.Data.Y = (double[])y1.ToVector(MWArrayComponent.Real);
                //s2.Data.Y = (double[])y2.ToVector(MWArrayComponent.Real);
            }
            if (this._model is FittingModel)
            {
                var f = ((FittingModel)this._model).IdRegion;
                s1.Data.X = f.VarProcess(s1.Data.X);
                s2.Data.X = f.VarProcess(s2.Data.X);
                s1.Data.Y = f.VarProcess(s1.Data.Y);
                s2.Data.Y = f.VarProcess(s2.Data.Y);
            }

            //绘制
            var lst = new List <Spectrum>();

            lst.Add(s1);
            lst.Add(s2);
            this.specGraph3.DrawSpec(lst);
            this.specGraph3.SetTitle("预处理后光谱");

            double[] tSQ;
            double   tTQ;

            RIPP.NIR.Data.Tools.MWCorr(s1.Data.Y, s2.Data.Y, mwin, out tTQ, out tSQ);


            var spec = RIPP.Lib.Serialize.DeepClone <Spectrum>(s1);

            spec.Data.Y = tSQ;
            spec.Name   = "SQ";
            spec.Color  = Color.Blue;
            this.specGraph2.DrawSpec(new List <Spectrum>()
            {
                spec
            });

            this.txbTQ.Text = tTQ.ToString("f3");
            this.txbSQ.Text = tSQ.Min().ToString("f3");
        }