Beispiel #1
0
 public AnalysisSpot(OpticalSystem system) : base(system)
 {
     _axes = new PlotAxes();
     _axes.set_show_axes(false, PlotAxes.AxisMask.XY);
     _axes.set_label("Sagittal distance", PlotAxes.AxisMask.X);
     _axes.set_label("Tangential distance", PlotAxes.AxisMask.Y);
     _axes.set_unit("m", true, true, -3, PlotAxes.AxisMask.XY);
 }
Beispiel #2
0
        void draw_axes_tic2(RendererViewport r, PlotAxes a, int i,
                            int pow10, bool oor, double x)
        {
            const int N = 2;
            Vector2   p = new Vector2(a.get_position().x(), a.get_position().y());

            PlotAxes.Axis ax            = a._axes[i];
            Vector2       vtic          = null;
            Vector2Pair   _window2d_fit = r.get_window2d_fit();

            if (!oor && ax._axis)
            {
                vtic = p;
                vtic = vtic.set(i, x + p.v(i));
                r.draw_point(vtic, r.get_style_color(Renderer.Style.StyleForeground),
                             Renderer.PointStyle.PointStyleCross);
            }

            if (a._frame)
            {
                vtic = _window2d_fit.v1;
                vtic = vtic.set(i, x + p.v(i));
                r.draw_point(vtic, r.get_style_color(Renderer.Style.StyleForeground),
                             Renderer.PointStyle.PointStyleCross);

                vtic = _window2d_fit.v0;
                vtic = vtic.set(i, x + p.v(i));
                r.draw_point(vtic, r.get_style_color(Renderer.Style.StyleForeground),
                             Renderer.PointStyle.PointStyleCross);
            }

            // draw tic value text
            if (ax._values)
            {
                int align0 = (int)Renderer.TextAlignMask.TextAlignCenter | (int)Renderer.TextAlignMask.TextAlignTop;
                int align1 = (int)Renderer.TextAlignMask.TextAlignRight | (int)Renderer.TextAlignMask.TextAlignMiddle;
                int align2 = (int)Renderer.TextAlignMask.TextAlignTop | (int)Renderer.TextAlignMask.TextAlignCenter;

                string s = String.Format("{0:G3}", (x + p.v(i) - a._origin.v(i)) / Math.Pow(10.0, pow10));
                switch (N)
                {
                case 2:
                    int align = i == 0
                            ? align0
                            : (i == 1 ? align1 : align2);
                    r.draw_text(vtic, Vector2.vector2_10, s, align, 12,
                                r.get_style_color(Renderer.Style.StyleForeground));
                    break;
                }
            }
        }
Beispiel #3
0
        public void draw_axes_2d(RendererViewport renderer, PlotAxes a)
        {
            int     N = 2;
            Vector2 p = new Vector2(a.get_position().x(), a.get_position().y());
            int     pow10;

            int[]       max           = new int[N];
            int[]       min           = new int[N];
            double[]    step          = new double[N];
            Vector2Pair _window2d     = renderer.get_window2d();
            Vector2Pair _window2d_fit = renderer.get_window2d_fit();

            if (a._frame)
            {
                draw_frame_2d(renderer);
            }

            for (int i = 0; i < N; i++)
            {
                PlotAxes.Axis ax = a._axes[i];
                Range         r  = new Range(_window2d_fit.v0.v(i), _window2d_fit.v1.v(i));

                double s = step[i] = Math.Abs(a.get_tics_step(i, r));

                min[i] = MathUtils.trunc((r.first - p.v(i)) / s);
                max[i] = MathUtils.trunc((r.second - p.v(i)) / s);

                pow10 = ax._pow10_scale ? (int)Math.Floor(Math.Log10(s)) : 0;

                string si_unit = "";

                if (ax._si_prefix)
                {
                    int u = (24 + pow10 + ax._pow10) / 3;
                    if (u >= 0 && u < 17)
                    {
                        si_unit = sc[u] + ax._unit;
                        pow10   = (u - 8) * 3 - ax._pow10;
                    }
                }

                Vector2 lp = null;
                Vector2 ld = null;

                switch (i)
                {
                case 0:
                    lp = new Vector2(
                        (_window2d.v0.x() + _window2d.v1.x()) / 2.0,
                        (_window2d_fit.v0.y() * .50 + _window2d.v0.y() * 1.50) / 2.0);
                    ld = Vector2.vector2_10;
                    break;

                case 1:
                    lp = new Vector2(
                        (_window2d_fit.v0.x() * .50 + _window2d.v0.x() * 1.50) / 2.0,
                        (_window2d.v0.y() + _window2d.v1.y()) / 2.0);
                    ld = Vector2.vector2_01;
                    break;

                default:
                    throw new InvalidOperationException("Invalid axis " + i);
                }

                // axis label
                {
                    string lx      = ax._label;
                    bool   useunit = ax._unit.Length > 0;
                    bool   usep10  = pow10 != 0;

                    if (si_unit.Length > 0)
                    {
                        lx += " (" + si_unit + ")";
                    }
                    else if (useunit || usep10)
                    {
                        lx += " (";
                        if (usep10)
                        {
                            //lx += string.format("x10^%i", pow10);
                            lx += string.Format("x10^{0:D}", pow10);
                        }
                        if (useunit && usep10)
                        {
                            lx += " ";
                        }
                        if (useunit)
                        {
                            lx += ax._unit;
                        }
                        lx += ")";
                    }

                    renderer.draw_text(lp, ld, lx,
                                       (int)Renderer.TextAlignMask.TextAlignCenter | (int)Renderer.TextAlignMask.TextAlignMiddle, 12,
                                       renderer.get_style_color(Renderer.Style.StyleForeground));
                }

                // skip out of range axis
                bool oor = false;
                for (int j = 0; j < N; j++)
                {
                    oor |= (j != i &&
                            ((p.v(j) <= Math.Min(_window2d_fit.v0.v(j), _window2d_fit.v1.v(j))) ||
                             (p.v(j) >= Math.Max(_window2d_fit.v0.v(j), _window2d_fit.v1.v(j)))));
                }

                // draw axis
                if (!oor && ax._axis)
                {
                    Vector2Pair seg = new Vector2Pair(p.set(i, r.first), p.set(i, r.second));
                    renderer.draw_segment(seg, renderer.get_style_color(Renderer.Style.StyleForeground));
                }

                // draw tics on axis
                if (ax._tics && (ax._axis || a._frame))
                {
                    for (int j = min[i]; j <= max[i]; j++)
                    {
                        draw_axes_tic2(renderer, a, i, pow10, oor, j * s);
                    }
                }
            }

            if (a._grid)
            {
                // draw grid
                for (int x = min[0]; x <= max[0]; x++)
                {
                    for (int y = min[1]; y <= max[1]; y++)
                    {
                        switch (N)
                        {
//                        case 3:
//                            for (int z = min[2]; z <= max[2]; z++)
//                                renderer.draw_point (new Vector3 (p[0] + x * step[0],
//                                p[1] + y * step[1],
//                                p[2] + z * step[2]),
//                            renderer.get_style_color (StyleForeground));
//                            break;

                        case 2:
                            renderer.draw_point(
                                new Vector2(p.v(0) + x * step[0], p.v(1) + y * step[1]),
                                renderer.get_style_color(Renderer.Style.StyleForeground),
                                Renderer.PointStyle.PointStyleDot);
                            break;
                        }
                    }
                }
            }
        }