1 2 /* 3 Provides the calling sequences for all the basic PetscDraw routines. 4 */ 5 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 6 7 8 /*@C 9 PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a PetscDraw 10 11 Not collective 12 13 Input Parameter: 14 + draw - a PetscDraw 15 . xmin,xmax,ymin,ymax - region to draw indicator function 16 - f - the indicator function 17 18 Level: developer 19 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; 26 PetscErrorCode ierr; 27 28 PetscFunctionBegin; 29 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 30 ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); 31 if (isnull) PetscFunctionReturn(0); 32 33 ierr = PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart);CHKERRQ(ierr); 34 ierr = PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,¥d);CHKERRQ(ierr); 35 if (yend < ystart) { PetscInt tmp = ystart; ystart = yend; yend = tmp; } 36 37 for (i=xstart; i<=xend; i++) { 38 for (j=ystart; j<=yend; j++) { 39 ierr = PetscDrawPixelToCoordinate(draw,i,j,&x,&y);CHKERRQ(ierr); 40 ierr = indicator(ctx,x,y,&flg);CHKERRQ(ierr); 41 if (flg) { 42 ierr = PetscDrawPointPixel(draw,i,j,c);CHKERRQ(ierr); 43 } 44 } 45 } 46 PetscFunctionReturn(0); 47 } 48 49 50 /*@C 51 PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location 52 53 Not collective 54 55 Input Parameters: 56 + draw - the draw where the coordinates are defined 57 - x,y - the coordinate location 58 59 Output Parameters: 60 - i,j - the pixel location 61 62 Level: developer 63 64 @*/ 65 PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j) 66 { 67 PetscErrorCode ierr; 68 69 PetscFunctionBegin; 70 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 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 ierr = (*draw->ops->coordinatetopixel)(draw,x,y,i,j);CHKERRQ(ierr); 73 PetscFunctionReturn(0); 74 } 75 76 /*@C 77 PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate 78 79 Not collective 80 81 Input Parameters: 82 + draw - the draw where the coordinates are defined 83 - i,j - the pixel location 84 85 Output Parameters: 86 . x,y - the coordinate location 87 88 Level: developer 89 90 @*/ 91 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y) 92 { 93 PetscErrorCode ierr; 94 95 PetscFunctionBegin; 96 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 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 ierr = (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);CHKERRQ(ierr); 99 PetscFunctionReturn(0); 100 } 101 102 /*@ 103 PetscDrawRectangle - PetscDraws a rectangle onto a drawable. 104 105 Not Collective 106 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 111 112 Level: beginner 113 114 .seealso: PetscDrawLine(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(), 115 PetscDrawMarker(), PetscDrawPoint(), PetscDrawString(), PetscDrawPoint(), PetscDrawArrow() 116 117 @*/ 118 PetscErrorCode PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4) 119 { 120 PetscErrorCode ierr; 121 122 PetscFunctionBegin; 123 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 124 if (!draw->ops->rectangle) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing rectangles",((PetscObject)draw)->type_name); 125 ierr = (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);CHKERRQ(ierr); 126 PetscFunctionReturn(0); 127 } 128