Пример #1
0
        /// <summary>
        /// 计算文件名符合特定格式的文件名的图像序列的孔隙率
        /// 默认情况下,白色是孔隙相,黑色是固体相,此时不需要对图像进行反相
        /// example :
        ///         ComputeParameters.ComputePorosity(@".\result\", "{0:D4}.bmp", 10, 21, ref porosity);
        /// </summary>
        /// /// <param name="folder">文件夹名称</param>
        /// <param name="pattern">文件名的格式</param>
        /// <param name="startIndex">起始index</param>
        /// <param name="endIndex">末尾index</param>
        /// <param name="porosity">孔隙率</param>
        /// <param name="needReverse">是否需要反相</param>
        /// <returns></returns>
        public static bool ComputePorosity(string folder, string pattern, int startIndex, int endIndex, ref double porosity, bool needReverse = false)
        {
            bool   res = true;
            string fn  = "";

            porosity = 0.0;
            Matrix <double> pMat = new Matrix <double>(endIndex - startIndex + 1, 1);
            Mat             img;

            for (int i = startIndex; i <= endIndex; i++)
            {
                fn  = string.Format(folder + pattern, i);
                img = CvInvoke.Imread(fn, Emgu.CV.CvEnum.LoadImageType.Grayscale);
                if (img.IsEmpty)
                {
                    res = false;
                    break;
                }
                if (needReverse)
                {
                    CvInvoke.BitwiseNot(img, img);
                }
                pMat[i - startIndex, 0] = CvInvoke.CountNonZero(img) * 1.0 / (img.Cols * img.Rows);
                porosity += pMat[i - startIndex, 0];
            }
            if (res)
            {
                DataReadWriteHelper.RecordInfo("porosity.txt", PackingSystemSetting.ResultDir, pMat, false);
            }
            return(res);
        }
Пример #2
0
        /// <summary>
        /// 计算文件夹中的所有的bmp文件组成的图像序列的孔隙率
        /// 默认情况下,白色是孔隙相,黑色是固体相,此时不需要对图像进行反相
        /// example :
        ///         ComputeParameters.ComputePorosity(dlg.SelectedPath, ref porosity, true)
        /// </summary>
        /// <param name="folder">文件夹名称</param>
        /// <param name="porosity">孔隙率</param>
        /// <param name="needReverse">是否需要反相</param>
        /// <returns></returns>
        public static bool ComputePorosity(string folder, ref double porosity, bool needReverse = false)
        {
            bool res = true;

            porosity = 0.0;
            if (Directory.Exists(folder))
            {
                var             files = Directory.GetFiles(folder, "*.bmp");
                Matrix <double> pMat  = new Matrix <double>(files.Count(), 1);
                Mat             img;
                int             index = 0;
                foreach (var file in files)
                {
                    img = CvInvoke.Imread(file, Emgu.CV.CvEnum.LoadImageType.Grayscale);
                    if (needReverse)
                    {
                        CvInvoke.BitwiseNot(img, img);
                    }
                    pMat[index++, 0] = CvInvoke.CountNonZero(img) * 1.0 / (img.Cols * img.Rows);
                    porosity        += pMat[index - 1, 0];
                }
                porosity /= files.Count();
                DataReadWriteHelper.RecordInfo("porosity.txt", PackingSystemSetting.ResultDir, pMat, false);
            }
            else
            {
                res = false;
            }

            return(res);
        }
 private void btnSaveInfo_Click(object sender, EventArgs e)
 {
     if (SaveSettings())
     {
         DataReadWriteHelper.SaveObjAsJsonFile(new PackSysSettingForSave(), PackingSystemSetting.SettingFilename);
         ReloadSystemSetting();
         this.Close();
     }
     else
     {
         MessageBox.Show("填充的信息有误,请检查其合法性!", "warning");
     }
 }
        /// <summary>
        /// 对数正态分布测试
        /// </summary>
        public static void TestLogNormalNumber()
        {
            int             num   = 10000;
            double          min   = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].MinDiameter;
            double          max   = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].MaxDiameter;
            double          mu    = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].LogMiu;
            double          sigma = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].LogSigma;
            Matrix <double> m     = new Matrix <double>(num, 1);

            for (int i = 0; i < num; i++)
            {
                m[i, 0] = RandomLogNormal(mu, sigma, min, max);
            }

            MCvScalar s = CvInvoke.Mean(m);

            DataReadWriteHelper.RecordInfo("data.txt", @"D:\MyDesktop\", m * 1e6, false);
            Console.WriteLine("random log normal number generation test : {0}", s.V0);
        }
