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