Revision 17836 trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/principalcomponents/PCStatisticsProcess.java
PCStatisticsProcess.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
package org.gvsig.remotesensing.principalcomponents; |
42 | 42 |
|
43 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
|
44 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
45 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
46 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
43 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
47 | 44 |
import org.gvsig.raster.buffer.BufferFactory; |
48 | 45 |
import org.gvsig.raster.buffer.RasterBuffer; |
49 |
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
|
50 | 46 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
51 | 47 |
import org.gvsig.raster.dataset.IRasterDataSource; |
52 | 48 |
import org.gvsig.raster.grid.Grid; |
53 | 49 |
import org.gvsig.raster.grid.GridException; |
54 |
import org.gvsig.raster.process.CancelEvent; |
|
55 |
import org.gvsig.raster.process.RasterTask; |
|
56 |
import org.gvsig.raster.process.RasterTaskQueue; |
|
57 | 50 |
import org.gvsig.raster.util.RasterToolsUtil; |
51 |
import org.gvsig.rastertools.RasterProcess; |
|
58 | 52 |
import org.gvsig.remotesensing.principalcomponents.gui.PrincipalComponentCalculusPanel; |
59 | 53 |
|
60 | 54 |
import Jama.EigenvalueDecomposition; |
... | ... | |
73 | 67 |
* @version 19/10/2007 |
74 | 68 |
*/ |
75 | 69 |
|
76 |
public class PCStatisticsProcess implements Runnable, IIncrementable, IncrementableListener{
|
|
70 |
public class PCStatisticsProcess extends RasterProcess{
|
|
77 | 71 |
|
78 | 72 |
private Grid inputGrid = null; |
79 | 73 |
private double autovalors[] = null; |
80 | 74 |
private Matrix coVarMatrix = null; |
81 | 75 |
private Matrix autoVectorMatrix = null; |
82 |
private IncrementableTask incrementableTask = null; |
|
83 | 76 |
private int percent = 0; |
84 | 77 |
private boolean cancel = false; |
85 |
private Thread blinker = null; |
|
86 |
private View view = null; |
|
87 |
private RasterTask rasterTask = new RasterTask(this); |
|
88 |
private IRasterDataSource raster = null; |
|
89 | 78 |
private boolean selectedBands[] =null; |
79 |
private FLyrRasterSE rasterSE = null; |
|
80 |
private View view = null; |
|
90 | 81 |
|
91 |
|
|
92 | 82 |
/** |
93 | 83 |
* Constructor |
94 |
* @param raster raster al que se aplica la transformacion de PC |
|
95 |
* @param view vista actual de la aplicacion |
|
96 |
* @param selectedBands bandas de la imagen seleccionadas para el proceso |
|
97 | 84 |
*/ |
98 |
public PCStatisticsProcess(IRasterDataSource raster,View view,boolean selectedBands[]) { |
|
99 |
this.raster= raster; |
|
100 |
this.view = view; |
|
101 |
this.selectedBands= selectedBands; |
|
85 |
public PCStatisticsProcess() { |
|
102 | 86 |
} |
103 | 87 |
|
104 | 88 |
|
... | ... | |
108 | 92 |
public void calculate() { |
109 | 93 |
//Calculo de matriz de covarianza: |
110 | 94 |
double coVar[][]= covarianceOptimize(); |
111 |
|
|
112 | 95 |
// Calculo de autovectores: |
113 | 96 |
coVarMatrix = new Matrix(coVar); |
114 | 97 |
EigenvalueDecomposition eigenvalueDecomp = new EigenvalueDecomposition(coVarMatrix); |
115 |
|
|
116 | 98 |
//Autovectores |
117 | 99 |
autoVectorMatrix= eigenvalueDecomp.getV(); |
118 |
|
|
119 | 100 |
// Autovalores |
120 | 101 |
autovalors= eigenvalueDecomp.getRealEigenvalues(); |
121 | 102 |
} |
... | ... | |
361 | 342 |
return coV; |
362 | 343 |
} |
363 | 344 |
|
364 |
|
|
365 |
/** |
|
366 |
* Lanza el proceso. |
|
367 |
* |
|
368 |
*/ |
|
369 |
public void start() { |
|
370 |
cancel = false; |
|
371 |
blinker = new Thread(this); |
|
372 |
blinker.start(); |
|
373 |
} |
|
374 |
|
|
375 |
|
|
376 |
/** |
|
377 |
* Proceso. |
|
378 |
*/ |
|
379 |
public void run() { |
|
380 |
|
|
381 |
RasterTaskQueue.register(rasterTask); //Registro de la tarea |
|
382 |
|
|
383 |
try{ |
|
384 |
// Se establece el grid con las bandas seleccionadas |
|
385 |
setGrid(); |
|
386 |
// Calculo de matriz de covarianza: |
|
387 |
double coVar[][]= covarianceOptimize(); |
|
388 |
|
|
389 |
// Calculo de autovectores: |
|
390 |
coVarMatrix = new Matrix(coVar); |
|
391 |
EigenvalueDecomposition eigenvalueDecomp = new EigenvalueDecomposition(coVarMatrix); |
|
392 |
//Autovectores |
|
393 |
autoVectorMatrix= eigenvalueDecomp.getV(); |
|
394 |
|
|
395 |
// Autovalores |
|
396 |
autovalors= eigenvalueDecomp.getRealEigenvalues(); |
|
397 | 345 |
|
398 |
}finally{ |
|
399 |
|
|
400 |
if (incrementableTask!=null){ |
|
401 |
incrementableTask.processFinalize(); |
|
402 |
} |
|
403 |
|
|
404 |
if(!cancel){ |
|
405 |
PrincipalComponentCalculusPanel altPrincipalComponentCalculusPanel = new PrincipalComponentCalculusPanel(view,this); |
|
406 |
PluginServices.getMDIManager().addWindow(altPrincipalComponentCalculusPanel); |
|
407 |
} |
|
408 |
RasterTaskQueue.remove(rasterTask); |
|
409 |
} |
|
410 |
} |
|
411 |
|
|
412 | 346 |
|
413 | 347 |
/** |
414 | 348 |
* Construye el grid con las bandas seleccionadas |
415 | 349 |
*/ |
416 | 350 |
public void setGrid(){ |
417 | 351 |
|
418 |
BufferFactory dataSource = new BufferFactory(raster); |
|
352 |
IRasterDataSource dsetCopy = null; |
|
353 |
dsetCopy = rasterSE.getDataSource().copy(); |
|
354 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy); |
|
355 |
|
|
419 | 356 |
int longitud=0; |
420 | 357 |
for (int i=0; i<selectedBands.length;i++) |
421 | 358 |
if (selectedBands[i]) longitud++; |
... | ... | |
428 | 365 |
j++; |
429 | 366 |
} |
430 | 367 |
try { |
431 |
inputGrid = new Grid(dataSource, bands);
|
|
368 |
inputGrid = new Grid(bufferFactory, bands);
|
|
432 | 369 |
} catch (RasterBufferInvalidException e) { |
433 | 370 |
e.printStackTrace(); |
434 | 371 |
} |
... | ... | |
468 | 405 |
return PluginServices.getText(this,"principal_components"); |
469 | 406 |
} |
470 | 407 |
|
471 |
/* |
|
472 |
* (non-Javadoc) |
|
473 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionCanceled |
|
408 |
/** |
|
409 |
* @return grid |
|
474 | 410 |
*/ |
475 |
public void actionCanceled(IncrementableEvent e) { |
|
476 |
cancel=true; |
|
477 |
rasterTask.setEvent(new CancelEvent(this)); |
|
411 |
public Grid getInputGrid() { |
|
412 |
return inputGrid; |
|
478 | 413 |
} |
479 |
|
|
480 |
/* |
|
481 |
* (non-Javadoc)
|
|
482 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionResumed
|
|
483 |
*/
|
|
484 |
public void actionResumed(IncrementableEvent e) {
|
|
414 |
|
|
415 |
/**
|
|
416 |
* @return raster de entrada
|
|
417 |
* */
|
|
418 |
public FLyrRasterSE getRasterLayer(){
|
|
419 |
return rasterSE;
|
|
485 | 420 |
} |
486 | 421 |
|
487 |
/* |
|
488 |
* (non-Javadoc) |
|
489 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionSuspended |
|
490 |
*/ |
|
491 |
public void actionSuspended(IncrementableEvent e) { |
|
492 |
} |
|
493 | 422 |
|
494 |
|
|
495 |
/* |
|
496 |
* (non-Javadoc) |
|
497 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#setIncrementableTask |
|
498 |
*/ |
|
499 |
public void setIncrementableTask(IncrementableTask incrementableTask) { |
|
500 |
this.incrementableTask = incrementableTask; |
|
501 |
this.incrementableTask.addIncrementableListener(this); |
|
423 |
public void init() { |
|
424 |
// Se toman los parametros del proceso |
|
425 |
selectedBands = (boolean []) getParam("selectedBands"); |
|
426 |
view = (View)getParam("view"); |
|
427 |
rasterSE = getLayerParam("layer"); |
|
428 |
|
|
502 | 429 |
} |
503 | 430 |
|
504 | 431 |
|
505 | 432 |
/** |
506 |
* @return grid |
|
507 |
*/ |
|
508 |
public Grid getInputGrid() { |
|
509 |
return inputGrid; |
|
433 |
* Proceso de calculo de estadisticas para Principal Component |
|
434 |
* */ |
|
435 |
public void process() throws InterruptedException { |
|
436 |
try{ |
|
437 |
// Se establece el grid con las bandas seleccionadas |
|
438 |
setGrid(); |
|
439 |
// Calculo de matriz de covarianza: |
|
440 |
double coVar[][]= covarianceOptimize(); |
|
441 |
// Calculo de autovectores: |
|
442 |
coVarMatrix = new Matrix(coVar); |
|
443 |
EigenvalueDecomposition eigenvalueDecomp = new EigenvalueDecomposition(coVarMatrix); |
|
444 |
//Autovectores |
|
445 |
autoVectorMatrix= eigenvalueDecomp.getV(); |
|
446 |
// Autovalores |
|
447 |
autovalors= eigenvalueDecomp.getRealEigenvalues(); |
|
448 |
|
|
449 |
}finally{ |
|
450 |
if(!cancel){ |
|
451 |
incrementableTask.processFinalize(); |
|
452 |
PrincipalComponentCalculusPanel altPrincipalComponentCalculusPanel = new PrincipalComponentCalculusPanel(view,this); |
|
453 |
PluginServices.getMDIManager().addWindow(altPrincipalComponentCalculusPanel); |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
510 | 457 |
} |
511 | 458 |
|
512 |
|
|
513 | 459 |
/** |
514 |
* @return r?ster de entrada |
|
515 |
*/ |
|
516 |
public IRasterDataSource getRaster(){ |
|
517 |
return raster; |
|
518 |
} |
|
519 |
|
|
520 |
/** |
|
521 | 460 |
* @return vista de la aplicacion |
522 | 461 |
*/ |
523 | 462 |
public View getView(){ |
Also available in: Unified diff