輪廓線就是圖形的邊界,任何封閉的頂點(diǎn)源跳過(guò)agg::conv_stroke階段,將會(huì)描繪實(shí)心的圖形,填充的顏色和邊界保持一致。如果不封閉的頂點(diǎn)源一旦跳過(guò)agg::conv_stroke就什么也不繪制。agg::conv_stroke就是用來(lái)描繪圖形邊界的。
10年的洞頭網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整洞頭建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“洞頭網(wǎng)站設(shè)計(jì)”,“洞頭網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
和agg::trans_affine對(duì)比可知,agg::conv_contour是擴(kuò)展圖形的輪廓線,通俗一點(diǎn)就是拓展圖形的邊界,對(duì)圖形的邊界進(jìn)行放縮(但是和agg::trans_affine仿射變換不同,這是中心位置不變的縮放)。
執(zhí)行examples/conv_stroke例程,提供如下的控制:
1)線段端點(diǎn)的切換
2)線段之間的連接方式
3)線段寬度
頭文件:#include"agg/include/agg_conv_stroke.h"
enum line_cap_e
{
butt_cap,//按鈕形狀,實(shí)際和方形形狀并無(wú)二致
square_cap,//設(shè)置之后,長(zhǎng)度比butt_cap長(zhǎng)一些
round_cap//半圓形狀
};
設(shè)置函數(shù):voidline_cap(line_cap_e lc)
設(shè)置函數(shù):voidwidth(double w)
當(dāng)然我們可以不調(diào)用line_cap,也可以不調(diào)用width,因?yàn)閟troke有默認(rèn)的構(gòu)造器,指定了默認(rèn)的參數(shù)如下:
m_width(0.5),
m_width_abs(0.5),
m_width_eps(0.5/1024.0),
m_width_sign(1),
m_miter_limit(4.0),
m_inner_miter_limit(1.01),
m_approx_scale(1.0),
m_line_cap(butt_cap),
m_line_join(miter_join),
m_inner_join(inner_miter)
采用的是實(shí)線的渲染方式,是否我們可以通過(guò)替換她,描述虛線:agg::conv_dash
結(jié)果發(fā)現(xiàn):什么也沒(méi)有渲染出來(lái)!!agg::conv_dash會(huì)單獨(dú)描述!!
ras.reset();
agg::path_storage ps1;
ps1.move_to(200,200);
ps1.line_to(300,300);
agg::line_cap_e cap = agg::round_cap;//設(shè)置線段端點(diǎn)的形狀
agg::conv_stroke<agg::path_storage> stroke(ps1);//線段的樣式
stroke.line_cap(cap);
stroke.width(50);//設(shè)置線段的寬度
ras.add_path(stroke);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
輪廓線是圖形的輪廓邊界,擴(kuò)展輪廓線也就是在圖形的中心位置不變的情況下,邊界進(jìn)行了放縮,和affine的仿射縮放不同,后者是中心位置也會(huì)產(chǎn)生偏移,針對(duì)于圓形非常好理解,可以嘗試對(duì)一個(gè)圓形分別進(jìn)行agg::conv_contour和agg::trans_affine處理,可以看到明顯的效果:
agg::conv_contour原地膨脹
agg::trans_affine圓心偏移,并且放縮
3.3 例子回放
//Vertex Source
agg::ellipse ell(100,100,50,50);
// Coordinate conversion pipeline
typedef agg::conv_contour<agg::ellipse> ell_cc_type;
ell_cc_type ccell(ell);
typedef agg::conv_stroke<ell_cc_type> ell_cc_cs_type;
ell_cc_cs_type csccell(ccell);
// Draw
renb.clear(agg::rgba8(255,255,255));
for(int i=0; i<3; i++)
{
ccell.width(i*50);//看清楚,這是對(duì)輪廓線的實(shí)例進(jìn)行的操作,而不是stroke實(shí)例
ras.add_path(csccell);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
}
分析:當(dāng)i = 0的時(shí)候,并沒(méi)有進(jìn)行輪廓的放縮,可以清晰的了解到,進(jìn)行輪廓放縮的時(shí)候,圓形變大了,實(shí)際上是圓形的輪廓邊界放大的緣故,但是圓心不變!!
網(wǎng)上提供的一般邏輯:
矩陣變換agg::conv_transform
輪廓邊界擴(kuò)展(實(shí)際上是邊界縮放)agg::conv_contour
轉(zhuǎn)換成多義線(顯示輪廓線)agg::conv_stroke
再次重申:agg::conv_contour和agg::conv_stroke作為“坐標(biāo)轉(zhuǎn)換管道Coordinateconversion pipeline”,conv_contour擴(kuò)展輪廓線,conv_stroke只顯示輪廓線(如果沒(méi)有conv_stroke就會(huì)顯示實(shí)心圓,可以去掉試試)。
conv_contour實(shí)際上是由vcgen_contour
真正實(shí)現(xiàn)的??!幾乎所有的實(shí)現(xiàn)都是調(diào)用了vcgen_contour
的generator函數(shù)
一個(gè)簡(jiǎn)單的測(cè)試?yán)樱?/p>
agg::ellipse ell(100,100,50,50);
agg::trans_affine mtx;
mtx.scale(2,1);
typedef agg::conv_transform<agg::ellipse> ell_ct_type;
ell_ct_type ctell(ell, mtx);
/************/
typedef agg::conv_contour<ell_ct_type> ell_cc_type;
ell_cc_type ccell(ctell); // 輪廓變換
ccell.width(6);//nothing happen
/************/
typedef agg::conv_stroke<ell_cc_type> ell_cc_cs_type;
ell_cc_cs_type csccell(ccell);
//csccell.width(6);
ras.add_path(ccell);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
正如名稱所言:自動(dòng)檢測(cè)方向,什么方向,可能很多人不了解,通過(guò)AGG郵件了解到幾點(diǎn):擴(kuò)展輪廓線跟圖形的繪制方向有關(guān)(也就是move_to,line_to,構(gòu)成的圖形的順時(shí)針,還是逆時(shí)針)。如下的兩個(gè)例子,一個(gè)是順時(shí)針繪制矩形,一個(gè)是逆時(shí)針繪制矩形,然后擴(kuò)展輪廓線。
agg::path_storage ps;
ps.move_to(395.5,200.5);
ps.line_to(295.5,200.5);
ps.line_to(295.5,210.5);
ps.line_to(395.5,210.5);
ps.close_polygon();
agg::conv_contour<agg::path_storage> contour(ps);
//contour.auto_detect_orientation(true);
contour.width(m_slider1.value());//獲取滑動(dòng)條的值
agg::conv_stroke<agg::conv_contour<agg::path_storage> >stroke(contour);
ras.add_path(stroke);
agg::path_storage ps;
ps.move_to(395.5,200.5);
ps.line_to(395.5,210.5);
ps.line_to(295.5,210.5);
ps.line_to(295.5,200.5);
agg::conv_contour<agg::path_storage>contour(ps);
contour.width(m_slider1.value());
agg::conv_stroke<agg::conv_contour<agg::path_storage> >stroke(contour);
ras.add_path(stroke);
結(jié)果分析:第二個(gè)例子順利的進(jìn)行擴(kuò)展線的放大或縮小,但是第一個(gè)例子剛好相反,兩個(gè)例子之間的區(qū)別就是圖形繪制的方向不同而已。所以為了解決這種問(wèn)題,才引入了contour.auto_detect_orientation函數(shù)。
把第一個(gè)例子的上面函數(shù)去掉注釋,就可以按照正常的邏輯進(jìn)行縮放輪廓線。
AGG里面大部分的函數(shù)參數(shù)都是需要高深的圖形計(jì)算的知識(shí),探究源碼更是需要深厚的功底。所以現(xiàn)在只能夠通過(guò)函數(shù)的調(diào)用,然后通過(guò)顯示的圖形,推導(dǎo)出該函數(shù)的具體含義。
結(jié)論如下:當(dāng)前是通過(guò)規(guī)則的圓形來(lái)示范發(fā)現(xiàn),當(dāng)設(shè)置width參數(shù)為200的時(shí)候,半徑是增加了100,其中的100都是以像素作為單位。每一個(gè)像素代表一個(gè)坐標(biāo)點(diǎn)。
如下是詳細(xì)的代碼:
void TestContourValue()
{
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
typedef agg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;
renderder_scanline_type rensl(renb);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
agg::path_storage ps;
ps.move_to(200,200);
ps.line_to(400,200);
ps.line_to(400,400);
ps.line_to(200,400);
ps.close_polygon();
agg::conv_stroke<agg::path_storage> stroke(ps);
ras.add_path(stroke);
agg::ellipse ell(300,300,100,100);
agg::conv_stroke<agg::ellipse> stroke1(ell);
ras.add_path(stroke1);
ps.remove_all();
ps.move_to(100,100);
ps.line_to(500,100);
ps.line_to(500,500);
ps.line_to(100,500);
ps.close_polygon();
agg::conv_stroke<agg::path_storage> stroke2(ps);
ras.add_path(stroke2);
agg::conv_contour<agg::ellipse> contour(ell);
contour.width(200);
agg::conv_stroke<agg::conv_contour<agg::ellipse> >stroke3(contour);
ras.add_path(stroke3);
ps.remove_all();
ps.move_to(0,0);
ps.line_to(600,0);
ps.line_to(600,600);
ps.line_to(0,600);
ps.close_polygon();
agg::conv_stroke<agg::path_storage> stroke4(ps);
ras.add_path(stroke4);
agg::conv_contour<agg::ellipse> contour1(ell);
contour1.width(400);
agg::conv_stroke<agg::conv_contour<agg::ellipse> >stroke5(contour1);
ras.add_path(stroke5);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(0,255,0));
}
agg::conv_contour無(wú)法應(yīng)用于自交的圖形
測(cè)試代碼:
void DrawIntersectContour()
{
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
typedef agg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;
renderder_scanline_type rensl(renb);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
agg::path_storage ps;
ps.move_to(200,400);
ps.line_to(500,500);
ps.line_to(200,500);
ps.line_to(500,400);
ps.line_to(200,400);
agg::conv_contour<agg::path_storage> contour(ps);
agg::conv_stroke<agg::conv_contour<agg::path_storage> >stroke(contour);
ras.add_path(stroke);
// agg::conv_stroke<agg::path_storage> stroke1(ps);
// ras.add_path(stroke1);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(0,255,0));
}
結(jié)果分析:嘗試?yán)L制一個(gè)三角形漏斗,但是通過(guò)擴(kuò)展輪廓線模塊,發(fā)現(xiàn)沒(méi)有進(jìn)行封閉,可通過(guò)取消注釋,查看具體的情況。實(shí)際上AGG提供的例子就是通過(guò)渲染a,實(shí)際上該字母本身就是自交的,導(dǎo)致了輪廓的放縮非常的奇怪??!
如下是作者的描述:
You can use conv_contour in your vectorpipeline. See
examples/conv_contour.cpp for details. Theonly problem is it won'twork for
self-intersecting contours, because thedirection of the polygons is
essential, but we can't talk about thepolygon direction if itintersects
itself.
當(dāng)前文章:AGG第二十一課agg::conv_contour擴(kuò)展輪廓線
本文網(wǎng)址:http://chinadenli.net/article38/ihcosp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、搜索引擎優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷推廣、網(wǎng)站制作、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)