1 | /* |
---|
2 | * $Id: GridCartesianRenderer.java,v 1.30 2003/08/22 23:02:32 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt; |
---|
14 | |
---|
15 | import gov.noaa.pmel.sgt.contour.Contour; |
---|
16 | import gov.noaa.pmel.sgt.contour.ContourLine; |
---|
17 | import gov.noaa.pmel.sgt.dm.SGTData; |
---|
18 | import gov.noaa.pmel.sgt.dm.SGTGrid; |
---|
19 | import gov.noaa.pmel.sgt.dm.SimpleGrid; |
---|
20 | import gov.noaa.pmel.util.Debug; |
---|
21 | import gov.noaa.pmel.util.GeoDate; |
---|
22 | import gov.noaa.pmel.util.Range2D; |
---|
23 | |
---|
24 | import java.awt.*; |
---|
25 | import java.beans.PropertyChangeEvent; |
---|
26 | import java.util.Enumeration; |
---|
27 | |
---|
28 | /** |
---|
29 | * Produces a cartesian plot from a <code>SGTGrid</code> object. |
---|
30 | * |
---|
31 | * @author Donald Denbo |
---|
32 | * @version $Revision: 1.30 $, $Date: 2003/08/22 23:02:32 $ |
---|
33 | * @since 1.0 |
---|
34 | */ |
---|
35 | public class GridCartesianRenderer |
---|
36 | extends CartesianRenderer |
---|
37 | { |
---|
38 | /** |
---|
39 | * @shapeType AggregationLink |
---|
40 | * @label grid |
---|
41 | * @undirected |
---|
42 | * @supplierCardinality 1 |
---|
43 | */ |
---|
44 | private SGTGrid grid_; |
---|
45 | /** |
---|
46 | * @shapeType AggregationLink |
---|
47 | * @label attr |
---|
48 | * @undirected |
---|
49 | * @supplierCardinality 1 |
---|
50 | */ |
---|
51 | private GridAttribute attr_ = null; |
---|
52 | |
---|
53 | /** |
---|
54 | * @link aggregationByValue |
---|
55 | * @supplierCardinality 1 |
---|
56 | * @label con |
---|
57 | */ |
---|
58 | private Contour con_ = null; |
---|
59 | |
---|
60 | // |
---|
61 | private void drawRaster( Graphics g ) |
---|
62 | { |
---|
63 | int nT, nX, nY, nZ; |
---|
64 | int[] xp, yp; |
---|
65 | int i, j; |
---|
66 | Color color; |
---|
67 | int xSize, ySize, count; |
---|
68 | double[] xValues, yValues, gValues; |
---|
69 | double val; |
---|
70 | GeoDate[] tValues; |
---|
71 | // |
---|
72 | if( grid_.isXTime() ) |
---|
73 | { |
---|
74 | if( grid_.getTimeArray().length <= 2 ) return; |
---|
75 | if( grid_.hasXEdges() ) |
---|
76 | { |
---|
77 | tValues = grid_.getTimeEdges(); |
---|
78 | xSize = tValues.length; |
---|
79 | xp = new int[xSize]; |
---|
80 | for( count = 0; count < xSize; count++ ) |
---|
81 | { |
---|
82 | xp[count] = cg_.getXUtoD( tValues[count] ); |
---|
83 | } |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | tValues = grid_.getTimeArray(); |
---|
88 | xSize = tValues.length; |
---|
89 | xp = new int[xSize + 1]; |
---|
90 | xp[0] = cg_.getXUtoD( tValues[0].subtract( |
---|
91 | ( tValues[1].subtract( tValues[0] ) ).divide( 2.0 ) ) ); |
---|
92 | for( count = 1; count < xSize; count++ ) |
---|
93 | { |
---|
94 | xp[count] = cg_.getXUtoD( |
---|
95 | ( tValues[count - 1].add( tValues[count] ) ).divide( 2.0 ) ); |
---|
96 | } |
---|
97 | xp[xSize] = cg_.getXUtoD( tValues[xSize - 1].add( |
---|
98 | ( tValues[xSize - 1].subtract( tValues[xSize - 2] ) ).divide( 2.0 ) ) ); |
---|
99 | } |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | if( grid_.getXArray().length <= 2 ) return; |
---|
104 | if( grid_.hasXEdges() ) |
---|
105 | { |
---|
106 | xValues = grid_.getXEdges(); |
---|
107 | xSize = xValues.length; |
---|
108 | xp = new int[xSize]; |
---|
109 | for( count = 0; count < xSize; count++ ) |
---|
110 | { |
---|
111 | xp[count] = cg_.getXUtoD( xValues[count] ); |
---|
112 | } |
---|
113 | } |
---|
114 | // VMIPSL |
---|
115 | else if( grid_ instanceof SimpleGrid && !( (SimpleGrid) grid_ ).isRealFullGrid() ) |
---|
116 | { |
---|
117 | xValues = grid_.getXArray(); |
---|
118 | xSize = xValues.length; |
---|
119 | xp = new int[xSize]; |
---|
120 | for( count = 0; count < xSize; count++ ) |
---|
121 | xp[count] = cg_.getXUtoD( xValues[count] ); |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | xValues = grid_.getXArray(); |
---|
126 | xSize = xValues.length; |
---|
127 | xp = new int[xSize + 1]; |
---|
128 | xp[0] = cg_.getXUtoD( xValues[0] - ( xValues[1] - xValues[0] ) * 0.5 ); |
---|
129 | for( count = 1; count < xSize; count++ ) |
---|
130 | { |
---|
131 | xp[count] = cg_.getXUtoD( ( xValues[count - 1] + xValues[count] ) * 0.5 ); |
---|
132 | } |
---|
133 | xp[xSize] = cg_.getXUtoD( xValues[xSize - 1] + |
---|
134 | ( xValues[xSize - 1] - xValues[xSize - 2] ) * 0.5 ); |
---|
135 | } |
---|
136 | } |
---|
137 | if( grid_.isYTime() ) |
---|
138 | { |
---|
139 | if( grid_.getTimeArray().length <= 2 ) return; |
---|
140 | if( grid_.hasYEdges() ) |
---|
141 | { |
---|
142 | tValues = grid_.getTimeEdges(); |
---|
143 | ySize = tValues.length; |
---|
144 | yp = new int[ySize]; |
---|
145 | for( count = 0; count < ySize; count++ ) |
---|
146 | { |
---|
147 | yp[count] = cg_.getYUtoD( tValues[count] ); |
---|
148 | } |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | tValues = grid_.getTimeArray(); |
---|
153 | ySize = tValues.length; |
---|
154 | yp = new int[ySize + 1]; |
---|
155 | yp[0] = cg_.getYUtoD( tValues[0].subtract( |
---|
156 | ( tValues[1].subtract( tValues[0] ) ).divide( 2.0 ) ) ); |
---|
157 | for( count = 1; count < ySize; count++ ) |
---|
158 | { |
---|
159 | yp[count] = cg_.getYUtoD( ( tValues[count - 1].add( |
---|
160 | tValues[count] ) ).divide( 2.0 ) ); |
---|
161 | } |
---|
162 | yp[ySize] = cg_.getYUtoD( tValues[ySize - 1].add( |
---|
163 | ( tValues[ySize - 1].subtract( tValues[ySize - 2] ) ).divide( 2.0 ) ) ); |
---|
164 | } |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | if( grid_.getYArray().length <= 2 ) return; |
---|
169 | if( grid_.hasYEdges() ) |
---|
170 | { |
---|
171 | yValues = grid_.getYEdges(); |
---|
172 | ySize = yValues.length; |
---|
173 | yp = new int[ySize]; |
---|
174 | for( count = 0; count < ySize; count++ ) |
---|
175 | { |
---|
176 | yp[count] = cg_.getYUtoD( yValues[count] ); |
---|
177 | } |
---|
178 | } |
---|
179 | else |
---|
180 | { |
---|
181 | yValues = grid_.getYArray(); |
---|
182 | ySize = yValues.length; |
---|
183 | yp = new int[ySize + 1]; |
---|
184 | yp[0] = cg_.getYUtoD( yValues[0] - ( yValues[1] - yValues[0] ) * 0.5 ); |
---|
185 | for( count = 1; count < ySize; count++ ) |
---|
186 | { |
---|
187 | yp[count] = cg_.getYUtoD( ( yValues[count - 1] + yValues[count] ) * 0.5 ); |
---|
188 | } |
---|
189 | yp[ySize] = cg_.getYUtoD( yValues[ySize - 1] + |
---|
190 | ( yValues[ySize - 1] - yValues[ySize - 2] ) * 0.5 ); |
---|
191 | } |
---|
192 | } |
---|
193 | // |
---|
194 | // draw raster |
---|
195 | // |
---|
196 | gValues = grid_.getZArray(); |
---|
197 | count = 0; |
---|
198 | |
---|
199 | // VMIPSl |
---|
200 | if( grid_ instanceof SimpleGrid && !( (SimpleGrid) grid_ ).isRealFullGrid() ) |
---|
201 | { |
---|
202 | for( i = 0; i < Math.max( xSize, ySize ); i++ ) |
---|
203 | { |
---|
204 | val = gValues[i]; |
---|
205 | if( !Double.isNaN( val ) ) |
---|
206 | { |
---|
207 | color = attr_.getColorMap().getColor( val ); |
---|
208 | g.setColor( color ); |
---|
209 | drawPoint( g, xp[i], yp[i], attr_ ); |
---|
210 | } |
---|
211 | } |
---|
212 | } |
---|
213 | else |
---|
214 | { |
---|
215 | for( i = 0; i < xSize; i++ ) |
---|
216 | { |
---|
217 | for( j = 0; j < ySize; j++ ) |
---|
218 | { |
---|
219 | val = gValues[count]; |
---|
220 | if( !Double.isNaN( val ) ) |
---|
221 | { |
---|
222 | color = attr_.getColorMap().getColor( val ); |
---|
223 | g.setColor( color ); |
---|
224 | drawRect( g, xp[i], yp[j], xp[i + 1], yp[j + 1] ); |
---|
225 | } |
---|
226 | count++; |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | /** |
---|
233 | * Get the <code>Attribute</code> associated with |
---|
234 | * the <code>SGTGrid</code> data. |
---|
235 | * |
---|
236 | * @return <code>Attribute</code> |
---|
237 | */ |
---|
238 | public Attribute getAttribute() |
---|
239 | { |
---|
240 | return attr_; |
---|
241 | } |
---|
242 | |
---|
243 | /** |
---|
244 | * Set the <code>GridAttribute</code> for the renderer. |
---|
245 | * |
---|
246 | * @since 2.0 |
---|
247 | */ |
---|
248 | public void setAttribute( GridAttribute attr ) |
---|
249 | { |
---|
250 | if( attr_ != null ) attr_.removePropertyChangeListener( this ); |
---|
251 | attr_ = attr; |
---|
252 | attr_.addPropertyChangeListener( this ); |
---|
253 | } |
---|
254 | |
---|
255 | private void drawRect( Graphics g, int x1, int y1, int x2, int y2 ) |
---|
256 | { |
---|
257 | int x, y, width, height; |
---|
258 | if( x1 < x2 ) |
---|
259 | { |
---|
260 | x = x1; |
---|
261 | width = x2 - x1; |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | x = x2; |
---|
266 | width = x1 - x2; |
---|
267 | } |
---|
268 | if( y1 < y2 ) |
---|
269 | { |
---|
270 | y = y1; |
---|
271 | height = y2 - y1; |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | y = y2; |
---|
276 | height = y1 - y2; |
---|
277 | } |
---|
278 | g.fillRect( x, y, width, height ); |
---|
279 | } |
---|
280 | |
---|
281 | // VMIPSL |
---|
282 | protected void drawPoint( final Graphics g, final int x, final int y, final GridAttribute attr ) |
---|
283 | { |
---|
284 | Layer ly = cg_.getLayer(); |
---|
285 | final PointAttribute pointAttribute = new PointAttribute(); |
---|
286 | PlotMark pm = new PlotMark( pointAttribute ); |
---|
287 | pm.setMarkHeightP( 0.2 ); |
---|
288 | |
---|
289 | pm.paintMark( g, ly, x, y ); |
---|
290 | } |
---|
291 | |
---|
292 | /** |
---|
293 | * Default constructor. The <code>GridCartesianRenderer</code> should |
---|
294 | * be created using the <code>CartesianRenderer.getRenderer</code> |
---|
295 | * method. |
---|
296 | * |
---|
297 | * @see CartesianRenderer#getRenderer |
---|
298 | * @see Graph |
---|
299 | */ |
---|
300 | public GridCartesianRenderer( CartesianGraph cg ) |
---|
301 | { |
---|
302 | this( cg, null, null ); |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | * Construct a <code>GridCartesianRenderer</code>. |
---|
307 | * The <code>GridCartesianRenderer</code> should |
---|
308 | * be created using the <code>CartesianRenderer.getRenderer</code> |
---|
309 | * method. |
---|
310 | * |
---|
311 | * @see CartesianRenderer#getRenderer |
---|
312 | * @see Graph |
---|
313 | */ |
---|
314 | public GridCartesianRenderer( CartesianGraph cg, SGTGrid data ) |
---|
315 | { |
---|
316 | this( cg, data, null ); |
---|
317 | } |
---|
318 | |
---|
319 | /** |
---|
320 | * Construct a <code>GridCartesianRenderer</code>. |
---|
321 | * The <code>GridCartesianRenderer</code> should |
---|
322 | * be created using the <code>CartesianRenderer.getRenderer</code> |
---|
323 | * method. |
---|
324 | * |
---|
325 | * @see CartesianRenderer#getRenderer |
---|
326 | * @see Graph |
---|
327 | */ |
---|
328 | public GridCartesianRenderer( CartesianGraph cg, SGTGrid grid, GridAttribute attr ) |
---|
329 | { |
---|
330 | cg_ = cg; |
---|
331 | grid_ = grid; |
---|
332 | attr_ = attr; |
---|
333 | if( attr_ != null ) attr_.addPropertyChangeListener( this ); |
---|
334 | } |
---|
335 | |
---|
336 | /** |
---|
337 | * Render the <code>SGTData</code>. This method should not |
---|
338 | * be directly called. |
---|
339 | * |
---|
340 | * @param g graphics context |
---|
341 | * @see Pane#draw |
---|
342 | */ |
---|
343 | public void draw( Graphics g ) |
---|
344 | { |
---|
345 | if( cg_.clipping_ ) |
---|
346 | { |
---|
347 | int xmin, xmax, ymin, ymax; |
---|
348 | int x, y, width, height; |
---|
349 | if( cg_.xTransform_.isSpace() ) |
---|
350 | { |
---|
351 | xmin = cg_.getXUtoD( cg_.xClipRange_.start ); |
---|
352 | xmax = cg_.getXUtoD( cg_.xClipRange_.end ); |
---|
353 | } |
---|
354 | else |
---|
355 | { |
---|
356 | xmin = cg_.getXUtoD( cg_.tClipRange_.start ); |
---|
357 | xmax = cg_.getXUtoD( cg_.tClipRange_.end ); |
---|
358 | } |
---|
359 | if( cg_.yTransform_.isSpace() ) |
---|
360 | { |
---|
361 | ymin = cg_.getYUtoD( cg_.yClipRange_.start ); |
---|
362 | ymax = cg_.getYUtoD( cg_.yClipRange_.end ); |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | ymin = cg_.getYUtoD( cg_.tClipRange_.start ); |
---|
367 | ymax = cg_.getYUtoD( cg_.tClipRange_.end ); |
---|
368 | } |
---|
369 | if( xmin < xmax ) |
---|
370 | { |
---|
371 | x = xmin; |
---|
372 | width = xmax - xmin; |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | x = xmax; |
---|
377 | width = xmin - xmax; |
---|
378 | } |
---|
379 | if( ymin < ymax ) |
---|
380 | { |
---|
381 | y = ymin; |
---|
382 | height = ymax - ymin; |
---|
383 | } |
---|
384 | else |
---|
385 | { |
---|
386 | y = ymax; |
---|
387 | height = ymin - ymax; |
---|
388 | } |
---|
389 | g.setClip( x, y, width, height ); |
---|
390 | } |
---|
391 | if( attr_.isRaster() ) |
---|
392 | { |
---|
393 | drawRaster( g ); |
---|
394 | } |
---|
395 | if( attr_.isAreaFill() ) |
---|
396 | { |
---|
397 | // |
---|
398 | // This is a temporary method based on the |
---|
399 | // PPLUS area fill algorthim |
---|
400 | // |
---|
401 | // To be replaced by a area fill method that |
---|
402 | // uses the ContourLines |
---|
403 | // |
---|
404 | double[] x = xArrayP(); |
---|
405 | double[] y = yArrayP(); |
---|
406 | double[] z = grid_.getZArray(); |
---|
407 | int i, j; |
---|
408 | int nx = x.length; |
---|
409 | int ny = y.length; |
---|
410 | double[] xt = new double[5]; |
---|
411 | double[] yt = new double[5]; |
---|
412 | double[] zt = new double[5]; |
---|
413 | for( i = 0; i < nx - 1; i++ ) |
---|
414 | { |
---|
415 | for( j = 0; j < ny - 1; j++ ) |
---|
416 | { |
---|
417 | xt[0] = x[i]; |
---|
418 | yt[0] = y[j]; |
---|
419 | zt[0] = z[j + i * ny]; |
---|
420 | // |
---|
421 | xt[1] = x[i + 1]; |
---|
422 | yt[1] = y[j]; |
---|
423 | zt[1] = z[j + ( i + 1 ) * ny]; |
---|
424 | // |
---|
425 | xt[2] = x[i + 1]; |
---|
426 | yt[2] = y[j + 1]; |
---|
427 | zt[2] = z[j + 1 + ( i + 1 ) * ny]; |
---|
428 | // |
---|
429 | xt[3] = xt[0]; |
---|
430 | yt[3] = yt[2]; |
---|
431 | zt[3] = z[j + 1 + i * ny]; |
---|
432 | // |
---|
433 | // repeat first point |
---|
434 | // |
---|
435 | xt[4] = xt[0]; |
---|
436 | yt[4] = yt[0]; |
---|
437 | zt[4] = zt[0]; |
---|
438 | // |
---|
439 | fillSquare( g, xt, yt, zt ); |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | if( attr_.isContour() ) |
---|
444 | { |
---|
445 | double val; |
---|
446 | String label; |
---|
447 | Range2D range = computeRange( 10 ); |
---|
448 | Format format; |
---|
449 | // con_ = new Contour(cg_, grid_, range); |
---|
450 | con_ = new Contour( cg_, grid_, attr_.getContourLevels() ); |
---|
451 | ContourLevels clevels = con_.getContourLevels(); |
---|
452 | DefaultContourLineAttribute attr; |
---|
453 | // |
---|
454 | // set labels |
---|
455 | // |
---|
456 | for( int i = 0; i < clevels.size(); i++ ) |
---|
457 | { |
---|
458 | try |
---|
459 | { |
---|
460 | val = clevels.getLevel( i ); |
---|
461 | attr = clevels.getDefaultContourLineAttribute( i ); |
---|
462 | if( attr.isAutoLabel() ) |
---|
463 | { |
---|
464 | if( attr.getLabelFormat().length() <= 0 ) |
---|
465 | { |
---|
466 | format = new Format( Format.computeFormat( range.start, |
---|
467 | range.end, |
---|
468 | attr.getSignificantDigits() ) ); |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | format = new Format( attr.getLabelFormat() ); |
---|
473 | } |
---|
474 | label = format.form( val ); |
---|
475 | attr.setLabelText( label ); |
---|
476 | } |
---|
477 | } |
---|
478 | catch( ContourLevelNotFoundException e ) |
---|
479 | { |
---|
480 | System.out.println( e ); |
---|
481 | } |
---|
482 | } |
---|
483 | con_.generateContourLines(); |
---|
484 | con_.generateContourLabels( g ); |
---|
485 | Enumeration elem = con_.elements(); |
---|
486 | ContourLine cl; |
---|
487 | while( elem.hasMoreElements() ) |
---|
488 | { |
---|
489 | cl = (ContourLine) elem.nextElement(); |
---|
490 | if( Debug.CONTOUR ) |
---|
491 | { |
---|
492 | System.out.println( " level = " + cl.getLevel() + |
---|
493 | ", length = " + cl.getKmax() + |
---|
494 | ", closed = " + cl.isClosed() ); |
---|
495 | } |
---|
496 | cl.draw( g ); |
---|
497 | } |
---|
498 | } |
---|
499 | // |
---|
500 | // reset clip |
---|
501 | // |
---|
502 | Rectangle rect = cg_.getLayer().getPane().getBounds(); |
---|
503 | g.setClip( rect ); |
---|
504 | } |
---|
505 | |
---|
506 | private void fillSquare( Graphics g, double[] x, |
---|
507 | double[] y, double[] z ) |
---|
508 | { |
---|
509 | ContourLevels clevels = attr_.getContourLevels(); |
---|
510 | IndexedColor cmap = (IndexedColor) attr_.getColorMap(); |
---|
511 | int i, j, cindex, npoly, maxindex; |
---|
512 | double zlev, zlevp1, f; |
---|
513 | Color col; |
---|
514 | double[] xpoly = new double[20]; |
---|
515 | double[] ypoly = new double[20]; |
---|
516 | double zmin = Math.min( z[0], z[1] ); |
---|
517 | double zmax = Math.max( z[0], z[1] ); |
---|
518 | for( i = 2; i <= 3; i++ ) |
---|
519 | { |
---|
520 | zmin = Math.min( zmin, z[i] ); |
---|
521 | zmax = Math.max( zmax, z[i] ); |
---|
522 | } |
---|
523 | if( Double.isNaN( zmax ) ) return; |
---|
524 | maxindex = clevels.getMaximumIndex(); |
---|
525 | for( cindex = -1; cindex <= maxindex; cindex++ ) |
---|
526 | { |
---|
527 | try |
---|
528 | { |
---|
529 | if( cindex == -1 ) |
---|
530 | { |
---|
531 | zlev = -Double.MAX_VALUE; |
---|
532 | } |
---|
533 | else |
---|
534 | { |
---|
535 | zlev = clevels.getLevel( cindex ); |
---|
536 | } |
---|
537 | if( cindex == maxindex ) |
---|
538 | { |
---|
539 | zlevp1 = Double.MAX_VALUE; |
---|
540 | } |
---|
541 | else |
---|
542 | { |
---|
543 | zlevp1 = clevels.getLevel( cindex + 1 ); |
---|
544 | } |
---|
545 | } |
---|
546 | catch( ContourLevelNotFoundException e ) |
---|
547 | { |
---|
548 | System.out.println( e ); |
---|
549 | break; |
---|
550 | } |
---|
551 | col = cmap.getColorByIndex( cindex + 1 ); |
---|
552 | if( zmin > zlevp1 || zmax < zlev ) continue; |
---|
553 | if( zmin >= zlev && zmax <= zlevp1 ) |
---|
554 | { |
---|
555 | fillPolygon( g, col, x, y, 4 ); |
---|
556 | return; |
---|
557 | } |
---|
558 | npoly = -1; |
---|
559 | for( j = 0; j < 4; j++ ) |
---|
560 | { /* sides */ |
---|
561 | if( z[j] < zlev ) |
---|
562 | { |
---|
563 | // |
---|
564 | // z[j] is below |
---|
565 | // |
---|
566 | if( z[j + 1] > zlevp1 ) |
---|
567 | { |
---|
568 | // |
---|
569 | // z[j+1] is above |
---|
570 | // |
---|
571 | npoly = npoly + 1; |
---|
572 | f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); |
---|
573 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
574 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
575 | // |
---|
576 | npoly = npoly + 1; |
---|
577 | f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); |
---|
578 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
579 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
580 | } |
---|
581 | else if( z[j + 1] >= zlev && |
---|
582 | z[j + 1] <= zlevp1 ) |
---|
583 | { |
---|
584 | // |
---|
585 | // z[j+1] is inside |
---|
586 | // |
---|
587 | npoly = npoly + 1; |
---|
588 | f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); |
---|
589 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
590 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
591 | // |
---|
592 | npoly = npoly + 1; |
---|
593 | xpoly[npoly] = x[j + 1]; |
---|
594 | ypoly[npoly] = y[j + 1]; |
---|
595 | } |
---|
596 | } |
---|
597 | else if( z[j] > zlevp1 ) |
---|
598 | { |
---|
599 | // |
---|
600 | // z[j] is above |
---|
601 | // |
---|
602 | if( z[j + 1] < zlev ) |
---|
603 | { |
---|
604 | // |
---|
605 | // z[j+1] is below |
---|
606 | // |
---|
607 | npoly = npoly + 1; |
---|
608 | f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); |
---|
609 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
610 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
611 | // |
---|
612 | npoly = npoly + 1; |
---|
613 | f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); |
---|
614 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
615 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
616 | } |
---|
617 | else if( z[j + 1] >= zlev && z[j + 1] <= zlevp1 ) |
---|
618 | { |
---|
619 | // |
---|
620 | // z[j+1] is inside |
---|
621 | // |
---|
622 | npoly = npoly + 1; |
---|
623 | f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); |
---|
624 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
625 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
626 | // |
---|
627 | npoly = npoly + 1; |
---|
628 | xpoly[npoly] = x[j + 1]; |
---|
629 | ypoly[npoly] = y[j + 1]; |
---|
630 | } |
---|
631 | } |
---|
632 | else |
---|
633 | { |
---|
634 | // |
---|
635 | // x[j] is inside |
---|
636 | // |
---|
637 | if( z[j + 1] > zlevp1 ) |
---|
638 | { |
---|
639 | // |
---|
640 | // z[j+1] is above |
---|
641 | // |
---|
642 | npoly = npoly + 1; |
---|
643 | f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); |
---|
644 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
645 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
646 | } |
---|
647 | else if( z[j + 1] < zlev ) |
---|
648 | { |
---|
649 | // |
---|
650 | // z[j+1] is below |
---|
651 | // |
---|
652 | npoly = npoly + 1; |
---|
653 | f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); |
---|
654 | xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); |
---|
655 | ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); |
---|
656 | } |
---|
657 | else |
---|
658 | { |
---|
659 | // |
---|
660 | // z[j+1] is inside |
---|
661 | // |
---|
662 | npoly = npoly + 1; |
---|
663 | xpoly[npoly] = x[j + 1]; |
---|
664 | ypoly[npoly] = y[j + 1]; |
---|
665 | } |
---|
666 | } |
---|
667 | } |
---|
668 | fillPolygon( g, col, xpoly, ypoly, npoly + 1 ); |
---|
669 | } |
---|
670 | } |
---|
671 | |
---|
672 | private void fillPolygon( Graphics g, Color c, |
---|
673 | double[] x, double[] y, |
---|
674 | int npoints ) |
---|
675 | { |
---|
676 | Layer layer = cg_.getLayer(); |
---|
677 | int[] xt = new int[20]; |
---|
678 | int[] yt = new int[20]; |
---|
679 | g.setColor( c ); |
---|
680 | for( int i = 0; i < npoints; i++ ) |
---|
681 | { |
---|
682 | xt[i] = layer.getXPtoD( x[i] ); |
---|
683 | yt[i] = layer.getYPtoD( y[i] ); |
---|
684 | } |
---|
685 | g.fillPolygon( xt, yt, npoints ); |
---|
686 | } |
---|
687 | |
---|
688 | private double[] xArrayP() |
---|
689 | { |
---|
690 | int i; |
---|
691 | double[] p; |
---|
692 | if( grid_.isXTime() ) |
---|
693 | { |
---|
694 | GeoDate[] t = grid_.getTimeArray(); |
---|
695 | p = new double[t.length]; |
---|
696 | for( i = 0; i < t.length; i++ ) |
---|
697 | { |
---|
698 | p[i] = cg_.getXUtoP( t[i] ); |
---|
699 | } |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | double[] x = grid_.getXArray(); |
---|
704 | p = new double[x.length]; |
---|
705 | for( i = 0; i < x.length; i++ ) |
---|
706 | { |
---|
707 | p[i] = cg_.getXUtoP( x[i] ); |
---|
708 | } |
---|
709 | } |
---|
710 | return p; |
---|
711 | } |
---|
712 | |
---|
713 | private double[] yArrayP() |
---|
714 | { |
---|
715 | int i; |
---|
716 | double[] p; |
---|
717 | if( grid_.isYTime() ) |
---|
718 | { |
---|
719 | GeoDate[] t = grid_.getTimeArray(); |
---|
720 | p = new double[t.length]; |
---|
721 | for( i = 0; i < t.length; i++ ) |
---|
722 | { |
---|
723 | p[i] = cg_.getYUtoP( t[i] ); |
---|
724 | } |
---|
725 | } |
---|
726 | else |
---|
727 | { |
---|
728 | double[] y = grid_.getYArray(); |
---|
729 | p = new double[y.length]; |
---|
730 | for( i = 0; i < y.length; i++ ) |
---|
731 | { |
---|
732 | p[i] = cg_.getYUtoP( y[i] ); |
---|
733 | } |
---|
734 | } |
---|
735 | return p; |
---|
736 | } |
---|
737 | |
---|
738 | private Range2D computeRange( int levels ) |
---|
739 | { |
---|
740 | Range2D range; |
---|
741 | double zmin = Double.POSITIVE_INFINITY; |
---|
742 | double zmax = Double.NEGATIVE_INFINITY; |
---|
743 | double[] array = grid_.getZArray(); |
---|
744 | for( int i = 0; i < array.length; i++ ) |
---|
745 | { |
---|
746 | if( !Double.isNaN( array[i] ) ) |
---|
747 | { |
---|
748 | zmin = Math.min( zmin, array[i] ); |
---|
749 | zmax = Math.max( zmax, array[i] ); |
---|
750 | } |
---|
751 | } |
---|
752 | range = Graph.computeRange( zmin, zmax, levels ); |
---|
753 | return range; |
---|
754 | } |
---|
755 | |
---|
756 | /** |
---|
757 | * Get the <code>SGTGrid</code>. |
---|
758 | * |
---|
759 | * @return <code>SGTGrid</code> |
---|
760 | */ |
---|
761 | public SGTGrid getGrid() |
---|
762 | { |
---|
763 | return grid_; |
---|
764 | } |
---|
765 | |
---|
766 | /** |
---|
767 | * Get the associated <code>CartesianGraph</code> object. |
---|
768 | * |
---|
769 | * @return <code>CartesianGraph</code> |
---|
770 | * @since 2.0 |
---|
771 | */ |
---|
772 | public CartesianGraph getCartesianGraph() |
---|
773 | { |
---|
774 | return cg_; |
---|
775 | } |
---|
776 | |
---|
777 | public void propertyChange( PropertyChangeEvent evt ) |
---|
778 | { |
---|
779 | // if(Debug.EVENT) { |
---|
780 | // System.out.println("GridCartesianRenderer: " + evt); |
---|
781 | // System.out.println(" " + evt.getPropertyName()); |
---|
782 | // } |
---|
783 | modified( "GridCartesianRenderer: propertyChange(" + |
---|
784 | evt.getSource().toString() + "[" + |
---|
785 | evt.getPropertyName() + "]" + ")" ); |
---|
786 | } |
---|
787 | |
---|
788 | /** |
---|
789 | * @since 3.0 |
---|
790 | */ |
---|
791 | public SGTData getDataAt( Point pt ) |
---|
792 | { |
---|
793 | return null; |
---|
794 | } |
---|
795 | } |
---|