public SpotData(PlrCrd pos, double thckness, double [] intens, double[] reflectivityes) { PlrPos = pos; Thickness = thckness; IntenList = intens; Reflectivity = reflectivityes; }
public static List <double []> ToCartesianReslt( this List <double []> polarRes) => polarRes.Select(x => { var crt = new PlrCrd(x[0], x[1]).ToCartesian() as CrtnCrd; return(crt != null ? new double [] { crt.X, crt.Y, x [2] } : new double [3]); }).ToList();
public static void test1() { double r = 3; double the = 30.0.ToRadian(); var pol1 = new PlrCrd(r, the); double r2 = 3; double the2 = 240.0.ToRadian(); var pol2 = new PlrCrd(r2, the2); var c1 = pol1.ToCartesian(); var c2 = pol2.ToCartesian(); }
public async Task <bool> ScanAutoRun() // Use Internal Config , not get config from method parameter { LoadModel(ModelFullPath); OpMaxSpeed(); OpORGMaxSpeed(); counter = 0; SetHWInternalParm( Config.RStgSpeed, Config.XStgSpeed, Config.Scan2Avg, Config.IntegrationTime, Config.Boxcar, Config.EdgeEnd ); // Ref Check -- if (!FlgRefReady) { return(false.Act(x => MessageBox.Show("Set Referance Please"))); } // Home And Check -- //if ( !FlgHomeDone ) if ( !OpHome() ) return false; OpHome(); FlgHomeDone = true; // Scan Ready And Check -- if (FlgDarkReady == false) { if (!OpReady(ScanReadyMode.Dark)) { return(false); } } FlgDarkReady = true; var toReflect = FnCalReflections(Darks, Refs, SelectedReflctFactors); var toSelected = FnIdxDataPicker(PickedIdx); var thetas = GetPosThetas(ScanPos); var calcTaskList = new Task <Tuple <PlrCrd, LEither <double>, double[]> > [ScanPos.ThetaList.Select(x => x.Length).Aggregate((f, s) => f + s)]; var wavelength = SDWaves; var res = new TEither(Stg as IStgCtrl, 12); // Controller , Timeout // Get Pos-Intensity || Task Calc Thickness -- int taskcounter = 0; try { var posIntenlist = ScanPos.RhoList.Select((rho, i) => { var logs = res.Bind(x => x.Act(f => { f.SendAndReady(f.GoAbs + rho.mmToPulse().ToOffPos(Axis.X)); f.SendAndReady(f.Go); }).ToTEither(), " X Stage Move Command Fail"); return(thetas[i].Select((theta, j) => { var pos = new PlrCrd(theta, rho).Print(); var logres = logs.Bind(x => x.Act(f => { f.SendAndReady(f.GoAbs + ((ScanPos.MovePosList[i][j] + 360 * (i > 1 ? i - 1 : 0))).Degree2Pulse().ToPos(Axis.R)); f.SendAndReady(f.Go); Thread.Sleep(500); }).ToTEither(), "R Stage Move Command Fail") .ToLEither(new double [] { }); //Thread.Sleep(SpectrometerDelayTime); var intenlist = logres.IsRight // Todo : Change to Match Function //? logres.Bind( x => toSelected( BkD_Spctrm ) ) ? logres.Bind(x => toSelected(GetSpectrum())) // Todo : Change to only toSelected( Spctr.GetSpectrum() ), not bind. cuz endpoint : logres.Act(x => Lggr.Log(x.Left, true)); // Logging Error evtSpectrum(intenlist.Right, SelectedWaves); var temp1 = ToThickness( toReflect(intenlist.Right) .Act(x => evtRefleectivity(x, SelectedWaves)) .ToLEither(intenlist.Left), wavelength, pos); // Estimate Thickness calcTaskList [taskcounter++] // Clac Thickness = Task.Run <Tuple <PlrCrd, LEither <double>, double[]> >( () => logres.IsRight ? ToThickness( toReflect(intenlist.Right) .Act(x => evtRefleectivity(x, SelectedWaves)) .ToLEither(intenlist.Left), wavelength, pos) // Estimate Thickness : Tuple.Create(pos, new LEither <double>(), new double[] {})); return Tuple.Create(pos, intenlist); }).ToList()); }).SelectMany(x => x).ToList(); // List [ Result , Result , Result ] // Thickness Result List -- // ( You dont need to use try catch pattern for catch all exception from tasklist ) //var posThicknesses = Task.WhenAll( calcTaskList ).Result.Duplicate0ToAllTheta().ToList(); var posThickReflec = Task.WhenAll(calcTaskList).Result.ToList(); int nochiIdx = 0; for (int i = 0; i < posThickReflec.Count; i++) { if (posThickReflec [i].Item1.Rho == 148) { if (posThickReflec [i].Item1.Theta == 0) { nochiIdx = i; } } } posThickReflec [nochiIdx] = Tuple.Create( posThickReflec [nochiIdx].Item1, ((posThickReflec.Last().Item2.Right + posThickReflec [nochiIdx + 1].Item2.Right) / 2.0) .ToLEither(posThickReflec [nochiIdx].Item2.Left), (posThickReflec.Last().Item3.Zip( posThickReflec [nochiIdx + 1].Item3, (f, s) => (f + s) / 2.0) ).ToArray()); // Reset Pos -- await Task.Run(() => res.Bind( x => x.Act(f => f.SendAndReady(f.GoAbs + 0.ToPos(Axis.W) + 0.ToPos())).ToTEither(1)) .Bind(x => x.Act(f => f.SendAndReady(f.Go)).ToTEither(1))); FlgAutoUpdate = false; //Zip ( Pos , Thickness , Intencity ) -- var posThickIntenReflc = posThickReflec .Zip(posIntenlist, (f, s) => new { Pos = f.Item1, Thickness = f.Item2, Intensity = s.Item2, Refelctivity = f.Item3 }); // -- Integration Log Result -- // bool isright = posThickReflec.Select(x => x.Item2.IsRight).Aggregate((f, s) => f && s); if (!isright) // If Task Error { var tasklogs = posThickIntenReflc.Where(x => x.Thickness.IsRight == false) .Select(x => x.Pos.ToString() + " ||" + x.Thickness.Left) .ActLoop(x => Lggr.Log(x, true)); ImgScanResult = new Image <Bgr, byte>(100, 100, new Bgr(100, 100, 100)); return(false); } else { var poses = posThickIntenReflc.Select(x => x.Pos).ToList(); var thckneses = posThickIntenReflc.Select(x => x.Thickness.Right).ToList(); var intens = posThickIntenReflc.Select(x => x.Intensity.Right).ToList(); var reflec = posThickIntenReflc.Select(x => x.Refelctivity).ToList(); ResultData = ToResult(poses, thckneses, intens, reflec, SelectedWaves); Stopwatch stw = new Stopwatch(); stw.Start(); CreateMapandBar(ResultData, 6) .Act(x => ImgScanResult = x); stw.ElapsedMilliseconds.Print("Draw Time"); return(true); } } catch (Exception e) { MessageBox.Show(e.ToString()); return(false); } }