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: @*/
 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;

 27:   PetscDrawIsNull(draw,&isnull);
 28:   if (isnull) return 0;

 30:   PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart);
 31:   PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,&yend);
 32:   if (yend < ystart) { PetscInt tmp = ystart; ystart = yend; yend = tmp; }

 34:   for (i=xstart; i<=xend; i++) {
 35:     for (j=ystart; j<=yend; j++) {
 36:       PetscDrawPixelToCoordinate(draw,i,j,&x,&y);
 37:       indicator(ctx,x,y,&flg);
 38:       if (flg) {
 39:         PetscDrawPointPixel(draw,i,j,c);
 40:       }
 41:     }
 42:   }
 43:   return 0;
 44: }

 46: /*@C
 47:    PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location

 49:    Not collective

 51:    Input Parameters:
 52: +  draw - the draw where the coordinates are defined
 53: .  x - the horizontal coordinate
 54: -  y - the vertical coordinate

 56:    Output Parameters:
 57: +  i - the horizontal pixel location
 58: -  j - the vertical pixel location

 60:    Level: developer

 62: @*/
 63: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j)
 64: {
 67:   (*draw->ops->coordinatetopixel)(draw,x,y,i,j);
 68:   return 0;
 69: }

 71: /*@C
 72:    PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate

 74:    Not collective

 76:    Input Parameters:
 77: +  draw - the draw where the coordinates are defined
 78: .  i - the horizontal pixel location
 79: -  j - the vertical pixel location

 81:    Output Parameters:
 82: +  x - the horizontal coordinate
 83: -  y - the vertical coordinate

 85:    Level: developer

 87: @*/
 88: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y)
 89: {
 92:   (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);
 93:   return 0;
 94: }

 96: /*@
 97:    PetscDrawRectangle - PetscDraws a rectangle  onto a drawable.

 99:    Not Collective

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

106:    Level: beginner

108: .seealso: PetscDrawLine(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(),
109:           PetscDrawMarker(), PetscDrawPoint(), PetscDrawString(), PetscDrawPoint(), PetscDrawArrow()

111: @*/
112: PetscErrorCode  PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
113: {
116:   (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);
117:   return 0;
118: }