Actual source code: drect.c


  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc/private/drawimpl.h>

  7: /*@C
  8:    PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw`

 10:    Not collective

 12:    Input Parameters:
 13: +  draw - a `PetscDraw`
 14: .  xmin,xmax,ymin,ymax - region to draw indicator function
 15: -  f - the indicator function

 17:    Level: developer

 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: {
 23:   int       i, j, xstart, ystart, xend, yend;
 24:   PetscReal x, y;
 25:   PetscBool isnull, flg;

 27:   PetscFunctionBegin;
 29:   PetscCall(PetscDrawIsNull(draw, &isnull));
 30:   if (isnull) PetscFunctionReturn(PETSC_SUCCESS);

 32:   PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
 33:   PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend));
 34:   if (yend < ystart) {
 35:     PetscInt tmp = ystart;
 36:     ystart       = yend;
 37:     yend         = tmp;
 38:   }

 40:   for (i = xstart; i <= xend; i++) {
 41:     for (j = ystart; j <= yend; j++) {
 42:       PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
 43:       PetscCall(indicator(ctx, x, y, &flg));
 44:       if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
 45:     }
 46:   }
 47:   PetscFunctionReturn(PETSC_SUCCESS);
 48: }

 50: /*@C
 51:    PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location

 53:    Not collective

 55:    Input Parameters:
 56: +  draw - the draw where the coordinates are defined
 57: .  x - the horizontal coordinate
 58: -  y - the vertical coordinate

 60:    Output Parameters:
 61: +  i - the horizontal pixel location
 62: -  j - the vertical pixel location

 64:    Level: developer

 66: .seealso: `PetscDraw`
 67: @*/
 68: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
 69: {
 70:   PetscFunctionBegin;
 72:   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
 73:   PetscFunctionReturn(PETSC_SUCCESS);
 74: }

 76: /*@C
 77:    PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate

 79:    Not collective

 81:    Input Parameters:
 82: +  draw - the draw where the coordinates are defined
 83: .  i - the horizontal pixel location
 84: -  j - the vertical pixel location

 86:    Output Parameters:
 87: +  x - the horizontal coordinate
 88: -  y - the vertical coordinate

 90:    Level: developer

 92: .seealso: `PetscDraw`
 93: @*/
 94: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
 95: {
 96:   PetscFunctionBegin;
 98:   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
 99:   PetscFunctionReturn(PETSC_SUCCESS);
100: }

102: /*@
103:    PetscDrawRectangle - draws a rectangle  onto a drawable.

105:    Not Collective

107:    Input Parameters:
108: +  draw - the drawing context
109: .  xl,yl,xr,yr - the coordinates of the lower left, upper right corners
110: -  c1,c2,c3,c4 - the colors of the four corners in counter clockwise order

112:    Level: beginner

114: .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
115:           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
116: @*/
117: PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
118: {
119:   PetscFunctionBegin;
121:   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
122:   PetscFunctionReturn(PETSC_SUCCESS);
123: }