Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
seto committed Nov 1, 2024
1 parent 5fb4e34 commit 33aad92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Crystallography/BetheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ Complex Lenz(in PointD k, in PointD kq, in double defocus)
{
for (int x = 0; x < width; x++)
{
var rVec = new PointD(-resolution * (x - cX), resolution * (y - cY)) + shift;//X座標はマイナス
var rVec = new PointD(resolution * (x - cX), -resolution * (y - cY)) + shift;//Y座標はマイナス
for (int t = 0; t < Thicknesses.Length; t++)
for (int d = 0; d < dLen; d++)
{
Expand Down Expand Up @@ -1571,7 +1571,7 @@ public void GetHRTEMImage(int BlochNum, double AccVol, Matrix3D rot, (double R,
Parallel.For(0, divTotal, div =>
{
int start = step * div, count = div == divTotal - 1 ? width * height - start : step;
var rVec = Enumerable.Range(start, count).SelectMany(n => new[] { -res * (n % width - cX) + shift.X, res * (n / width - cY) + shift.Y }).ToArray();//X座標はマイナス
var rVec = Enumerable.Range(start, count).SelectMany(n => new[] { res * (n % width - cX) + shift.X, -res * (n / width - cY) + shift.Y }).ToArray();//Y座標はマイナス
var results = NativeWrapper.HRTEM_Solver(gPsi, gVec, gLenz, rVec, quasiMode);
for (var i = 0; i < defLen; i++)
Array.Copy(results, i * count, _images[t][i], start, count);
Expand All @@ -1581,7 +1581,7 @@ public void GetHRTEMImage(int BlochNum, double AccVol, Matrix3D rot, (double R,
{
Parallel.For(0, width * height, n =>
{
PointD r = new(-(n % width - cX) * res + shift.X, (n / width - cY) * res + shift.Y), _vec = new(double.NaN, double.NaN);//X座標はマイナス
PointD r = new((n % width - cX) * res + shift.X, -(n / width - cY) * res + shift.Y), _vec = new(double.NaN, double.NaN);//Y座標はマイナス
var sums = new Complex[defLen];
var exp = new Complex(0, 0);
foreach (var (Psi, Vec, Lenz) in gList)
Expand Down
17 changes: 10 additions & 7 deletions ReciPro/ImageSimulator/FormImageSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ private void simulateSTEM(bool realtimeMode = false)
{
var x = (w - radius + 0.5) / (radius - 0.5) * sin;
var y = -(h - radius + 0.5) / (radius - 0.5) * sin;//結晶の座標系は、X軸が右、Y軸が上、Z軸が手前なのでYを反転

directions.Add(new Vector3DBase(x, y, -Sqrt(1 - x * x - y * y)));
}

Expand Down Expand Up @@ -476,6 +477,8 @@ private void stemCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//SendImage(ThicknessArray.Length, DefocusArray.Length, FormMain.Crystal.Bethe.STEM_Image, ImageSize.Width, ImageSize.Height);
GeneratePseudBitmap();


toolStripProgressBar.Value = toolStripProgressBar.Maximum;
toolStripStatusLabel1.Text = $"Completed! Total ellapsed time: {(s1 + s2 + s3 + s4) / 1000.0:f1} sec.";
toolStripStatusLabel1.Text += $" Stage 1: {s1 / 1000.0:f1} sec. Stage 2: {s2 / 1000.0:f1} sec. Stage 3: {s3 / 1000.0:f1} sec. Stage 4: {s4 / 1000.0:f1} sec.";
Expand Down Expand Up @@ -537,9 +540,10 @@ private void simulatePotential(bool realtimeMode = false)
Beams = FormMain.Crystal.Bethe.GetDifractedBeamAmpriltudes(BlochNum, AccVol, FormMain.Crystal.RotationMatrix, ThicknessArray[0]);
var images = FormMain.Crystal.Bethe.GetPotentialImage(Beams, ImageSize, ImageResolution, radioButtonPotentialModeMagAndPhase.Checked);

//画像が上下左右反転しているみたいなので、処理 20230304
for (int i = 0; i < images.Length; i++)
images[i] = [.. images[i].Reverse()];
//画像が上下左右反転 (180度回転) しているみたいなので、処理 20230304
//なぜかまた上下左右反転 (180度回転) しているみたいなので、削除 20241101
//for (int i = 0; i < images.Length; i++)
// images[i] = [.. images[i].Reverse()];


var temp = sw1.ElapsedMilliseconds;
Expand Down Expand Up @@ -677,6 +681,9 @@ public void GeneratePseudBitmap()
for (int t = 0; t < tLen; t++)
_images[t] = new double[dLen][];

//20241101 生成した画像が180度回転していることが発覚したため、ここで修正


//作成したイメージをPseudoBitmapに変換
var pseudo = radioButtonHorizontalDefocus.Checked ? new PseudoBitmap[tLen, dLen] : new PseudoBitmap[dLen, tLen];
var mat = rot * FormMain.Crystal.MatrixReal;
Expand Down Expand Up @@ -1150,7 +1157,6 @@ private void drawSymbols(Graphics g, Func<PointD, PointD> conv, double zoom, Ima


}

private enum formatEnum { Meta, PNG, TIFF }
private enum actionEnum { Save, Copy }
private void Save(formatEnum format, actionEnum action)
Expand Down Expand Up @@ -1295,9 +1301,6 @@ private void FormImageSimulator_KeyDown(object sender, KeyEventArgs e)
private void ToolStripMenuItemSavePNG_Click(object sender, EventArgs e) => Save(formatEnum.PNG, actionEnum.Save);
private void ToolStripMenuItemSaveTIFF_Click(object sender, EventArgs e) => Save(formatEnum.TIFF, actionEnum.Save);
private void ToolStripMenuItemSaveMetafile_Click(object sender, EventArgs e) => Save(formatEnum.Meta, actionEnum.Save);



private void ToolStripMenuItemCopyImage_Click(object sender, EventArgs e) => Save(formatEnum.PNG, actionEnum.Copy);
private void ToolStripMenuItemCopyMetafile_Click(object sender, EventArgs e) => Save(formatEnum.Meta, actionEnum.Copy);
#endregion 画像のコピー/保存
Expand Down
1 change: 1 addition & 0 deletions ReciPro/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal static class Version

public const string History =
"History" +
"\r\n ver4.893(2024/11/01) Fixed bugs on the 'Diffraction Simulator' and 'HRTEM/STEM simulator' (thanks to lukmuk-san and Nakamura-san!)." +
"\r\n ver4.892(2024/10/04) Added several 'Macro' functions." +
"\r\n ver4.891(2024/09/06) Added the function to simulate electron trajectories based on the Monte Carlo method." +
"\r\n ver4.890(2024/08/10) Improved 'Macro' functions." +
Expand Down

0 comments on commit 33aad92

Please sign in to comment.