Revision 4436 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/util/DefaultRasterUtils.java
DefaultRasterUtils.java | ||
---|---|---|
48 | 48 |
public class DefaultRasterUtils implements RasterUtils { |
49 | 49 |
public static final int MAX_BYTE_BIT_VALUE = 255; |
50 | 50 |
public static final int MAX_SHORT_BIT_VALUE = 65535; |
51 |
|
|
51 |
|
|
52 | 52 |
public boolean loadInMemory(RasterDataStore datasource) { |
53 | 53 |
return (datasource.getFileSize() < (RasterLibrary.cacheSize * 1048576)); |
54 | 54 |
} |
55 |
|
|
56 |
public boolean isBufferTooBig(double[] coords, int bands) {
|
|
55 |
|
|
56 |
public boolean isBufferTooBig(double[] coords, int bands) { |
|
57 | 57 |
int w = (int)Math.abs(coords[2] - coords[0]); |
58 | 58 |
int h = (int)Math.abs(coords[3] - coords[1]); |
59 | 59 |
|
60 |
long windowSize = w * h * bands;
|
|
60 |
long windowSize = w * h * bands; |
|
61 | 61 |
return (windowSize > (RasterLibrary.cacheSize * 1048576)); |
62 |
}
|
|
63 |
|
|
62 |
} |
|
63 |
|
|
64 | 64 |
public boolean isBufferTooBig(double[] coords, double resolution, int bands) { |
65 | 65 |
double wPx = (coords[0] - coords[2]) / resolution; |
66 | 66 |
double hPx = (coords[1] - coords[3]) / resolution; |
67 | 67 |
return isBufferTooBig(new double[]{0, 0, wPx, hPx}, bands); |
68 |
}
|
|
68 |
} |
|
69 | 69 |
|
70 | 70 |
// --------------------------------------------------------------- |
71 | 71 |
// TIPOS DE DATOS |
... | ... | |
158 | 158 |
str.append(list[i] + ","); |
159 | 159 |
return str.toString(); |
160 | 160 |
} |
161 |
|
|
161 |
|
|
162 | 162 |
// --------------------------------------------------------------- |
163 | 163 |
// CONVERSI?N DE COORDENADAS |
164 | 164 |
|
... | ... | |
221 | 221 |
return true; |
222 | 222 |
return false; |
223 | 223 |
} |
224 |
|
|
224 |
|
|
225 | 225 |
public Extent intersection(Extent e1, Extent e2) { |
226 | 226 |
if( (e1.getMin().getX() > e2.getMax().getX()) || |
227 | 227 |
(e1.getMax().getX() < e2.getMin().getX()) || |
... | ... | |
258 | 258 |
} |
259 | 259 |
|
260 | 260 |
public boolean isInside(Extent e1, Extent e2) { |
261 |
return ((e1.getMin().getX() >= e2.getMin().getX()) &&
|
|
262 |
(e1.getMin().getY() >= e2.getMin().getY()) &&
|
|
263 |
(e1.getMax().getX() <= e2.getMax().getX()) &&
|
|
261 |
return ((e1.getMin().getX() >= e2.getMin().getX()) && |
|
262 |
(e1.getMin().getY() >= e2.getMin().getY()) && |
|
263 |
(e1.getMax().getX() <= e2.getMax().getX()) && |
|
264 | 264 |
(e1.getMax().getY() <= e2.getMax().getY())); |
265 | 265 |
} |
266 |
|
|
266 |
|
|
267 | 267 |
public boolean isInside(Point2D p1, Extent e1) { |
268 | 268 |
return ((p1.getX() >= e1.getMin().getX()) && (p1.getX() <= e1.getMax().getX()) && (p1.getY() >= e1.getMin().getY())) && (p1.getY() <= e1.getMax().getY()); |
269 | 269 |
} |
... | ... | |
321 | 321 |
/** |
322 | 322 |
* Gets the exception trace |
323 | 323 |
* @param e |
324 |
* @return |
|
324 |
* @return the exception trace
|
|
325 | 325 |
*/ |
326 | 326 |
public String getTrace(Exception e) { |
327 | 327 |
Throwable throwable = e; |
... | ... | |
330 | 330 |
for (int i = 0; i < elemList.length; i++) { |
331 | 331 |
r += " !!!-" + elemList[i].toString() + "\n"; |
332 | 332 |
} |
333 |
|
|
333 |
|
|
334 | 334 |
while(throwable.getCause() != null) { |
335 | 335 |
elemList = throwable.getCause().getStackTrace(); |
336 | 336 |
for (int i = 0; i < elemList.length; i++) { |
... | ... | |
340 | 340 |
} |
341 | 341 |
return r; |
342 | 342 |
} |
343 |
|
|
343 |
|
|
344 | 344 |
public String formatTime(long time) { |
345 | 345 |
int days = 0; |
346 | 346 |
int hours = 0; |
... | ... | |
400 | 400 |
} |
401 | 401 |
return coordPx; |
402 | 402 |
} |
403 |
|
|
403 |
|
|
404 | 404 |
public Extent calculateAdjustedView(Extent extToAdj, Extent imgExt) { |
405 | 405 |
double vx = extToAdj.minX(); |
406 | 406 |
double vy = extToAdj.minY(); |
... | ... | |
424 | 424 |
|
425 | 425 |
public Extent calculateAdjustedView(Extent extToAdj, AffineTransform at, double w, double h) { |
426 | 426 |
// Obtenemos los cuatro puntos de la petici?n de origen |
427 |
Point2D ul = new Point2D.Double(extToAdj.getULX(), extToAdj.getULY()); |
|
428 |
Point2D lr = new Point2D.Double(extToAdj.getLRX(), extToAdj.getLRY()); |
|
427 |
Point2D src_ul = new Point2D.Double(extToAdj.getULX(), extToAdj.getULY()); |
|
428 |
Point2D src_lr = new Point2D.Double(extToAdj.getLRX(), extToAdj.getLRY()); |
|
429 |
Point2D ul = new Point2D.Double(); |
|
430 |
Point2D lr = new Point2D.Double(); |
|
429 | 431 |
|
430 | 432 |
// Los convertimos a coordenadas pixel con la matriz de transformaci?n |
431 | 433 |
try { |
432 |
at.inverseTransform(ul, ul); |
|
433 |
at.inverseTransform(lr, lr); |
|
434 |
at.inverseTransform(src_ul, ul);
|
|
435 |
at.inverseTransform(src_lr, lr);
|
|
434 | 436 |
} catch (NoninvertibleTransformException e) { |
435 | 437 |
return extToAdj; |
436 | 438 |
} |
... | ... | |
455 | 457 |
lr.setLocation(lr.getX(), h); |
456 | 458 |
|
457 | 459 |
// Lo convertimos a coordenadas reales nuevamente |
458 |
at.transform(ul, ul); |
|
459 |
at.transform(lr, lr); |
|
460 |
return new ExtentImpl(ul, lr); |
|
460 |
Point2D real_ul = new Point2D.Double(); |
|
461 |
Point2D real_lr = new Point2D.Double(); |
|
462 |
at.transform(ul, real_ul); |
|
463 |
at.transform(lr, real_lr); |
|
464 |
return new ExtentImpl(real_ul, real_lr); |
|
461 | 465 |
} |
462 | 466 |
|
463 | 467 |
public void saveGeoInfo(String outRmf, AffineTransform at, Point2D dim) throws IOException { |
... | ... | |
466 | 470 |
manager.addClient(ser3); |
467 | 471 |
manager.write(); |
468 | 472 |
} |
469 |
|
|
473 |
|
|
470 | 474 |
/** |
471 | 475 |
* Obtiene el extent m?ximo de todas las ROIs pasadas por par?metro. |
472 | 476 |
* @param rois Lista de ROIs para calcular la extensi?n m?xima que ocupan |
... | ... | |
494 | 498 |
} |
495 | 499 |
return RasterLocator.getManager().getDataStructFactory().createExtent(minx, miny, maxx, maxy); |
496 | 500 |
} |
497 |
|
|
498 |
|
|
501 |
|
|
502 |
|
|
499 | 503 |
/** |
500 | 504 |
* Convierte un histograma al rango de valores de RGB, en pocas palabras |
501 | 505 |
* aplica una operacion 0xff a cada pixel para quitar los numeros negativos |
... | ... | |
507 | 511 |
return null; |
508 | 512 |
|
509 | 513 |
BufferHistogramImpl histImp = (BufferHistogramImpl)histogram; |
510 |
|
|
514 |
|
|
511 | 515 |
if (histImp.getDataType() != Buffer.TYPE_BYTE) |
512 | 516 |
return histogram; |
513 | 517 |
|
... | ... | |
539 | 543 |
|
540 | 544 |
double mins[] = new double[histImp.getNumBands()]; |
541 | 545 |
double maxs[] = new double[histImp.getNumBands()]; |
542 |
|
|
546 |
|
|
543 | 547 |
for (int i = 0; i < mins.length; i++) { |
544 | 548 |
mins[i] = 0; |
545 | 549 |
maxs[i] = 255; |
... | ... | |
551 | 555 |
|
552 | 556 |
return histogramNew; |
553 | 557 |
} |
554 |
|
|
558 |
|
|
555 | 559 |
public void copyToBuffer(Buffer bufResult, Extent tileExtent, |
556 | 560 |
Buffer buf, Extent ex, double rel, boolean hasAlphaBand) { |
557 | 561 |
double distx = Math.abs(ex.getULX() - tileExtent.getULX()); |
... | ... | |
590 | 594 |
} |
591 | 595 |
} |
592 | 596 |
} |
593 |
|
|
597 |
|
|
594 | 598 |
//En el resto de casos no se usa banda de transparencia sino que las zonas del tile fuera de la imagen |
595 | 599 |
//se inicializaron previamente a NoData |
596 |
|
|
600 |
|
|
597 | 601 |
if(bufResult.getDataType() == Buffer.TYPE_SHORT) { |
598 | 602 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
599 | 603 |
for (int i = distpxy; (i < bufResult.getHeight() && (i - distpxy) < buf.getHeight()); i++) { |
... | ... | |
631 | 635 |
} |
632 | 636 |
} |
633 | 637 |
} |
634 |
|
|
638 |
|
|
635 | 639 |
} |
Also available in: Unified diff