1af0996ceSBarry Smith #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/
25c6c1daeSBarry Smith
35c6c1daeSBarry Smith /*@C
4811af0c4SBarry Smith PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw`
55c6c1daeSBarry Smith
620f4b53cSBarry Smith Not Collective
75c6c1daeSBarry Smith
8d8d19677SJose E. Roman Input Parameters:
9811af0c4SBarry Smith + draw - a `PetscDraw`
102fe279fdSBarry Smith . xmin - region to draw indicator function
112fe279fdSBarry Smith . xmax - region to draw indicator function
122fe279fdSBarry Smith . ymin - region to draw indicator function
132fe279fdSBarry Smith . ymax - region to draw indicator function
1410450e9eSJacob Faibussowitsch . c - the color of the region
1510450e9eSJacob Faibussowitsch . indicator - the indicator function
1610450e9eSJacob Faibussowitsch - ctx - the context to pass to the indicator function
175c6c1daeSBarry Smith
185c6c1daeSBarry Smith Level: developer
195c6c1daeSBarry Smith
20811af0c4SBarry Smith .seealso: `PetscDraw`
215c6c1daeSBarry Smith @*/
PetscDrawIndicatorFunction(PetscDraw draw,PetscReal xmin,PetscReal xmax,PetscReal ymin,PetscReal ymax,int c,PetscErrorCode (* indicator)(void *,PetscReal,PetscReal,PetscBool *),PetscCtx ctx)22*2a8381b2SBarry Smith PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), PetscCtx ctx)
23d71ae5a4SJacob Faibussowitsch {
24a7e8706aSLisandro Dalcin int i, j, xstart, ystart, xend, yend;
255c6c1daeSBarry Smith PetscReal x, y;
265c6c1daeSBarry Smith PetscBool isnull, flg;
275c6c1daeSBarry Smith
285c6c1daeSBarry Smith PetscFunctionBegin;
295c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
309566063dSJacob Faibussowitsch PetscCall(PetscDrawIsNull(draw, &isnull));
313ba16761SJacob Faibussowitsch if (isnull) PetscFunctionReturn(PETSC_SUCCESS);
325c6c1daeSBarry Smith
339566063dSJacob Faibussowitsch PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
349566063dSJacob Faibussowitsch PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, ¥d));
359371c9d4SSatish Balay if (yend < ystart) {
366497c311SBarry Smith int tmp = ystart;
379371c9d4SSatish Balay ystart = yend;
389371c9d4SSatish Balay yend = tmp;
399371c9d4SSatish Balay }
4045f3bb6eSLisandro Dalcin
4145f3bb6eSLisandro Dalcin for (i = xstart; i <= xend; i++) {
4245f3bb6eSLisandro Dalcin for (j = ystart; j <= yend; j++) {
439566063dSJacob Faibussowitsch PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
449566063dSJacob Faibussowitsch PetscCall(indicator(ctx, x, y, &flg));
451baa6e33SBarry Smith if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
465c6c1daeSBarry Smith }
475c6c1daeSBarry Smith }
483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
495c6c1daeSBarry Smith }
505c6c1daeSBarry Smith
51cc4c1da9SBarry Smith /*@
52811af0c4SBarry Smith PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location
535c6c1daeSBarry Smith
5420f4b53cSBarry Smith Not Collective
555c6c1daeSBarry Smith
565c6c1daeSBarry Smith Input Parameters:
575c6c1daeSBarry Smith + draw - the draw where the coordinates are defined
586b867d5aSJose E. Roman . x - the horizontal coordinate
596b867d5aSJose E. Roman - y - the vertical coordinate
605c6c1daeSBarry Smith
615c6c1daeSBarry Smith Output Parameters:
626b867d5aSJose E. Roman + i - the horizontal pixel location
636b867d5aSJose E. Roman - j - the vertical pixel location
645c6c1daeSBarry Smith
655c6c1daeSBarry Smith Level: developer
665c6c1daeSBarry Smith
67811af0c4SBarry Smith .seealso: `PetscDraw`
685c6c1daeSBarry Smith @*/
PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int * i,int * j)69d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
70d71ae5a4SJacob Faibussowitsch {
715c6c1daeSBarry Smith PetscFunctionBegin;
725c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
73dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
743ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
755c6c1daeSBarry Smith }
765c6c1daeSBarry Smith
77cc4c1da9SBarry Smith /*@
78811af0c4SBarry Smith PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate
795c6c1daeSBarry Smith
8020f4b53cSBarry Smith Not Collective
815c6c1daeSBarry Smith
825c6c1daeSBarry Smith Input Parameters:
835c6c1daeSBarry Smith + draw - the draw where the coordinates are defined
846b867d5aSJose E. Roman . i - the horizontal pixel location
856b867d5aSJose E. Roman - j - the vertical pixel location
865c6c1daeSBarry Smith
875c6c1daeSBarry Smith Output Parameters:
886b867d5aSJose E. Roman + x - the horizontal coordinate
896b867d5aSJose E. Roman - y - the vertical coordinate
905c6c1daeSBarry Smith
915c6c1daeSBarry Smith Level: developer
925c6c1daeSBarry Smith
93811af0c4SBarry Smith .seealso: `PetscDraw`
945c6c1daeSBarry Smith @*/
PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal * x,PetscReal * y)95d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
96d71ae5a4SJacob Faibussowitsch {
975c6c1daeSBarry Smith PetscFunctionBegin;
985c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
99dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
1003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1015c6c1daeSBarry Smith }
1025c6c1daeSBarry Smith
1035c6c1daeSBarry Smith /*@
1042fe279fdSBarry Smith PetscDrawRectangle - draws a rectangle onto a `PetscDraw` object
1055c6c1daeSBarry Smith
1065c6c1daeSBarry Smith Not Collective
1075c6c1daeSBarry Smith
1085c6c1daeSBarry Smith Input Parameters:
1095c6c1daeSBarry Smith + draw - the drawing context
1102fe279fdSBarry Smith . xl - coordinates of the lower left corner
1112fe279fdSBarry Smith . yl - coordinates of the lower left corner
1122fe279fdSBarry Smith . xr - coordinate of the upper right corner
1132fe279fdSBarry Smith . yr - coordinate of the upper right corner
1142fe279fdSBarry Smith . c1 - the color of the first corner
1152fe279fdSBarry Smith . c2 - the color of the second corner
1162fe279fdSBarry Smith . c3 - the color of the third corner
1172fe279fdSBarry Smith - c4 - the color of the fourth corner
1185c6c1daeSBarry Smith
1195c6c1daeSBarry Smith Level: beginner
1205c6c1daeSBarry Smith
12142747ad1SJacob Faibussowitsch .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
122aec76313SJacob Faibussowitsch `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawArrow()`
1235c6c1daeSBarry Smith @*/
PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)124d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
125d71ae5a4SJacob Faibussowitsch {
1265c6c1daeSBarry Smith PetscFunctionBegin;
1275c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
128dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
1293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1305c6c1daeSBarry Smith }
131