예제 #1
0
 public static List <double []> Result2TRThArr(
     this IPSResult self)
 => self.SpotDataList.Select(x =>
                             new double [] { Math.Round(x.PlrPos.Theta)
                                             , Math.Round(x.PlrPos.Rho / 10.0)
                                             , x.Thickness })
 .ToList();
예제 #2
0
        public void SaveRawReflectivity(
            string path,
            IPSResult result,
            List <double> wavelen)
        {
            if (!CheckResult(result))
            {
                return;
            }
            StringBuilder stb_raw = new StringBuilder();

            stb_raw.Append("WaveLength");
            result.SpotDataList.ForEach(x =>
            {
                stb_raw.Append("," + x.CrtPos.X.ToString("N2") + " " + x.CrtPos.Y.ToString("N2"));
            });
            stb_raw.Append(Environment.NewLine);

            for (int i = 0; i < wavelen.Count; i++)
            {
                stb_raw.Append(wavelen [i].ToString());
                result.SpotDataList.ForEach(x =>
                {
                    stb_raw.Append("," + x.Reflectivity [i]);
                });
                stb_raw.Append(Environment.NewLine);
            }

            File.WriteAllText(path, stb_raw.ToString());
        }
 public void SetBtnTag(IPSResult result)           // done
 {
     Just(result)
     .Lift(CalcTagPos)
     .ForEach(DrawBtnTag);
     var poslist = CalcTagPos(result);
 }
예제 #4
0
 private bool CheckResult(IPSResult res)
 {
     if (res == null)
     {
         MessageBox.Show("Scan result is not exist. Save is canceled");
         return(false);
     }
     return(true);
 }
예제 #5
0
        public IPSResult ToResult(List <PlrCrd> pos, List <double> thckness, List <double []> intens, List <double []> reflectivities, List <double> wavelen)
        {
            var res = new IPSResult(wavelen);

            for (int i = 0; i < pos.Count; i++)
            {
                res.SpotDataList.Add(new SpotData(pos [i], thckness [i], intens [i], reflectivities [i]));
            }
            return(res);
        }
예제 #6
0
        public void SaveResult(string path, IPSResult result)
        {
            if (!CheckResult(result))
            {
                return;
            }
            StringBuilder stb = new StringBuilder();

            //stb.Append( "Theta" + "," + "Rho" + "," + "Thickness" );
            stb.Append("X" + "," + "Y" + "," + "Thickness");
            stb.Append(Environment.NewLine);
            result?.SpotDataList.ForEach(x =>
            {
                stb.Append(x.CrtPos.X.ToString("N2") + "," + x.CrtPos.Y.ToString("N2"));
                //stb.Append( x.PlrPos.Theta.ToString() + "," +  x.PlrPos.Rho.ToString() );
                stb.Append("," + x.Thickness);
                stb.Append(Environment.NewLine);
            });
            File.WriteAllText(path, stb.ToString());
        }
예제 #7
0
        public void SaveRaw(
            string path,
            IPSResult result,
            List <double> wavelen,
            List <double> dark,
            List <double> refer,
            List <double> absreflect)
        {
            if (!CheckResult(result))
            {
                return;
            }
            StringBuilder stb = new StringBuilder();

            stb.Append("WaveLength,Dark,Referance,Abs_Reflectivity");

            result.SpotDataList.ForEach(x =>
            {
                stb.Append("," + x.CrtPos.X.ToString("N2") + " " + x.CrtPos.Y.ToString("N2"));

                //stb.Append( "," + x.PlrPos.Theta.ToString() + " " + x.PlrPos.Rho.ToString() + ",Reflectivity" );
            });
            stb.Append(Environment.NewLine);

            for (int i = 0; i < dark.Count; i++)
            {
                stb.Append(
                    wavelen[i].ToString() + "," +
                    dark[i].ToString() + "," +
                    refer[i].ToString() + "," +
                    absreflect[i].ToString()
                    );
                result.SpotDataList.ForEach(x =>
                {
                    stb.Append("," + x.IntenList[i]);
                });
                stb.Append(Environment.NewLine);
            }

            File.WriteAllText(path, stb.ToString());
        }
        public static AnalysisState ToState(
            this IPSResult self)
        {
            var resState = new Dictionary <int, IPSResultData>();
            var wave     = self.WaveLen;
            var count    = self.SpotDataList.Count();
            int i        = 0;

            foreach (var spot in self.SpotDataList)
            {
                var dictdata = new IPSResultData(
                    spot.IntenList,
                    spot.Reflectivity,
                    wave,
                    spot.Thickness,
                    new mCrtCrd(Just(spot.CrtPos.X), Just(spot.CrtPos.Y)));                        //

                resState.Add(i++, dictdata);
            }
            return(CreateState(resState));
        }
        private List <ValPosCrt> CalcTagPos(IPSResult result)          // done
        {
            var w0 = 300;
            var h0 = 300;
            var w1 = this.ActualWidth - 60;
            var h1 = this.ActualHeight - 60;

            var w2 = this.Width;
            var h2 = this.Height;



            var RealToCanvas = FnReScale(w0, h0, w1, h1, w1 / 2 + 10, h1 / 2 + 10);
            Func <Tuple <CrtnCrd, double>, ValPosCrt> toValPos
                = posval => RealToCanvas(ValPosCrt(posval.Item1.X, posval.Item1.Y, posval.Item2));

            var scaledPosList = result.SpotDataList.Lift(x => Tuple.Create(x.CrtPos, x.Thickness))
                                .Lift(toValPos)
                                .ToList();

            return(scaledPosList);
        }
