Esempio n. 1
0
        public override void on_draw()
        {
            pixfmt_alpha_blend_rgb pf       = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
            renderer_base          ren_base = new renderer_base(pf);

            ren_base.clear(new rgba(1.0, 1.0, 0.95));
            renderer_scanline_aa_solid ren = new renderer_scanline_aa_solid(ren_base);

            rasterizer_scanline_aa ras = new rasterizer_scanline_aa();
            scanline_unpacked_8    sl  = new scanline_unpacked_8();

            path_storage path = new path_storage(new vertex_block_storage());

            double x, y;
            double curve_time = 0;

            path.remove_all();
            curve4 curve;

            curve.approximation_method(curve_approximation_method_e(m_curve_type.cur_item()));
            curve.approximation_scale(m_approximation_scale.value());
            curve.angle_tolerance(deg2rad(m_angle_tolerance.value()));
            curve.cusp_limit(deg2rad(m_cusp_limit.value()));
            curve_time = measure_time(curve);
            double max_angle_error_01  = 0;
            double max_angle_error_1   = 0;
            double max_angle_error1    = 0;
            double max_angle_error_10  = 0;
            double max_angle_error_100 = 0;
            double max_error_01        = 0;
            double max_error_1         = 0;
            double max_error1          = 0;
            double max_error_10        = 0;
            double max_error_100       = 0;

            max_error_01  = calc_max_error(curve, 0.01, &max_angle_error_01);
            max_error_1   = calc_max_error(curve, 0.1, &max_angle_error_1);
            max_error1    = calc_max_error(curve, 1, &max_angle_error1);
            max_error_10  = calc_max_error(curve, 10, &max_angle_error_10);
            max_error_100 = calc_max_error(curve, 100, &max_angle_error_100);

            curve.approximation_scale(m_approximation_scale.value());
            curve.angle_tolerance(deg2rad(m_angle_tolerance.value()));
            curve.cusp_limit(deg2rad(m_cusp_limit.value()));
            curve.init(m_curve1.x1(), m_curve1.y1(),
                       m_curve1.x2(), m_curve1.y2(),
                       m_curve1.x3(), m_curve1.y3(),
                       m_curve1.x4(), m_curve1.y4());

            path.concat_path(curve);
//path.move_to(m_curve1.x1(), m_curve1.y1());
//path.line_to(m_curve1.x2(), m_curve1.y2());
//path.line_to(m_curve1.x3(), m_curve1.y3());
//path.line_to(m_curve1.x4(), m_curve1.y4());


            conv_stroke stroke = new conv_stroke(path);

            stroke.width(m_width.value());
            stroke.line_join(line_join_e(m_line_join.cur_item()));
            stroke.line_cap(line_cap_e(m_line_cap.cur_item()));
            stroke.inner_join(inner_join_e(m_inner_join.cur_item()));
            stroke.inner_miter_limit(1.01);

            ras.add_path(stroke);
            ren.color(rgba(0, 0.5, 0, 0.5));
            render_scanlines(ras, sl, ren);

            uint cmd;
            uint num_points1 = 0;

            path.rewind(0);
            while (!is_stop(cmd = path.vertex(&x, &y)))
            {
                if (m_show_points.status())
                {
                    Shape.Ellipse ell = new agg.Shape.Ellipse(x, y, 1.5, 1.5, 8);
                    ras.add_path(ell);
                    ren.color(rgba(0, 0, 0, 0.5));
                    render_scanlines(ras, sl, ren);
                }
                ++num_points1;
            }

            if (m_show_outline.status())
            {
                // Draw a stroke of the stroke to see the internals
                //--------------
                conv_stroke stroke2 = new conv_stroke(stroke);
                ras.add_path(stroke2);
                ren.color(rgba(0, 0, 0, 0.5));
                render_scanlines(ras, sl, ren);
            }

            // Check ellipse and arc for the number of points
            //---------------
            //ellipse a(100, 100, m_width.value(), m_width.value(), 0);
            //ras.add_path(a);
            //ren.color(rgba(0.5,0,0, 0.5));
            //render_scanlines(ras, sl, ren);
            //a.rewind(0);
            //while(!is_stop(cmd = a.vertex(&x, &y)))
            //{
            //    if(is_vertex(cmd))
            //    {
            //        ellipse ell(x, y, 1.5, 1.5, 8);
            //        ras.add_path(ell);
            //        ren.color(rgba(0,0,0,0.5));
            //        render_scanlines(ras, sl, ren);
            //    }
            //}


            // Check a circle with huge radius (10,000,000) and high approximation accuracy
            //---------------
            //double circle_pnt_count = 0;
            //bezier_arc ell(0,0, 10000000, 10000000, 0, 2*pi);
            //conv_curve<bezier_arc, curve3_div, curve4_div3> crv(ell);
            //crv.approximation_scale(10.0);
            //crv.rewind(0);
            //while(crv.vertex(&x, &y)) ++circle_pnt_count;


            string   buf;
            gsv_text t;

            t.size(8.0);

            conv_stroke pt = new conv_stroke(t);

            pt.line_cap(round_cap);
            pt.line_join(round_join);
            pt.width(1.5);

            /*
             * sprintf(buf, "Num Points=%d Time=%.2fmks\n\n"
             *           " Dist Error: x0.01=%.5f x0.1=%.5f x1=%.5f x10=%.5f x100=%.5f\n\n"
             *           "Angle Error: x0.01=%.1f x0.1=%.1f x1=%.1f x10=%.1f x100=%.1f",
             *      num_points1, curve_time,
             *      max_error_01,
             *      max_error_1,
             *      max_error1,
             *      max_error_10,
             *      max_error_100,
             *      max_angle_error_01,
             *      max_angle_error_1,
             *      max_angle_error1,
             *      max_angle_error_10,
             *      max_angle_error_100);
             */

            t.start_point(10.0, 85.0);
            t.text(buf);

            ras.add_path(pt);
            ren.color(rgba(0, 0, 0));
            render_scanlines(ras, sl, ren);

            render_ctrl(ras, sl, ren_base, m_curve1);
            render_ctrl(ras, sl, ren_base, m_angle_tolerance);
            render_ctrl(ras, sl, ren_base, m_approximation_scale);
            render_ctrl(ras, sl, ren_base, m_cusp_limit);
            render_ctrl(ras, sl, ren_base, m_width);
            render_ctrl(ras, sl, ren_base, m_show_points);
            render_ctrl(ras, sl, ren_base, m_show_outline);
            render_ctrl(ras, sl, ren_base, m_curve_type);
            render_ctrl(ras, sl, ren_base, m_case_type);
            render_ctrl(ras, sl, ren_base, m_inner_join);
            render_ctrl(ras, sl, ren_base, m_line_join);
            render_ctrl(ras, sl, ren_base, m_line_cap);
        }
