svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / georeferencing / geotransform / GeoTransformProcess.java @ 18276
History | View | Annotate | Download (7.35 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.georeferencing.geotransform; |
42 |
|
43 |
import org.gvsig.rastertools.RasterProcess; |
44 |
|
45 |
import Jama.Matrix; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
|
49 |
/**
|
50 |
* Clase que representa una transformacion polinomial para la convertir las
|
51 |
* coordenadas de una imagen en la imagen rectificada.
|
52 |
*
|
53 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
54 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
55 |
* @version 20/1/2008
|
56 |
**/
|
57 |
public class GeoTransformProcess extends RasterProcess { |
58 |
|
59 |
// Esto va a cambiar dependiendo del formato de los punto de la interfaz
|
60 |
// de momento geo_points puntos sobre imagen georeferenciada, image_points
|
61 |
// puntos sobre imagen a georeferenciar.
|
62 |
|
63 |
protected double geo_points[][]=new double[2][]; |
64 |
protected double image_points[][]=new double[2][]; |
65 |
|
66 |
// porcentage del proceso global de la tarea
|
67 |
private int percent=0; |
68 |
|
69 |
// orden del polinomio aproximador
|
70 |
protected int orden = 0; |
71 |
|
72 |
// numero minimo de puntos
|
73 |
protected int minGPC=0; |
74 |
|
75 |
// coeficientes del polinomio de transformacion para las coordenadas en X
|
76 |
private double []coefX=null; |
77 |
|
78 |
// coeficientes del polinomio de transformacion para las coordenadas en Y
|
79 |
private double []coefY=null; |
80 |
|
81 |
|
82 |
/** Metodo que recoge los parametros del proceso de clasificacion de
|
83 |
* m?xima probabilidad
|
84 |
* <LI>geo_points: lista de puntos con coordenadas reales</LI>
|
85 |
* <LI> image_points: lista de puntos coordenadas pixel</LI>
|
86 |
* <LI> orden: orden del polinomio de transformacion </LI>
|
87 |
*/
|
88 |
public void init() { |
89 |
geo_points =(double[][]) getParam("geoPoints"); |
90 |
image_points=(double[][]) getParam("imagePoints"); |
91 |
orden= (int)getIntParam("orden"); |
92 |
minGPC = (orden+1)*(orden+2)/2; |
93 |
// Chequear si el numero de puntos es suficiente para determinar la transformacion de orden n.
|
94 |
if(!enoughPoints()){
|
95 |
// NOTIFICAR, NO SUFICIENTES PUNTOS PARA ORDEN SELECCIONADO
|
96 |
return;
|
97 |
} |
98 |
} |
99 |
|
100 |
/**
|
101 |
* @return true si se proporciona el numero minimo de puntos de entrada
|
102 |
* para la transformaci?n. false en caso contrario.
|
103 |
* */
|
104 |
public boolean enoughPoints() { |
105 |
return (geo_points[0].length>minGPC && image_points[0].length>minGPC); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Proceso de calculo de los coeficientes del polinomio.
|
110 |
**/
|
111 |
public void process() throws InterruptedException { |
112 |
// Obtencion polinomio de transformacion en x
|
113 |
getPolinomyalCoefX(); |
114 |
|
115 |
// Obtencion del polinomio de transformaci?n en y
|
116 |
getPolinomialCoefY(); |
117 |
} |
118 |
|
119 |
|
120 |
/**
|
121 |
* @return coeficientes para el polinomio de transformaci?n en x.
|
122 |
* */
|
123 |
public double[] getPolinomyalCoefX(){ |
124 |
if(coefX==null) |
125 |
setDxGeneral(); |
126 |
return coefX;
|
127 |
} |
128 |
|
129 |
|
130 |
/**
|
131 |
* @return coeficientes para el polinomio de transformaci?n en y.
|
132 |
* */
|
133 |
public double[] getPolinomialCoefY(){ |
134 |
if(coefY==null) |
135 |
setDyGeneral(); |
136 |
return coefY;
|
137 |
} |
138 |
|
139 |
|
140 |
/////////!!!!!!! Obtiene matriz general a partir de los puntos de control y el orden del polinomio aproximador
|
141 |
public void setDxGeneral(){ |
142 |
double matrixDx[][]= new double [minGPC][minGPC]; |
143 |
double result[]= new double[minGPC]; |
144 |
int exp[][]=new int[minGPC][2]; |
145 |
int k=-1; |
146 |
// Obtencion de la primera fila de la matriz
|
147 |
|
148 |
for (int filas=0; filas<minGPC;filas++) |
149 |
{ k=-1;
|
150 |
for (int i=0; i<=orden; i++) |
151 |
for(int j=0; j<=i; j++){ |
152 |
k++; |
153 |
for(int v=0; v<geo_points.length;v++) |
154 |
matrixDx[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
155 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1])); |
156 |
// Para la fila 0 se guardan los exponentes
|
157 |
if(filas==0){ |
158 |
exp[k][0]=i-j;
|
159 |
exp[k][1]=j;
|
160 |
|
161 |
// Se calcula el resultado de !!!!!
|
162 |
for(int v=0; v<geo_points.length;v++) |
163 |
result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0]; |
164 |
} |
165 |
|
166 |
} |
167 |
} |
168 |
Matrix matrixResult= new Matrix(matrixDx);
|
169 |
try {
|
170 |
coefX=solveSistemforCramer(matrixResult,result); |
171 |
} catch (BadDeteminantException e) {
|
172 |
// Resolver sistema de ecuaciones o por otro metodo
|
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
|
178 |
// TO DO: Ver la manera de unificar con setDxGeneral(Parametrizar un metodo general)..... Estudiar optimizaciones!!!
|
179 |
public void setDyGeneral(){ |
180 |
double matrixDx[][]= new double [minGPC][minGPC]; |
181 |
double result[]= new double[minGPC]; |
182 |
int exp[][]=new int[minGPC][2]; |
183 |
int k=-1; |
184 |
// Obtencion de la primera fila de la matriz
|
185 |
|
186 |
for (int filas=0; filas<minGPC;filas++) |
187 |
{ k=-1;
|
188 |
for (int i=0; i<=orden; i++) |
189 |
for(int j=0; j<=i; j++){ |
190 |
k++; |
191 |
for(int v=0; v<geo_points.length;v++) |
192 |
matrixDx[filas][k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][0],exp[filas][0])) |
193 |
* (Math.pow(geo_points[v][1],j)* Math.pow(geo_points[v][1],exp[filas][1])); |
194 |
// Para la fila 0 se guardan los exponentes
|
195 |
if(filas==0){ |
196 |
exp[k][0]=i-j;
|
197 |
exp[k][1]=j;
|
198 |
|
199 |
// Se calcula el resultado de !!!!!
|
200 |
for(int v=0; v<geo_points.length;v++) |
201 |
result[k]+=(Math.pow(geo_points[v][0],i-j)* Math.pow(geo_points[v][1],exp[filas][1]))*image_points[v][0]; |
202 |
} |
203 |
|
204 |
} |
205 |
} |
206 |
Matrix matrixResult= new Matrix(matrixDx);
|
207 |
try {
|
208 |
coefX=solveSistemforCramer(matrixResult,result); |
209 |
} catch (BadDeteminantException e) {
|
210 |
// Resolver sistema de ecuaciones opor otro metodo
|
211 |
} |
212 |
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Resoluci?n del sistema por la regla de Cramer.
|
217 |
* @return array con la solucion al sistema de ecuadiones.
|
218 |
* */
|
219 |
public double[] solveSistemforCramer(Matrix matrix, double columResult[]) throws BadDeteminantException{ |
220 |
double xCoef []= new double[minGPC]; |
221 |
double det= matrix.det();
|
222 |
if(det==0) |
223 |
throw new BadDeteminantException(); |
224 |
double aux[][]= matrix.getArrayCopy(); |
225 |
Matrix m=null;
|
226 |
|
227 |
// Resolucion del sistema por cramer
|
228 |
for(int k=0; k<columResult.length; k++) |
229 |
{ |
230 |
for(int i=0;i<columResult.length;i++) |
231 |
aux[i][k]= columResult[i]; |
232 |
m= new Matrix (aux);
|
233 |
xCoef[k]= m.det()/det; |
234 |
aux=matrix.getArrayCopy();; |
235 |
} |
236 |
return xCoef;
|
237 |
} |
238 |
|
239 |
|
240 |
public String getTitle() { |
241 |
return PluginServices.getText(this,"transformacion"); |
242 |
} |
243 |
|
244 |
|
245 |
public String getLog() { |
246 |
return PluginServices.getText(this,"calculando_transformacion"); |
247 |
} |
248 |
|
249 |
|
250 |
public int getPercent() { |
251 |
// TODO Auto-generated method stub
|
252 |
return percent;
|
253 |
} |
254 |
|
255 |
|
256 |
} |
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|