Actual source code: drect.c

petsc-3.10.5 2019-03-28
Report Typos and Errors

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


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

 11:    Not collective

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

 18:    Level: developer

 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;

 30:   PetscDrawIsNull(draw,&isnull);
 31:   if (isnull) return(0);

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

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


 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,y - the coordinate location

 59:    Output Parameters:
 60: -  i,j - the pixel location

 62:    Level: developer

 64: @*/
 65: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j)
 66: {

 71:   if (!draw->ops->coordinatetopixel) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support locating pixels",((PetscObject)draw)->type_name);
 72:   (*draw->ops->coordinatetopixel)(draw,x,y,i,j);
 73:   return(0);
 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,j - the pixel location

 85:    Output Parameters:
 86: .  x,y - the coordinate location

 88:    Level: developer

 90: @*/
 91: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y)
 92: {

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

102: /*@
103:    PetscDrawRectangle - PetscDraws 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:    Concepts: drawing^rectangle
115:    Concepts: graphics^rectangle
116:    Concepts: rectangle

118: .seealso: PetscDrawLine(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(),
119:           PetscDrawMarker(), PetscDrawPoint(), PetscDrawString(), PetscDrawPoint(), PetscDrawArrow()

121: @*/
122: PetscErrorCode  PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
123: {

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