Exemplo n.º 1
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");
        }
        private void btnSaveRenderer_Click(object sender, EventArgs e)
        {
            string fn = String.Format("{0}screenshot{1}.png", PackingSystemSetting.ResultDir, DateTime.Now.ToString("yyyyMMhh-HHmmss"));

            CuteTools.SaveRendererWindowsAsPic(fn, ref rwcShowSlices);
        }