📄 mainvoxmaptest.html
字号:
<TITLE>COG 2.1: Voxel maps</TITLE><h1>Voxel maps (grayscale)</h1> <p>Sometimes a geometry is described by a 3D pixel array. A typical case is the result of computer tomography (CT).Usually we have a 3D picture created from various2D xy-sections for different z-values. Here we show how such 3Dpixel arrays may be used to define a grid with COG. <P><IMG SRC="voxmaptest.gif"> <p>Code for defined by 3D grayscale pixel arrays can be found in the following files: <A HREF="cogenvoxmap.cxx">cogenvoxmap.cxx</A>, <A HREF="cogenvoxmap.hxx">cogenvoxmap.hxx</A>, <A HREF="wzvoxmap.cxx">wzvoxmap.cxx</A>, <A HREF="wzvoxmap.hxx">wzvoxmap.hxx</A>. <p>We have no special implementations to read in such 3D arrays.The following test code may be used as a base for a future implementationof functions which read such 3D arrays from file formats.<PRE>#include "<A HREF="coglib.hxx">cog/coglib.hxx</A>"#include "<A HREF="cogenvoxmap.hxx">cog/cogenvoxmap.hxx</A>"int main(){</PRE><h2> Grayscale table </h2> <p>To indentify gray values with region, you have to define a translation of ranges of gray values into region numbers. This is done by the class <b>wzGrayScaleTable</b>:<PRE> wzGrayScaleTable table; table.addRange(2,0,2); table.addRange(1,0,5); table.addRange(3,0,wzWhite);</PRE> <p>The first parameter of <b>addRange</b>is a region number (here as a single char - type wzByte).The other two parameters of type <b>wzGrayValue</b> (short unsigned int, between wzBlack = 0 and wzWhite = 0xff)define a range of gray values which will be associated with thisregion number. For overlapping ranges, the first range counts.<h2> Pixmap initialization </h2> <p>We also have to define the pixmap itself. The initializationrequires already the size (number of pixels) of the pixmap in the three directions.The real sizes (coordinates of the first and last pixels) can be setseparately using <b>setXRange, setYRange, setZRange</b> (0.0,1.0 are defaults):<PRE> wzIndex xlen = 3; wzIndex ylen = 3; wzIndex zlen = 3; cogenVoxmap map = new CogenVoxmap(xlen,ylen,zlen); map->setXRange(0.0,1.0); map->setYRange(0.0,1.0); map->setZRange(0.0,1.0);</PRE><h2> Filling the pixmap with values </h2> <P>Then you have to fill the pixel array with the regions. We assume that you read the <i>grayvalue</i> for a given pixel defined by <i>ix,iy,iz</i> from a file, but here we use the sum<i>ix+iy+iz</i> as a simple example:<PRE> int ix,iy,iz; for(ix=0;ix<map->lx();ix++){ for(iy=0;iy<map->ly();iy++){ for(iz=0;iz<map->lz();iz++){ wzGrayValue grayvalue = ix+iy+iz; // or something else from file map->pixmap()(ix,iy,iz) = table(grayvalue); } } }</PRE><h2> Transformation of existing grayscale arrays </h2><p>A variant would be to use an array of grayscale values (maybe you have already a function which creates such an arrayfor some file format) and then to transfer it into <b>CogenVoxmap</b> using the <i>table</i>. Here, we initializeat first such a grayscale array (of class <b>wzGrayScaleVoxmap</b>) in the same way as before,and then initialize the <b>CogenVoxmap</b> using the greyscale array and the translation table:<PRE> wzGrayScaleVoxmap* gmap = new wzGrayScaleVoxmap(xlen,ylen,zlen); for(ix=0;ix<map->lx();ix++){ for(iy=0;iy<map->ly();iy++){ for(iz=0;iz<map->lz();iz++){ wzGrayValue grayvalue = ix+iy+iz; // or something else from file (*gmap)(ix,iy,iz) = grayvalue; } } }// map = new CogenVoxmap(*gmap,table); delete gmap;</PRE><p>Note that after the initialization the original grayscale array may be deleted.<h2>Grid generation</h2> <p>Now, everything is ready to create the grid as usual. The grid generator is derived from the usual <b>CogenOctree</b>generator, and its functionality may be used here:<PRE> map->refinementGlobal(0.4,0.4,0.4); map->faceRefinementGlobal(0.1,1.0); map->setBorder(0,1,0,1,0,1); wzgrid grid = (*map->generator())(); grid->write("test.sg"); }</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -