| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 | 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{    /// <summary>    /// 夹杂物(inclusion)    ///     /// </summary>    public class Inclusion    {        /// <summary>        /// 构成夹杂物的微粒集合        /// </summary>        public List<Particle> particles;        /// <summary>        /// 当前夹杂物判定所使用的标准        /// </summary>        public InclusionsStandard standard;        /// <summary>        /// 像素长度        /// </summary>        public double pixelLength;        /// <summary>        /// 像素宽度        /// </summary>        public double pixelWidth;        /// <summary>        /// 物理长度        /// </summary>        public double physicalLength;        /// <summary>        /// 物理宽度        /// </summary>        public double physicalWidth;        /// <summary>        /// 长宽比        /// </summary>        public double lwRatio;        /// <summary>        /// 评级-用于平均视场        /// </summary>        public double rating;        /// <summary>        /// 视场编号        /// </summary>        public int viewNum;        /// <summary>        /// 视场左限        /// </summary>        public int viewLeft;        /// <summary>        /// 视场上限        /// </summary>        public int viewTop;        /// <summary>        /// 视场右限        /// </summary>        public int viewRight;        /// <summary>        /// 视场下限        /// </summary>        public int viewBottom;        /// <summary>        /// 矩形轮廓        /// </summary>        public Rectangle rectProfile;        /// <summary>        /// 矩形轮廓(K法)        /// </summary>        public Rectangle rectKMethodProfile;        public int offsetX;        public int offsetY;        // 排列方式        public InclusionArrangement arrangement        {            get            {                return particles.Count > 1 ? InclusionArrangement.Aligned : InclusionArrangement.Scattered;            }        }        /// <summary>        /// 形状        /// </summary>        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;                }            }        }        /// <summary>        /// 形状系数(shape factor)        /// </summary>        public double shapeFactor;        /// <summary>        /// 面积(area)        /// </summary>        public double area;        /// <summary>        /// 面积(area)        /// </summary>        public double areaK;        /// <summary>        /// 直径(diameter)        /// </summary>        public double diameter;        /// <summary>        /// 评级行号        /// </summary>        public int rowNumber;        /// <summary>        /// 评级列号        /// </summary>        public int columnNumber;        /// <summary>        ///         /// </summary>        public int isEdit = 0;        /// <summary>        /// 夹杂物分类        /// </summary>        public ClassesOfInclusions classes;        /// <summary>        /// 夹杂物类型        /// </summary>        public TypesOfInclusions type;        /// <summary>        /// 夹杂物颜色        /// </summary>        private ColorOfInclusions color_;        public ColorOfInclusions 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 Inclusion(InclusionsStandard standard)        {            this.particles = new List<Particle>();            this.standard = standard;        }        public Inclusion(InclusionsStandard 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);            this.isEdit = 1;        }        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 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);        }    }    /// <summary>    /// 排列方式    /// </summary>    public enum InclusionArrangement    {        /// <summary>        /// 分散的        /// </summary>        Scattered,        /// <summary>        /// 排成行的        /// </summary>        Aligned    }    /// <summary>    /// 形状    /// </summary>    public enum ParticleShape    {        /// <summary>        /// 拉长的        /// </summary>        Elongated,        /// <summary>        /// 球状的        /// </summary>        Globular    }    /// <summary>    /// 夹杂物分类    /// </summary>    public enum ClassesOfInclusions    {        α, β, γ, δ    }}
 |