Revision 14801 trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/principalcomponents/PCStatisticsProcess.java
PCStatisticsProcess.java | ||
---|---|---|
38 | 38 |
* +34 967 599 200 |
39 | 39 |
*/ |
40 | 40 |
|
41 |
|
|
42 | 41 |
package org.gvsig.remotesensing.principalcomponents; |
43 | 42 |
|
44 | 43 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
... | ... | |
62 | 61 |
import com.iver.andami.PluginServices; |
63 | 62 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
64 | 63 |
|
65 |
|
|
66 |
|
|
67 | 64 |
/** |
68 |
*
|
|
69 |
* Clase principal para el c?lculo de Componentes Principales.
|
|
70 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
|
65 |
* PCStatisticsProcess es la clase que implementa el proceso c?lculo de estad?sticas avanzado
|
|
66 |
* para el an?lisis de componentes principales. Para la imagen y las bandas de entrada se calcula
|
|
67 |
* la matriz de varianza-covarianza y los atovalores y autovectrores asociados .
|
|
71 | 68 |
* |
69 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es) |
|
70 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) |
|
71 |
* @version 19/10/2007 |
|
72 | 72 |
*/ |
73 |
|
|
73 | 74 |
public class PCStatisticsProcess implements Runnable, IIncrementable, IncrementableListener{ |
74 | 75 |
|
75 | 76 |
private Grid inputGrid = null; |
76 |
private double result[] = null;
|
|
77 |
private double autovalors[] = null;
|
|
77 | 78 |
private Matrix coVarMatrix = null; |
78 | 79 |
private Matrix autoVectorMatrix = null; |
79 | 80 |
private IncrementableTask incrementableTask = null; |
... | ... | |
86 | 87 |
private boolean selectedBands[] =null; |
87 | 88 |
|
88 | 89 |
|
89 |
/** Calculo de la matriz de covarianza, autovalores y autovectores.*/ |
|
90 |
/** |
|
91 |
* Constructor |
|
92 |
* @param raster raster al que se aplica la transformacion de PC |
|
93 |
* @param view vista actual de la aplicacion |
|
94 |
* @param selectedBands bandas de la imagen seleccionadas para el proceso |
|
95 |
*/ |
|
96 |
public PCStatisticsProcess(IRasterDataSource raster,View view,boolean selectedBands[]) { |
|
97 |
this.raster= raster; |
|
98 |
this.view = view; |
|
99 |
this.selectedBands= selectedBands; |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
/** |
|
104 |
* C?lculo de la matriz de covarianza, autovalores y autovectores. |
|
105 |
*/ |
|
90 | 106 |
public void calculate() { |
91 | 107 |
//Calculo de matriz de covarianza: |
92 | 108 |
double coVar[][]= covarianceOptimize(); |
93 | 109 |
|
94 |
|
|
95 | 110 |
// Calculo de autovectores: |
96 | 111 |
coVarMatrix = new Matrix(coVar); |
97 | 112 |
EigenvalueDecomposition eigenvalueDecomp = new EigenvalueDecomposition(coVarMatrix); |
... | ... | |
100 | 115 |
autoVectorMatrix= eigenvalueDecomp.getV(); |
101 | 116 |
|
102 | 117 |
// Autovalores |
103 |
result= eigenvalueDecomp.getRealEigenvalues();
|
|
118 |
autovalors= eigenvalueDecomp.getRealEigenvalues();
|
|
104 | 119 |
} |
105 | 120 |
|
106 |
|
|
107 |
public PCStatisticsProcess(IRasterDataSource raster,View view,boolean selectedBands[]) { |
|
108 |
this.raster= raster; |
|
109 |
this.view = view; |
|
110 |
this.selectedBands= selectedBands; |
|
111 |
} |
|
112 |
|
|
113 |
|
|
121 |
|
|
122 |
/** |
|
123 |
* @return array con los autovalores |
|
124 |
*/ |
|
114 | 125 |
public double[] getResult() { |
115 |
return result; |
|
116 |
|
|
126 |
return autovalors; |
|
117 | 127 |
} |
118 | 128 |
|
129 |
/** |
|
130 |
* @return Matriz de autovectores |
|
131 |
*/ |
|
119 | 132 |
public Matrix getAutoVectorMatrix(){ |
120 |
|
|
121 | 133 |
return autoVectorMatrix; |
122 | 134 |
} |
123 | 135 |
|
124 | 136 |
|
137 |
/** |
|
138 |
* @return Matriz varianza-covarianza |
|
139 |
*/ |
|
125 | 140 |
public Matrix getcoVarMatrix(){ |
126 |
|
|
127 | 141 |
return coVarMatrix; |
128 | 142 |
} |
129 | 143 |
|
... | ... | |
139 | 153 |
double cancelMatrix[][]= new double[][]{{0}}; |
140 | 154 |
double valorBandai=0, valorBandaj=0; |
141 | 155 |
int bandCount = inputGrid.getRasterBuf().getBandCount(); |
142 |
|
|
143 |
|
|
144 | 156 |
if(inputGrid.getRasterBuf().getDataType() == RasterBuffer.TYPE_BYTE){ |
145 | 157 |
// Se recorre el grid obener la matriz de cov |
146 | 158 |
for (int i = 0; i < bandCount; i++) { |
... | ... | |
337 | 349 |
return coV; |
338 | 350 |
} |
339 | 351 |
|
340 |
|
|
341 |
|
|
352 |
|
|
342 | 353 |
/** |
343 | 354 |
* Lanza el proceso. |
344 | 355 |
* |
... | ... | |
349 | 360 |
blinker.start(); |
350 | 361 |
} |
351 | 362 |
|
363 |
|
|
352 | 364 |
/** |
353 | 365 |
* Proceso. |
354 | 366 |
*/ |
... | ... | |
357 | 369 |
RasterTaskQueue.register(rasterTask); //Registro de la tarea |
358 | 370 |
|
359 | 371 |
try{ |
360 |
|
|
372 |
// Se establece el grid con las bandas seleccionadas |
|
361 | 373 |
setGrid(); |
362 | 374 |
// Calculo de matriz de covarianza: |
363 | 375 |
double coVar[][]= covarianceOptimize(); |
... | ... | |
369 | 381 |
autoVectorMatrix= eigenvalueDecomp.getV(); |
370 | 382 |
|
371 | 383 |
// Autovalores |
372 |
result= eigenvalueDecomp.getRealEigenvalues();
|
|
384 |
autovalors= eigenvalueDecomp.getRealEigenvalues();
|
|
373 | 385 |
|
374 | 386 |
}finally{ |
387 |
|
|
375 | 388 |
if (incrementableTask!=null){ |
376 | 389 |
incrementableTask.processFinalize(); |
377 | 390 |
} |
391 |
|
|
378 | 392 |
if(!cancel){ |
379 | 393 |
PrincipalComponentCalculusPanel altPrincipalComponentCalculusPanel = new PrincipalComponentCalculusPanel(view,this); |
380 | 394 |
PluginServices.getMDIManager().addWindow(altPrincipalComponentCalculusPanel); |
381 | 395 |
} |
382 | 396 |
RasterTaskQueue.remove(rasterTask); |
383 |
} |
|
397 |
}
|
|
384 | 398 |
} |
385 | 399 |
|
386 | 400 |
|
401 |
/** |
|
402 |
* Construye el grid con las bandas seleccionadas |
|
403 |
*/ |
|
404 |
public void setGrid(){ |
|
387 | 405 |
|
388 |
public void setGrid(){ |
|
389 |
|
|
390 |
// Construccion del grid con las bandas seleccionadas |
|
391 |
BufferFactory dataSource = new BufferFactory(raster); |
|
392 |
|
|
406 |
BufferFactory dataSource = new BufferFactory(raster); |
|
393 | 407 |
int longitud=0; |
394 | 408 |
for (int i=0; i<selectedBands.length;i++) |
395 | 409 |
if (selectedBands[i]) longitud++; |
396 | 410 |
|
397 |
|
|
398 | 411 |
int bands[]= new int[longitud]; |
399 | 412 |
int j=0; |
400 | 413 |
for (int i=0; i<selectedBands.length; i++) |
... | ... | |
410 | 423 |
} |
411 | 424 |
|
412 | 425 |
|
413 |
|
|
426 |
/* |
|
427 |
* (non-Javadoc) |
|
428 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLabel() |
|
429 |
*/ |
|
414 | 430 |
public String getLabel() { |
415 | 431 |
return PluginServices.getText(this,"procesando"); |
416 | 432 |
} |
417 | 433 |
|
434 |
/* |
|
435 |
* (non-Javadoc) |
|
436 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLog() |
|
437 |
*/ |
|
418 | 438 |
public String getLog() { |
419 | 439 |
return PluginServices.getText(this,"calculando_estadisticas")+"..."; |
420 | 440 |
} |
421 | 441 |
|
442 |
|
|
443 |
/* |
|
444 |
* (non-Javadoc) |
|
445 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
446 |
*/ |
|
422 | 447 |
public int getPercent() { |
423 | 448 |
return percent; |
424 | 449 |
} |
425 | 450 |
|
451 |
/* |
|
452 |
* (non-Javadoc) |
|
453 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
454 |
*/ |
|
426 | 455 |
public String getTitle() { |
427 | 456 |
return PluginServices.getText(this,"principal_components"); |
428 | 457 |
} |
429 | 458 |
|
459 |
/* |
|
460 |
* (non-Javadoc) |
|
461 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionCanceled |
|
462 |
*/ |
|
430 | 463 |
public void actionCanceled(IncrementableEvent e) { |
431 | 464 |
cancel=true; |
432 |
rasterTask.setEvent(new CancelEvent(this)); |
|
433 |
|
|
465 |
rasterTask.setEvent(new CancelEvent(this)); |
|
434 | 466 |
} |
435 | 467 |
|
468 |
/* |
|
469 |
* (non-Javadoc) |
|
470 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionResumed |
|
471 |
*/ |
|
436 | 472 |
public void actionResumed(IncrementableEvent e) { |
437 | 473 |
} |
438 | 474 |
|
475 |
/* |
|
476 |
* (non-Javadoc) |
|
477 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#actionSuspended |
|
478 |
*/ |
|
439 | 479 |
public void actionSuspended(IncrementableEvent e) { |
440 | 480 |
} |
441 | 481 |
|
482 |
|
|
483 |
/* |
|
484 |
* (non-Javadoc) |
|
485 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#setIncrementableTask |
|
486 |
*/ |
|
442 | 487 |
public void setIncrementableTask(IncrementableTask incrementableTask) { |
443 | 488 |
this.incrementableTask = incrementableTask; |
444 | 489 |
this.incrementableTask.addIncrementableListener(this); |
445 | 490 |
} |
446 | 491 |
|
447 | 492 |
|
493 |
/** |
|
494 |
* @return grid |
|
495 |
*/ |
|
448 | 496 |
public Grid getInputGrid() { |
449 | 497 |
return inputGrid; |
450 | 498 |
} |
451 | 499 |
|
452 | 500 |
|
501 |
/** |
|
502 |
* @return r?ster de entrada |
|
503 |
*/ |
|
453 | 504 |
public IRasterDataSource getRaster(){ |
454 |
return raster; |
|
455 |
|
|
505 |
return raster; |
|
456 | 506 |
} |
457 | 507 |
|
508 |
/** |
|
509 |
* @return vista de la aplicacion |
|
510 |
*/ |
|
458 | 511 |
public View getView(){ |
459 |
return view; |
|
460 |
|
|
512 |
return view; |
|
461 | 513 |
} |
462 | 514 |
} |
Also available in: Unified diff