1 2 /* 3 Provides the calling sequences for all the basic PetscDraw routines. 4 */ 5 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 6 7 /*@C 8 PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a PetscDraw 9 10 Not collective 11 12 Input Parameters: 13 + draw - a PetscDraw 14 . xmin,xmax,ymin,ymax - region to draw indicator function 15 - f - the indicator function 16 17 Level: developer 18 19 @*/ 20 PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw,PetscReal xmin,PetscReal xmax,PetscReal ymin,PetscReal ymax,int c,PetscErrorCode (*indicator)(void*,PetscReal,PetscReal,PetscBool*),void *ctx) 21 { 22 int i,j,xstart,ystart,xend,yend; 23 PetscReal x,y; 24 PetscBool isnull,flg; 25 26 PetscFunctionBegin; 27 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 28 PetscCall(PetscDrawIsNull(draw,&isnull)); 29 if (isnull) PetscFunctionReturn(0); 30 31 PetscCall(PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart)); 32 PetscCall(PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,¥d)); 33 if (yend < ystart) { PetscInt tmp = ystart; ystart = yend; yend = tmp; } 34 35 for (i=xstart; i<=xend; i++) { 36 for (j=ystart; j<=yend; j++) { 37 PetscCall(PetscDrawPixelToCoordinate(draw,i,j,&x,&y)); 38 PetscCall(indicator(ctx,x,y,&flg)); 39 if (flg) PetscCall(PetscDrawPointPixel(draw,i,j,c)); 40 } 41 } 42 PetscFunctionReturn(0); 43 } 44 45 /*@C 46 PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location 47 48 Not collective 49 50 Input Parameters: 51 + draw - the draw where the coordinates are defined 52 . x - the horizontal coordinate 53 - y - the vertical coordinate 54 55 Output Parameters: 56 + i - the horizontal pixel location 57 - j - the vertical pixel location 58 59 Level: developer 60 61 @*/ 62 PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j) 63 { 64 PetscFunctionBegin; 65 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 66 PetscUseTypeMethod(draw,coordinatetopixel ,x,y,i,j); 67 PetscFunctionReturn(0); 68 } 69 70 /*@C 71 PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate 72 73 Not collective 74 75 Input Parameters: 76 + draw - the draw where the coordinates are defined 77 . i - the horizontal pixel location 78 - j - the vertical pixel location 79 80 Output Parameters: 81 + x - the horizontal coordinate 82 - y - the vertical coordinate 83 84 Level: developer 85 86 @*/ 87 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y) 88 { 89 PetscFunctionBegin; 90 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 91 PetscUseTypeMethod(draw,pixeltocoordinate ,i,j,x,y); 92 PetscFunctionReturn(0); 93 } 94 95 /*@ 96 PetscDrawRectangle - PetscDraws a rectangle onto a drawable. 97 98 Not Collective 99 100 Input Parameters: 101 + draw - the drawing context 102 . xl,yl,xr,yr - the coordinates of the lower left, upper right corners 103 - c1,c2,c3,c4 - the colors of the four corners in counter clockwise order 104 105 Level: beginner 106 107 .seealso: `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`, 108 `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()` 109 110 @*/ 111 PetscErrorCode PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4) 112 { 113 PetscFunctionBegin; 114 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 115 PetscUseTypeMethod(draw,rectangle ,xl,yl,xr,yr,c1,c2,c3,c4); 116 PetscFunctionReturn(0); 117 } 118