コード例 #1
0
ファイル: wrap_Font.cpp プロジェクト: Kivutar/love-libretro
int w_newRasterizer(lua_State *L)
{
	if (lua_type(L, 1) == LUA_TNUMBER || lua_type(L, 2) == LUA_TNUMBER || lua_isnone(L, 1))
	{
		// First or second argument is a number: call newTrueTypeRasterizer.
		return w_newTrueTypeRasterizer(L);
	}
	else if (lua_isnoneornil(L, 2))
	{
		// Single argument of another type: call Font::newRasterizer.
		Rasterizer *t = nullptr;
		filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);

		luax_catchexcept(L,
			[&]() { t = instance()->newRasterizer(d); },
			[&](bool) { d->release(); }
		);

		luax_pushtype(L, FONT_RASTERIZER_ID, t);
		t->release();
		return 1;
	}
	else
	{
		// Otherwise call newBMFontRasterizer.
		return w_newBMFontRasterizer(L);
	}
}
コード例 #2
0
void drawTriangle(SDL_Surface *screen)
{
	Rasterizer r;
	r.setScissorRect(0, 0, 640, 480);
	r.setPixelShader<PixelShader>();
	PixelShader::surface = screen;

	RasterizerVertex v0, v1, v2;
	
	v0.x = 320;
	v0.y = 100;
	v0.avar[0] = 1.0f;
	v0.avar[1] = 0.0f;
	v0.avar[2] = 0.0f;

	v1.x = 480;
	v1.y = 200;
	v1.avar[0] = 0.0f;
	v1.avar[1] = 1.0f;
	v1.avar[2] = 0.0f;

	v2.x = 120;
	v2.y = 300;
	v2.avar[0] = 0.0f;
	v2.avar[1] = 0.0f;
	v2.avar[2] = 1.0f;

	r.drawTriangle(v0, v1, v2);
}
コード例 #3
0
ファイル: Renderer.cpp プロジェクト: guoxx/Renderer
void Renderer::renderTriangle(int verticesCnt,
                              Vec3f *vertices,
                              Vec3f *colors,
                              Vec3f *normals,
                              Vec3f *textures,
                              std::shared_ptr<Texture> tex) {
    // TODO: face culling

    Vertex *vertCache = new Vertex[verticesCnt];
    Rasterizer rasterizer;

    _vp->updateTransforms(*this);
    int triangleCnt = verticesCnt / 3;
    for (int i = 0; i < triangleCnt; i = i + 1) {
        _vp->triangle(vertices + i * 3,
                      normals + i * 3,
                      colors + i * 3,
                      textures + i * 3,
                      vertCache + i * 3);
    }
    rasterizer.setupTexture(tex);
    for (int i = 0; i < triangleCnt; i = i + 1) {
        rasterizer.triangle(vertCache + i * 3, *_fp, *_frameBuffer);
    }

    delete [] vertCache;
}
コード例 #4
0
ファイル: Glyph.cpp プロジェクト: kenygia/xy-vsfilter
void Glyph::Rasterize()
{
    if (!path_bkg.IsEmpty()) {
        ras_bkg.ScanConvert(path_bkg, bbox);
        ras_bkg.Rasterize(tl.x, tl.y);
    }

    ras.ScanConvert(path, bbox);

    if (style.background.type == L"outline" && style.background.size > 0) {
        ras.CreateWidenedRegion((int)(GetBackgroundSize() + 0.5));
    }

    //

    Rasterizer* r = path_bkg.IsEmpty() ? &ras : &ras_bkg;
    int plane = path_bkg.IsEmpty() ? (style.font.color.a < 255 ? 2 : 1) : 0;

    ras.Rasterize(tl.x, tl.y);
    r->Blur(style.background.blur, plane);

    if (style.shadow.depth > 0) {
        ras_shadow.Reuse(*r);

        float depth = GetShadowDepth();

        tls.x = tl.x + (int)(depth * cos(deg2rad(style.shadow.angle)) + 0.5);
        tls.y = tl.y + (int)(depth * -sin(deg2rad(style.shadow.angle)) + 0.5);

        ras_shadow.Rasterize(tls.x, tls.y);
        ras_shadow.Blur(style.shadow.blur, plane ? 1 : 0);
    }
}
コード例 #5
0
ファイル: scanline_boolean2.cpp プロジェクト: GordonSmith/agg
unsigned count_spans(Rasterizer& ras, Scanline& sl)
{
    unsigned n = 0;
    if(ras.rewind_scanlines())
    {
        sl.reset(ras.min_x(), ras.max_x());
        while(ras.sweep_scanline(sl))
        {
            n += sl.num_spans();
        }
    }
    return n;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: ohs50439/DX11ModelView
void CrateDeferredPipeLine(GraphicsPipeLine &GPL){
	//=====================================================//
	//            ラスライザ情報
	//=====================================================//
	D3D11_RASTERIZER_DESC rasterizerDesc = {
		D3D11_FILL_SOLID, // ワイヤーフレーム (レンダリング時に使用する描画モードを決定)
		D3D11_CULL_FRONT, // 裏面ポリゴンをカリング(指定の方向を向いている三角形が描画されないことを示す)
		FALSE,			  // 三角形が前向きか後ろ向きかを決定する
		0,				  // 指定のピクセルに加算する深度値
		0.0f,             // ピクセルの最大深度バイアス
		FALSE,			  // 指定のピクセルのスロープに対するスカラ
		FALSE,			  // 距離に基づいてクリッピングを有効
		FALSE,            // シザー矩形カリングを有効
		FALSE,			  // マルチサンプリングのアンチエイリアシングを有効
		FALSE			  // 線のアンチエイリアシングを有効
	};
	Rasterizer *rast = new Rasterizer();// ラスタライザの生成
	rast->Create(&rasterizerDesc);

	GPL.Attach(rast); // パイプラインにラスタライザを追加
	//=====================================================//
	//            サンプラー情報
	//=====================================================//
	// サンプラーの生成
	D3D11_SAMPLER_DESC sampDesc;
	//サンプラーの設定
	sampDesc.Filter = D3D11_FILTER_ANISOTROPIC;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.BorderColor[0] = 0.0f;
	sampDesc.BorderColor[1] = 0.0f;
	sampDesc.BorderColor[2] = 0.0f;
	sampDesc.BorderColor[3] = 0.0f;
	sampDesc.MipLODBias = 0.0f;
	sampDesc.MaxAnisotropy = 2;
	sampDesc.MinLOD = FLT_MAX * -1;
	sampDesc.MaxLOD = FLT_MAX;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	Sampler *samp = new Sampler();
	samp->Create(0, &sampDesc);
	samp->Attach(1, samp, 0);
	samp->Attach(2, samp, 0);
	samp->Attach(3, samp, 0);

	GPL.Attach(samp); // パイプラインにサンプラーを追加

}
コード例 #7
0
ファイル: main.cpp プロジェクト: codeezer/3d-crane
void mouse_event(int button, int state, int x, int y)
{
    glClear(GL_COLOR_BUFFER_BIT);
    light.draw();
    r.clearZbuffer();
    switch(button)
    {
    case GLUT_LEFT_BUTTON:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =SCH*o.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        break;
    }
    case GLUT_RIGHT_BUTTON:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =SCL*o.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        break;
    }
    }
    glFlush();
    glutSwapBuffers();

}
コード例 #8
0
ファイル: agg_font_freetype.cpp プロジェクト: sweetdark/navi
 void decompose_ft_bitmap_gray8(const FT_Bitmap& bitmap,
                                int x, int y,
                                bool flip_y,
                                Rasterizer& ras,
                                Scanline& sl,
                                ScanlineStorage& storage)
 {
     int i, j;
     const int8u* buf = (const int8u*)bitmap.buffer;
     int pitch = bitmap.pitch;
     sl.reset(x, x + bitmap.width);
     storage.prepare(bitmap.width + 2);
     if(flip_y)
     {
         buf += bitmap.pitch * (bitmap.rows - 1);
         y += bitmap.rows;
         pitch = -pitch;
     }
     for(i = 0; i < bitmap.rows; i++)
     {
         sl.reset_spans();
         const int8u* p = buf;
         for(j = 0; j < bitmap.width; j++)
         {
             if(*p) sl.add_cell(x + j, ras.apply_gamma(*p));
             ++p;
         }
         buf += pitch;
         if(sl.num_spans())
         {
             sl.finalize(y - i - 1);
             storage.render(sl);
         }
     }
 }