예제 #10
0
        public static IPSResult ToIPSResult(
            this AnalysisState self)
        {
            List <SpotData> spotlist;
            var             temp    = self.State[0].WaveLegth.ToList();
            List <double>   WaveLen = self.State[0].WaveLegth.Select(x => (double)x).ToList();

            spotlist = self.State.Select(x =>

                                         new SpotData
                                             (x.Value.Position.Pos.Value.ToPolar() as PlrCrd,
                                             x.Value.DThickness,
                                             x.Value.DIntenList.ToArray(),
                                             x.Value.DReflectivity.ToArray())).ToList();

            var res = new IPSResult(WaveLen)
            {
                SpotDataList = spotlist
            };

            return(res);
        }
예제 #11
0
        public static Image <Bgr, byte> CreateMapandBar(IPSResult src, int divide)
        {
            int dotSize        = 5;
            var sizemultiflier = 8;
            var imgshiftoffset = 10;
            var offset         = src.SpotDataList.Select(x => x.PlrPos.Rho / 10.0).Max();    // Padding Size
            var thcklist       = src.SpotDataList.Select(x => x.Thickness);

            // Choose Data Scale
            // normalization -> In trust region 95% , fit outlier data to boundary -> rescale from  0 to 255
            //var pinnedArr = GCHandle.Alloc( thcklist , GCHandleType.Pinned);

            //int size = Marshal.SizeOf(thcklist);
            //var pointer = Marshal.AllocHGlobal(size);
            //Marshal.StructureToPtr( thcklist , pointer , true );



            //var inputarr = new Mat(new int[] { 1, thcklist.Count() } , Emgu.CV.CvEnum.DepthType.Cv64F ,  pointer  );
            //CvInvoke.MeanStdDev( inputarr , ref mean , ref std );
            //Matrix<double> datas = new Matrix<double>(1, thcklist.Count() , pointer);
            //pinnedArr.Free();

            //var zscore = thcklist.Select( x => (x - mean.V0)/std.V0 )
            //							  .Select( x => x >  1.96 ? 1.96 :
            //											x < -1.96 ? -1.96
            //											: x).ToArray()
            //							  ;

            //var n = (double)thcklist.Count();
            //var mean = thcklist.Sum()/n;
            //var std = Math.Sqrt( thcklist.Select( x => Math.Pow(x - mean,2)).Sum() /  n );

            var min = thcklist.Min();
            var max = thcklist.Max();

            var cm = new ColorMap().Inferno_cm;

            // Interpolation


            var srcdatas = src.Result2TRThArr().Select(x => x).ToList();

            /*
             #region
             * // Extact Color Position
             * "".Print();
             * "".Print();
             * "".Print();
             * "STart Point".Print();
             * var xyCm2 = srcdatas.ToCartesianReslt()
             *                              .OrderBy( x=> x[0])
             *                              .ThenBy( x => x[1])
             *                              .AsParallel()
             *                              .AsOrdered()
             *                              //.Select( x => new double[] { x[0] , x[1] , ( x[2] - mean ) / std } )
             *                              //.Select( x => new double[] { x[0] , x[1] , x[2] >  1.96 ? 1.96 :
             *                              //										   x[2] < -1.96 ? -1.96
             *                              //										   : x[2] } )
             *                              .Select( x => new
             *                              {
             *                                      X  = offset + x[0] ,
             *                                      Y  = offset + x[1] ,
             *                                      Cm = (min - max) == 0
             *                                                                              ? cm[127]  //color double[r,g,b]
             *                                                                              : cm[ (int)(( x[2] -min )/(max - min)*255) ] ,
             *                                      Gry = (int)(( x[2] -min )/(max - min)*255 + 1)
             *                              }).ToList();
             *
             * var circleLst2 = xyCm2.Select((x,i) =>
             *                                              new
             *                                              {
             *                                                      pos = new System.Drawing.Point(
             *                                                                                                                              (int)(x.X*sizemultiflier)+imgshiftoffset,
             *                                                                                                                              (int)(x.Y*sizemultiflier)+imgshiftoffset),
             *
             *                                                      color = new MCvScalar(x.Cm[2]*255 , x.Cm[1]*255 , x.Cm[0]*255).Act( test22 )
             *                                              }).ToArray();
             * "End Point".Print();
             * "".Print();
             * "".Print();
             * "".Print();
             #endregion
             * var imgsize = Math.Max(
             *       xyCm2.Select( x => x.X).Max(),
             *       xyCm2.Select( x => x.Y).Max()
             *      );
             *
             * var imgData = new byte[(int)(imgsize*sizemultiflier + imgshiftoffset*2.0) ,(int)(imgsize*sizemultiflier+imgshiftoffset*2.0),3];
             * Image<Bgr,byte> img = new Image<Bgr, byte>(imgData);
             * circleLst2.ActLoop( x => CvInvoke.Circle( img, x.pos, dotSize, x.color, -1, Emgu.CV.CvEnum.LineType.EightConnected ) );
             */

            for (int i = 0; i < divide; i++)
            {
                srcdatas = srcdatas.Interpol_Theta(1).Select(x => x).ToList()
                           .Interpol_Rho(1).Select(x => x).ToList();
            }

            // Extact Color Position
            var xyCm = srcdatas.ToCartesianReslt()
                       .OrderBy(x => x[0])
                       .ThenBy(x => x[1])
                       .AsParallel()
                       .AsOrdered()
                       //.Select( x => new double[] { x[0] , x[1] , ( x[2] - mean ) / std } )
                       //.Select( x => new double[] { x[0] , x[1] , x[2] >  1.96 ? 1.96 :
                       //										   x[2] < -1.96 ? -1.96
                       //										   : x[2] } )
                       .Select(x => new
            {
                X  = offset + x[0],
                Y  = offset + x[1],
                Cm = (min - max) == 0
                                                                                                        ? cm[127]  //color double[r,g,b]
                                                                                                        : cm[(int)((x[2] - min) / (max - min) * 255)],
                Gry = (int)((x[2] - min) / (max - min) * 255 + 1)
            }).ToList();

            var imgsize = Math.Max(
                xyCm.Select(x => x.X).Max(),
                xyCm.Select(x => x.Y).Max()
                );

            var imgData           = new byte[(int)(imgsize * sizemultiflier + imgshiftoffset * 2.0), (int)(imgsize * sizemultiflier + imgshiftoffset * 2.0), 3];
            Image <Bgr, byte> img = new Image <Bgr, byte>(imgData);
            var circleLst         = xyCm.Select((x, i) =>
                                                new
            {
                pos = new System.Drawing.Point(
                    (int)(x.X * sizemultiflier) + imgshiftoffset,
                    (int)(x.Y * sizemultiflier) + imgshiftoffset),

                color = new MCvScalar(x.Cm[2] * 255, x.Cm[1] * 255, x.Cm[0] * 255)
            });



            circleLst.ActLoop(x => CvInvoke.Circle(img, x.pos, dotSize, x.color, -1, Emgu.CV.CvEnum.LineType.EightConnected));
            //circleLst.ActLoop( (x,i) => CvInvoke.Circle( grayimg , x.pos , dotSize , new MCvScalar( xyCm[i].Gry) , -1 , Emgu.CV.CvEnum.LineType.EightConnected ) );

            img = img.Median(5);
            img = img.SmoothGaussian(3);

            return(img);
        }
예제 #12
0
 IPSResult SetStateLib(IPSResult result)
 {
     StateLib = result.ToState();
     return(result);
 }