Actual source code: dviewp.c
1: /*$Id: dviewp.c,v 1.45 2001/03/23 23:20:08 balay Exp $*/
2: /*
3: Provides the calling sequences for all the basic PetscDraw routines.
4: */
5: #include src/sys/src/draw/drawimpl.h
7: #undef __FUNCT__
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: int 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: }
43: #undef __FUNCT__
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: int PetscDrawSplitViewPort(PetscDraw draw)
62: {
63: int rank,size,n,ierr;
64: PetscTruth isnull;
65: PetscReal xl,xr,yl,yr,h;
69: PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
70: if (isnull) return(0);
72: MPI_Comm_rank(draw->comm,&rank);
73: MPI_Comm_size(draw->comm,&size);
75: n = (int)(.1 + sqrt((double)size));
76: while (n*n < size) {n++;}
78: h = 1.0/n;
79: xl = (rank % n)*h;
80: xr = xl + h;
81: yl = (rank/n)*h;
82: yr = yl + h;
84: PetscDrawLine(draw,xl,yl,xl,yr,PETSC_DRAW_BLACK);
85: PetscDrawLine(draw,xl,yr,xr,yr,PETSC_DRAW_BLACK);
86: PetscDrawLine(draw,xr,yr,xr,yl,PETSC_DRAW_BLACK);
87: PetscDrawLine(draw,xr,yl,xl,yl,PETSC_DRAW_BLACK);
88: PetscDrawSynchronizedFlush(draw);
90: draw->port_xl = xl + .1*h;
91: draw->port_xr = xr - .1*h;
92: draw->port_yl = yl + .1*h;
93: draw->port_yr = yr - .1*h;
95: if (draw->ops->setviewport) {
96: (*draw->ops->setviewport)(draw,xl,yl,xr,yr);
97: }
98: return(0);
99: }
101: #undef __FUNCT__
103: /*@C
104: PetscDrawViewPortsCreate - Splits a window into smaller
105: view ports. Each processor shares all the viewports.
107: Collective on PetscDraw
109: Input Parameter:
110: . draw - the drawing context
112: Output Parameter:
113: . divide - a PetscDrawViewPorts context (C structure)
115: Level: advanced
117: Concepts: drawing^in subset of window
119: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsDestroy()
121: @*/
122: int PetscDrawViewPortsCreate(PetscDraw draw,int nports,PetscDrawViewPorts **ports)
123: {
124: int i,ierr,n;
125: PetscTruth isnull;
126: PetscReal *xl,*xr,*yl,*yr,h;
130: PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);
131: if (isnull) {
132: *ports = PETSC_NULL;
133: return(0);
134: }
136: ierr = PetscNew(PetscDrawViewPorts,ports);
137: (*ports)->draw = draw;
138: (*ports)->nports = nports;
140: PetscObjectReference((PetscObject)draw);
142: n = (int)(.1 + sqrt((double)nports));
143: while (n*n < nports) {n++;}
144:
145: PetscMalloc(n*n*sizeof(PetscReal),&xl);(*ports)->xl = xl;
146: PetscMalloc(n*n*sizeof(PetscReal),&xr);(*ports)->xr = xr;
147: PetscMalloc(n*n*sizeof(PetscReal),&yl);(*ports)->yl = yl;
148: PetscMalloc(n*n*sizeof(PetscReal),&yr);(*ports)->yr = yr;
150: h = 1.0/n;
152: for (i=0; i<n*n; i++) {
153: xl[i] = (i % n)*h;
154: xr[i] = xl[i] + h;
155: yl[i] = (i/n)*h;
156: yr[i] = yl[i] + h;
158: PetscDrawLine(draw,xl[i],yl[i],xl[i],yr[i],PETSC_DRAW_BLACK);
159: PetscDrawLine(draw,xl[i],yr[i],xr[i],yr[i],PETSC_DRAW_BLACK);
160: PetscDrawLine(draw,xr[i],yr[i],xr[i],yl[i],PETSC_DRAW_BLACK);
161: PetscDrawLine(draw,xr[i],yl[i],xl[i],yl[i],PETSC_DRAW_BLACK);
163: xl[i] += .1*h;
164: xr[i] -= .1*h;
165: yl[i] += .1*h;
166: yr[i] -= .1*h;
167: }
168: PetscDrawSynchronizedFlush(draw);
170: return(0);
171: }
173: #undef __FUNCT__
175: /*@C
176: PetscDrawViewPortsDestroy - frees a PetscDrawViewPorts object
178: Collective on PetscDraw inside PetscDrawViewPorts
180: Input Parameter:
181: . ports - the PetscDrawViewPorts object
183: Level: advanced
185: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsCreate()
187: @*/
188: int PetscDrawViewPortsDestroy(PetscDrawViewPorts *ports)
189: {
190: int ierr;
194: if (!ports) return(0);
195: if (ports->draw) {PetscDrawDestroy(ports->draw);}
196: PetscFree(ports->xl);
197: PetscFree(ports->xr);
198: PetscFree(ports->yl);
199: PetscFree(ports->yr);
200: PetscFree(ports);
202: return(0);
203: }
205: #undef __FUNCT__
207: /*@C
208: PetscDrawViewPortsSet - sets a draw object to use a particular subport
210: Collective on PetscDraw inside PetscDrawViewPorts
212: Input Parameter:
213: + ports - the PetscDrawViewPorts object
214: - port - the port number, from 0 to nports-1
216: Level: advanced
218: Concepts: drawing^in subset of window
220: .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsDestroy(), PetscDrawViewPortsCreate()
222: @*/
223: int PetscDrawViewPortsSet(PetscDrawViewPorts *ports,int port)
224: {
225: int ierr;
228: if (ports) {
229: if (port < 0 || port > ports->nports-1) {
230: SETERRQ2(1,"Port is out of range requested %d from 0 to %dn",port,ports->nports);
231: }
232: PetscDrawSetViewPort(ports->draw,ports->xl[port],ports->yl[port],ports->xr[port],ports->yr[port]);
233: }
234: return(0);
235: }