コード例 #9
0
ファイル: wrap_Font.cpp プロジェクト: Kivutar/love-libretro
int w_newImageRasterizer(lua_State *L)
{
	Rasterizer *t = nullptr;

	convimagedata(L, 1);

	image::ImageData *d = luax_checktype<image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
	std::string glyphs = luax_checkstring(L, 2);
	int extraspacing = (int) luaL_optnumber(L, 3, 0);

	luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); });

	luax_pushtype(L, FONT_RASTERIZER_ID, t);
	t->release();
	return 1;
}
コード例 #10
0
ファイル: renderer.cpp プロジェクト: Nelarius/octoraster
void Render( Rasterizer& r, const std::vector< Vector4f >& buffer, const Matrix4f& model, const OrthoCamera& c ) {
    for ( std::size_t i = 0u; i < buffer.size(); i += 3 ) {
        Vector4f v1 = OrthoProjection( c ) * model * buffer[i];
        Vector4f v2 = OrthoProjection( c ) * model * buffer[i+1];
        Vector4f v3 = OrthoProjection( c ) * model * buffer[i+2];
        r.rasterize( v1, v2, v3 );
    }
}
コード例 #11
0
ファイル: agg_helpers.hpp プロジェクト: FlavioFalcao/mapnik
void set_join_caps_aa(Stroke const& stroke_, Rasterizer & ras)
{

    line_join_e join=stroke_.get_line_join();
    switch (join)
    {
    case MITER_JOIN:
        ras.line_join(agg::outline_miter_accurate_join);
        break;
    case MITER_REVERT_JOIN:
        ras.line_join(agg::outline_no_join);
        break;
    case ROUND_JOIN:
        ras.line_join(agg::outline_round_join);
        break;
    default:
        ras.line_join(agg::outline_no_join);
    }

    line_cap_e cap=stroke_.get_line_cap();
    switch (cap)
    {
    case BUTT_CAP:
        ras.round_cap(false);
        break;
    case SQUARE_CAP:
        ras.round_cap(false);
        break;
    default:
        ras.round_cap(true);
    }
}
コード例 #12
0
void set_join_caps_aa(Symbolizer const& sym, Rasterizer & ras, Feature & feature, attributes const& vars)
{
    line_join_enum join = get<line_join_enum, keys::stroke_linejoin>(sym, feature, vars);
    switch (join)
    {
    case MITER_JOIN:
        ras.line_join(agg::outline_miter_accurate_join);
        break;
    case MITER_REVERT_JOIN:
        ras.line_join(agg::outline_no_join);
        break;
    case ROUND_JOIN:
        ras.line_join(agg::outline_round_join);
        break;
    default:
        ras.line_join(agg::outline_no_join);
    }

    line_cap_enum cap = get<line_cap_enum, keys::stroke_linecap>(sym, feature, vars);

    switch (cap)
    {
    case BUTT_CAP:
        ras.round_cap(false);
        break;
    case SQUARE_CAP:
        ras.round_cap(false);
        break;
    default:
        ras.round_cap(true);
    }
}
コード例 #13
0
ファイル: Renderer.cpp プロジェクト: guoxx/Renderer
void Renderer::renderLine(int verticesCnt,
                          Vec3f *vertices,
                          Vec3f *colors) {
    Vertex *vertCache = new Vertex[verticesCnt];

    Rasterizer rasterizer;

    _vp->updateTransforms(*this);
    int lineCnt = verticesCnt / 2;
    for (int i = 0; i < lineCnt; i = i + 1) {
        _vp->line(vertices + i * 2, colors + i * 2, vertCache + i * 2);
    }
    for (int i = 0; i < lineCnt; i = i + 1) {
        rasterizer.line(vertCache + i * 2, *_fp, *_frameBuffer);
    }

    delete [] vertCache;
}
コード例 #14
0
 void draw_polyline(Rasterizer& ras, 
                    Renderer& ren, 
                    const double* polyline, 
                    int num_points)
 {
     agg::poly_plain_adaptor<double> vs(polyline, num_points, m_line1.close());
     agg::conv_transform<agg::poly_plain_adaptor<double> > trans(vs, m_scale);
     ras.add_path(trans);
 }
コード例 #15
0
ファイル: clockapp.cpp プロジェクト: bbidulock/dockapps
void ClockDraw::draw_shape(double angle, const ClockConfig::Shape& shape)
{
	typedef std::vector<Vertex>::iterator VIT;
	typedef std::vector<ClockConfig::Polygon>::const_iterator PIT;

	ras->begin_shape();
	for (PIT pp = shape.pgons.begin(); pp != shape.pgons.end(); ++pp)
	{
		std::vector<Vertex> v = pp->v;

		std::for_each(v.begin(), v.end(), Vector_add_rotator(shape.origin, angle));

		ras->begin_pgon();

		std::for_each(v.begin(), v.end(), Rasterize_vertex(ras));

		ras->end_pgon(true);
	}
	ras->end_shape(shape.color);
}
コード例 #16
0
ファイル: line_patterns.cpp プロジェクト: Bashakov/agg
 void draw_curve(Pattern& patt, 
                 Rasterizer& ras, 
                 Renderer& ren, 
                 PatternSource& src, 
                 VertexSource& vs)
 {
     patt.create(src);
     ren.scale_x(m_scale_x.value());
     ren.start_x(m_start_x.value());
     ras.add_path(vs);
 }
