Actual source code: drect.c

petsc-3.7.0 2016-04-25
Report Typos and Errors
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc/private/drawimpl.h>  /*I "petscdraw.h" I*/


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

 13:    Not collective

 15:    Input Parameter:
 16: +  draw - a PetscDraw
 17: .  xmin,xmax,ymin,ymax - region to draw indicator function
 18: -  f - the indicator function

 20:    Level: developer

 22: @*/
 23: PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw,PetscReal xmin,PetscReal xmax,PetscReal ymin,PetscReal ymax,int c,PetscErrorCode (*indicator)(void*,PetscReal,PetscReal,PetscBool*),void *ctx)
 24: {
 25:   int            i,j,xstart,ystart,xend,yend;
 26:   PetscReal      x,y;
 27:   PetscBool      isnull,flg;

 32:   PetscDrawIsNull(draw,&isnull);
 33:   if (isnull) return(0);

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

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


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

 57:    Not collective

 59:    Input Parameters:
 60: +  draw - the draw where the coordinates are defined
 61: -  x,y - the coordinate location

 63:    Output Parameters:
 64: -  i,j - the pixel location

 66:    Level: developer

 68: @*/
 69: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j)
 70: {

 75:   if (!draw->ops->coordinatetopixel) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support locating pixels",((PetscObject)draw)->type_name);
 76:   (*draw->ops->coordinatetopixel)(draw,x,y,i,j);
 77:   return(0);
 78: }

 82: /*@C
 83:    PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate

 85:    Not collective

 87:    Input Parameters:
 88: +  draw - the draw where the coordinates are defined
 89: -  i,j - the pixel location

 91:    Output Parameters:
 92: .  x,y - the coordinate location

 94:    Level: developer

 96: @*/
 97: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y)
 98: {

103:   if (!draw->ops->pixeltocoordinate) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support locating coordinates",((PetscObject)draw)->type_name);
104:   (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);
105:   return(0);
106: }

110: /*@
111:    PetscDrawRectangle - PetscDraws a rectangle  onto a drawable.

113:    Not Collective

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

120:    Level: beginner

122:    Concepts: drawing^rectangle
123:    Concepts: graphics^rectangle
124:    Concepts: rectangle

126: @*/
127: PetscErrorCode  PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
128: {

133:   if (!draw->ops->rectangle) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing rectangles",((PetscObject)draw)->type_name);
134:   (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);
135:   return(0);
136: }