Пример #5
0
        /// <summary>
        /// 迭代求解整个动态过程
        /// </summary>
        public void SolveProblem()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            // find max velocity and acceleration of all balls
            double maxV = 0, maxA = 0;

            for (int j = 0; j < objNum; j++)
            {
                if (maxV <= CvInvoke.Norm(rtVel.GetRow(j), Emgu.CV.CvEnum.NormType.L2))
                {
                    maxV = CvInvoke.Norm(rtVel.GetRow(j), Emgu.CV.CvEnum.NormType.L2);
                }
                if (maxA <= CvInvoke.Norm(rtAcc.GetRow(j), Emgu.CV.CvEnum.NormType.L2))
                {
                    maxA = CvInvoke.Norm(rtAcc.GetRow(j), Emgu.CV.CvEnum.NormType.L2);
                }
            }
            MaxVel = maxV;

            CuteTools.ComputeMatDist(rtPos, ref distances);
            //开始求解时,会先找出所有小球的附近小球的下标
            UpdateLocalBallsIndex();

            //Stopwatch siter = new Stopwatch();
            for (; currIter < iteration; currIter++)
            {
                //siter.Restart();
                CuteTools.ComputeMatDist(rtPos, ref distances);
                //Console.WriteLine( "compute matreix dist: " + siter.ElapsedMilliseconds );
                //每隔100次,更新一下小球的附近小球的下标
                if (currIter % 100 == 0)
                {
                    //siter.Restart();
                    UpdateLocalBallsIndex();
                    //Console.WriteLine("update local balls index: " + siter.ElapsedMilliseconds);
                }
                shouldVelBeDecayed.SetValue(0);
                //siter.Restart();
                ComputeAcc(currIter);
                //Console.WriteLine("compute acc: " + siter.ElapsedMilliseconds);
                //siter.Restart();
                ComputeVel();
                //Console.WriteLine("compute vel: " + siter.ElapsedMilliseconds);
                //siter.Restart();
                ComputePos();
                //Console.WriteLine("compute pos: " + siter.ElapsedMilliseconds);
                //ComputeBounds();

                //计算最大速度与加速度
                maxV = 0; maxA = 0;
                for (int j = 0; j < objNum; j++)
                {
                    if (maxV <= CvInvoke.Norm(rtVel.GetRow(j), Emgu.CV.CvEnum.NormType.L2))
                    {
                        maxV = CvInvoke.Norm(rtVel.GetRow(j), Emgu.CV.CvEnum.NormType.L2);
                    }
                    if (maxA <= CvInvoke.Norm(rtAcc.GetRow(j), Emgu.CV.CvEnum.NormType.L2))
                    {
                        maxA = CvInvoke.Norm(rtAcc.GetRow(j), Emgu.CV.CvEnum.NormType.L2);
                    }
                }
                MaxVel = maxV;

                //siter.Restart();
                energy[currIter, 0] = ComputeEnergy();
                //Console.WriteLine("compute energy: " + siter.ElapsedMilliseconds);
                string s = String.Format("current iteration : {0:D4}, system energy : {1:F4}, elapsed time : {2} ms, max Vel is: {3}, max Acc is {4} .",
                                         currIter, energy[currIter, 0], sw.ElapsedMilliseconds, maxV, maxA);
                log.Info(s);
                //if( i % 20 == 0 )
                if (true)
                {
                    RefreshHandler(currIter, rtPos);
                }
            }

            DataReadWriteHelper.RecordInfo("rePos" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", PackingSystemSetting.ResultDir, rtPos * PackingSystemSetting.ResolutionUmPerSysUnit);
            DataReadWriteHelper.RecordInfo("reVel" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", PackingSystemSetting.ResultDir, rtVel);
            DataReadWriteHelper.RecordInfo("reAcc" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", PackingSystemSetting.ResultDir, rtAcc);
            DataReadWriteHelper.RecordInfo("radii" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", PackingSystemSetting.ResultDir, radii * PackingSystemSetting.ResolutionUmPerSysUnit);
            DataReadWriteHelper.RecordInfo("energy" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", PackingSystemSetting.ResultDir, energy);

            sw.Stop();

            Console.WriteLine("Process Time : " + sw.ElapsedMilliseconds + "ms");
        }