1 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 2 3 /*@C 4 PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw` 5 6 Not Collective 7 8 Input Parameters: 9 + draw - a `PetscDraw` 10 . xmin - region to draw indicator function 11 . xmax - region to draw indicator function 12 . ymin - region to draw indicator function 13 . ymax - region to draw indicator function 14 - f - the indicator function 15 16 Level: developer 17 18 .seealso: `PetscDraw` 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(PETSC_SUCCESS); 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(PETSC_SUCCESS); 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 { 69 PetscFunctionBegin; 70 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 71 PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j); 72 PetscFunctionReturn(PETSC_SUCCESS); 73 } 74 75 /*@C 76 PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate 77 78 Not Collective 79 80 Input Parameters: 81 + draw - the draw where the coordinates are defined 82 . i - the horizontal pixel location 83 - j - the vertical pixel location 84 85 Output Parameters: 86 + x - the horizontal coordinate 87 - y - the vertical coordinate 88 89 Level: developer 90 91 .seealso: `PetscDraw` 92 @*/ 93 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) 94 { 95 PetscFunctionBegin; 96 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 97 PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y); 98 PetscFunctionReturn(PETSC_SUCCESS); 99 } 100 101 /*@ 102 PetscDrawRectangle - draws a rectangle onto a `PetscDraw` object 103 104 Not Collective 105 106 Input Parameters: 107 + draw - the drawing context 108 . xl - coordinates of the lower left corner 109 . yl - coordinates of the lower left corner 110 . xr - coordinate of the upper right corner 111 . yr - coordinate of the upper right corner 112 . c1 - the color of the first corner 113 . c2 - the color of the second corner 114 . c3 - the color of the third corner 115 - c4 - the color of the fourth corner 116 117 Level: beginner 118 119 .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`, 120 `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()` 121 @*/ 122 PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) 123 { 124 PetscFunctionBegin; 125 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 126 PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4); 127 PetscFunctionReturn(PETSC_SUCCESS); 128 } 129