using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using static PaintDotNet.Base.DedicatedAnalysis.Inclusions.InclusionsGlobalSettings; namespace PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model { /// /// 夹杂物(inclusion) /// /// public class Inclusion { /// /// 构成夹杂物的微粒集合 /// public List particles; /// /// 当前夹杂物判定所使用的标准 /// public InclusionsStandard standard; /// /// 像素长度 /// public double pixelLength; /// /// 像素宽度 /// public double pixelWidth; /// /// 物理长度 /// public double physicalLength; /// /// 物理宽度 /// public double physicalWidth; /// /// 长宽比 /// public double lwRatio; /// /// 评级-用于平均视场 /// public double rating; /// /// 视场编号 /// public int viewNum; /// /// 视场左限 /// public int viewLeft; /// /// 视场上限 /// public int viewTop; /// /// 视场右限 /// public int viewRight; /// /// 视场下限 /// public int viewBottom; /// /// 矩形轮廓 /// public Rectangle rectProfile; /// /// 矩形轮廓(K法) /// public Rectangle rectKMethodProfile; public int offsetX; public int offsetY; // 排列方式 public InclusionArrangement arrangement { get { return particles.Count > 1 ? InclusionArrangement.Aligned : InclusionArrangement.Scattered; } } /// /// 形状 /// private ParticleShape shape_; public ParticleShape shape { get { return shape_; } set { shape_ = value; switch (value) { case ParticleShape.Elongated: { switch (this.arrangement) { case InclusionArrangement.Aligned: { this.classes = ClassesOfInclusions.γ; } break; case InclusionArrangement.Scattered: { this.classes = ClassesOfInclusions.α; } break; default: break; } } break; case ParticleShape.Globular: { switch (this.arrangement) { case InclusionArrangement.Aligned: { this.classes = ClassesOfInclusions.β; } break; case InclusionArrangement.Scattered: { this.classes = ClassesOfInclusions.δ; } break; default: break; } } break; default: break; } } } /// /// 形状系数(shape factor) /// public double shapeFactor; /// /// 面积(area) /// public double area; /// /// 面积(area) /// public double areaK; /// /// 直径(diameter) /// public double diameter; /// /// 评级行号 /// public int rowNumber; /// /// 评级列号 /// public int columnNumber; /// /// /// public int isEdit = 0; /// /// 夹杂物分类 /// public ClassesOfInclusions classes; /// /// 夹杂物类型 /// public TypesOfInclusions type; /// /// 夹杂物颜色 /// private ColorOfInclusions color_; public ColorOfInclusions color { get { return color_; } set { color_ = value; this.standard.determineType(this); } } /// /// 化学特性 /// public String chemicalCharacteristics = ""; public bool superBig = false; /// /// 构造函数 /// /// public Inclusion(InclusionsStandard standard) { this.particles = new List(); this.standard = standard; } public Inclusion(InclusionsStandard standard, PointF[] points) { this.particles = new List(); this.standard = standard; OpenCvSharp.Point[] cvPoints = new OpenCvSharp.Point[points.Length]; for (int i = 0; i < points.Length; i++) { OpenCvSharp.Point point = new OpenCvSharp.Point(points[i].X, points[i].Y); cvPoints[i] = point; } Particle particle = new Particle(cvPoints, standard); this.addParticles(particle); this.isEdit = 1; } public void addParticles(Particle particle) { this.particles.Add(particle); parametersCalculation(); } public void addParticles(List particles) { this.particles.AddRange(particles); parametersCalculation(); } public void removeParticles(Particle particle) { this.particles.Remove(particle); parametersCalculation(); } /// /// 参数计算 /// private void parametersCalculation() { if (this.particles.Count == 0) { return; } int minx = 0, miny = 0, maxx = 0, maxy = 0; int minxK = 0, minyK = 0, maxxK = 0, maxyK = 0; int countGlobular=0; for (int i = 0; i < this.particles.Count; i++) { Particle particle = this.particles[i]; if (i == 0) { this.offsetX = particle.offsetX; this.offsetY = particle.offsetY; } if (particle.shape == ParticleShape.Globular) { countGlobular++; } if (i == 0) { minx = particle.rectProfile.Left; maxx = particle.rectProfile.Right; miny = particle.rectProfile.Top; maxy = particle.rectProfile.Bottom; minxK = particle.rectKMethodProfile.Left; maxxK = particle.rectKMethodProfile.Right; minyK = particle.rectKMethodProfile.Top; maxyK = particle.rectKMethodProfile.Bottom; continue; } if (particle.rectProfile.Left < minx) { minx = particle.rectProfile.Left; minxK = particle.rectKMethodProfile.Left; } if (particle.rectProfile.Right > maxx) { maxx = particle.rectProfile.Right; maxxK = particle.rectKMethodProfile.Left; } if (particle.rectProfile.Top < miny) { miny = particle.rectProfile.Top; minyK = particle.rectKMethodProfile.Left; } if (particle.rectProfile.Bottom > maxy) { maxy = particle.rectProfile.Bottom; maxyK = particle.rectKMethodProfile.Left; } } // 计算长度,宽度/直径,面积,形状系数,长宽比 if (this.standard.globalSettings.rollingDirection == RollingDirection.PORTRAIT) { this.pixelLength = maxy - miny; this.pixelWidth = maxx - minx; } else { this.pixelWidth = maxy - miny; this.pixelLength = maxx - minx; } this.physicalLength = this.pixelLength * this.standard.globalSettings.pxPerUnit; this.physicalWidth = this.pixelWidth * this.standard.globalSettings.pxPerUnit; this.diameter = this.physicalLength > this.physicalWidth? this.physicalLength : this.physicalWidth; if (countGlobular/this.particles.Count > 0.8) { this.shape = ParticleShape.Globular; this.area = this.diameter* this.diameter*(Math.PI/4); } else { this.shape = ParticleShape.Elongated; this.area = this.physicalLength * this.physicalWidth * (Math.PI / 4); } this.areaK = this.particles.Sum(m => m.areaK); this.shapeFactor = Math.Log((Math.PI / 4)*(this.physicalLength * this.physicalLength / this.area) / Math.Log(this.physicalLength / 1)); this.lwRatio = Math.Round(this.physicalLength / this.physicalWidth,2); this.rectProfile = new Rectangle(minx, miny, maxx - minx, maxy - miny); this.rectKMethodProfile = new Rectangle(minxK, minyK, maxx - minx, maxy - miny); this.standard.determineType(this); } } /// /// 排列方式 /// public enum InclusionArrangement { /// /// 分散的 /// Scattered, /// /// 排成行的 /// Aligned } /// /// 形状 /// public enum ParticleShape { /// /// 拉长的 /// Elongated, /// /// 球状的 /// Globular } /// /// 夹杂物分类 /// public enum ClassesOfInclusions { α, β, γ, δ } }