xref: /petsc/include/petsc/private/drawimpl.h (revision 9dd11ecf0918283bb567d8b33a92f53ac4ea7840)
1 /*
2        Abstract data structure and functions for graphics.
3 */
4 
5 #pragma once
6 
7 #include <petsc/private/petscimpl.h>
8 #include <petscdraw.h>
9 
10 PETSC_EXTERN PetscBool      PetscDrawRegisterAllCalled;
11 PETSC_EXTERN PetscErrorCode PetscDrawRegisterAll(void);
12 
13 struct _PetscDrawOps {
14   PetscErrorCode (*setdoublebuffer)(PetscDraw);
15   PetscErrorCode (*flush)(PetscDraw);
16   PetscErrorCode (*line)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal, int);
17   PetscErrorCode (*linesetwidth)(PetscDraw, PetscReal);
18   PetscErrorCode (*linegetwidth)(PetscDraw, PetscReal *);
19   PetscErrorCode (*point)(PetscDraw, PetscReal, PetscReal, int);
20   PetscErrorCode (*pointsetsize)(PetscDraw, PetscReal);
21   PetscErrorCode (*string)(PetscDraw, PetscReal, PetscReal, int, const char[]);
22   PetscErrorCode (*stringvertical)(PetscDraw, PetscReal, PetscReal, int, const char[]);
23   PetscErrorCode (*stringsetsize)(PetscDraw, PetscReal, PetscReal);
24   PetscErrorCode (*stringgetsize)(PetscDraw, PetscReal *, PetscReal *);
25   PetscErrorCode (*setviewport)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal);
26   PetscErrorCode (*clear)(PetscDraw);
27   PetscErrorCode (*rectangle)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal, int, int, int, int);
28   PetscErrorCode (*triangle)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, int, int, int);
29   PetscErrorCode (*ellipse)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal, int);
30   PetscErrorCode (*getmousebutton)(PetscDraw, PetscDrawButton *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
31   PetscErrorCode (*pause)(PetscDraw);
32   PetscErrorCode (*beginpage)(PetscDraw);
33   PetscErrorCode (*endpage)(PetscDraw);
34   PetscErrorCode (*getpopup)(PetscDraw, PetscDraw *);
35   PetscErrorCode (*settitle)(PetscDraw, const char[]);
36   PetscErrorCode (*checkresizedwindow)(PetscDraw);
37   PetscErrorCode (*resizewindow)(PetscDraw, int, int);
38   PetscErrorCode (*destroy)(PetscDraw);
39   PetscErrorCode (*view)(PetscDraw, PetscViewer);
40   PetscErrorCode (*getsingleton)(PetscDraw, PetscDraw *);
41   PetscErrorCode (*restoresingleton)(PetscDraw, PetscDraw *);
42   PetscErrorCode (*save)(PetscDraw);
43   PetscErrorCode (*getimage)(PetscDraw, unsigned char[][3], unsigned int *, unsigned int *, unsigned char *[]);
44   PetscErrorCode (*setcoordinates)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal);
45   PetscErrorCode (*arrow)(PetscDraw, PetscReal, PetscReal, PetscReal, PetscReal, int);
46   PetscErrorCode (*coordinatetopixel)(PetscDraw, PetscReal, PetscReal, int *, int *);
47   PetscErrorCode (*pixeltocoordinate)(PetscDraw, int, int, PetscReal *, PetscReal *);
48   PetscErrorCode (*pointpixel)(PetscDraw, int, int, int);
49   PetscErrorCode (*boxedstring)(PetscDraw, PetscReal, PetscReal, int, int, const char[], PetscReal *, PetscReal *);
50   PetscErrorCode (*setvisible)(PetscDraw, PetscBool);
51 };
52 
53 struct _p_PetscDraw {
54   PETSCHEADER(struct _PetscDrawOps);
55   PetscReal           pause; /* sleep time after a synchronized flush */
56   PetscReal           port_xl, port_yl, port_xr, port_yr;
57   PetscReal           coor_xl, coor_yl, coor_xr, coor_yr;
58   PetscReal           currentpoint_x[20], currentpoint_y[20];
59   PetscReal           boundbox_xl, boundbox_yl, boundbox_xr, boundbox_yr; /* need to have this for each current point? */
60   PetscInt            currentpoint;
61   PetscDrawMarkerType markertype;
62   char               *title;
63   char               *display;
64   PetscDraw           popup;
65   int                 x, y, h, w;
66   char               *savefilename;
67   char               *saveimageext;
68   char               *savemovieext;
69   PetscInt            savefilecount;
70   PetscBool           savesinglefile;
71   PetscInt            savemoviefps;
72   char               *savefinalfilename;
73   PetscBool           saveonclear; /* save a new image for every PetscDrawClear() called */
74   PetscBool           saveonflush; /* save a new image for every PetscDrawFlush() called */
75   void               *data;
76 };
77 
78 /* Contains the data structure for plotting several line
79  * graphs in a window with an axis. This is intended for line
80  * graphs that change dynamically by adding more points onto
81  * the end of the X axis.
82  */
83 struct _p_PetscDrawLG {
84   PETSCHEADER(int);
85   PetscErrorCode (*destroy)(PetscDrawLG);
86   PetscErrorCode (*view)(PetscDrawLG, PetscViewer);
87   int           len, loc;
88   PetscDraw     win;
89   PetscDrawAxis axis;
90   PetscReal     xmin, xmax, ymin, ymax, *x, *y;
91   int           nopts, dim, *colors;
92   PetscBool     use_markers;
93   char        **legend;
94 };
95 #define PETSC_DRAW_LG_CHUNK_SIZE 100
96 
97 struct _p_PetscDrawAxis {
98   PETSCHEADER(int);
99   PetscReal xlow, ylow, xhigh, yhigh;                         /* User - coord limits */
100   PetscErrorCode (*ylabelstr)(PetscReal, PetscReal, char **); /* routines to generate labels */
101   PetscErrorCode (*xlabelstr)(PetscReal, PetscReal, char **);
102   PetscErrorCode (*xticks)(PetscReal, PetscReal, int, int *, PetscReal *, int);
103   PetscErrorCode (*yticks)(PetscReal, PetscReal, int, int *, PetscReal *, int);
104   /* location and size of ticks */
105   PetscDraw win;
106   int       ac, tc, cc; /* axis,tick, character color */
107   char     *xlabel, *ylabel, *toplabel;
108   PetscBool hold;
109 };
110 
111 PETSC_INTERN PetscErrorCode PetscADefTicks(PetscReal, PetscReal, int, int *, PetscReal *, int);
112 PETSC_INTERN PetscErrorCode PetscADefLabel(PetscReal, PetscReal, char **);
113 PETSC_INTERN PetscErrorCode PetscAGetNice(PetscReal, PetscReal, int, PetscReal *);
114 PETSC_INTERN PetscErrorCode PetscAGetBase(PetscReal, PetscReal, int, PetscReal *, int *);
115 
116 PETSC_INTERN PetscErrorCode PetscStripe0(char *);
117 PETSC_INTERN PetscErrorCode PetscStripAllZeros(char *);
118 PETSC_INTERN PetscErrorCode PetscStripTrailingZeros(char *);
119 PETSC_INTERN PetscErrorCode PetscStripInitialZero(char *);
120 PETSC_INTERN PetscErrorCode PetscStripZeros(char *);
121 PETSC_INTERN PetscErrorCode PetscStripZerosPlus(char *);
122 
123 struct _p_PetscDrawBar {
124   PETSCHEADER(int);
125   PetscErrorCode (*destroy)(PetscDrawSP);
126   PetscErrorCode (*view)(PetscDrawSP, PetscViewer);
127   PetscDraw     win;
128   PetscDrawAxis axis;
129   PetscReal     ymin, ymax;
130   int           numBins;
131   PetscReal    *values;
132   int           color;
133   char        **labels;
134   PetscBool     sort;
135   PetscReal     sorttolerance;
136 };
137 
138 struct _p_PetscDrawSP {
139   PETSCHEADER(int);
140   PetscErrorCode (*destroy)(PetscDrawSP);
141   PetscErrorCode (*view)(PetscDrawSP, PetscViewer);
142   int           len, loc;
143   PetscDraw     win;
144   PetscDrawAxis axis;
145   PetscReal     xmin, xmax, ymin, ymax, *x, *y;
146   PetscReal     zmax, zmin, *z;
147   int           nopts, dim;
148   PetscBool     colorized;
149 };
150 #define PETSC_DRAW_SP_CHUNK_SIZE 100
151