コード例 #17
0
ファイル: wrap_Font.cpp プロジェクト: Kivutar/love-libretro
int w_newBMFontRasterizer(lua_State *L)
{
	Rasterizer *t = nullptr;

	filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
	std::vector<image::ImageData *> images;

	if (lua_istable(L, 2))
	{
		for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
		{
			lua_rawgeti(L, 2, i);

			convimagedata(L, -1);
			image::ImageData *id = luax_checktype<image::ImageData>(L, -1, IMAGE_IMAGE_DATA_ID);
			images.push_back(id);
			id->retain();

			lua_pop(L, 1);
		}
	}
	else
	{
		for (int i = 2; i <= lua_gettop(L); i++)
		{
			convimagedata(L, i);
			image::ImageData *id = luax_checktype<image::ImageData>(L, i, IMAGE_IMAGE_DATA_ID);
			images.push_back(id);
			id->retain();
		}
	}

	luax_catchexcept(L,
		[&]() { t = instance()->newBMFontRasterizer(d, images); },
		[&](bool) { d->release(); for (auto id : images) id->release(); }
	);

	luax_pushtype(L, FONT_RASTERIZER_ID, t);
	t->release();
	return 1;
}
コード例 #18
0
ファイル: wrap_Font.cpp プロジェクト: Kivutar/love-libretro
int w_newTrueTypeRasterizer(lua_State *L)
{
	Rasterizer *t = nullptr;
	TrueTypeRasterizer::Hinting hinting = TrueTypeRasterizer::HINTING_NORMAL;

	if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1))
	{
		// First argument is a number: use the default TrueType font.
		int size = (int) luaL_optnumber(L, 1, 12);

		const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2);
		if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
			return luaL_error(L, "Invalid TrueType font hinting mode: %s", hintstr);

		luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size, hinting); });
	}
	else
	{
		love::Data *d = nullptr;

		if (luax_istype(L, 1, DATA_ID))
			d = luax_checkdata(L, 1);
		else
			d = filesystem::luax_getfiledata(L, 1);

		int size = (int) luaL_optnumber(L, 2, 12);

		const char *hintstr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
		if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
			return luaL_error(L, "Invalid TrueType font hinting mode: %s", hintstr);

		luax_catchexcept(L,
			[&]() { t = instance()->newTrueTypeRasterizer(d, size, hinting); },
			[&](bool) { d->release(); }
		);
	}

	luax_pushtype(L, FONT_RASTERIZER_ID, t);
	t->release();
	return 1;
}
コード例 #19
0
void renderTriangle(int left, int top, int numParams, const Vertex *vertices, 
	PixelShaderState *shaderState, int width, int height)
{
	shaderState->setUpTriangle(
		vertices[0].coord[0], vertices[0].coord[1], vertices[0].coord[2],
		vertices[1].coord[0], vertices[1].coord[1], vertices[1].coord[2],
		vertices[2].coord[0], vertices[2].coord[1], vertices[2].coord[2]);

	for (int param = 0; param < numParams; param++)
	{
		shaderState->setUpParam(param, vertices[0].params[param],
			vertices[1].params[param], vertices[2].params[param]);
	}

	rasterizer.rasterizeTriangle(shaderState, left, top,
		(int)(vertices[0].coord[0] * width), 
		(int)(vertices[0].coord[1] * height), 
		(int)(vertices[1].coord[0] * width), 
		(int)(vertices[1].coord[1] * height), 
		(int)(vertices[2].coord[0] * width), 
		(int)(vertices[2].coord[1] * height));
}
コード例 #20
0
    void render(Rasterizer& ras,
                Scanline& sl,
                Renderer& ren,
                agg::trans_affine const& mtx,
                double opacity,
                box2d<double> const& symbol_bbox)

    {
        using namespace agg;

        trans_affine transform;
        curved_stroked_trans_type curved_stroked_trans(curved_stroked_,transform);
        curved_trans_type         curved_trans(curved_,transform);
        curved_trans_contour_type curved_trans_contour(curved_trans);

        curved_trans_contour.auto_detect_orientation(true);

        for(unsigned i = 0; i < attributes_.size(); ++i)
        {
            mapnik::svg::path_attributes const& attr = attributes_[i];
            if (!attr.visibility_flag)
                continue;

            transform = attr.transform;

            transform *= mtx;
            double scl = transform.scale();
            //curved_.approximation_method(curve_inc);
            curved_.approximation_scale(scl);
            curved_.angle_tolerance(0.0);

            typename PixelFormat::color_type color;

            if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
            {
                ras.reset();

                // https://github.com/mapnik/mapnik/issues/1129
                if(std::fabs(curved_trans_contour.width()) <= 1)
                {
                    ras.add_path(curved_trans, attr.index);
                }
                else
                {
                    curved_trans_contour.miter_limit(attr.miter_limit);
                    ras.add_path(curved_trans_contour, attr.index);
                }

                if(attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
                {
                    render_gradient(ras, sl, ren, attr.fill_gradient, transform, attr.fill_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index);
                }
                else
                {
                    ras.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
                    color = attr.fill_color;
                    color.opacity(color.opacity() * attr.fill_opacity * attr.opacity * opacity);
                    ScanlineRenderer ren_s(ren);
                    color.premultiply();
                    ren_s.color(color);
                    render_scanlines(ras, sl, ren_s);
                }
            }

            if (attr.stroke_flag || attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
            {
                curved_stroked_.width(attr.stroke_width);
                //m_curved_stroked.line_join((attr.line_join == miter_join) ? miter_join_round : attr.line_join);
                curved_stroked_.line_join(attr.line_join);
                curved_stroked_.line_cap(attr.line_cap);
                curved_stroked_.miter_limit(attr.miter_limit);
                curved_stroked_.inner_join(inner_round);
                curved_stroked_.approximation_scale(scl);

                // If the *visual* line width is considerable we
                // turn on processing of curve cusps.
                //---------------------
                if(attr.stroke_width * scl > 1.0)
                {
                    curved_.angle_tolerance(0.2);
                }
                ras.reset();
                ras.add_path(curved_stroked_trans, attr.index);

                if(attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
                {
                    render_gradient(ras, sl, ren, attr.stroke_gradient, transform, attr.stroke_opacity * attr.opacity * opacity, symbol_bbox, curved_trans, attr.index);
                }
                else
                {
                    ras.filling_rule(fill_non_zero);
                    color = attr.stroke_color;
                    color.opacity(color.opacity() * attr.stroke_opacity * attr.opacity * opacity);
                    ScanlineRenderer ren_s(ren);
                    color.premultiply();
                    ren_s.color(color);
                    render_scanlines(ras, sl, ren_s);
                }
            }
        }
    }
コード例 #21
0
ファイル: scanline_boolean2.cpp プロジェクト: GordonSmith/agg
    unsigned render_sbool(Rasterizer& ras1, Rasterizer& ras2)
    {
        pixfmt pf(rbuf_window());
        agg::renderer_base<pixfmt> rb(pf);
        agg::renderer_scanline_aa_solid<agg::renderer_base<pixfmt> > ren(rb);
        agg::scanline_p8 sl;

        ras1.filling_rule(m_fill_rule.cur_item() ? agg::fill_non_zero : agg::fill_even_odd);
        ras2.filling_rule(m_fill_rule.cur_item() ? agg::fill_non_zero : agg::fill_even_odd);

        switch(m_polygons.cur_item())
        {
            case 0:
            {
                //------------------------------------
                // Two simple paths
                //
                agg::path_storage ps1;
                agg::path_storage ps2;

                double x = m_x - initial_width()/2 + 100;
                double y = m_y - initial_height()/2 + 100;
                ps1.move_to(x+140, y+145);
                ps1.line_to(x+225, y+44);
                ps1.line_to(x+296, y+219);
                ps1.close_polygon();

                ps1.line_to(x+226, y+289);
                ps1.line_to(x+82,  y+292);

                ps1.move_to(x+220, y+222);
                ps1.line_to(x+363, y+249);
                ps1.line_to(x+265, y+331);

                ps1.move_to(x+242, y+243);
                ps1.line_to(x+325, y+261);
                ps1.line_to(x+268, y+309);

                ps1.move_to(x+259, y+259);
                ps1.line_to(x+273, y+288);
                ps1.line_to(x+298, y+266);

                ps2.move_to(100+32,  100+77);
                ps2.line_to(100+473, 100+263);
                ps2.line_to(100+351, 100+290);
                ps2.line_to(100+354, 100+374);

                ras1.reset();
                ras1.add_path(ps1);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(ps2);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;

            case 1:
            {
                //------------------------------------
                // Closed stroke
                //
                agg::path_storage ps1;
                agg::path_storage ps2;
                agg::conv_stroke<agg::path_storage> stroke(ps2);
                stroke.width(15.0);

                double x = m_x - initial_width()/2 + 100;
                double y = m_y - initial_height()/2 + 100;
                ps1.move_to(x+140, y+145);
                ps1.line_to(x+225, y+44);
                ps1.line_to(x+296, y+219);
                ps1.close_polygon();

                ps1.line_to(x+226, y+289);
                ps1.line_to(x+82,  y+292);

                ps1.move_to(x+220-50, y+222);
                ps1.line_to(x+363-50, y+249);
                ps1.line_to(x+265-50, y+331);
                ps1.close_polygon();

                ps2.move_to(100+32,  100+77);
                ps2.line_to(100+473, 100+263);
                ps2.line_to(100+351, 100+290);
                ps2.line_to(100+354, 100+374);
                ps2.close_polygon();

                ras1.reset();
                ras1.add_path(ps1);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(stroke);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 2:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                agg::path_storage gb_poly;
                agg::path_storage arrows;
                make_gb_poly(gb_poly);
                make_arrows(arrows);

                agg::trans_affine mtx1;
                agg::trans_affine mtx2;
                mtx1 *= agg::trans_affine_translation(-1150, -1150);
                mtx1 *= agg::trans_affine_scaling(2.0);

                mtx2 = mtx1;
                mtx2 *= agg::trans_affine_translation(m_x - initial_width()/2, 
                                                      m_y - initial_height()/2);

                agg::conv_transform<agg::path_storage> trans_gb_poly(gb_poly, mtx1);
                agg::conv_transform<agg::path_storage> trans_arrows(arrows, mtx2);

                ras2.add_path(trans_gb_poly);
                ren.color(agg::rgba(0.5, 0.5, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                agg::conv_stroke<agg::conv_transform<agg::path_storage> > stroke_gb_poly(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                ras1.add_path(stroke_gb_poly);
                ren.color(agg::rgba(0, 0, 0));
                agg::render_scanlines(ras1, sl, ren);
        
                ras2.add_path(trans_arrows);
                ren.color(agg::rgba(0.0, 0.5, 0.5, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                ras1.reset();
                ras1.add_path(trans_gb_poly);

                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 3:
            {
                //------------------------------------
                // Great Britain and a Spiral
                //
                spiral sp(m_x, m_y, 10, 150, 30, 0.0);
                agg::conv_stroke<spiral> stroke(sp);
                stroke.width(15.0);

                agg::path_storage gb_poly;
                make_gb_poly(gb_poly);

                agg::trans_affine mtx;
                mtx *= agg::trans_affine_translation(-1150, -1150);
                mtx *= agg::trans_affine_scaling(2.0);
                mtx *= trans_affine_resizing();

                agg::conv_transform<agg::path_storage> trans_gb_poly(gb_poly, mtx);


                ras1.add_path(trans_gb_poly);
                ren.color(agg::rgba(0.5, 0.5, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                agg::conv_stroke<agg::conv_transform<agg::path_storage> > stroke_gb_poly(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                ras1.reset();
                ras1.add_path(stroke_gb_poly);
                ren.color(agg::rgba(0, 0, 0));
                agg::render_scanlines(ras1, sl, ren);
        
                ras2.reset();
                ras2.add_path(stroke);
                ren.color(agg::rgba(0.0, 0.5, 0.5, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                ras1.reset();
                ras1.add_path(trans_gb_poly);
                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 4:
            {
                //------------------------------------
                // Spiral and glyph
                //
                spiral sp(m_x, m_y, 10, 150, 30, 0.0);
                agg::conv_stroke<spiral> stroke(sp);
                stroke.width(15.0);

                agg::path_storage glyph;
                glyph.move_to(28.47, 6.45);
                glyph.curve3(21.58, 1.12, 19.82, 0.29);
                glyph.curve3(17.19, -0.93, 14.21, -0.93);
                glyph.curve3(9.57, -0.93, 6.57, 2.25);
                glyph.curve3(3.56, 5.42, 3.56, 10.60);
                glyph.curve3(3.56, 13.87, 5.03, 16.26);
                glyph.curve3(7.03, 19.58, 11.99, 22.51);
                glyph.curve3(16.94, 25.44, 28.47, 29.64);
                glyph.line_to(28.47, 31.40);
                glyph.curve3(28.47, 38.09, 26.34, 40.58);
                glyph.curve3(24.22, 43.07, 20.17, 43.07);
                glyph.curve3(17.09, 43.07, 15.28, 41.41);
                glyph.curve3(13.43, 39.75, 13.43, 37.60);
                glyph.line_to(13.53, 34.77);
                glyph.curve3(13.53, 32.52, 12.38, 31.30);
                glyph.curve3(11.23, 30.08, 9.38, 30.08);
                glyph.curve3(7.57, 30.08, 6.42, 31.35);
                glyph.curve3(5.27, 32.62, 5.27, 34.81);
                glyph.curve3(5.27, 39.01, 9.57, 42.53);
                glyph.curve3(13.87, 46.04, 21.63, 46.04);
                glyph.curve3(27.59, 46.04, 31.40, 44.04);
                glyph.curve3(34.28, 42.53, 35.64, 39.31);
                glyph.curve3(36.52, 37.21, 36.52, 30.71);
                glyph.line_to(36.52, 15.53);
                glyph.curve3(36.52, 9.13, 36.77, 7.69);
                glyph.curve3(37.01, 6.25, 37.57, 5.76);
                glyph.curve3(38.13, 5.27, 38.87, 5.27);
                glyph.curve3(39.65, 5.27, 40.23, 5.62);
                glyph.curve3(41.26, 6.25, 44.19, 9.18);
                glyph.line_to(44.19, 6.45);
                glyph.curve3(38.72, -0.88, 33.74, -0.88);
                glyph.curve3(31.35, -0.88, 29.93, 0.78);
                glyph.curve3(28.52, 2.44, 28.47, 6.45);
                glyph.close_polygon();

                glyph.move_to(28.47, 9.62);
                glyph.line_to(28.47, 26.66);
                glyph.curve3(21.09, 23.73, 18.95, 22.51);
                glyph.curve3(15.09, 20.36, 13.43, 18.02);
                glyph.curve3(11.77, 15.67, 11.77, 12.89);
                glyph.curve3(11.77, 9.38, 13.87, 7.06);
                glyph.curve3(15.97, 4.74, 18.70, 4.74);
                glyph.curve3(22.41, 4.74, 28.47, 9.62);
                glyph.close_polygon();

                agg::trans_affine mtx;
                mtx *= agg::trans_affine_scaling(4.0);
                mtx *= agg::trans_affine_translation(220, 200);
                agg::conv_transform<agg::path_storage> trans(glyph, mtx);
                agg::conv_curve<agg::conv_transform<agg::path_storage> > curve(trans);

                ras1.reset();
                ras1.add_path(stroke);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(curve);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;
        }

        return 0;
    }
コード例 #22
0
ファイル: scanline_boolean2.cpp プロジェクト: GordonSmith/agg
    void render_scanline_boolean(Rasterizer& ras1, Rasterizer& ras2)
    {
        if(m_operation.cur_item() > 0)
        {
            agg::sbool_op_e op;
            switch(m_operation.cur_item())
            {
                case 1: op = agg::sbool_or;        break;
                case 2: op = agg::sbool_and;       break;
                case 3: op = agg::sbool_xor;       break;
                case 4: op = agg::sbool_xor_saddle;break;
                case 5: op = agg::sbool_a_minus_b; break;
                case 6: op = agg::sbool_b_minus_a; break;
            }

            typedef agg::renderer_base<pixfmt> renderer_base;
            pixfmt pixf(rbuf_window());
            renderer_base rb(pixf);

            double t1 = 0.0;
            double t2 = 0.0;
            unsigned num_spans = 0;

            switch(m_scanline_type.cur_item())
            {
                case 0:
                {
                    typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_p8 scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;

                    // The intermediate storage is used only to test the perfoprmance,
                    // the short variant can be as follows:
                    // ------------------------
                    // ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    // agg::sbool_combine_shapes_aa(op, ras1, ras2, sl1, sl2, sl, ren);

                    agg::scanline_storage_aa8 storage;
                    agg::scanline_storage_aa8 storage1;
                    agg::scanline_storage_aa8 storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_aa(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;

                case 1:
                {
                    typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_u8 scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;
                    agg::scanline_storage_aa8 storage;
                    agg::scanline_storage_aa8 storage1;
                    agg::scanline_storage_aa8 storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_aa(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;


                case 2:
                {
                    typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_bin scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;

                    agg::scanline_storage_bin storage;
                    agg::scanline_storage_bin storage1;
                    agg::scanline_storage_bin storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_bin(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;

            }


            char buf[100];
            sprintf(buf, "Combine=%.3fms\n\nRender=%.3fms\n\nnum_spans=%d", t1, t2, num_spans);
            agg::renderer_scanline_aa_solid<renderer_base> ren(rb);
            agg::scanline_p8 sl;
            agg::gsv_text txt;
            agg::conv_stroke<agg::gsv_text> txt_stroke(txt);
            txt_stroke.width(1.0);
            txt_stroke.line_cap(agg::round_cap);
            txt.size(8.0);
            txt.start_point(420, 40);
            txt.text(buf);
            ras1.add_path(txt_stroke);
            ren.color(agg::rgba(0.0, 0.0, 0.0));
            agg::render_scanlines(ras1, sl, ren);

        
        }
    }
コード例 #23
0
ファイル: main.cpp プロジェクト: codeezer/3d-crane
void special_keyboard(int key,int ,int)
{
    glClear(GL_COLOR_BUFFER_BIT);
    r.clearZbuffer();
    DrawTriangle(x_y_zCoordinate(-450,0,3000),Color(1,1,0),x_y_zCoordinate(-600,-350,-1000),
                 Color(0,1,0),x_y_zCoordinate(600,-350,-1000),Color(0,1,1));
    DrawTriangle(x_y_zCoordinate(-450,0,3000),Color(1,1,0),x_y_zCoordinate(600,0,-1000),
                 Color(0,1,0),x_y_zCoordinate(600,-350,-1000),Color(0,1,1));
    light.draw();
    switch (key)
    {
    case GLUT_KEY_DOWN:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =DOWN*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =DOWN*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =DOWN*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =DOWN*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));

        break;
    }
    case GLUT_KEY_UP:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =UP*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =UP*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =UP*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =UP*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }
    case GLUT_KEY_RIGHT:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =T*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =T*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =T*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =T*hook.vertices[i];
        }
        cout<<"rotation\n";
        RR.display();
        cout<<"NNpaxadi\n";
        NN.display();
        cout<<"agadi\n";
        MM.display();
        RR = RR*T;
        MM = MM*T;
        NN = NN*T;

        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }
    case GLUT_KEY_LEFT:
    {
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =T2*o.vertices[i];

        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =T2*rem.vertices[i];

        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =T2*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =T2*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }
    case GLUT_KEY_F1:
    {

    }
    default:
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }

    glFlush();
    glutSwapBuffers();
}
コード例 #24
0
    void render_id(Rasterizer& ras,
                   Scanline& sl,
                   Renderer& ren,
                   int feature_id,
                   agg::trans_affine const& mtx,
                   double opacity,
                   const box2d<double> &symbol_bbox)

    {
        using namespace agg;

        trans_affine transform;
        curved_stroked_trans_type curved_stroked_trans(curved_stroked_,transform);
        curved_trans_type         curved_trans(curved_,transform);
        curved_trans_contour_type curved_trans_contour(curved_trans);

        curved_trans_contour.auto_detect_orientation(true);

        for(unsigned i = 0; i < attributes_.size(); ++i)
        {
            mapnik::svg::path_attributes const& attr = attributes_[i];
            if (!attr.visibility_flag)
                continue;

            transform = attr.transform;

            double bx1,by1,bx2,by2;
            bounding_rect_single(curved_trans, attr.index, &bx1, &by1, &bx2, &by2);
            box2d<double> path_bbox(bx1,by1,bx2,by2);

            transform *= mtx;
            double scl = transform.scale();
            //curved_.approximation_method(curve_inc);
            curved_.approximation_scale(scl);
            curved_.angle_tolerance(0.0);

            mapnik::gray16 color(feature_id);

            if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
            {
                ras.reset();

                if(fabs(curved_trans_contour.width()) <= 1)
                {
                    ras.add_path(curved_trans, attr.index);
                }
                else
                {
                    curved_trans_contour.miter_limit(attr.miter_limit);
                    ras.add_path(curved_trans_contour, attr.index);
                }

                ras.filling_rule(attr.even_odd_flag ? fill_even_odd : fill_non_zero);
                ScanlineRenderer ren_s(ren);
                ren_s.color(color);
                render_scanlines(ras, sl, ren_s);
            }

            if (attr.stroke_flag || attr.stroke_gradient.get_gradient_type() != NO_GRADIENT)
            {
                curved_stroked_.width(attr.stroke_width);
                //m_curved_stroked.line_join((attr.line_join == miter_join) ? miter_join_round : attr.line_join);
                curved_stroked_.line_join(attr.line_join);
                curved_stroked_.line_cap(attr.line_cap);
                curved_stroked_.miter_limit(attr.miter_limit);
                curved_stroked_.inner_join(inner_round);
                curved_stroked_.approximation_scale(scl);

                // If the *visual* line width is considerable we
                // turn on processing of curve cusps.
                //---------------------
                if(attr.stroke_width * scl > 1.0)
                {
                    curved_.angle_tolerance(0.2);
                }
                ras.reset();
                ras.add_path(curved_stroked_trans, attr.index);

                ras.filling_rule(fill_non_zero);
                ScanlineRenderer ren_s(ren);
                ren_s.color(color);
                render_scanlines(ras, sl, ren_s);
            }
        }
    }
コード例 #25
0
ファイル: main.cpp プロジェクト: qlands/GOBLET
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    //Command line arguments
    TCLAP::CmdLine cmd("GOBLET (c) 2012, International Livestock Research Institute (ILRI) \n Developed by Carlos Quiros ([email protected])", ' ', "1.0 (Beta 1)");
    //Required arguments
    TCLAP::ValueArg<std::string> databaseArg("d","database","Database name",true,"","string");
    TCLAP::ValueArg<std::string> datasetArg("t","dataset","Dataset name",true,"","string");
    TCLAP::ValueArg<std::string> shapeArg("S","shapefile","Shape file",true,"","string");
    TCLAP::ValueArg<std::string> datasetDescArg("s","datasetDescription","Dataset description",true,"","string");
    //Non required arguments
    TCLAP::ValueArg<std::string> pathArg("a","path","Path to database. Default .",false,".","string");
    TCLAP::ValueArg<std::string> hostArg("H","host","Connect to host. Default localhost",false,"localhost","string");
    TCLAP::ValueArg<std::string> portArg("P","port","Port number to use. Default 3306",false,"3306","string");
    TCLAP::ValueArg<std::string> userArg("u","user","User. Default empty",false,"","string");
    TCLAP::ValueArg<std::string> passArg("p","password","Passwork. Default no password",false,"","string");
    TCLAP::ValueArg<std::string> unitArg("U","units","New unit for the dataset",false,"Not set","string");
    TCLAP::ValueArg<std::string> metaArg("m","metadata","File containing metadata",false,"None","string");

    //Switches
    TCLAP::SwitchArg remoteSwitch("r","remote","Connect to remote host", cmd, false);
    TCLAP::SwitchArg overwriteSwitch("o","overwrite","Overwrite the previous dataset if present", cmd, false);

    TCLAP::SwitchArg rasterSwitch("n","notrasterize","Not rasterize the shape (false by default)", cmd, false);

    cmd.add(databaseArg);
    cmd.add(datasetArg);
    cmd.add(shapeArg);
    cmd.add(datasetDescArg);
    cmd.add(pathArg);
    cmd.add(hostArg);
    cmd.add(portArg);
    cmd.add(userArg);
    cmd.add(passArg);
    cmd.add(unitArg);
    cmd.add(metaArg);

    //Parsing the command lines
    cmd.parse( argc, argv );

    //Getting the variables from the command
    bool remote = remoteSwitch.getValue();
    QString path = QString::fromUtf8(pathArg.getValue().c_str());
    QString dbName = QString::fromUtf8(databaseArg.getValue().c_str());
    QString host = QString::fromUtf8(hostArg.getValue().c_str());
    QString port = QString::fromUtf8(portArg.getValue().c_str());
    QString userName = QString::fromUtf8(userArg.getValue().c_str());
    QString password = QString::fromUtf8(passArg.getValue().c_str());
    QString tableName = QString::fromUtf8(datasetArg.getValue().c_str());
    QString shapeFile = QString::fromUtf8(shapeArg.getValue().c_str());
    QString tableDesc = QString::fromUtf8(datasetDescArg.getValue().c_str());

    QString unit = QString::fromUtf8(unitArg.getValue().c_str());
    QString meta = QString::fromUtf8(metaArg.getValue().c_str());

    bool replace = overwriteSwitch.getValue();
    bool rasterize = !rasterSwitch.getValue();

    myDBConn con;
    QSqlDatabase mydb;
    if (!remote)
    {
        QDir dir;
        dir.setPath(path);
        if (con.connectToDB(dir.absolutePath()) == 1)
        {
            if (!dir.cd(dbName))
            {
                gbtLog(QObject::tr("The database does not exists"));
                con.closeConnection();
                return 1;
            }
            mydb = QSqlDatabase::addDatabase(con.getDriver(),"connection1");
        }
    }
    else
    {
        mydb = QSqlDatabase::addDatabase("QMYSQL","connection1");
        mydb.setHostName(host);
        mydb.setPort(port.toInt());
        if (!userName.isEmpty())
           mydb.setUserName(userName);
        if (!password.isEmpty())
           mydb.setPassword(password);
    }

    mydb.setDatabaseName(dbName);

    if (!mydb.open())
    {
        gbtLog(QObject::tr("Cannot open database"));
        con.closeConnection();
        return 1;
    }
    else
    {
        QTime procTime;
        procTime.start();

        QString sql;
        QSqlQuery qry(mydb);

        if (replace)
        {
            sql = "DROP TABLE IF EXISTS " + tableName;
            qry.exec(sql);

            sql = "DELETE FROM datasetinfo WHERE dataset_id = '" + tableName + "'";
            if (!qry.exec(sql))
            {
                gbtLog(QObject::tr("Cannot remove previous dataset."));
                gbtLog(qry.lastError().databaseText());
                mydb.close();
                con.closeConnection();
                return 1;
            }

            //We need to drop the _raster of the table

            sql = "DROP TABLE IF EXISTS " + tableName + "_raster";
            qry.exec(sql);

        }

        // This process insert the shapeFile into mysql using geometries
        // This process if based on Jeff Lounsbury's shape to mysql program
        insertShape insShape;
        insShape.setTableName(tableName);
        insShape.setShapeFile(shapeFile);
        insShape.loadShape();

        QStringList sqls;
        sqls.append(insShape.getSQLs());
        for (int pos = 0; pos <= sqls.count()-1;pos++)
        {
            sql = sqls[pos].replace("\n","");
            if (!qry.exec(sql))
            {
                gbtLog(QObject::tr("Cannot remove previous dataset."));
                gbtLog(qry.lastError().databaseText());
                mydb.close();
                con.closeConnection();
                return 1;
            }
        }

        sql = "ALTER TABLE " + tableName + " ADD COLUMN num_cells INT(11) default 0";

        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot add numcells to dataset."));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }

        sql = "CREATE TABLE " + tableName + "_raster (";
        sql = sql + "geokey VARCHAR(14) NOT NULL ,";
        sql = sql + "xpos DECIMAL(7) NULL ,";
        sql = sql + "ypos DECIMAL(7) NULL ,";
        sql = sql + "shapeid INT(11) ,";
        sql = sql + "PRIMARY KEY (geokey)) ENGINE = MyISAM";

        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot create dataset. It might already exists"));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }

        //Get the cellSize of the database
        double dbCellSize;
        dbCellSize = 0.0;

        sql = "SELECT cellSize FROM gbtconfig";
        if (qry.exec(sql))
        {
            if (qry.first())
                dbCellSize = qry.value(0).toDouble();            
        }


        //Rasterize the shapefile

        sql = "ALTER TABLE " + tableName + "_raster DISABLE KEYS";
        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot disable keys"));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }
        Rasterizer rasterizeShape;
        if (rasterize)
        {
            gbtLog(QObject::tr("Rasterizing shape"));

            //Then we need to rasterize the shapes.

            rasterizeShape.loadShapeFile(shapeFile,dbCellSize,-9999,tableName);
            rasterizeShape.setTableName(tableName + "_raster");

            uploadCSV uploadData;
            uploadData.setTableName(tableName + "_raster");
            uploadData.setPath(path);
            uploadData.setDataBase(dbName);
            uploadData.setRemote(remote);
            uploadData.setHost(host);
            uploadData.setPort(port.toInt());
            uploadData.setUser(userName);
            uploadData.setPassword(password);
            rasterizeShape.start();
            uploadData.start();
            rasterizeShape.wait();
            uploadData.wait();
        }

        sql = "ALTER TABLE " + tableName + "_raster ENABLE KEYS";
        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot enable keys"));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }

        //Update the number of cells
        if (rasterize)
        {
            sql = "UPDATE " + tableName + " TA SET num_cells = (SELECT count(geokey) FROM ";
            sql = sql + tableName + "_raster TB WHERE TA.shapeid = TB.shapeid);";

            if (!qry.exec(sql))
            {
                gbtLog(QObject::tr("Cannot update number of cells"));
                gbtLog(qry.lastError().databaseText());
                mydb.close();
                con.closeConnection();
                return 1;
            }
        }
        //Insert the dataset into the dataset information table

        if (rasterize)
        {
            sql = "INSERT INTO datasetinfo (dataset_id,dataset_desc,dataset_unit,dataset_type,ncols,nrows,xllcenter,yllcenter,shapefiletype)";
            sql = sql + " VALUES ('" + tableName +"',";
            sql = sql + "'" + tableDesc +"',";
            sql = sql + "'" + unit +"',2,";
            sql = sql + QString::number(rasterizeShape.getNCols()) + ",";
            sql = sql + QString::number(rasterizeShape.getNRows()) + ",";
            sql = sql + QString::number(rasterizeShape.getXllCenter(),'f',11) + ",";
            sql = sql + QString::number(rasterizeShape.getYllCenter(),'f',11) + ",";
            sql = sql + QString::number(rasterizeShape.getShapeType()) + ")";
        }
        else
        {
            sql = "INSERT INTO datasetinfo (dataset_id,dataset_desc,dataset_unit,dataset_type,shapefiletype)";
            sql = sql + " VALUES ('" + tableName +"',";
            sql = sql + "'" + tableDesc +"',";
            sql = sql + "'" + unit +"',2,";
            sql = sql + QString::number(insShape.getShapeType()) + ")";
        }

        if (!qry.exec(sql))
        {
            gbtLog(QObject::tr("Cannot insert dataset."));
            gbtLog(qry.lastError().databaseText());
            mydb.close();
            con.closeConnection();
            return 1;
        }

        if (meta != "None")
        {
            if (QFile::exists(meta))
            {
                QFile metaFile(meta);
                if(metaFile.open(QIODevice::ReadOnly))
                {
                    QByteArray ba;
                    ba = metaFile.readAll();
                    metaFile.close();

                    qry.prepare("UPDATE datasetinfo SET dataset_metadata = :metafile WHERE dataset_id = '" + tableName + "'");
                    qry.bindValue(":metafile", ba);
                    if (!qry.exec())
                    {
                        gbtLog(QObject::tr("Cannot insert the metadata."));
                        gbtLog(qry.lastError().databaseText());
                    }
                }
                else
                {
                    gbtLog(QObject::tr("Cannot open the metadata file."));
                    gbtLog(qry.lastError().databaseText());
                }
            }
            else
            {
                gbtLog(QObject::tr("The metadata file does not exits."));
                gbtLog(qry.lastError().databaseText());
            }
        }

        int Hours;
        int Minutes;
        int Seconds;
        int Milliseconds;

        Milliseconds = procTime.elapsed();

        Hours = Milliseconds / (1000*60*60);
        Minutes = (Milliseconds % (1000*60*60)) / (1000*60);
        Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000;

        printf("\n");

        gbtLog("Finished in " + QString::number(Hours) + " Hours," + QString::number(Minutes) + " Minutes and " + QString::number(Seconds) + " Seconds.");

        mydb.close();

        con.closeConnection();

        return 0;
    }

    return 0;

}
コード例 #26
0
ファイル: main.cpp プロジェクト: alexunder/X-toys
int main(int argc, char *argv[]) {
    if (argc != 2) {
        fprintf(stderr, "usage: mbrast [grid_file.out]\n");
        return 1;
    }

    // Read grids from grid dump file
    std::vector<ShadedGrid> grids;
    if (!ReadGrids(argv[1], &grids))
        return 1;

    InitSamples();

    // Extract the name of the scene in case a full pathname was provided
    // on the command line
    char *sceneName = rindex(argv[1], '/');
    if (sceneName != NULL)
        ++sceneName;
    else
        sceneName = argv[1];

    // Remove trailing ".grids" from scene name
    char *end = rindex(sceneName, '.');
    assert(end);
    *end = '\0';

    printf("Rendering scene \"%s\"\n", sceneName);

    // Change this call to switch to creating an instance of your 3D
    // rasterizer once you start implementing it.

#if MBRAST_MODE == NAIVE_RAST_2D || MBRAST_MODE == SMART_RAST_2D
    Rasterizer *rast = Create2DRasterizer();
#elif MBRAST_MODE == BASIC_RAST_3D || MBRAST_MODE == INTER_RAST_3D
    Rasterizer *rast = Create3DRasterizer();
#elif MBRAST_MODE == BASIC_RAST_5D
    Rasterizer *rast = Create5DRasterizer();
#endif

    // Initialize task system for multithreading if the rasterizer
    // indicates that it's thread safe.
    bool useTasks = rast->IsThreadSafe();
    int nThreads = NumSystemCores();
    assert(nThreads < MAX_CORES);
    if (useTasks) {
        printf("Using %d threads!\n", nThreads);
        TasksInit();
    }

    // Render the scene multiple times, with each of the pixelSamples
    // sample counts.  The sample counts must all be powers of two.
    // The bucketSize array, which must be the same size as
    // pixelSamples[], gives the length of the side of the bucket we'll
    // decompose the image into for the corresponding sample count.
    int pixelSamples[] = { 1, 4, 32 };
    int bucketSize[] = { 64, 32, 8 };
    assert(sizeof(pixelSamples) == sizeof(bucketSize));
    int samplesSize = sizeof(pixelSamples) / sizeof(pixelSamples[0]);

    int failures = 0;
    for (int samplesIndex = 0; samplesIndex < samplesSize; ++samplesIndex) {
        assert(pixelSamples[samplesIndex] <= MAX_SAMPLES_PER_PIXEL);
        int nPixelSamples = pixelSamples[samplesIndex];
        int bucketExtent = bucketSize[samplesIndex];

        printf("Rendering with %d samples per pixel\n", nPixelSamples);

        // 720p resolution.  (This can't be easily changed, as it's baked
        // into the xy coordinates of the micropolygons.  So changing this
        // here would require a corresponding adjustment to those
        // coordinate values when the grids are read in....)
        int xRes = 1280, yRes = 720;

        // Allow the rasterizer to preprocess the grids
        ResetAndStartTimer();
        rast->PreprocessGrids(grids, bucketExtent, xRes, yRes);
        double preprocessCycles = GetElapsedMCycles() / 1024.;
        printf("  Spent %.3f billion cycles on grid preprocessing.\n",
               preprocessCycles);

        // Allocate final output image as well as one Bucket structure for
        // each rasterization task thread we're running; this way the
        // rasterizer can update the framebuffer in its Bucket directly
        // without needing to coordinate with any other rasterizer threads.
        uint8_t *image = new uint8_t[xRes * yRes * 3];
        Bucket *buckets[MAX_CORES];
        int nBuckets = useTasks ? nThreads : 1;
        for (int i = 0; i < nBuckets; ++i)
            buckets[i] = new Bucket(bucketExtent, nPixelSamples);

        // Render with intervals set from 1 to the number of pixel samples
        // in multiples of two.
        for (int logIntervals = 0; (1 << logIntervals) <= nPixelSamples;
             ++logIntervals) {
            int nIntervals = (1 << logIntervals);

            printf("  Rendering with %d intervals: ", nIntervals);
            fflush(stdout);

            if (useTasks) {
                // Create a RastTask instance for each of the buckets of
                // the image; do this outside of the timer so as not to
                // penalize for the unnecessary dynamic allocation overhead
                // in the implementation here.
                std::vector<Task *> rastTasks;
                for (int y = 0; y < yRes; y += bucketExtent) {
                    for (int x = 0; x < xRes; x += bucketExtent) {
                        int x1 = std::min(x + bucketExtent, xRes);
                        int y1 = std::min(y + bucketExtent, yRes);
                        RastTask *rt = new RastTask(rast, &buckets[0], x, y,
                                                    x1, y1, nIntervals, grids,
                                                    image, xRes, yRes);
                        rastTasks.push_back(rt);
                    }
                }

                ResetAndStartTimer();
                EnqueueTasks(rastTasks);
                WaitForAllTasks();
            }
            else {
                // If not using tasks, just loop over all of the buckets
                // and rasterize.
                ResetAndStartTimer();
                for (int y = 0; y < yRes; y += bucketExtent) {
                    for (int x = 0; x < xRes; x += bucketExtent) {
                        buckets[0]->Start(x, y, std::min(x + bucketExtent, xRes),
                                          std::min(y + bucketExtent, yRes));
                        rast->Rasterize(grids, nIntervals, buckets[0]);
                        buckets[0]->Resolve(image, xRes, yRes);
                    }
                }
            }

            // Report total time for rasterization
            double rastGCycles = GetElapsedMCycles() / 1024.;
            printf("  %.3f billion cycles\n", rastGCycles);

            // Write the image
            char outName[256];
            sprintf(outName, "%s_int%d_samp%d.ppm", sceneName, nIntervals,
                    nPixelSamples);
            WritePPM(image, xRes, yRes, outName);
            printf("  Wrote output image \"%s\"\n", outName);

            // Compare to the "golden" image for correctness
            char goldenName[256];
            sprintf(goldenName, "golden/%s_%d.ppm", sceneName,
                    nPixelSamples);
            if (!CompareToGolden(image, xRes, yRes, goldenName, outName))
                ++failures;
        }
        printf("\n");

        for (int i = 0; i < nBuckets; ++i)
            delete buckets[i];

        delete[] image;
    }

    if (useTasks)
        TasksCleanup();

    delete rast;
    return failures;
}
コード例 #27
0
ファイル: main.cpp プロジェクト: joshb/linedrawing
int
main(int argc, char *argv[])
{
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		cerr << "SDL_Init failed" << endl;
		return 1;
	}

	SDL_Window *window = SDL_CreateWindow("Line Drawing Demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
	if (!window) {
		cerr << "SDL_CreateWindow failed" << endl;
		SDL_Quit();
		return 1;
	}

	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
	if (!renderer) {
		cerr << "SDL_CreateRenderer failed" << endl;
		SDL_Quit();
		return 1;
	}

	SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, WINDOW_WIDTH, WINDOW_HEIGHT);
	if (!texture) {
		cerr << "SDL_CreateTexture failed" << endl;
		SDL_Quit();
		return 1;
	}

	Rasterizer rast;
	float r = 0.0f;
	unsigned int lastTicks = SDL_GetTicks();

	// loop until we're done running the program
	while (g_Running) {
		HandleEvents();

		void *pixels;
		int pitch;
		if (SDL_LockTexture(texture, NULL, &pixels, &pitch) != 0) {
			cerr << "SDL_LockTexture failed" << endl;
			break;
		}

		rast.SetFrameBuffer((uint32_t *)pixels, WINDOW_WIDTH, WINDOW_HEIGHT);
		rast.Clear();

		// calculate coordinates for triangle
		const float size = 110.0f;
		float x1 = (float)(WINDOW_WIDTH / 2) + cosf(r - M_PI_F / 6.0f) * size;
		float y1 = (float)(WINDOW_HEIGHT / 2) + sinf(r - M_PI_F / 6.0f) * size;
		float x2 = (float)(WINDOW_WIDTH / 2) + cosf(r + M_PI_F / 2.0f) * size;
		float y2 = (float)(WINDOW_HEIGHT / 2) + sinf(r + M_PI_F / 2.0f) * size;
		float x3 = (float)(WINDOW_WIDTH / 2) + cosf(r + M_PI_F + M_PI_F / 6.0f) * size;
		float y3 = (float)(WINDOW_HEIGHT / 2) + sinf(r + M_PI_F + M_PI_F / 6.0f) * size;

		// colors for each point of the triangle
		Color color1(1.0f, 0.0f, 0.0f);
		Color color2(0.0f, 1.0f, 0.0f);
		Color color3(0.0f, 0.0f, 1.0f);

		// render triangle
		rast.DrawLine(color1, x1, y1, color2, x2, y2);
		rast.DrawLine(color2, x2, y2, color3, x3, y3);
		rast.DrawLine(color3, x3, y3, color1, x1, y1);

		SDL_UnlockTexture(texture);

		if (SDL_RenderClear(renderer) != 0) {
			cerr << "SDL_RenderClear failed" << endl;
			break;
		}

		if (SDL_RenderCopy(renderer, texture, NULL, NULL) != 0) {
			cerr << "SDL_RenderCopy failed" << endl;
			break;
		}

		SDL_RenderPresent(renderer);

		// calculate the number of seconds that
		// have passed since the last update
		unsigned int ticks = SDL_GetTicks();
		unsigned int ticksDiff = ticks - lastTicks;
		if (ticksDiff == 0) {
			continue;
		}
		float time = ticksDiff / 1000.0f;
		lastTicks = ticks;

		// update rotation
		r += M_PI_F / 2.0f * time;

		// display frames per second
		unsigned int fps = 1000 / ticksDiff;
		cout << "Frames per second: " << fps << "\t\r";
	}

	SDL_DestroyTexture(texture);
	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
	SDL_Quit();
	return 0;
}
コード例 #28
0
ファイル: main.cpp プロジェクト: codeezer/3d-crane
void keyboard_event(unsigned char key,int x,int y)
{

    glClear(GL_COLOR_BUFFER_BIT);
    r.clearZbuffer();

    x+=0;y+=0;
    DrawTriangle(x_y_zCoordinate(-450,0,3000),Color(1,1,0),x_y_zCoordinate(-600,-350,-1000),
                 Color(0,1,0),x_y_zCoordinate(600,-350,-1000),Color(0,1,1));
    DrawTriangle(x_y_zCoordinate(-450,0,3000),Color(1,1,0),x_y_zCoordinate(600,0,-1000),
                 Color(0,1,0),x_y_zCoordinate(600,-350,-1000),Color(0,1,1));
    light.draw();
    for(unsigned int i=0;i<hook.face_size;i++){
    if ((hook.vertices[i].x > ligh.x -10 && hook.vertices[i].x < ligh.x +10) && (hook.vertices[i].y > ligh.y -10
       && hook.vertices[i].y < ligh.y +10)&& (hook.vertices[i].z > ligh.z -10 && hook.vertices[i].z < ligh.z +10))
    {
        set = true;
    }}
    //c1.create();

    switch(key)
    {
    case 'o':
    {
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =TTTT*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));

        break;
    }
    case'i':
    {
        if(set==true){
            for(unsigned int i=0;i<light.Total_Points;i++)
            {
                light.Vertices[i]=LLLL*light.Vertices[i];
            }}

            for(unsigned int i=0;i<hook.face_size;i++)
            {
                hook.vertices[i] =LLLL*hook.vertices[i];
            }

        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }


    case 'q':
    {
        /* for(unsigned int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = IN*sph.Vertices[i];
        }
        //drawLine(-600,0,600,0);
        //drawLine(0,350,0,-350);
        sph.draw();*/
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =IN*o.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));

        break;
    }
    case 'e':
    {
        /*for(unsigned int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = OUT*sph.Vertices[i];
        }
        //drawLine(-600,0,600,0);
        //drawLine(0,350,0,-350);
        sph.draw();*/
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =OUT*o.vertices[i];
        }

        break;
    }
    case 'x':
    {
        /*for(int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = XR*sph.Vertices[i];
        }
        sph.draw();*/

        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =XR*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =XR*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =XR*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =XR*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        cout<<"\nx";
        break;
    }
    case 'y':
    {
        /* for(int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = YR*sph.Vertices[i];

        }
        sph.draw();*/

        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =YR*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =YR*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =YR*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =YR*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        cout<<"\ny";
        break;
    }
    case 'z':
    {
        /* for(int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = ZR*sph.Vertices[i];
        }

        sph.draw();*/

        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =ZR*o.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        cout<<"\nz";
        break;
    }
    case 'l':
    {
        //for(int i=0;i<sph.Total_Points;i++)
        //{
        //  sph.Vertices[i] = SCL*sph.Vertices[i];
        //}
        //sph.draw();
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =SCL*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =SCL*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =SCL*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =SCL*hook.vertices[i];
        }
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        cout<<"\nl";
        break;
    }
    case 'h':
    {
        /*for(int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = SCH*sph.Vertices[i];
        }
        sph.draw();*/
        for(unsigned int i=0;i<o.face_size;i++)
        {
            o.vertices[i] =SCH*o.vertices[i];
        }
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =SCH*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =SCH*boom.vertices[i];
        }
        for(unsigned int i=0;i<hook.face_size;i++)
        {
            hook.vertices[i] =SCH*hook.vertices[i];
        }
        //o.draw(Color(0.3,0.2,0.3));
        //rem.draw(Color(1.0,1.2,0.1));
        //boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        cout<<"\nh";
        break;
    }
    case 'm':
    {
        /*for(unsigned int i=0;i<sph.Total_Points;i++)
        {
            sph.Vertices[i] = RR*sph.Vertices[i];
        }
        sph.draw();*/
        for(unsigned int i=0;i<rem.face_size;i++)
        {
            rem.vertices[i] =NN*RR*MM*rem.vertices[i];
        }
        for(unsigned int i=0;i<boom.face_size;i++)
        {
            boom.vertices[i] =NN*RR*MM*boom.vertices[i];
        }
        for(unsigned int i=0;i<=hook.face_size;i++)
        {
            hook.vertices[i] =NN*RR*MM*hook.vertices[i];
        }

        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        break;
    }
    case 'c':
    {
        break;
    }

    case 'p':
    {
        x_y_zCoordinate cc111(-600,-310,10),cc222(-512,310,10),cc333(0,280,10);

        x_y_zCoordinate cc11(0,0,0),cc22(480,0,0),cc33(0,350,0);

        x_y_zCoordinate cc1(0,0,10),cc2(340,0,10),cc3(0,340,10);


        Color c1(1,0,0),c2(0,1,0),c3(0,0,1);
        DrawTriangle(cc1,c3,cc2,c3,cc3,c3);
        DrawTriangle(cc11,c1,cc22,c1,cc33,c1);
        DrawTriangle(cc111,c2,cc222,c2,cc333,c2);

        //DrawTriangle();
        break;
    }
    case 'b':
    {
        o.draw(Color(0.3,0.2,0.3));
        rem.draw(Color(1.0,1.2,0.1));
        boom.draw(Color(0.8,0.9,1));
        hook.draw(Color(0.1,0,1));
        setPixel(0,0,Color(1,0,0));
        break;
    }
    default:
        //drawLine(-600,0,600,0);
        //drawLine(0,350,0,-350);
         exit(-1);//terminate the program
        break; // do nothing
    }

    glFlush();
    glutSwapBuffers();
}
コード例 #29
0
ファイル: renderMesh.cpp プロジェクト: FRex/brender
void draw(Rasterizer& raster, const Mesh& mesh, const arma::mat44& mat, const arma::mat44& rotmat,
        std::vector<BufferedVertice>& buff, ECULLING_MODE cull)
{
    const unsigned * idxs = mesh.getIndices();
    const unsigned idxc = mesh.getIndexCount();
    const unsigned vc = mesh.getVertexCount();
    arma::vec4 av;
    arma::vec4 nv;

    buff.clear();

    for(int i = 0; i < vc; ++i)
    {
        const Vertex& a = mesh.getVertex(i);

        av(0) = a.position.x;
        av(1) = a.position.y;
        av(2) = a.position.z;
        av(3) = 1.f;
        av = mat * av;

        nv(0) = a.normal.x;
        nv(1) = a.normal.y;
        nv(2) = a.normal.z;
        nv(3) = 1.f;
        nv = rotmat * nv;

        av(0) = av(0) * (kProjPlaneDist / std::fabs(av(2))) + halfscreenwidth;
        av(1) = av(1) * (kProjPlaneDist / std::fabs(av(2))) + halfscreenheight;

        buff.push_back(BufferedVertice(av(0), av(1), av(2), a.color, a.u, a.v, nv(0), nv(1), nv(2)));

    }//for

    int culled = 0;
    for(int i = 0; (i + 2) < idxc; i += 3)
    {
        const BufferedVertice& a = buff[idxs[i]];
        const BufferedVertice& b = buff[idxs[i + 1]];
        const BufferedVertice& c = buff[idxs[i + 2]];
        bool skip = cw(a, b, c);
        switch(cull)
        {
            case ECM_BACKFACE:
                skip = skip;
                break;
            case ECM_FRONTFACE:
                skip = !skip;
                break;
            default:
                skip = false;
                break;
        }//switch cull
        if(skip)
        {
            ++culled;
            continue;
        }
        raster.addVertex(a.x, a.y, a.c, a.z, a.u, a.v, a.nx, a.ny, a.nz);
        raster.addVertex(b.x, b.y, b.c, b.z, b.u, b.v, b.nx, b.ny, b.nz);
        raster.addVertex(c.x, c.y, c.c, c.z, c.u, c.v, c.nx, c.ny, c.nz);
    }//for
    std::printf("CULLED: %d\n", culled);
}
コード例 #30
0
ファイル: consolerenderer.cpp プロジェクト: leuat/gamer
void ConsoleRenderer::RenderSkybox(QStringList param)
{
    if (param.size()!=5) {
        qDebug() << param.size();
        cout << "Incorrect usage/parameters for galaxy. Usage: " << endl;
        PrintUsage();
        exit(1);

    }
    m_rasterizer = nullptr;
    if (param[1].toLower()=="omp") {
        m_rasterizer = new Rasterizer();
    }
    if (param[1].toLower()=="thread") {
        m_rasterizer = new RasterThread(&m_renderingParams);
    }
    if (m_rasterizer==nullptr) {
        cout << "ERROR! Cannot recognize " << param[1].toStdString() << endl;
        cout << "Must be 'omp' or 'thread'" << endl;
        exit(1);

    }
    Util::path = "";
    m_renderingParams.Load(Util::path + param[2]);
    QString galaxyFile = param[3];
    m_renderingParams.setSize(param[4].toFloat());

    Galaxy galaxy;
    galaxy.Load(galaxyFile);

    m_rasterizer->setRenderingParams(&m_renderingParams);
    m_rasterizer->AddGalaxy(new GalaxyInstance(&galaxy, galaxy.galaxyParams().name(),
                                              QVector3D(0,0,0), QVector3D(0,1,0).normalized(), 1, 0)  );


    RenderQueue rq;
    rq.RenderSkybox(m_rasterizer, m_renderingParams);

    cout << "Starting rendering on " <<  QString::number(std::thread::hardware_concurrency()).toStdString() << " cores." << endl;
    Q_TIMER_START();
    rq.Update();
    while (rq.isRendering()) {
        if (rq.current()== nullptr) {

        }
          else {
        Rasterizer* rast = &rq.current()->rasterizer();
        int prevP = 0;
        while (rast->getState()!= Rasterizer::State::done) {
            int curP = (rast->getPercentDone()*1000.0);
            if (curP!=prevP) {

                float time = ttimer.elapsed();
                float percentage = rast->getPercentDone();
                float timeLeft = time/(percentage) - time;
                QString t;
                t.sprintf("%2.1f", curP*0.1);
                cout << "\r[ " << t.toStdString() <<  "% ]  with ETA in " << Util::MilisecondToString(timeLeft).toStdString() <<   std::flush;
                prevP = curP;

            }
        }
        cout << endl;

        rast->AssembleImage();
        rast->getImageShadowBuffer()->save(rq.current()->filename()+ ".png");
        cout << "Image saved to file " << rq.current()->filename().toStdString() << ".png" << endl;

    }
        rq.Update();
        rq.Update();

}
    Q_TIMER_ELAPSED("Rendering");

}