Actual source code: dviewp.c
1: #define PETSC_DLL
2: /*
3: Provides the calling sequences for all the basic PetscDraw routines.
4: */
5: #include src/sys/draw/drawimpl.h
9: /*@
10: PetscDrawSetViewPort - Sets the portion of the window (page) to which draw
11: routines will write.
13: Collective on PetscDraw
15: Input Parameters:
16: + xl,yl,xr,yr - upper right and lower left corners of subwindow
17: These numbers must always be between 0.0 and 1.0.
18: Lower left corner is (0,0).
19: - draw - the drawing context
21: Level: advanced
23: Concepts: drawing^in subset of window
24: Concepts: graphics^in subset of window
26: @*/
27: PetscErrorCode PetscDrawSetViewPort(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr)
28: {
32: if (xl < 0.0 || xr > 1.0 || yl < 0.0 || yr > 1.0 || xr <= xl || yr <= yl) {
33: SETERRQ4(PETSC_ERR_ARG_OUTOFRANGE,"ViewPort values must be >= 0 and <= 1: Instead %G %G %G %G",xl,yl,xr,yr);
34: }
35: draw->port_xl = xl; draw->port_yl = yl;
36: draw->port_xr = xr; draw->port_yr = yr;
37: if (draw->ops->setviewport) {
38: (*draw->ops->setviewport)(draw,xl,yl,xr,yr);
39: }
40: return(0);
41: }
45: /*@
46: PetscDrawSplitViewPort - Splits a window shared by several processes into smaller
47: view ports. One for each process.
49: Collective on PetscDraw
51: Input Parameter:
52: . draw - the drawing context
54: Level: advanced
56: Concepts: drawing^in subset of window
58: .seealso: PetscDrawDivideViewPort(), PetscDrawSetViewPort()
60: @*/
61: PetscErrorCode PetscDrawSplitViewPort(PetscDraw draw)
62: {
64: PetscMPIInt rank,size;
65: int n;
66: PetscTruth isnull;
67: PetscReal xl,xr,yl,yr,h;
71: PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
72: if (isnull) return(0);
74: MPI_Comm_rank(draw->comm,&rank);
75: MPI_Comm_size(draw->comm,&size);
77: n = (int)(.1 + sqrt((double)size));
78: while (n*n < size) {n++;}
80: h = 1.0/n;
81: xl = (rank % n)*h;
82: xr = xl + h;
83: yl = (rank/n)*h;
84: yr = yl + h;
86: PetscDrawLine(draw,xl,yl,xl,yr,PETSC_DRAW_BLACK);
87: PetscDrawLine(draw,xl,yr,xr,yr,PETSC_DRAW_BLACK);
88: PetscDrawLine(draw,xr,yr,xr,yl,PETSC_DRAW_BLACK);
89: PetscDrawLine(draw,xr,yl,xl,yl,PETSC_DRAW_BLACK);
90: PetscDrawSynchronizedFlush(draw);
92: draw->port_xl = xl + .1*h;
93: draw->port_xr = xr - .1*h;
94: draw->port_yl = yl + .1*h;
95: draw->port_yr = yr - .1*h;
97: if (draw->ops->setviewport) {
98: (*draw->ops->setviewport)(draw,xl,yl,xr,yr);
99: }
100: return(0);
101: }
105: /*@C
106: PetscDrawViewPortsCreate - Splits a window into smaller
107: view ports. Each processor shares all the viewports.
109: Collective on PetscDraw
111: Input Parameter:
112: . draw - the drawing context
114: Output Parameter:
115: . divide - a PetscDrawViewPorts context (C structure)
117: Level: advanced
119: Concepts: drawing^in subset of window
121: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsDestroy()
123: @*/
124: PetscErrorCode PetscDrawViewPortsCreate(PetscDraw draw,int nports,PetscDrawViewPorts **ports)
125: {
126: int i,n;
128: PetscTruth isnull;
129: PetscReal *xl,*xr,*yl,*yr,h;
134: PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
135: if (isnull) {
136: *ports = PETSC_NULL;
137: return(0);
138: }
140: PetscNew(PetscDrawViewPorts,ports);
141: (*ports)->draw = draw;
142: (*ports)->nports = nports;
144: PetscObjectReference((PetscObject)draw);
146: n = (int)(.1 + sqrt((double)nports));
147: while (n*n < nports) {n++;}
148:
149: PetscMalloc(n*n*sizeof(PetscReal),&xl);(*ports)->xl = xl;
150: PetscMalloc(n*n*sizeof(PetscReal),&xr);(*ports)->xr = xr;
151: PetscMalloc(n*n*sizeof(PetscReal),&yl);(*ports)->yl = yl;
152: PetscMalloc(n*n*sizeof(PetscReal),&yr);(*ports)->yr = yr;
154: h = 1.0/n;
156: for (i=0; i<n*n; i++) {
157: xl[i] = (i % n)*h;
158: xr[i] = xl[i] + h;
159: yl[i] = (i/n)*h;
160: yr[i] = yl[i] + h;
162: PetscDrawLine(draw,xl[i],yl[i],xl[i],yr[i],PETSC_DRAW_BLACK);
163: PetscDrawLine(draw,xl[i],yr[i],xr[i],yr[i],PETSC_DRAW_BLACK);
164: PetscDrawLine(draw,xr[i],yr[i],xr[i],yl[i],PETSC_DRAW_BLACK);
165: PetscDrawLine(draw,xr[i],yl[i],xl[i],yl[i],PETSC_DRAW_BLACK);
167: xl[i] += .1*h;
168: xr[i] -= .1*h;
169: yl[i] += .1*h;
170: yr[i] -= .1*h;
171: }
172: PetscDrawSynchronizedFlush(draw);
174: return(0);
175: }
179: /*@C
180: PetscDrawViewPortsDestroy - frees a PetscDrawViewPorts object
182: Collective on PetscDraw inside PetscDrawViewPorts
184: Input Parameter:
185: . ports - the PetscDrawViewPorts object
187: Level: advanced
189: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsCreate()
191: @*/
192: PetscErrorCode PetscDrawViewPortsDestroy(PetscDrawViewPorts *ports)
193: {
198: if (!ports) return(0);
199: if (ports->draw) {PetscDrawDestroy(ports->draw);}
200: PetscFree(ports->xl);
201: PetscFree(ports->xr);
202: PetscFree(ports->yl);
203: PetscFree(ports->yr);
204: PetscFree(ports);
206: return(0);
207: }
211: /*@C
212: PetscDrawViewPortsSet - sets a draw object to use a particular subport
214: Collective on PetscDraw inside PetscDrawViewPorts
216: Input Parameter:
217: + ports - the PetscDrawViewPorts object
218: - port - the port number, from 0 to nports-1
220: Level: advanced
222: Concepts: drawing^in subset of window
224: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsDestroy(), PetscDrawViewPortsCreate()
226: @*/
227: PetscErrorCode PetscDrawViewPortsSet(PetscDrawViewPorts *ports,int port)
228: {
232: if (ports) {
233: if (port < 0 || port > ports->nports-1) {
234: SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Port is out of range requested %d from 0 to %d\n",port,ports->nports);
235: }
236: PetscDrawSetViewPort(ports->draw,ports->xl[port],ports->yl[port],ports->xr[port],ports->yr[port]);
237: }
238: return(0);
239: }