コード例 #1
0
ファイル: lion_outline.cs プロジェクト: MichealWen/sharpmapv2
        public override void OnDraw()
        {
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;


            IPixelFormat        pixf          = new FormatRGB(rbuf_window(), new BlenderBGR());
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

            IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
            mtx.Scale(g_scale);
            mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble());
            mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
            mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2));

            if (m_scanline.status())
            {
                g_rasterizer.SetVectorClipBox(0, 0, width, height);

                ConvStroke <T> stroke = new ConvStroke <T>(g_path);
                stroke.Width    = m_width_slider.value();
                stroke.LineJoin = LineJoin.RoundJoin;
                ConvTransform <T> trans = new ConvTransform <T>(stroke, mtx);
                Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);
            }
            else
            {
                /*
                 * double w = m_width_slider.Value() * mtx.scale();
                 *
                 * line_profile_aa profile = new line_profile_aa(w, new gamma_none());
                 * renderer_outline_aa ren = new renderer_outline_aa(rb, profile);
                 * rasterizer_outline_aa ras = new rasterizer_outline_aa(ren);
                 *
                 * conv_transform trans = new conv_transform(g_path, mtx);
                 *
                 * ras.render_all_paths(trans, g_colors, g_path_idx, g_npaths);
                 */
            }

            base.OnDraw();
        }
コード例 #2
0
ファイル: lion.cs プロジェクト: MichealWen/sharpmapv2
        public override void OnDraw()
        {
#if use_timers
            AllTimer.Start();
#endif
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;

            uint i;
            for (i = 0; i < m_NumPaths; i++)
            {
                // g_colors[i].A_Byte = (byte)(m_AlphaSlider.value() * 255);
                g_colors[i] = RGBA_Bytes.ModifyComponent(g_colors[i], Component.A, (byte)(m_AlphaSlider.value().ToDouble() * 255));
            }

            IAffineTransformMatrix <T> transform = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            transform.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
            transform.Scale(MatrixFactory <T> .CreateVector2D(g_scale, g_scale));
            transform.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), g_angle + Math.PI);
            transform.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
            transform.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(width).Divide(2), M.New <T>(height).Divide(2)));

            // This code renders the lion:
            ConvTransform <T> transformedPathStorage = new ConvTransform <T>(g_PathStorage, transform);
#if use_timers
            Lion50Timer.Start();
            for (uint j = 0; j < 200; j++)
#endif
            {
                this.GetRenderer().Render(transformedPathStorage, g_colors, g_path_idx, m_NumPaths);
            }
#if use_timers
            Lion50Timer.Stop();
#endif

#if use_timers
            AllTimer.Stop();
            CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds());
            CExecutionTimer.Instance.Reset();
#endif
            base.OnDraw();
        }
コード例 #3
0
        public override void OnDraw()
        {
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;

            if (m_num_cb.value().NotEqual(m_slider_value))
            {
                generate_alpha_mask(width, height);
                m_slider_value = m_num_cb.value();
            }

            g_rasterizer.SetVectorClipBox(0, 0, width, height);

            IPixelFormat pf = new FormatRGB(rbuf_window(), new BlenderBGR());

            unsafe
            {
                fixed(byte *pAlphaBuffer = m_alpha_buf)
                {
                    m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)width, (uint)height, width, 1);

                    AGG.PixelFormat.AlphaMaskAdaptor pixFormatAlphaMaskAdaptor = new AGG.PixelFormat.AlphaMaskAdaptor(pf, m_alpha_mask);
                    FormatClippingProxy alphaMaskClippingProxy = new FormatClippingProxy(pixFormatAlphaMaskAdaptor);
                    FormatClippingProxy clippingProxy          = new FormatClippingProxy(pf);

                    IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

                    mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
                    mtx.Scale(g_scale);
                    mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble());
                    mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
                    mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2));

                    clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

                    // draw a background to show how the mask is working better
                    int RectWidth = 30;

                    for (int i = 0; i < 40; i++)
                    {
                        for (int j = 0; j < 40; j++)
                        {
                            if ((i + j) % 2 != 0)
                            {
                                VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0);
                                rect.NormalizeRadius();

                                // Drawing as an outline
                                g_rasterizer.AddPath(rect);
                                Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.9, .9, .9));
                            }
                        }
                    }

                    //int x, y;

                    // Render the lion
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, mtx);

                    Renderer <T> .RenderSolidAllPaths(alphaMaskClippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);

                    /*
                     * // Render random Bresenham lines and markers
                     * agg::renderer_markers<amask_ren_type> m(r);
                     * for(i = 0; i < 50; i++)
                     * {
                     *  m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          (randGenerator.Next() & 0x7F) + 0x7F));
                     *  m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          (randGenerator.Next() & 0x7F) + 0x7F));
                     *
                     *  m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
                     *         m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));
                     *
                     *  m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
                     *           agg::marker_e(randGenerator.Next() % agg::end_of_markers));
                     * }
                     *
                     *
                     * // Render random anti-aliased lines
                     * double w = 5.0;
                     * agg::line_profile_aa profile;
                     * profile.width(w);
                     *
                     * typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
                     * renderer_type ren(r, profile);
                     *
                     * typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
                     * rasterizer_type ras(ren);
                     * ras.round_cap(true);
                     *
                     * for(i = 0; i < 50; i++)
                     * {
                     *  ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
                     *                       randGenerator.Next() & 0x7F,
                     *                       randGenerator.Next() & 0x7F,
                     *                       //255));
                     *                       (randGenerator.Next() & 0x7F) + 0x7F);
                     *  ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                     *  ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                     *  ras.render(false);
                     * }
                     *
                     *
                     * // Render random circles with gradient
                     * typedef agg::gradient_linear_color<color_type> grad_color;
                     * typedef agg::gradient_circle grad_func;
                     * typedef agg::span_interpolator_linear<> interpolator_type;
                     * typedef agg::span_gradient<color_type,
                     *                        interpolator_type,
                     *                        grad_func,
                     *                        grad_color> span_grad_type;
                     *
                     * agg::trans_affine grm;
                     * grad_func grf;
                     * grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
                     * agg::ellipse ell;
                     * agg::span_allocator<color_type> sa;
                     * interpolator_type inter(grm);
                     * span_grad_type sg(inter, grf, grc, 0, 10);
                     * agg::renderer_scanline_aa<amask_ren_type,
                     *                        agg::span_allocator<color_type>,
                     *                        span_grad_type> rg(r, sa, sg);
                     * for(i = 0; i < 50; i++)
                     * {
                     *  x = randGenerator.Next() % width;
                     *  y = randGenerator.Next() % height;
                     *  double r = randGenerator.Next() % 10 + 5;
                     *  grm.reset();
                     *  grm *= agg::trans_affine_scaling(r / 10.0);
                     *  grm *= agg::trans_affine_translation(x, y);
                     *  grm.invert();
                     *  grc.colors(agg::rgba8(255, 255, 255, 0),
                     *             agg::rgba8(randGenerator.Next() & 0x7F,
                     *                        randGenerator.Next() & 0x7F,
                     *                        randGenerator.Next() & 0x7F,
                     *                        255));
                     *  sg.color_function(grc);
                     *  ell.init(x, y, r, r, 32);
                     *  g_rasterizer.add_path(ell);
                     *  agg::render_scanlines(g_rasterizer, g_scanline, rg);
                     * }
                     */

                    //m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
                }

                m_alpha_mask_rbuf.dettachBuffer();
            }
            base.OnDraw();
        }