/*@ PetscDrawScalePopup - PetscDraws a contour scale window. Collective on PetscDraw Input Parameters: + popup - the window (often a window obtained via PetscDrawGetPopup() . min - minimum value being plotted - max - maximum value being plotted Level: intermediate Notes: All processors that share the draw MUST call this routine @*/ PetscErrorCode PetscDrawScalePopup(PetscDraw popup,PetscReal min,PetscReal max) { PetscReal xl = 0.0,yl = 0.0,xr = 2.0,yr = 1.0,value; PetscErrorCode ierr; int i,c = PETSC_DRAW_BASIC_COLORS,rank; char string[32]; MPI_Comm comm; PetscFunctionBegin; ierr = PetscDrawCheckResizedWindow(popup);CHKERRQ(ierr); ierr = PetscObjectGetComm((PetscObject)popup,&comm);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); if (rank) PetscFunctionReturn(0); for (i=0; i<10; i++) { ierr = PetscDrawRectangle(popup,xl,yl,xr,yr,c,c,c,c);CHKERRQ(ierr); yl += .1; yr += .1; c = (int)((double)c + (245. - PETSC_DRAW_BASIC_COLORS)/9.); } for (i=0; i<10; i++) { value = min + i*(max-min)/9.0; /* look for a value that should be zero, but is not due to round-off */ if (PetscAbsReal(value) < 1.e-10 && max-min > 1.e-6) value = 0.0; sprintf(string,"%18.16e",(double)value); ierr = PetscDrawString(popup,.2,.02 + i/10.0,PETSC_DRAW_BLACK,string);CHKERRQ(ierr); } ierr = PetscDrawSetTitle(popup,"Contour Scale");CHKERRQ(ierr); ierr = PetscDrawFlush(popup);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ PetscDrawScalePopup - draws a contour scale window. Collective on PetscDraw Input Parameters: + popup - the window (often a window obtained via PetscDrawGetPopup() . min - minimum value being plotted - max - maximum value being plotted Level: intermediate Notes: All processors that share the draw MUST call this routine .seealso: PetscDrawGetPopup(), PetscDrawTensorContour() @*/ PetscErrorCode PetscDrawScalePopup(PetscDraw popup,PetscReal min,PetscReal max) { PetscBool isnull; PetscReal xl = 0.0,yl = 0.0,xr = 1.0,yr = 1.0; PetscMPIInt rank; PetscErrorCode ierr; int i; char string[32]; PetscFunctionBegin; if (!popup) PetscFunctionReturn(0); PetscValidHeaderSpecific(popup,PETSC_DRAW_CLASSID,1); ierr = PetscDrawIsNull(popup,&isnull); CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)popup),&rank); CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(popup); CHKERRQ(ierr); ierr = PetscDrawClear(popup); CHKERRQ(ierr); ierr = PetscDrawSetTitle(popup,"Contour Scale"); CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(popup,xl,yl,xr,yr); CHKERRQ(ierr); ierr = PetscDrawCollectiveBegin(popup); CHKERRQ(ierr); if (!rank) { for (i=0; i<10; i++) { int c = PetscDrawRealToColor((PetscReal)i/9,0,1); ierr = PetscDrawRectangle(popup,xl,yl,xr,yr,c,c,c,c); CHKERRQ(ierr); yl += 0.1; } for (i=0; i<10; i++) { PetscReal value = min + i*(max-min)/9; /* look for a value that should be zero, but is not due to round-off */ if (PetscAbsReal(value) < 1.e-10 && max-min > 1.e-6) value = 0.0; ierr = PetscSNPrintf(string,sizeof(string),"%18.16e",(double)value); CHKERRQ(ierr); ierr = PetscDrawString(popup,0.2,0.02+i/10.0,PETSC_DRAW_BLACK,string); CHKERRQ(ierr); } } ierr = PetscDrawCollectiveEnd(popup); CHKERRQ(ierr); ierr = PetscDrawFlush(popup); CHKERRQ(ierr); ierr = PetscDrawSave(popup); CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode MatFDColoringView_Draw_Zoom(PetscDraw draw,void *Aa) { MatFDColoring fd = (MatFDColoring)Aa; PetscErrorCode ierr; PetscInt i,j; PetscReal x,y; PetscFunctionBegin; /* loop over colors */ for (i=0; i<fd->ncolors; i++) { for (j=0; j<fd->nrows[i]; j++) { y = fd->M - fd->rows[i][j] - fd->rstart; x = fd->columnsforrow[i][j]; ierr = PetscDrawRectangle(draw,x,y,x+1,y+1,i+1,i+1,i+1,i+1);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
static PetscErrorCode MatFDColoringView_Draw_Zoom(PetscDraw draw,void *Aa) { MatFDColoring fd = (MatFDColoring)Aa; PetscErrorCode ierr; PetscInt i,j,nz,row; PetscReal x,y; MatEntry *Jentry=fd->matentry; PetscFunctionBegin; /* loop over colors */ nz = 0; for (i=0; i<fd->ncolors; i++) { for (j=0; j<fd->nrows[i]; j++) { row = Jentry[nz].row; y = fd->M - row - fd->rstart; x = (PetscReal)Jentry[nz++].col; ierr = PetscDrawRectangle(draw,x,y,x+1,y+1,i+1,i+1,i+1,i+1);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
void PETSC_STDCALL petscdrawrectangle_(PetscDraw draw,PetscReal *xl,PetscReal *yl,PetscReal *xr,PetscReal *yr,int *c1,int *c2,int *c3,int *c4, int *__ierr ){ *__ierr = PetscDrawRectangle( (PetscDraw)PetscToPointer((draw) ),*xl,*yl,*xr,*yr,*c1,*c2,*c3,*c4); }
/*@ PetscDrawBarDraw - Redraws a bar graph. Collective on PetscDrawBar Input Parameter: . bar - The bar graph context Level: intermediate .seealso: PetscDrawBar, PetscDrawBarCreate(), PetscDrawBarSetData() @*/ PetscErrorCode PetscDrawBarDraw(PetscDrawBar bar) { PetscDraw draw; PetscBool isnull; PetscReal xmin,xmax,ymin,ymax,*values,binLeft,binRight; PetscInt numValues,i,bcolor,color,idx,*perm,nplot; PetscMPIInt rank; PetscErrorCode ierr; char **labels; PetscFunctionBegin; PetscValidHeaderSpecific(bar,PETSC_DRAWBAR_CLASSID,1); ierr = PetscDrawIsNull(bar->win,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)bar),&rank);CHKERRQ(ierr); if (bar->numBins < 1) PetscFunctionReturn(0); color = bar->color; if (color == PETSC_DRAW_ROTATE) bcolor = PETSC_DRAW_BLACK+1; else bcolor = color; numValues = bar->numBins; values = bar->values; if (bar->ymin == bar->ymax) { /* user has not set bounds on bars so set them based on the data */ ymin = PETSC_MAX_REAL; ymax = PETSC_MIN_REAL; for (i=0; i<numValues; i++) { ymin = PetscMin(ymin,values[i]); ymax = PetscMax(ymax,values[i]); } } else { ymin = bar->ymin; ymax = bar->ymax; } nplot = numValues; /* number of points to actually plot; if some are lower than requested tolerance */ xmin = 0.0; xmax = nplot; labels = bar->labels; if (bar->sort) { ierr = PetscMalloc1(numValues,&perm);CHKERRQ(ierr); for (i=0; i<numValues;i++) perm[i] = i; ierr = PetscSortRealWithPermutation(numValues,values,perm);CHKERRQ(ierr); if (bar->sorttolerance) { for (i=0; i<numValues;i++) { if (values[perm[numValues - i - 1]] < bar->sorttolerance) { nplot = i; break; } } } } draw = bar->win; ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); ierr = PetscDrawAxisSetLimits(bar->axis,xmin,xmax,ymin,ymax);CHKERRQ(ierr); ierr = PetscDrawAxisDraw(bar->axis);CHKERRQ(ierr); ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr); if (!rank) { /* Draw bins */ for (i=0; i<nplot; i++) { idx = (bar->sort ? perm[numValues - i - 1] : i); binLeft = xmin + i; binRight = xmin + i + 1; ierr = PetscDrawRectangle(draw,binLeft,ymin,binRight,values[idx],bcolor,bcolor,bcolor,bcolor);CHKERRQ(ierr); ierr = PetscDrawLine(draw,binLeft,ymin,binLeft,values[idx],PETSC_DRAW_BLACK);CHKERRQ(ierr); ierr = PetscDrawLine(draw,binRight,ymin,binRight,values[idx],PETSC_DRAW_BLACK);CHKERRQ(ierr); ierr = PetscDrawLine(draw,binLeft,values[idx],binRight,values[idx],PETSC_DRAW_BLACK);CHKERRQ(ierr); if (labels) { PetscReal h; ierr = PetscDrawStringGetSize(draw,NULL,&h);CHKERRQ(ierr); ierr = PetscDrawStringCentered(draw,.5*(binLeft+binRight),ymin - 1.5*h,bcolor,labels[idx]);CHKERRQ(ierr); } if (color == PETSC_DRAW_ROTATE) bcolor++; if (bcolor > PETSC_DRAW_BASIC_COLORS-1) bcolor = PETSC_DRAW_BLACK+1; } } ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr); if (bar->sort) {ierr = PetscFree(perm);CHKERRQ(ierr);} ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); PetscFunctionReturn(0); }
int main(int argc,char **argv) { PetscDraw draw; PetscErrorCode ierr; int i,j,w,h; int k = PETSC_DRAW_BLACK; int r = PETSC_DRAW_RED; int g = PETSC_DRAW_GREEN; int b = PETSC_DRAW_BLUE; int y = PETSC_DRAW_YELLOW; int c0 = PETSC_DRAW_BASIC_COLORS; int c2 = 255; int c1 = (c0+c2)/2; ierr = PetscInitialize(&argc,&argv,NULL,help);CHKERRQ(ierr); ierr = PetscDrawCreate(PETSC_COMM_WORLD,0,"Draw Example",PETSC_DECIDE,PETSC_DECIDE,101,101,&draw);CHKERRQ(ierr); /*ierr = PetscDrawSetPause(draw,2.0);CHKERRQ(ierr);*/ ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawGetWindowSize(draw,&w,&h);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,0,0,--w,--h);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); /* one-pixel lines in the window corners */ ierr = PetscDrawLine(draw,0,0,0,0,r);CHKERRQ(ierr); ierr = PetscDrawLine(draw,w,0,w,0,r);CHKERRQ(ierr); ierr = PetscDrawLine(draw,0,h,0,h,r);CHKERRQ(ierr); ierr = PetscDrawLine(draw,w,h,w,h,r);CHKERRQ(ierr); /* border lines with two pixels from borders */ ierr = PetscDrawLine(draw,0+2,0,w-2,0,k);CHKERRQ(ierr); ierr = PetscDrawLine(draw,0+2,h,w-2,h,k);CHKERRQ(ierr); ierr = PetscDrawLine(draw,0,0+2,0,h-2,k);CHKERRQ(ierr); ierr = PetscDrawLine(draw,w,0+2,w,h-2,k);CHKERRQ(ierr); /* oblique lines */ ierr = PetscDrawLine(draw,0+2,h/2,w-2,h-2,b);CHKERRQ(ierr); ierr = PetscDrawLine(draw,0+1,h-1,w-1,0+1,b);CHKERRQ(ierr); /* vertical up and down arrow, two pixels from borders */ ierr = PetscDrawArrow(draw,1*w/4,0+2,1*w/4,h-2,g);CHKERRQ(ierr); ierr = PetscDrawArrow(draw,3*w/4,h-2,3*w/4,0+2,g);CHKERRQ(ierr); /* horizontal right and left arrow, two pixels from borders */ ierr = PetscDrawArrow(draw,0+2,3*h/4,w-2,3*h/4,g);CHKERRQ(ierr); ierr = PetscDrawArrow(draw,w-2,1*h/4,0+2,1*h/4,g);CHKERRQ(ierr); /* flush, save, and pause */ ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawSave(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawGetWindowSize(draw,&w,&h);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,0,0,--w,--h);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); /* one-pixel rectangles in the window corners */ ierr = PetscDrawRectangle(draw,0,0,0,0,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,w,0,w,0,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,0,h,0,h,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,w,h,w,h,k,k,k,k);CHKERRQ(ierr); /* border rectangles with two pixels from borders */ ierr = PetscDrawRectangle(draw,0+2,0,w-2,0,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,0+2,h,w-2,h,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,0,0+2,0,h-2,k,k,k,k);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,w,0+2,w,h-2,k,k,k,k);CHKERRQ(ierr); /* more rectangles */ ierr = PetscDrawRectangle(draw,0+2,0+2,w/2-1,h/2-1,b,b,b,b);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,0+2,h/2+1,w/2-1,h-2,r,r,r,r);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,w/2+1,h/2+1,w-2,h-2,g,g,g,g);CHKERRQ(ierr); ierr = PetscDrawRectangle(draw,w/2+1,0+2,w-2,h/2-1,y,y,y,y);CHKERRQ(ierr); /* flush, save, and pause */ ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawSave(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawGetWindowSize(draw,&w,&h);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,0,0,--w,--h);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); /* interpolated triangles, one pixel from borders */ ierr = PetscDrawTriangle(draw,0+1,0+1,w-1,0+1,w-1,h-1,c0,c1,c2);CHKERRQ(ierr); ierr = PetscDrawTriangle(draw,0+1,0+1,0+1,h-1,w-1,h-1,c0,c1,c2);CHKERRQ(ierr); /* interpolated triangle, oblique, inside canvas */ ierr = PetscDrawTriangle(draw,w/4,h/4,w/2,3*h/4,3*w/4,h/2,c2,c1,c0);CHKERRQ(ierr); /* flush, save, and pause */ ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawSave(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr); ierr = PetscDrawGetWindowSize(draw,&w,&h);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,0,0,--w,--h);CHKERRQ(ierr); ierr = PetscDrawClear(draw);CHKERRQ(ierr); /* circles and ellipses */ ierr = PetscDrawEllipse(draw,w/2,h/2,w-1,h-1,r);CHKERRQ(ierr); ierr = PetscDrawEllipse(draw,w,h/2,w/2,h,g);CHKERRQ(ierr); ierr = PetscDrawEllipse(draw,0,0,w,h/2,b);CHKERRQ(ierr); ierr = PetscDrawEllipse(draw,w/4,3*h/4,w/2,h/4,y);CHKERRQ(ierr); ierr = PetscDrawCoordinateToPixel(draw,w/2,h/2,&i,&j);CHKERRQ(ierr); ierr = PetscDrawPointPixel(draw,i,j,k);CHKERRQ(ierr); /* flush, save, and pause */ ierr = PetscDrawFlush(draw);CHKERRQ(ierr); ierr = PetscDrawSave(draw);CHKERRQ(ierr); ierr = PetscDrawPause(draw);CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }