xref: /petsc/src/sys/classes/draw/interface/drect.c (revision e611a964e9853b74d61a56642fe9d06a6e51780f)
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 #undef __FUNCT__
9 #define __FUNCT__ "PetscDrawIndicatorFunction"
10 /*@C
11    PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a PetscDraw
12 
13    Not collective
14 
15    Input Parameter:
16 +  draw - a PetscDraw
17 .  xmin,xmax,ymin,ymax - region to draw indicator function
18 -  f - the indicator function
19 
20    Level: developer
21 
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;
28   PetscErrorCode ierr;
29 
30   PetscFunctionBegin;
31   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
32   ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr);
33   if (isnull) PetscFunctionReturn(0);
34 
35   ierr = PetscDrawCoordinateToPixel(draw,xmin,ymin,&xstart,&ystart);CHKERRQ(ierr);
36   ierr = PetscDrawCoordinateToPixel(draw,xmax,ymax,&xend,&yend);CHKERRQ(ierr);
37   if (yend < ystart) { PetscInt tmp = ystart; ystart = yend; yend = tmp; }
38 
39   for (i=xstart; i<=xend; i++) {
40     for (j=ystart; j<=yend; j++) {
41       ierr = PetscDrawPixelToCoordinate(draw,i,j,&x,&y);CHKERRQ(ierr);
42       ierr = indicator(ctx,x,y,&flg);CHKERRQ(ierr);
43       if (flg) {
44         ierr = PetscDrawPointPixel(draw,i,j,c);CHKERRQ(ierr);
45       }
46     }
47   }
48   PetscFunctionReturn(0);
49 }
50 
51 
52 #undef __FUNCT__
53 #define __FUNCT__ "PetscDrawCoordinateToPixel"
54 /*@C
55    PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location
56 
57    Not collective
58 
59    Input Parameters:
60 +  draw - the draw where the coordinates are defined
61 -  x,y - the coordinate location
62 
63    Output Parameters:
64 -  i,j - the pixel location
65 
66    Level: developer
67 
68 @*/
69 PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw,PetscReal x,PetscReal y,int *i,int *j)
70 {
71   PetscErrorCode ierr;
72 
73   PetscFunctionBegin;
74   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
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   ierr = (*draw->ops->coordinatetopixel)(draw,x,y,i,j);CHKERRQ(ierr);
77   PetscFunctionReturn(0);
78 }
79 
80 #undef __FUNCT__
81 #define __FUNCT__ "PetscDrawPixelToCoordinate"
82 /*@C
83    PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate
84 
85    Not collective
86 
87    Input Parameters:
88 +  draw - the draw where the coordinates are defined
89 -  i,j - the pixel location
90 
91    Output Parameters:
92 .  x,y - the coordinate location
93 
94    Level: developer
95 
96 @*/
97 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw,int i,int j,PetscReal *x,PetscReal *y)
98 {
99   PetscErrorCode ierr;
100 
101   PetscFunctionBegin;
102   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
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   ierr = (*draw->ops->pixeltocoordinate)(draw,i,j,x,y);CHKERRQ(ierr);
105   PetscFunctionReturn(0);
106 }
107 
108 #undef __FUNCT__
109 #define __FUNCT__ "PetscDrawRectangle"
110 /*@
111    PetscDrawRectangle - PetscDraws a rectangle  onto a drawable.
112 
113    Not Collective
114 
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
119 
120    Level: beginner
121 
122    Concepts: drawing^rectangle
123    Concepts: graphics^rectangle
124    Concepts: rectangle
125 
126 @*/
127 PetscErrorCode  PetscDrawRectangle(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int c1,int c2,int c3,int c4)
128 {
129   PetscErrorCode ierr;
130 
131   PetscFunctionBegin;
132   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
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   ierr = (*draw->ops->rectangle)(draw,xl,yl,xr,yr,c1,c2,c3,c4);CHKERRQ(ierr);
135   PetscFunctionReturn(0);
136 }
137