Esempio n. 2
0
    public override void on_draw()
    {
        pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
        renderer_base ren_base = new renderer_base(pf);
        ren_base.clear(new rgba(1.0, 1.0, 0.95));
        renderer_scanline_aa_solid ren = new renderer_scanline_aa_solid(ren_base);

        rasterizer_scanline_aa ras = new rasterizer_scanline_aa();
        scanline_unpacked_8 sl = new scanline_unpacked_8();

        path_storage path = new path_storage(new vertex_block_storage());

        double x, y;
        double curve_time = 0;

        path.remove_all();
        curve4 curve;
        curve.approximation_method(curve_approximation_method_e(m_curve_type.cur_item()));
        curve.approximation_scale(m_approximation_scale.value());
        curve.angle_tolerance(deg2rad(m_angle_tolerance.value()));
        curve.cusp_limit(deg2rad(m_cusp_limit.value()));
        curve_time = measure_time(curve);
        double max_angle_error_01 = 0;
        double max_angle_error_1 = 0;
        double max_angle_error1 = 0;
        double max_angle_error_10 = 0;
        double max_angle_error_100 = 0;
        double max_error_01 = 0;
        double max_error_1 = 0;
        double max_error1 = 0;
        double max_error_10 = 0;
        double max_error_100 = 0;

        max_error_01   = calc_max_error(curve, 0.01, &max_angle_error_01);
        max_error_1    = calc_max_error(curve, 0.1,  &max_angle_error_1);
        max_error1     = calc_max_error(curve, 1,    &max_angle_error1);
        max_error_10   = calc_max_error(curve, 10,   &max_angle_error_10);
        max_error_100  = calc_max_error(curve, 100,  &max_angle_error_100);

        curve.approximation_scale(m_approximation_scale.value());
        curve.angle_tolerance(deg2rad(m_angle_tolerance.value()));
        curve.cusp_limit(deg2rad(m_cusp_limit.value()));
        curve.init(m_curve1.x1(), m_curve1.y1(),
                   m_curve1.x2(), m_curve1.y2(),
                   m_curve1.x3(), m_curve1.y3(),
                   m_curve1.x4(), m_curve1.y4());

        path.concat_path(curve);
//path.move_to(m_curve1.x1(), m_curve1.y1());
//path.line_to(m_curve1.x2(), m_curve1.y2());
//path.line_to(m_curve1.x3(), m_curve1.y3());
//path.line_to(m_curve1.x4(), m_curve1.y4());


        conv_stroke stroke = new conv_stroke(path);
        stroke.width(m_width.value());
        stroke.line_join(line_join_e(m_line_join.cur_item()));
        stroke.line_cap(line_cap_e(m_line_cap.cur_item()));
        stroke.inner_join(inner_join_e(m_inner_join.cur_item()));
        stroke.inner_miter_limit(1.01);

        ras.add_path(stroke);
        ren.color(rgba(0, 0.5, 0, 0.5));
        render_scanlines(ras, sl, ren);

        uint cmd;
        uint num_points1 = 0;
        path.rewind(0);
        while(!is_stop(cmd = path.vertex(&x, &y)))
        {
            if(m_show_points.status())
            {
                Shape.Ellipse ell = new agg.Shape.Ellipse(x, y, 1.5, 1.5, 8);
                ras.add_path(ell);
                ren.color(rgba(0,0,0, 0.5));
                render_scanlines(ras, sl, ren);
            }
            ++num_points1;
        }

        if(m_show_outline.status())
        {
            // Draw a stroke of the stroke to see the internals
            //--------------
            conv_stroke stroke2 = new conv_stroke(stroke);
            ras.add_path(stroke2);
            ren.color(rgba(0,0,0, 0.5));
            render_scanlines(ras, sl, ren);
        }

        // Check ellipse and arc for the number of points
        //---------------
        //ellipse a(100, 100, m_width.value(), m_width.value(), 0);
        //ras.add_path(a);
        //ren.color(rgba(0.5,0,0, 0.5));
        //render_scanlines(ras, sl, ren);
        //a.rewind(0);
        //while(!is_stop(cmd = a.vertex(&x, &y)))
        //{
        //    if(is_vertex(cmd))
        //    {
        //        ellipse ell(x, y, 1.5, 1.5, 8);
        //        ras.add_path(ell);
        //        ren.color(rgba(0,0,0,0.5));
        //        render_scanlines(ras, sl, ren);
        //    }
        //}


        // Check a circle with huge radius (10,000,000) and high approximation accuracy
        //---------------
        //double circle_pnt_count = 0;
        //bezier_arc ell(0,0, 10000000, 10000000, 0, 2*pi);
        //conv_curve<bezier_arc, curve3_div, curve4_div3> crv(ell);
        //crv.approximation_scale(10.0);
        //crv.rewind(0);
        //while(crv.vertex(&x, &y)) ++circle_pnt_count;


        string buf;
        gsv_text t;
        t.size(8.0);

        conv_stroke pt = new conv_stroke(t);
        pt.line_cap(round_cap);
        pt.line_join(round_join);
        pt.width(1.5);

        /*
        sprintf(buf, "Num Points=%d Time=%.2fmks\n\n"
                     " Dist Error: x0.01=%.5f x0.1=%.5f x1=%.5f x10=%.5f x100=%.5f\n\n"
                     "Angle Error: x0.01=%.1f x0.1=%.1f x1=%.1f x10=%.1f x100=%.1f", 
                num_points1, curve_time, 
                max_error_01,  
                max_error_1,   
                max_error1,   
                max_error_10,  
                max_error_100,
                max_angle_error_01,
                max_angle_error_1,
                max_angle_error1,
                max_angle_error_10,
                max_angle_error_100);
         */

        t.start_point(10.0, 85.0);
        t.text(buf);

        ras.add_path(pt);
        ren.color(rgba(0,0,0));
        render_scanlines(ras, sl, ren);

        render_ctrl(ras, sl, ren_base, m_curve1);
        render_ctrl(ras, sl, ren_base, m_angle_tolerance);
        render_ctrl(ras, sl, ren_base, m_approximation_scale);
        render_ctrl(ras, sl, ren_base, m_cusp_limit);
        render_ctrl(ras, sl, ren_base, m_width);
        render_ctrl(ras, sl, ren_base, m_show_points);
        render_ctrl(ras, sl, ren_base, m_show_outline);
        render_ctrl(ras, sl, ren_base, m_curve_type);
        render_ctrl(ras, sl, ren_base, m_case_type);
        render_ctrl(ras, sl, ren_base, m_inner_join);
        render_ctrl(ras, sl, ren_base, m_line_join);
        render_ctrl(ras, sl, ren_base, m_line_cap);
    }