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