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