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;
29: PetscDrawIsNull(draw,&isnull);
30: if (isnull) return(0);
32: PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart);
33: PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,¥d);
34: if (yend < ystart) { PetscInt tmp = ystart; ystart = yend; yend = tmp; }
36: for (i=xstart; i<=xend; i++) {
37: for (j=ystart; j<=yend; j++) {
38: PetscDrawPixelToCoordinate(draw,i,j,&x,&y);
39: indicator(ctx,x,y,&flg);
40: if (flg) {
41: PetscDrawPointPixel(draw,i,j,c);
42: }
43: }
44: }
45: return(0);
46: }
48: /*@C
49: PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location
51: Not collective
53: Input Parameters:
54: + draw - the draw where the coordinates are defined
55: . x - the horizontal coordinate
56: - y - the vertical coordinate
58: Output Parameters:
59: + i - the horizontal pixel location
60: - j - the vertical 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 - 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: @*/
93: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y)
94: {
99: if (!draw->ops->pixeltocoordinate) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support locating coordinates",((PetscObject)draw)->type_name);
100: (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);
101: return(0);
102: }
104: /*@
105: PetscDrawRectangle - PetscDraws a rectangle onto a drawable.
107: Not Collective
109: Input Parameters:
110: + draw - the drawing context
111: . xl,yl,xr,yr - the coordinates of the lower left, upper right corners
112: - c1,c2,c3,c4 - the colors of the four corners in counter clockwise order
114: Level: beginner
116: .seealso: PetscDrawLine(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(),
117: PetscDrawMarker(), PetscDrawPoint(), PetscDrawString(), PetscDrawPoint(), PetscDrawArrow()
119: @*/
120: PetscErrorCode PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
121: {
126: if (!draw->ops->rectangle) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing rectangles",((PetscObject)draw)->type_name);
127: (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);
128: return(0);
129: }