📄 mainpixmaptest.html
字号:
<TITLE>COG 2.0: Pixmaps</TITLE><H1>Pixmaps</H1><PRE>#include "<A HREF="cogenpixmap.hxx">cogenpixmap.hxx</A>"</PRE>The class <B>CogenPixmap</B> is defined in <A HREF="cogenpixmap.cxx">cogenpixmap.cxx</A>. In our example, weread a 2D pixmap (PPM format, 512 x 259 pixels) <P><IMG SRC="pixmapinput.gif"> <P>and create the following grid with 21879 nodes: <P><IMG SRC="pixmaptest.gif"> <P>The refinement near the boundary we have made slightly moreaccurate than pixel size. This gives the correct geometry even forthe highly non-convex parts of this picture: <P><IMG SRC="pixmap1test.gif"> <IMG SRC="pixmap2test.gif"><H2>Reading the pixmap</H2> <P>The idea is defined by the principle <B>one color - oneregion</B>. If you have more than necessary or a continuum of colors,the algorithm works too: close enough colors will be identified.A coarse upper bound is <B>maxcolors</B>:<PRE>#include "<A HREF="coglib.hxx">cog/coglib.hxx</A>"int main(){ cogIndex maxcolors=20; // maximal number of colors allowed cogenPixmap gen = new CogenPixmap("cog/pixmapinput.ppm",maxcolors);</PRE> <P>Currently we support only <B>PPM</B> format, but it is easy totransform pictures into this format (I use <B>xv</B> for thispurpose).<H2>Specification of the box containing the picture</H2> <P>Now, let's define the box. You possibly want to have anon-distorted result but don't know the pixel numbers in abovedirections. For this purpose, you can define the range in onedirection (setHorizontal or setVertical) and define a single value forthe other direction with specification of the alignment (alignMinimum,alignCenter, alignMaximum):<PRE> gen->setHorizontal(-1,1); // gen->setVertical(-1,1); gen->alignCenter(0);</PRE> <P>If you want to specify all values (possibly with distortion of thepicture) simply use setHorizontal and setVertical.<H2>Identifying colors and regions</H2> <P>To identify the colors with region numbers, define a list ofcolors and their related region numbers:<PRE> int listlength=2, region[3]; wzColor color[3], black(""), blue("#11f"), yellow("#a70"); color[0] = black; color[1] = blue; region[1] = wzRegion(3); color[2] = yellow; region[2] = wzRegion(2); gen->fitColorList(listlength,color,region);</PRE> <P>To find out which colors have been found you can print out thecolors with <B>printColors</B>:<PRE> gen->printColors();</PRE><H2>Refinement</H2> <P>Now, you have to be careful with the refinement. In our case, therefinement near the faces defined by <B>faceRefinementGlobal</B> isapproximately pixel size:<PRE> gen->refinementGlobal(0.2,0.2); gen->faceRefinementGlobal(0.005,1.0);</PRE> <P>Thus, once a boundary has been detected, it will be found accurateenough.<H2>Special Points</H2> <P> But there are some regions (islands and lakes) too small to befound with certainty with the global refinement used here.Especially, the lake near the center will not be found. To catch thislake, we add the coordinates of one point inside the lake:<PRE> gen->addPlanesOfPoint(-0.0901,-0.208);</PRE> <P>Now, we generate the grid and write it out as usual:<PRE> wzgrid grid = (*gen)(); grid->write("test.sg");}</PRE><H2>Warnings</H2><A NAME="badParameter"><HR></A><H3>bad input parameter</H3> <P>Check your input paramters. If you define alignment, you cannotdefine as horizontal, as vertical boundaries.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -