Skip to content

Commit 0f7705c

Browse files
committed
update
1 parent d33895e commit 0f7705c

1 file changed

Lines changed: 32 additions & 25 deletions

File tree

ReciPro/DiffractionSimulator/FormDiffractionSimulator.cs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ private static PointD getLabelPosition(IEnumerable<PointD> list, PointD origin,
701701
#region ガウス関数で描画するローカル関数
702702
//int bgR = colorControlBackGround.Color.R, bgG = colorControlBackGround.Color.G, bgB = colorControlBackGround.Color.B;
703703
int gradation = 32;
704+
var reuseBrush = new SolidBrush(Color.Black); //260403Cl GDIオブジェクト再利用
705+
var reusePath = new GraphicsPath(); //260403Cl GDIオブジェクト再利用
704706
double fillCircleSpread(Color c, PointD pt, double intensity, double sigma)
705707
{
706708
//計算する二次元ガウス関数は、 f(x,y) = intensity/ (2 pi sigma^2) * e^{- (x^2+y^2) /2/sigma^2)
@@ -739,17 +741,18 @@ double fillCircleSpread(Color c, PointD pt, double intensity, double sigma)
739741
alpha = 255;
740742
}
741743

742-
var brush = new SolidBrush(Color.FromArgb(alpha, c));
744+
//var brush = new SolidBrush(Color.FromArgb(alpha, c)); //260403Cl Brush/Path再利用に変更
745+
reuseBrush.Color = Color.FromArgb(alpha, c);
743746
if (j < gradation - 1 && radius2 > 0)
744747
{
745-
var path = new GraphicsPath();
746-
path.AddArc((float)(pt.X - radius1), (float)(pt.Y - radius1), (float)(radius1 * 2), (float)(radius1 * 2), 0, 360);
747-
path.AddArc((float)(pt.X - radius2), (float)(pt.Y - radius2), (float)(radius2 * 2), (float)(radius2 * 2), 0, -360);
748-
graphics.FillPath(brush, path);
748+
reusePath.Reset(); //260403Cl 再利用
749+
reusePath.AddArc((float)(pt.X - radius1), (float)(pt.Y - radius1), (float)(radius1 * 2), (float)(radius1 * 2), 0, 360);
750+
reusePath.AddArc((float)(pt.X - radius2), (float)(pt.Y - radius2), (float)(radius2 * 2), (float)(radius2 * 2), 0, -360);
751+
graphics.FillPath(reuseBrush, reusePath);
749752
}
750753
else
751754
{
752-
graphics.FillEllipse(brush, (float)(pt.X - radius1), (float)(pt.Y - radius1), (float)(2 * radius1), (float)(2 * radius1));
755+
graphics.FillEllipse(reuseBrush, (float)(pt.X - radius1), (float)(pt.Y - radius1), (float)(2 * radius1), (float)(2 * radius1));
753756
return maxRadius;
754757
}
755758
}
@@ -803,8 +806,11 @@ double fillCircleSpread(Color c, PointD pt, double intensity, double sigma)
803806
.Select(g => new Vector3D(crystal.RotationMatrix * g) { Index = g.Index, Flag1 = true, RelativeIntensity = g.RelativeIntensity, Text = g.Text })//回転させて新しいリストを作る
804807
.Where(g => g.Length2 - 2 * g.Z * maxEwaldR < 0 && g.Z2 / g.Length2 > minCosTheta2).ToList();//限界エワルド球に入り、後方散乱して検出器に入る可能性のある逆格子だけを選別
805808
if (gVector.Count == 0) return null;
806-
//indexだけを保存するリストも作成しておく (高速化のため)
807-
var indexList = gVector.Select(g => g.Index).ToList();
809+
//260403Cl indexから位置へのDictionaryを構築 (IndexOfの線形検索→O(1)ルックアップ)
810+
//var indexList = gVector.Select(g => g.Index).ToList();
811+
var indexDict = new Dictionary<(int h, int k, int l), int>();
812+
for (int i = 0; i < gVector.Count; i++)
813+
indexDict.TryAdd(gVector[i].Index, i);
808814
//原点を通る直線状にある逆格子ベクトルをまとめる
809815
Parallel.ForEach(gVector, g =>
810816
{
@@ -814,8 +820,7 @@ double fillCircleSpread(Color c, PointD pt, double intensity, double sigma)
814820
int h = g.Index.h / n, k = g.Index.k / n, l = g.Index.l / n;//既約なh,k,lを計算
815821
for (int m = 1; m < n; m++)//既約なh,k,lが存在するとは限らないので、h,k,lを整数倍して探索する
816822
{
817-
var j = indexList.IndexOf((m * h, m * k, m * l));
818-
if (j != -1)
823+
if (indexDict.TryGetValue((m * h, m * k, m * l), out var j)) //260403Cl Dictionary化
819824
{
820825
g.Flag1 = false;
821826
lock (lockObj)
@@ -1542,25 +1547,27 @@ public void SetVector(bool renewCrystal = false)
15421547

15431548
var latticeType = crystal.Symmetry.LatticeTypeStr;
15441549

1550+
//260403Cl 3回のWhere走査を1回のforeachに統合
15451551
var noConditionColor = formMain.Crystals.Length == 1 && !checkBoxUseCrystalColor.Checked ? colorControlNoCondition.Color.ToArgb() : crystal.Argb;
1546-
foreach (var gtemp in crystal.VectorOfG.Where(g => g.Extinction.Length == 0))
1547-
{
1548-
gtemp.Flag1 = true;
1549-
gtemp.Argb = noConditionColor;
1550-
}
1551-
15521552
var latticeColor = colorControlForbiddenLattice.Color.ToArgb();
1553-
foreach (var gtemp in crystal.VectorOfG.Where(g => g.Extinction.Length > 0 && g.Extinction[0] == latticeType))
1554-
{
1555-
gtemp.Flag1 = !checkBoxExtinctionLattice.Checked;
1556-
gtemp.Argb = latticeColor;
1557-
}
1558-
15591553
var screwGlideColor = colorControlScrewGlide.Color.ToArgb();
1560-
foreach (var gtemp in crystal.VectorOfG.Where(g => g.Extinction.Length > 0 && g.Extinction[0] != latticeType))
1554+
foreach (var gtemp in crystal.VectorOfG)
15611555
{
1562-
gtemp.Flag1 = !checkBoxExtinctionAll.Checked;
1563-
gtemp.Argb = screwGlideColor;
1556+
if (gtemp.Extinction.Length == 0)
1557+
{
1558+
gtemp.Flag1 = true;
1559+
gtemp.Argb = noConditionColor;
1560+
}
1561+
else if (gtemp.Extinction[0] == latticeType)
1562+
{
1563+
gtemp.Flag1 = !checkBoxExtinctionLattice.Checked;
1564+
gtemp.Argb = latticeColor;
1565+
}
1566+
else
1567+
{
1568+
gtemp.Flag1 = !checkBoxExtinctionAll.Checked;
1569+
gtemp.Argb = screwGlideColor;
1570+
}
15641571
}
15651572
}
15661573
}

0 commit comments

Comments
 (0)