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 .seealso: `PetscDraw` 20 @*/ 21 PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx) 22 { 23 int i, j, xstart, ystart, xend, yend; 24 PetscReal x, y; 25 PetscBool isnull, flg; 26 27 PetscFunctionBegin; 28 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 29 PetscCall(PetscDrawIsNull(draw, &isnull)); 30 if (isnull) PetscFunctionReturn(PETSC_SUCCESS); 31 32 PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart)); 33 PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, ¥d)); 34 if (yend < ystart) { 35 PetscInt tmp = ystart; 36 ystart = yend; 37 yend = tmp; 38 } 39 40 for (i = xstart; i <= xend; i++) { 41 for (j = ystart; j <= yend; j++) { 42 PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y)); 43 PetscCall(indicator(ctx, x, y, &flg)); 44 if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c)); 45 } 46 } 47 PetscFunctionReturn(PETSC_SUCCESS); 48 } 49 50 /*@C 51 PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location 52 53 Not collective 54 55 Input Parameters: 56 + draw - the draw where the coordinates are defined 57 . x - the horizontal coordinate 58 - y - the vertical coordinate 59 60 Output Parameters: 61 + i - the horizontal pixel location 62 - j - the vertical pixel location 63 64 Level: developer 65 66 .seealso: `PetscDraw` 67 @*/ 68 PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) 69 { 70 PetscFunctionBegin; 71 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 72 PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j); 73 PetscFunctionReturn(PETSC_SUCCESS); 74 } 75 76 /*@C 77 PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate 78 79 Not collective 80 81 Input Parameters: 82 + draw - the draw where the coordinates are defined 83 . i - the horizontal pixel location 84 - j - the vertical pixel location 85 86 Output Parameters: 87 + x - the horizontal coordinate 88 - y - the vertical coordinate 89 90 Level: developer 91 92 .seealso: `PetscDraw` 93 @*/ 94 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) 95 { 96 PetscFunctionBegin; 97 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 98 PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y); 99 PetscFunctionReturn(PETSC_SUCCESS); 100 } 101 102 /*@ 103 PetscDrawRectangle - draws a rectangle onto a drawable. 104 105 Not Collective 106 107 Input Parameters: 108 + draw - the drawing context 109 . xl,yl,xr,yr - the coordinates of the lower left, upper right corners 110 - c1,c2,c3,c4 - the colors of the four corners in counter clockwise order 111 112 Level: beginner 113 114 .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`, 115 `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()` 116 @*/ 117 PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) 118 { 119 PetscFunctionBegin; 120 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 121 PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4); 122 PetscFunctionReturn(PETSC_SUCCESS); 123 } 124