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` 10*2fe279fdSBarry Smith . xmin - region to draw indicator function 11*2fe279fdSBarry Smith . xmax - region to draw indicator function 12*2fe279fdSBarry Smith . ymin - region to draw indicator function 13*2fe279fdSBarry Smith . ymax - region to draw indicator function 145c6c1daeSBarry Smith - f - the indicator function 155c6c1daeSBarry Smith 165c6c1daeSBarry Smith Level: developer 175c6c1daeSBarry Smith 18811af0c4SBarry Smith .seealso: `PetscDraw` 195c6c1daeSBarry Smith @*/ 20d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx) 21d71ae5a4SJacob Faibussowitsch { 22a7e8706aSLisandro Dalcin int i, j, xstart, ystart, xend, yend; 235c6c1daeSBarry Smith PetscReal x, y; 245c6c1daeSBarry Smith PetscBool isnull, flg; 255c6c1daeSBarry Smith 265c6c1daeSBarry Smith PetscFunctionBegin; 275c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 289566063dSJacob Faibussowitsch PetscCall(PetscDrawIsNull(draw, &isnull)); 293ba16761SJacob Faibussowitsch if (isnull) PetscFunctionReturn(PETSC_SUCCESS); 305c6c1daeSBarry Smith 319566063dSJacob Faibussowitsch PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart)); 329566063dSJacob Faibussowitsch PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, ¥d)); 339371c9d4SSatish Balay if (yend < ystart) { 349371c9d4SSatish Balay PetscInt tmp = ystart; 359371c9d4SSatish Balay ystart = yend; 369371c9d4SSatish Balay yend = tmp; 379371c9d4SSatish Balay } 3845f3bb6eSLisandro Dalcin 3945f3bb6eSLisandro Dalcin for (i = xstart; i <= xend; i++) { 4045f3bb6eSLisandro Dalcin for (j = ystart; j <= yend; j++) { 419566063dSJacob Faibussowitsch PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y)); 429566063dSJacob Faibussowitsch PetscCall(indicator(ctx, x, y, &flg)); 431baa6e33SBarry Smith if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c)); 445c6c1daeSBarry Smith } 455c6c1daeSBarry Smith } 463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 475c6c1daeSBarry Smith } 485c6c1daeSBarry Smith 495c6c1daeSBarry Smith /*@C 50811af0c4SBarry Smith PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location 515c6c1daeSBarry Smith 5220f4b53cSBarry Smith Not Collective 535c6c1daeSBarry Smith 545c6c1daeSBarry Smith Input Parameters: 555c6c1daeSBarry Smith + draw - the draw where the coordinates are defined 566b867d5aSJose E. Roman . x - the horizontal coordinate 576b867d5aSJose E. Roman - y - the vertical coordinate 585c6c1daeSBarry Smith 595c6c1daeSBarry Smith Output Parameters: 606b867d5aSJose E. Roman + i - the horizontal pixel location 616b867d5aSJose E. Roman - j - the vertical pixel location 625c6c1daeSBarry Smith 635c6c1daeSBarry Smith Level: developer 645c6c1daeSBarry Smith 65811af0c4SBarry Smith .seealso: `PetscDraw` 665c6c1daeSBarry Smith @*/ 67d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) 68d71ae5a4SJacob Faibussowitsch { 695c6c1daeSBarry Smith PetscFunctionBegin; 705c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 71dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j); 723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 735c6c1daeSBarry Smith } 745c6c1daeSBarry Smith 755c6c1daeSBarry Smith /*@C 76811af0c4SBarry Smith PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate 775c6c1daeSBarry Smith 7820f4b53cSBarry Smith Not Collective 795c6c1daeSBarry Smith 805c6c1daeSBarry Smith Input Parameters: 815c6c1daeSBarry Smith + draw - the draw where the coordinates are defined 826b867d5aSJose E. Roman . i - the horizontal pixel location 836b867d5aSJose E. Roman - j - the vertical pixel location 845c6c1daeSBarry Smith 855c6c1daeSBarry Smith Output Parameters: 866b867d5aSJose E. Roman + x - the horizontal coordinate 876b867d5aSJose E. Roman - y - the vertical coordinate 885c6c1daeSBarry Smith 895c6c1daeSBarry Smith Level: developer 905c6c1daeSBarry Smith 91811af0c4SBarry Smith .seealso: `PetscDraw` 925c6c1daeSBarry Smith @*/ 93d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) 94d71ae5a4SJacob Faibussowitsch { 955c6c1daeSBarry Smith PetscFunctionBegin; 965c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 97dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y); 983ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 995c6c1daeSBarry Smith } 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith /*@ 102*2fe279fdSBarry Smith PetscDrawRectangle - draws a rectangle onto a `PetscDraw` object 1035c6c1daeSBarry Smith 1045c6c1daeSBarry Smith Not Collective 1055c6c1daeSBarry Smith 1065c6c1daeSBarry Smith Input Parameters: 1075c6c1daeSBarry Smith + draw - the drawing context 108*2fe279fdSBarry Smith . xl - coordinates of the lower left corner 109*2fe279fdSBarry Smith . yl - coordinates of the lower left corner 110*2fe279fdSBarry Smith . xr - coordinate of the upper right corner 111*2fe279fdSBarry Smith . yr - coordinate of the upper right corner 112*2fe279fdSBarry Smith . c1 - the color of the first corner 113*2fe279fdSBarry Smith . c2 - the color of the second corner 114*2fe279fdSBarry Smith . c3 - the color of the third corner 115*2fe279fdSBarry Smith - c4 - the color of the fourth corner 1165c6c1daeSBarry Smith 1175c6c1daeSBarry Smith Level: beginner 1185c6c1daeSBarry Smith 119811af0c4SBarry Smith .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`, 120db781477SPatrick Sanan `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()` 1215c6c1daeSBarry Smith @*/ 122d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) 123d71ae5a4SJacob Faibussowitsch { 1245c6c1daeSBarry Smith PetscFunctionBegin; 1255c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 126dbbe0bcdSBarry Smith PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4); 1273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1285c6c1daeSBarry Smith } 129