public STEMAreaDialog(STEMArea Area, SimArea simArea) { InitializeComponent(); xStartBox.Text = Area.xStart.ToString("f2"); xFinishBox.Text = Area.xFinish.ToString("f2"); yStartBox.Text = Area.yStart.ToString("f2"); yFinishBox.Text = Area.yFinish.ToString("f2"); xPxBox.Text = Area.xPixels.ToString(); yPxBox.Text = Area.yPixels.ToString(); xstart = Area.xStart; ystart = Area.yStart; xfinish = Area.xFinish; yfinish = Area.yFinish; xpx = Area.xPixels; ypx = Area.yPixels; simxStart = simArea.xStart; simxFinish = simArea.xFinish; simyStart = simArea.yStart; simyFinish = simArea.yFinish; xPxBox.TextChanged += new TextChangedEventHandler(PixelValidCheck); yPxBox.TextChanged += new TextChangedEventHandler(PixelValidCheck); xStartBox.TextChanged += new TextChangedEventHandler(RangeValidCheck); yStartBox.TextChanged += new TextChangedEventHandler(RangeValidCheck); xFinishBox.TextChanged += new TextChangedEventHandler(RangeValidCheck); yFinishBox.TextChanged += new TextChangedEventHandler(RangeValidCheck); }
private void OKButton_Click(object sender, RoutedEventArgs e) { if (!goodxpx || !goodxrange || !goodypx || !goodyrange) { //some sort error return; } var temp = new STEMArea { xStart = xstart, xFinish = xfinish, yStart = ystart, yFinish = yfinish, xPixels = xpx, yPixels = ypx }; AddSTEMAreaEvent(this, new StemAreaArgs(temp)); this.Close(); }
private void SimulateSTEM(int TDSruns, ref ProgressReporter progressReporter, ref Stopwatch timer, ref CancellationToken ct, int multistem) { LockedDetectors = Detectors; LockedArea = STEMRegion; foreach (DetectorItem dt in LockedDetectors) { dt.PixelScaleX = LockedArea.getxInterval; dt.PixelScaleY = LockedArea.getyInterval; dt.SetPositionReadoutElements(ref LeftXCoord, ref LeftYCoord); } if (LockedDetectors.Count == 0) { var result = MessageBox.Show("No Detectors Have Been Set", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } int numPix = LockedArea.xPixels * LockedArea.yPixels; int pix = 0; foreach (DetectorItem i in LockedDetectors) { i.ImageData = new float[numPix]; i.Min = float.MaxValue; i.Max = float.MinValue; } int runs = 1; if (doTDS_STEM) { runs = TDSruns; } int totalPix = numPix * runs; mCL.initialiseSTEMSimulation(CurrentResolution, SimRegion.xStart, SimRegion.yStart, SimRegion.xFinish, SimRegion.yFinish, isFull3D, isFD, dz, integrals, multistem); float xInterval = LockedArea.getxInterval; float yInterval = LockedArea.getyInterval; //List<float[]> TDSImages = new List<float[]>(); List <float> fCoordxs = new List <float>(); List <Tuple <Int32, Int32> > Pixels = new List <Tuple <Int32, Int32> >(); for (int posY = 0; posY < LockedArea.yPixels; posY++) { for (int posX = 0; posX < LockedArea.xPixels; posX++) { Pixels.Add(new Tuple <Int32, Int32>(posX, posY)); } } for (int j = 0; j < runs; j++) { Shuffler.Shuffle <Tuple <Int32, Int32> >(Pixels); // Reset image contrast limits for every run.... foreach (DetectorItem i in LockedDetectors) { i.Min = float.MaxValue; i.Max = float.MinValue; } //for (int posY = 0; posY < LockedArea.yPixels * LockedArea.xPixels; posY+=multistem) // won't loop over end? //{ int posY = 0; int conPix = multistem; // numPix // multistem while (posY < numPix) { mCL.sortStructure(doTDS_STEM); int thisPosY = posY; if (posY + multistem > numPix && posY + multistem - numPix + 1 < multistem) { conPix = numPix - posY; posY = numPix; } else { posY += multistem; } for (int i = 1; i <= conPix; i++) { mCL.initialiseSTEMWaveFunction(((LockedArea.xStart + Pixels[(thisPosY + i - 1)].Item1 * xInterval - SimRegion.xStart) / pixelScale), ((LockedArea.yStart + Pixels[(thisPosY + i - 1)].Item2 * yInterval - SimRegion.yStart) / pixelScale), i); } // Use Background worker to progress through each step int NumberOfSlices = 0; mCL.getNumberSlices(ref NumberOfSlices, isFD); // Seperate into setup, loop over slices and final steps to allow for progress reporting. for (int i = 1; i <= NumberOfSlices; i++) { if (ct.IsCancellationRequested == true) { break; } timer.Start(); mCL.doMultisliceStep(i, NumberOfSlices, conPix); timer.Stop(); int mem = mCL.getCLMemoryUsed(); float ms = timer.ElapsedMilliseconds; progressReporter.ReportProgress((val) => { CancelButton.IsEnabled = true; // Note: code passed to "ReportProgress" can access UI elements freely. UI_UpdateSimulationProgressSTEM(ms, totalPix, pix, NumberOfSlices, i, mem); }, i); } pix += conPix; if (ct.IsCancellationRequested == true) { break; } for (int i = 1; i <= conPix; i++) { // After a complete run if TDS need to sum up the DIFF... //mCL.AddTDSDiffImage(TDSImages[i-1], CurrentResolution,i); // Sum it in C++ also for the stem pixel measurement... //mCL.AddTDS(i); mCL.getSTEMDiff(i); } progressReporter.ReportProgress((val) => { CancelButton.IsEnabled = false; //UpdateTDSImage(); }, j); for (int p = 1; p <= conPix; p++) { // loop through and get each STEM pixel for each detector at the same time foreach (DetectorItem i in LockedDetectors) { float pixelVal = mCL.getSTEMPixel(i.Inner, i.Outer, i.xCentre, i.yCentre, p); float newVal = i.ImageData[LockedArea.xPixels * Pixels[thisPosY + p - 1].Item2 + Pixels[thisPosY + p - 1].Item1] + pixelVal; i.ImageData[LockedArea.xPixels * Pixels[thisPosY + p - 1].Item2 + Pixels[thisPosY + p - 1].Item1] = newVal; //if (j == runs-1) // Only use final values to set contrast limits //{ if (newVal < i.Min) { i.Min = newVal; } if (newVal > i.Max) { i.Max = newVal; } //} } } // This will update display after each tds run... progressReporter.ReportProgress((val) => { foreach (DetectorItem i in LockedDetectors) { UpdateDetectorImage(i); } }, thisPosY); if (ct.IsCancellationRequested == true) { break; } } // Reset TDS arrays after pixel values retrieved //mCL.ClearTDS(multistem); //fCoordxs.Clear(); if (ct.IsCancellationRequested == true) { break; } } }
public StemAreaArgs(STEMArea s) { AreaParams = s; }