Actual source code: drect.c
petsc-3.5.4 2015-05-23
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 (*f)(void*,PetscReal,PetscReal,PetscBool*),void *ctx)
24: {
25: PetscInt xstart,ystart,xend,yend,i,j,tmp;
27: PetscReal x,y;
28: PetscBool isnull,flg;
32: PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
33: if (isnull) return(0);
35: PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart);
36: PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,¥d);
37: if (yend < ystart) {
38: tmp = ystart;
39: ystart = yend;
40: yend = tmp;
41: }
42: for (i=xstart; i<xend+1; i++) {
43: for (j=ystart; j<yend+1; j++) {
44: PetscDrawPixelToCoordinate(draw,i,j,&x,&y);
45: f(ctx,x,y,&flg);
46: if (flg) {
47: PetscDrawPointPixel(draw,i,j,c);
48: }
49: }
50: }
51: return(0);
52: }
57: /*@C
58: PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location
60: Not collective
62: Input Parameters:
63: + draw - the draw where the coordinates are defined
64: - x,y - the coordinate location
66: Output Parameters:
67: - i,j - the pixel location
69: Level: developer
71: @*/
72: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,PetscInt *i,PetscInt *j)
73: {
75: PetscBool isnull;
79: PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
80: if (isnull) return(0);
81: if (!draw->ops->coordinatetopixel) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_SUP,"No support for locating pixel");
82: (*draw->ops->coordinatetopixel)(draw,x,y,i,j);
83: return(0);
84: }
88: /*@C
89: PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate
91: Not collective
93: Input Parameters:
94: + draw - the draw where the coordinates are defined
95: - i,j - the pixel location
97: Output Parameters:
98: . x,y - the coordinate location
100: Level: developer
102: @*/
103: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,PetscInt i,PetscInt j,PetscReal *x,PetscReal *y)
104: {
106: PetscBool isnull;
110: PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
111: if (isnull) return(0);
112: if (!draw->ops->pixeltocoordinate) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_SUP,"No support for locating coordiante from ");
113: (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);
114: return(0);
115: }
119: /*@
120: PetscDrawRectangle - PetscDraws a rectangle onto a drawable.
122: Not Collective
124: Input Parameters:
125: + draw - the drawing context
126: . xl,yl,xr,yr - the coordinates of the lower left, upper right corners
127: - c1,c2,c3,c4 - the colors of the four corners in counter clockwise order
129: Level: beginner
131: Concepts: drawing^rectangle
132: Concepts: graphics^rectangle
133: Concepts: rectangle
135: @*/
136: PetscErrorCode PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
137: {
139: PetscBool isnull;
143: PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
144: if (isnull) return(0);
145: if (!draw->ops->rectangle) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_SUP,"No support for drawing rectangle");
146: (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);
147: return(0);
148: }
152: /*@
153: PetscDrawSave - Saves a drawn image
155: Not Collective
157: Input Parameters:
158: . draw - the drawing context
160: Level: advanced
162: Notes: this is not normally called by the user, it is called by PetscDrawClear_X() to save a sequence of images.
164: .seealso: PetscDrawSetSave()
166: @*/
167: PetscErrorCode PetscDrawSave(PetscDraw draw)
168: {
170: PetscBool isnull;
174: PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
175: if (isnull) return(0);
176: if (!draw->ops->save) return(0);
177: (*draw->ops->save)(draw);
178: return(0);
179: }