Пример #1
0
        /// <summary>
        /// Updates profile plot if profile annotation has been made.
        /// </summary>
        internal void UpdateProfile()
        {
            if (Mode == MouseMode.Profile && ProfileAnnotation != null && ProfileAnnotation.ControlPoints.Count >= 2)
            {
                Vec2 profileStart = ProfileAnnotation.ControlPoints[0].GetXY();
                Vec2 profileEnd   = ProfileAnnotation.ControlPoints[1].GetXY();
                ProfileAnnotation.LineWidth = Profile.ProfileWidth;
                double profileRadius = ProfileAnnotation.LineWidth / 2;

                Vec2   delta = profileEnd - profileStart;
                double l     = delta.Norm();
                Vec2   n     = new Vec2(delta.Y, -delta.X) / l; // Unit normal

                // Extract profile data
                Profile.Clear();
                double tstep = 1.0 / Math.Max(Math.Abs(delta.X), Math.Abs(delta.Y));
                for (double t = 0; t <= 1; t += tstep)
                {
                    Vec2   f = profileStart + t * delta;
                    double r = t * l;

                    double sum   = 0.0;
                    double count = 0.0;

                    for (double s = 0; s < profileRadius; s++)
                    {
                        sum += PictureBox.GetValueImage(f + s * n);
                        count++;

                        if (s > 0)
                        {
                            sum += PictureBox.GetValueImage(f - s * n);
                            count++;
                        }
                    }

                    Profile.AddPoint(r, sum / count);
                }

                Profile.Location = PointToScreen(Point.Round(PictureBox.PictureToScreen(profileEnd).ToPointF()));
                Profile.Draw();
                if (!Profile.Visible)
                {
                    Profile.Show();
                }
            }
        }