Revision 4436 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/datastruct/ExtentImpl.java
ExtentImpl.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
/** |
41 | 41 |
* Clase que getiona el extent de una imagen |
42 |
*
|
|
42 |
* |
|
43 | 43 |
* @author Luis W.Sevilla (sevilla_lui@gva.es) |
44 | 44 |
*/ |
45 | 45 |
public class ExtentImpl implements Extent { |
46 | 46 |
public static final String PERSISTENT_NAME = "Extent_Persistent"; |
47 | 47 |
public static final String PERSISTENT_DESCRIPTION = "Extent Persistent"; |
48 |
|
|
48 |
|
|
49 | 49 |
Point2D min = null; |
50 | 50 |
Point2D max = null; |
51 |
|
|
51 |
|
|
52 | 52 |
Point2D ul = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
53 | 53 |
Point2D lr = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
54 | 54 |
Point2D ur = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
55 | 55 |
Point2D ll = new Point2D.Double(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
56 |
|
|
56 |
|
|
57 | 57 |
/** |
58 | 58 |
* Constructor sin par?metros |
59 | 59 |
*/ |
... | ... | |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
/** |
66 |
* Constructor
|
|
67 |
* @param pt1 punto que representa la esquina superior izquierda
|
|
68 |
* @param pt2 punto que representa la esquina inferior derecha
|
|
66 |
* Constructor |
|
67 |
* @param ul punto que representa la esquina superior izquierda
|
|
68 |
* @param lr punto que representa la esquina inferior derecha
|
|
69 | 69 |
*/ |
70 | 70 |
public ExtentImpl(Point2D ul, Point2D lr) { |
71 | 71 |
this.ul = ul; |
72 | 72 |
this.lr = lr; |
73 | 73 |
newExtent(ul.getX(), ul.getY(), lr.getX(), lr.getY()); |
74 | 74 |
} |
75 |
|
|
75 |
|
|
76 | 76 |
/** |
77 |
* Constructor
|
|
77 |
* Constructor |
|
78 | 78 |
* @param ul punto que representa la esquina superior izquierda |
79 | 79 |
* @param lr punto que representa la esquina inferior derecha |
80 | 80 |
* @param ur punto que representa la esquina superior derecha |
... | ... | |
85 | 85 |
this.lr = lr; |
86 | 86 |
this.ur = ur; |
87 | 87 |
this.ll = ll; |
88 |
min = new Point2D.Double(
|
|
89 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())),
|
|
90 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY())));
|
|
91 |
max = new Point2D.Double(
|
|
92 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())),
|
|
88 |
min = new Point2D.Double( |
|
89 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())), |
|
90 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY()))); |
|
91 |
max = new Point2D.Double( |
|
92 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())), |
|
93 | 93 |
Math.max(Math.max(ul.getY(), lr.getY()), Math.max(ur.getY(), ll.getY()))); |
94 | 94 |
} |
95 | 95 |
|
... | ... | |
129 | 129 |
min = new Point2D.Double(ext.minX(), ext.minY()); |
130 | 130 |
max = new Point2D.Double(ext.maxX(), ext.maxY()); |
131 | 131 |
} |
132 |
|
|
132 |
|
|
133 | 133 |
public Extent encloseBoundinBoxes(Extent ext) { |
134 | 134 |
Point2D pUl = new Point2D.Double( |
135 |
Math.min(getULX(), ext.getULX()),
|
|
135 |
Math.min(getULX(), ext.getULX()), |
|
136 | 136 |
Math.max(getULY(), ext.getULY())); |
137 | 137 |
Point2D pLr = new Point2D.Double( |
138 |
Math.max(getLRX(), ext.getLRX()),
|
|
138 |
Math.max(getLRX(), ext.getLRX()), |
|
139 | 139 |
Math.min(getLRY(), ext.getLRY())); |
140 | 140 |
return new ExtentImpl(pUl, pLr); |
141 | 141 |
} |
142 |
|
|
142 |
|
|
143 | 143 |
public Extent intersection(Extent ext) { |
144 | 144 |
if(intersects(ext)) { |
145 | 145 |
Point2D pUl = new Point2D.Double( |
146 |
Math.max(getULX(), ext.getULX()),
|
|
146 |
Math.max(getULX(), ext.getULX()), |
|
147 | 147 |
Math.min(getULY(), ext.getULY())); |
148 | 148 |
Point2D pLr = new Point2D.Double( |
149 |
Math.min(getLRX(), ext.getLRX()),
|
|
149 |
Math.min(getLRX(), ext.getLRX()), |
|
150 | 150 |
Math.max(getLRY(), ext.getLRY())); |
151 | 151 |
return new ExtentImpl(pUl, pLr); |
152 | 152 |
} |
... | ... | |
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
public boolean intersects(Extent ext) { |
157 |
if (getMin().getX() > ext.getMax().getX())
|
|
157 |
if (getMin().getX() > ext.getMax().getX()) |
|
158 | 158 |
return false; |
159 |
else if (getMax().getX() < ext.getMin().getX())
|
|
159 |
else if (getMax().getX() < ext.getMin().getX()) |
|
160 | 160 |
return false; |
161 |
if (getMin().getY() > ext.getMax().getY())
|
|
161 |
if (getMin().getY() > ext.getMax().getY()) |
|
162 | 162 |
return false; |
163 |
else if (getMax().getY() < ext.getMin().getY())
|
|
163 |
else if (getMax().getY() < ext.getMin().getY()) |
|
164 | 164 |
return false; |
165 | 165 |
return true; |
166 | 166 |
} |
... | ... | |
173 | 173 |
ExtentImpl e = new ExtentImpl(); |
174 | 174 |
e.min = min != null ? (Point2D) min.clone() : null; |
175 | 175 |
e.max = max != null ? (Point2D) max.clone() : null; |
176 |
|
|
176 |
|
|
177 | 177 |
e.ul = ul != null ? (Point2D) ul.clone() : null; |
178 | 178 |
e.lr = lr != null ? (Point2D) lr.clone() : null; |
179 | 179 |
e.ur = ur != null ? (Point2D) ur.clone() : null; |
... | ... | |
217 | 217 |
public double maxY() { |
218 | 218 |
return max.getY(); |
219 | 219 |
} |
220 |
|
|
220 |
|
|
221 | 221 |
/** |
222 | 222 |
* Obtiene el punto m?nimo |
223 | 223 |
* @return m?nimo |
... | ... | |
235 | 235 |
} |
236 | 236 |
|
237 | 237 |
public boolean isAt(Point2D pt) { |
238 |
if (pt.getX() < minX())
|
|
238 |
if (pt.getX() < minX()) |
|
239 | 239 |
return false; |
240 |
|
|
241 |
if (pt.getX() > maxX())
|
|
240 |
|
|
241 |
if (pt.getX() > maxX()) |
|
242 | 242 |
return false; |
243 |
|
|
243 |
|
|
244 | 244 |
if (pt.getY() < minY()) |
245 | 245 |
return false; |
246 |
|
|
247 |
if (pt.getY() > maxY())
|
|
246 |
|
|
247 |
if (pt.getY() > maxY()) |
|
248 | 248 |
return false; |
249 |
|
|
249 |
|
|
250 | 250 |
return true; |
251 | 251 |
} |
252 | 252 |
|
... | ... | |
257 | 257 |
public double height() { |
258 | 258 |
return Math.abs(maxY() - minY()); |
259 | 259 |
} |
260 |
|
|
260 |
|
|
261 | 261 |
/** |
262 | 262 |
* Obtiene el centro en X del extent |
263 |
* @return |
|
263 |
* @return coordinate X of center
|
|
264 | 264 |
*/ |
265 | 265 |
public double getCenterX() { |
266 | 266 |
return minX() + (width() / 2); |
267 | 267 |
} |
268 |
|
|
268 |
|
|
269 | 269 |
/** |
270 | 270 |
* Obtiene el centro en Y del extent |
271 |
* @return |
|
271 |
* @return coordinate Y of center
|
|
272 | 272 |
*/ |
273 | 273 |
public double getCenterY() { |
274 | 274 |
return minY() + (height() / 2); |
... | ... | |
276 | 276 |
|
277 | 277 |
/** |
278 | 278 |
* Verifica un punto, y modifica el extent si no est? incluido |
279 |
* @param pt |
|
279 | 280 |
*/ |
280 | 281 |
public void add(Point2D pt) { |
281 | 282 |
if (pt == null) { |
... | ... | |
301 | 302 |
* Obtiene la escala |
302 | 303 |
* @param width Ancho |
303 | 304 |
* @param height Alto |
304 |
* @return |
|
305 |
* @return the scale
|
|
305 | 306 |
*/ |
306 | 307 |
public double[] getScale(int width, int height) { |
307 | 308 |
return getScale((double) width, (double) height); |
... | ... | |
330 | 331 |
public interface Has { |
331 | 332 |
public Extent getExtent(); |
332 | 333 |
} |
333 |
|
|
334 |
|
|
334 | 335 |
public Point2D getUL() { |
335 | 336 |
return (Point2D)ul.clone(); |
336 | 337 |
} |
337 |
|
|
338 |
|
|
338 | 339 |
public Point2D getLR() { |
339 | 340 |
return (Point2D)lr.clone(); |
340 | 341 |
} |
341 |
|
|
342 |
|
|
342 | 343 |
/** |
343 | 344 |
* Obtiene la coordenada X de la esquina superior izquierda. Esta, en condiciones normales |
344 | 345 |
* conincide con el minimo en X pero cuando un raster est? rotado esto puede variar. |
... | ... | |
349 | 350 |
return minX(); |
350 | 351 |
return ul.getX(); |
351 | 352 |
} |
352 |
|
|
353 |
|
|
353 | 354 |
/** |
354 | 355 |
* Obtiene la coordenada Y de la esquina superior izquierda. Esta, en condiciones normales |
355 | 356 |
* conincide con el maximo en Y pero cuando un raster est? rotado esto puede variar. |
... | ... | |
360 | 361 |
return maxY(); |
361 | 362 |
return ul.getY(); |
362 | 363 |
} |
363 |
|
|
364 |
|
|
364 | 365 |
/** |
365 | 366 |
* Obtiene la coordenada X de la esquina inferior derecha. Esta, en condiciones normales |
366 | 367 |
* conincide con el m?ximo en X pero cuando un raster est? rotado esto puede variar. |
... | ... | |
371 | 372 |
return maxX(); |
372 | 373 |
return lr.getX(); |
373 | 374 |
} |
374 |
|
|
375 |
|
|
375 | 376 |
/** |
376 | 377 |
* Obtiene la coordenada Y de la esquina inferior derecha. Esta, en condiciones normales |
377 | 378 |
* conincide con el minimo en Y pero cuando un raster est? rotado esto puede variar. |
378 | 379 |
* @return lry |
379 | 380 |
*/ |
380 | 381 |
public double getLRY() { |
381 |
if(lr.getX() == -999999999.0)
|
|
382 |
if(lr.getY() == -999999999.0)
|
|
382 | 383 |
return minY(); |
383 | 384 |
return lr.getY(); |
384 | 385 |
} |
385 |
|
|
386 |
|
|
386 | 387 |
/** |
387 |
* Obtiene la coordenada X de la esquina superior derecha.
|
|
388 |
* Obtiene la coordenada X de la esquina superior derecha. |
|
388 | 389 |
* @return urx |
389 | 390 |
*/ |
390 | 391 |
public double getURX() { |
391 | 392 |
return ur.getX(); |
392 | 393 |
} |
393 |
|
|
394 |
|
|
394 | 395 |
/** |
395 | 396 |
* Obtiene la coordenada Y de la esquina superior derecha. |
396 | 397 |
* @return uly |
... | ... | |
398 | 399 |
public double getURY() { |
399 | 400 |
return ur.getY(); |
400 | 401 |
} |
401 |
|
|
402 |
|
|
402 | 403 |
/** |
403 | 404 |
* Obtiene la coordenada X de la esquina inferior izquierda. |
404 | 405 |
* @return lrx |
... | ... | |
406 | 407 |
public double getLLX() { |
407 | 408 |
return ll.getX(); |
408 | 409 |
} |
409 |
|
|
410 |
|
|
410 | 411 |
/** |
411 | 412 |
* Obtiene la coordenada Y de la esquina inferior izquierda. |
412 | 413 |
* @return lly |
... | ... | |
414 | 415 |
public double getLLY() { |
415 | 416 |
return ll.getY(); |
416 | 417 |
} |
417 |
|
|
418 |
|
|
418 | 419 |
/** |
419 | 420 |
* Asigna la coordenada X de la esquina superior izquierda al m?nimo X |
420 | 421 |
*/ |
... | ... | |
422 | 423 |
ul.setLocation(minX(), ul.getY()); |
423 | 424 |
lr.setLocation(maxX(), lr.getY()); |
424 | 425 |
} |
425 |
|
|
426 |
|
|
426 | 427 |
/** |
427 | 428 |
* Asigna la coordenada X de la esquina superior izquierda al m?ximo X |
428 | 429 |
*/ |
... | ... | |
430 | 431 |
ul.setLocation(maxX(), ul.getY()); |
431 | 432 |
lr.setLocation(minX(), lr.getY()); |
432 | 433 |
} |
433 |
|
|
434 |
|
|
434 | 435 |
/** |
435 | 436 |
* Asigna la coordenada Y de la esquina superior izquierda al m?nimo Y |
436 | 437 |
*/ |
... | ... | |
438 | 439 |
ul.setLocation(ul.getX(), minY()); |
439 | 440 |
lr.setLocation(lr.getX(), maxY()); |
440 | 441 |
} |
441 |
|
|
442 |
|
|
442 | 443 |
/** |
443 | 444 |
* Asigna la coordenada Y de la esquina superior izquierda al m?ximo Y |
444 | 445 |
*/ |
... | ... | |
446 | 447 |
ul.setLocation(ul.getX(), maxY()); |
447 | 448 |
lr.setLocation(lr.getX(), minY()); |
448 | 449 |
} |
449 |
|
|
450 |
|
|
450 | 451 |
/** |
451 | 452 |
* Asigna la coordenada X de la esquina inferior derecha al m?nimo X |
452 | 453 |
*/ |
453 | 454 |
public void setLRXToMin() { |
454 | 455 |
lr.setLocation(minX(), lr.getY()); |
455 | 456 |
ul.setLocation(maxX(), ul.getY()); |
456 |
|
|
457 |
|
|
457 | 458 |
} |
458 |
|
|
459 |
|
|
459 | 460 |
/** |
460 | 461 |
* Asigna la coordenada X de la esquina inferior derecha al m?ximo X |
461 | 462 |
*/ |
... | ... | |
463 | 464 |
lr.setLocation(maxX(), lr.getY()); |
464 | 465 |
ul.setLocation(minX(), ul.getY()); |
465 | 466 |
} |
466 |
|
|
467 |
|
|
467 | 468 |
/** |
468 | 469 |
* Asigna la coordenada Y de la esquina inferior derecha al m?nimo Y |
469 | 470 |
*/ |
... | ... | |
471 | 472 |
lr.setLocation(lr.getX(), minY()); |
472 | 473 |
ul.setLocation(ul.getX(), maxX()); |
473 | 474 |
} |
474 |
|
|
475 |
|
|
475 | 476 |
/** |
476 | 477 |
* Asigna la coordenada Y de la esquina inferior derecha al m?ximo Y |
477 | 478 |
*/ |
... | ... | |
479 | 480 |
lr.setLocation(lr.getX(), maxY()); |
480 | 481 |
ul.setLocation(ul.getX(), minY()); |
481 | 482 |
} |
482 |
|
|
483 |
|
|
483 | 484 |
public Extent convert(ICoordTrans trans) { |
484 | 485 |
Rectangle2D rect = new Rectangle2D.Double(getURX(), getLRY(), width(), height()); |
485 | 486 |
Rectangle2D rectDest = trans.convert(rect); |
... | ... | |
488 | 489 |
} |
489 | 490 |
|
490 | 491 |
return new ExtentImpl( |
491 |
rectDest.getMinX(),
|
|
492 |
rectDest.getMaxY(),
|
|
493 |
rectDest.getMaxX(),
|
|
492 |
rectDest.getMinX(), |
|
493 |
rectDest.getMaxY(), |
|
494 |
rectDest.getMaxX(), |
|
494 | 495 |
rectDest.getMinY()); |
495 | 496 |
} |
496 |
|
|
497 |
|
|
497 | 498 |
public boolean equals(Object obj) { |
498 | 499 |
if(!(obj instanceof Extent)) |
499 | 500 |
return false; |
... | ... | |
507 | 508 |
this.getLLX() == e1.getLLX() && |
508 | 509 |
this.getLLY() == e1.getLLY()); |
509 | 510 |
} |
510 |
|
|
511 |
|
|
511 | 512 |
/** |
512 | 513 |
* Given a cell size, converts a point in raster coordinates to world coordinates |
513 | 514 |
* @param pt Point to transform |
... | ... | |
533 | 534 |
} |
534 | 535 |
return p; |
535 | 536 |
} |
536 |
|
|
537 |
|
|
537 | 538 |
public void loadFromState(PersistentState state) |
538 | 539 |
throws PersistenceException { |
539 | 540 |
double ulx = state.getDouble("ulx"); |
... | ... | |
548 | 549 |
lr.setLocation(lrx, lry); |
549 | 550 |
ur.setLocation(urx, ury); |
550 | 551 |
ll.setLocation(llx, lly); |
551 |
if( ur.getX() != Double.POSITIVE_INFINITY &&
|
|
552 |
if( ur.getX() != Double.POSITIVE_INFINITY && |
|
552 | 553 |
ur.getY() != Double.POSITIVE_INFINITY && |
553 | 554 |
ll.getX() != Double.POSITIVE_INFINITY && |
554 | 555 |
ll.getY() != Double.POSITIVE_INFINITY) { |
555 |
min = new Point2D.Double(
|
|
556 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())),
|
|
557 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY())));
|
|
558 |
max = new Point2D.Double(
|
|
559 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())),
|
|
556 |
min = new Point2D.Double( |
|
557 |
Math.min(Math.min(ul.getX(), lr.getX()), Math.min(ur.getX(), ll.getX())), |
|
558 |
Math.min(Math.min(ul.getY(), lr.getY()), Math.min(ur.getY(), ll.getY()))); |
|
559 |
max = new Point2D.Double( |
|
560 |
Math.max(Math.max(ul.getX(), lr.getX()), Math.max(ur.getX(), ll.getX())), |
|
560 | 561 |
Math.max(Math.max(ul.getY(), lr.getY()), Math.max(ur.getY(), ll.getY()))); |
561 | 562 |
} else { |
562 | 563 |
newExtent(ulx, uly, lrx, lry); |
... | ... | |
572 | 573 |
state.set("ury", getURY()); |
573 | 574 |
state.set("llx", getLLX()); |
574 | 575 |
state.set("lly", getLLY()); |
575 |
}
|
|
576 |
|
|
576 |
} |
|
577 |
|
|
577 | 578 |
public static void registerPersistence() { |
578 | 579 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
579 | 580 |
DynStruct definition = manager.getDefinition(PERSISTENT_NAME); |
... | ... | |
582 | 583 |
Extent.class, |
583 | 584 |
PERSISTENT_NAME, |
584 | 585 |
PERSISTENT_DESCRIPTION, |
585 |
null,
|
|
586 |
null, |
|
586 | 587 |
null |
587 | 588 |
); |
588 |
|
|
589 |
|
|
589 | 590 |
definition.addDynFieldDouble("ulx").setMandatory(true); |
590 | 591 |
definition.addDynFieldDouble("uly").setMandatory(true); |
591 | 592 |
definition.addDynFieldDouble("lrx").setMandatory(true); |
... | ... | |
596 | 597 |
definition.addDynFieldDouble("lly").setMandatory(false); |
597 | 598 |
} |
598 | 599 |
} |
599 |
|
|
600 |
|
|
600 | 601 |
protected void finalize() throws Throwable { |
601 | 602 |
min = null; |
602 | 603 |
max = null; |
Also available in: Unified diff