📄 wzgridview.cxx
字号:
#include <math.h>#include <stdio.h>#include <time.h>extern "C"{#include <GL/gl.h>#include "gltools/glwin.h"}#include "ibg2.hxx"#include "wzoutput.hxx"//#include "ibgoutput.hxx"#include "wzdefault.hxx"#include "wzview.hxx"static wzInteger von=0,voc=0,vor=0,vof=0;static wzFloat *sh = wzCurrentData::shift;static wzFloat *fac = wzCurrentData::factor;//static wzIndex iso = 1;static wzgrid grid;static void wzViewCallback(wzWindow win, void *data);static void DrawFaceLine(double *p1, double *p2, wzFace f);static void DrawRegionTriangle(double *p1, double *p2, double *p3, wzRegion r);static void DrawFaceTriangle(double *p1, double *p2, double *p3, wzFace f);static void DrawTetrahedron(double *p1, double *p2, double *p3, double *p4, wzRegion r);static int checkPosition(double* x, double* min, double* max, double* center, int mode);static int checkCorrectness(wzgrid g, wzInteger cc);const wzInteger SwitchOutside = 0;const wzInteger SwitchBad = 1;const wzInteger SwitchOrientation = 2;const wzInteger SwitchRegionMaterial = 3;const wzInteger ModeBase = 4;const wzInteger ModePrint = 5;const wzInteger ModeSide = 6;const wzInteger ModeSlice = 7;const wzInteger ValueNode = 8;const wzInteger ValueCell = 9;const wzInteger ValueRegion =10;const wzInteger ValueFace =11;const wzInteger ValueShrink =12;const wzInteger ValueSide =13;const wzInteger ActionCenter =14;const wzInteger ActionInfo =15;char* BaseModi[] = {"faces","cells"};int baseModi = 2;char* PrintModi[] = {"none","nodes","cells"};int printModi = 3;char* SideModi[] = {"all","behind", "not before", "before", "not behind"};int sideModi = 5;char* SliceModi[] = {"none","x", "y", "z"};int sliceModi = 4;//const wzInteger BaseFaces = 0;const wzInteger BaseCells = 1;const wzInteger SideAll = 0;const wzInteger SideBehind = 1;const wzInteger SideNotBefore = 2;const wzInteger SideBefore = 3;const wzInteger SideNotBehind = 4;// color settings;static wzDefaultSegmentDescriptionClass black_background;static wzDefaultSegmentDescriptionClass white_background;class wzInitializeColorNow{public: wzInitializeColorNow() { white_background.use(); wzRegion( ).color()="#aa0000"; // error: red wzRegion( 1).color()="#090171"; // dark blue wzRegion( 2).color()="#503030"; // brown (red) wzRegion( 3).color()="#0040b1"; // blue wzRegion( 4).color()="#00d110"; // green wzRegion( 5).color()="#b1a015"; // yellow wzRegion( 6).color()="#812011"; // red wzRegion( 7).color()="#10a0a0"; // cyan wzRegion( 8).color()="#666666"; // gray (yellow) wzRegion( 9).color()="#402191"; // violet wzRegion(10).color()="#607191"; // gray wzRegion(11).color()="#403000"; // brown (green) wzRegion(12).color()="#666666"; wzRegion(13).color()="#100171"; wzRegion(14).color()="#4071b1"; wzFace ( ).color()="#aa0000"; wzFace ( 1).color()="#090171"; wzFace ( 2).color()="#503030"; wzFace ( 3).color()="#0040b1"; wzFace ( 4).color()="#00d110"; wzFace ( 5).color()="#b1a015"; wzFace ( 6).color()="#813031"; wzFace ( 7).color()="#10a0a0"; wzFace ( 8).color()="#666666"; wzFace ( 9).color()="#402191"; wzFace (10).color()="#607191"; wzFace (11).color()="#403000"; wzFace (12).color()="#666666"; wzFace (13).color()="#100171"; wzFace (14).color()="#4071b1"; }};static wzInitializeColorNow initialize_color_now;static void ibgMarkCells(wzWindow win, wzgrid grid, wzArray<wzIndex> hidden){ wzInteger obj = wzwGetObject(win); wzInteger cc,cl,cr,*cn0,l,i,u,ul,ur; wzCellType t; wzInteger vn,vc,vr,vf,vs; wzInteger mode; wzInteger showOutside,showBad,material; wzwGetEnum(win,obj,ModeBase,&mode); wzwGetSwitch(win,obj,SwitchOutside,&showOutside); wzwGetSwitch(win,obj,SwitchRegionMaterial,&material); wzwGetSwitch(win,obj,SwitchBad,&showBad); wzwGetInteger(win,obj,ValueNode,&vn); wzwGetInteger(win,obj,ValueCell,&vc); wzwGetInteger(win,obj,ValueRegion,&vr); wzwGetInteger(win,obj,ValueFace,&vf); wzwGetInteger(win,obj,ValueSide,&vs); if(vn!=von){von = vn; grid->pn(vn);} if(vc!=voc){voc = vc; grid->pc(vc);} if(vr!=vor){vor = vr; grid->pr(vr);} if(vf!=vof){vof = vf; grid->pf(vf);} wzRangeLoop(grid->cells,cc){ t = grid->cct(cc); l = wzCellTypePoints(t); cn0 = grid->ccn(cc); u = grid->ccu(cc); if(material){ if(wzCellTypeIsRegion(t)) u = (wzRegion(u)).material(); else if(wzCellTypeIsFace(t)) u = (wzFace(u)).type(); } if(vc){ if(cc==vc) hidden[cc] = 0; else hidden[cc] = 1; continue; }else if(vn){ hidden[cc] = 1; for(i=0;i<l;i++) if(cn0[i]==vn) hidden[cc] = 0; if(wzCellTypeIsRegion(t)){ if(vr>0) { if(u != vr) hidden[cc]=1;} else if(vr<0) { if(u == -vr) hidden[cc]=1;} }else if(wzCellTypeIsFace(t)){ if(vf>0) { if(u != vf) hidden[cc]=1;} else if(vf<0) { if(u == -vf) hidden[cc]=1;} } continue; } hidden[cc] = 1; if(mode==BaseCells){ if(!wzCellTypeIsRegion(t)) continue; if(vr>0){ if(u != vr) continue; }else if(vr<0){ if(u == -vr) continue; } }else{ if(!wzCellTypeIsFace(t)) continue; if(!showOutside){ cl = grid->ccleft( cc,t); if(cl<=0 || grid->ccu(cl)==0) continue; cr = grid->ccright(cc,t); if(cr<=0 || grid->ccu(cr)==0) continue; } if(vr){ ul = grid->culeft( cc,t); ur = grid->curight(cc,t); if(material){ ul = (wzRegion(ul)).material(); ur = (wzRegion(ur)).material(); } if(vr>0){ if(ul != vr && ur != vr) continue; }else if(vr<0){ if(ul == -vr || ur == -vr) continue; } } if(vf>0){ if(u != vf) continue; }else if(vf<0){ if(u == -vf) continue; } } if(showBad) if(checkCorrectness(grid,cc)) continue; hidden[cc] = 0; }}static void ibgComputeBoundingBox(wzWindow win, wzgrid grid, wzArray<wzIndex> hidden, wzFloat *xm, wzFloat *xp){ wzIndex i,j,l,t,cc; wzInteger *cn0; wzFloat *f; for(i=0;i<3;i++) xm[i] = +wzInfty; for(i=0;i<3;i++) xp[i] = -wzInfty; wzRangeLoop(grid->cells,cc){ if(hidden[cc]) continue; t = grid->cct(cc); l = wzCellTypePoints(t); cn0 = grid->ccn(cc); for(j=0;j<l;j++){ f=grid->cnx(cn0[j]); for(i=0;i<3;i++){ if(xm[i]>f[i]) xm[i] = f[i]; if(xp[i]<f[i]) xp[i] = f[i]; } } } for(i=0;i<3;i++) if(xm[i]>xp[i]){xm[i]=grid->cgmin(i);xp[i]=grid->cgmax(i);}}/*static void ibgTransformBoundingBox(wzgrid grid, wzFloat *xm, wzFloat *xp, wzFloat *xmi, wzFloat *xpi){ wzFloat dd,xc[3],dx[3]; wzIndex i; for(i=0;i<3;i++){ if(xm[i] < grid->cgmin(i)) xm[i] = grid->cgmin(i); if(xp[i] > grid->cgmax(i)) xp[i] = grid->cgmax(i); } dd = 0; for(i=0;i<3;i++){ dx[i] = (xp[i]-xm[i]); xc[i] = 0.5*(xp[i]+xm[i]); if(dd<dx[i]) dd=dx[i]; } for(i=0;i<3;i++){ xm[i] = xc[i]-dd; xp[i] = xc[i]+dd; if(xm[i] < grid->cgmin(i)) xm[i] = grid->cgmin(i); if(xp[i] > grid->cgmax(i)) xp[i] = grid->cgmax(i); } if(iso){ fac[0] = grid->cgmax(0)-grid->cgmin(0); fac[1] = grid->cgmax(1)-grid->cgmin(1); fac[2] = grid->cgmax(2)-grid->cgmin(2); }else{ fac[0]=fac[1]=fac[2]=1; } for(i=0;i<3;i++){ if(fac[i]==0) fac[i]=1; xmi[i] = xm[i]/fac[i]; xpi[i] = xp[i]/fac[i]; }}*/void wzGrid::pg(){ wzOutput& pout = wzOutput::Default; pout("<>D grid, <> nodes, <> cells\n"),gdim(),points.last(),cells.last(); pout(" in [<>,<>]x[<>,<>]x[<>,<>]\n"), cgmin(0),cgmax(0), cgmin(1),cgmax(1), cgmin(2),cgmax(2);}void wzGrid::pr(ibgInteger r){ wzOutput& pout = wzOutput::Default; pout("region <> chosen;\n"),r;}void wzGrid::pf(ibgInteger f){ wzOutput& pout = wzOutput::Default; pout("face <> chosen;\n"),f;}void wzGrid::pn(ibgInteger n){ wzOutput& pout = wzOutput::Default; char* name[4]={"region","face","line","vertex"}; if(n<=0 || n> points.last()){ pout("node <> invalid - last node is <>;\n"),n,points.last(); return; } wzPoint& p = Point[n]; pout("<> (<>) node <> [<>,<>,<>]\n")<<name[p.codim()],p.segment().index(), n,p[0],p[1],p[2];}void wzGrid::pc(ibgInteger c){ int i; wzCellType t; wzOutput& pout = wzOutput::Default; if(c<=0 || c> cells.last()){ pout("cell <> invalid - last cell is <>;\n"),c,cells.last(); return; } pout("<> <> with nodes"),wzCellTypename[t=cct(c)],c; for(i=0;i<wzCellTypepoints[t];i++){ pout(" <>")<<ccn(c)[i]; } pout("<>")<< " and neighbours "; for(i=0;i<wzCellTypesides[t];i++){ pout(" <>")<<ccs(c)[i]; } switch(wzCellTypeCODIM(t)){ case 0: pout("\n in region <>\n")<< (wzIndex)((wzSegment*)&CellSegment[c])->region(); break; case 1: pout("\n on face <>")<< CellSegment[c]; // (wzIndex)((wzSegment*)&CellSegment[c])->face(); pout(" between <>,<>\n")<< ccs(c)[i],ccs(c)[i+1]; break; } pout("<>\n")<< " ";}static void wzGridInfo(wzWindow win, void *data){ wzgrid grid = *(wzgrid *) &data; wzInteger vn,vc,vr,vf; wzInteger obj = wzwGetObject(win); wzwGetInteger(win,obj,ValueNode,&vn); wzwGetInteger(win,obj,ValueCell,&vc); wzwGetInteger(win,obj,ValueRegion,&vr); wzwGetInteger(win,obj,ValueFace,&vf); grid->pg(); if(vn){grid->pn(vn);} if(vc){grid->pc(vc);} if(vr){grid->pr(vr);} if(vf){grid->pf(vf);}}static void ibgBoundingBox(wzWindow win, void *data){ wzFloat xm[3],xp[3],xmi[3],xpi[3];//,dd,xc[3],dx[3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -