using System;
using System.Collections.Generic;
using System.Drawing;
using static PaintDotNet.Base.DedicatedAnalysis.Porosity.PorositysGlobalSettings;
namespace PaintDotNet.Base.DedicatedAnalysis.Porosity.Model
{
///
/// 孔隙(Porosity)
///
///
public class Porositys
{
///
/// 构成孔隙的微粒集合
///
public List particles;
///
/// 当前孔隙判定所使用的标准
///
public PorositysStandard standard;
///
/// 像素长度
///
public double pixelLength;
///
/// 像素宽度
///
public double pixelWidth;
///
/// 物理长度
///
public double physicalLength;
///
/// 物理宽度
///
public double physicalWidth;
///
/// 最小卡轨直径
///
public float MinimumCaliperDiameter;
///
/// 矩形轮廓
///
public Rectangle rectProfile;
// 排列方式
public PorosityArrangement arrangement
{
get
{
return particles.Count > 1 ? PorosityArrangement.Aligned : PorosityArrangement.Scattered;
}
}
///
/// 面积(area)
///
public double area;
///
/// 直径(diameter)
///
public double diameter;
///
/// 孔隙分类
///
public ClassesOfPorositys classes;
///
/// 孔隙类型
///
public TypesOfPorositys type;
///
/// 孔隙颜色
///
private ColorOfPorositys color_;
public ColorOfPorositys color
{
get
{
return color_;
}
set
{
color_ = value;
this.standard.determineType(this);
}
}
///
/// 化学特性
///
public String chemicalCharacteristics = "";
public bool superBig = false;
///
/// 构造函数
///
///
public Porositys(PorositysStandard standard)
{
this.particles = new List();
this.standard = standard;
}
public Porositys(PorositysStandard 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);
}
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 countGlobular = 0;
Particle particle = this.particles[0];
minx = particle.rectProfile.Left;
maxx = particle.rectProfile.Right;
miny = particle.rectProfile.Top;
maxy = particle.rectProfile.Bottom;
// 计算长度,宽度/直径,面积,形状系数,长宽比
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;
this.area = this.physicalLength * this.physicalWidth * (Math.PI / 4);
this.MinimumCaliperDiameter = particle.MinimumCaliperDiameter;
this.rectProfile = new Rectangle(minx, miny, maxx - minx, maxy - miny);
this.standard.determineType(this);
//}
}
///
/// 排列方式
///
public enum PorosityArrangement
{
///
/// 分散的
///
Scattered,
///
/// 排成行的
///
Aligned
}
///
/// 孔隙分类
///
public enum ClassesOfPorositys
{
D, F, S,G
}
}
}