root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / HistogramPanel.java @ 8026
History | View | Annotate | Download (24.1 KB)
1 | 8026 | nacho | /*
|
---|---|---|---|
2 | * Created on 19-jul-2006
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | */
|
||
25 | package org.cresques.ui.raster; |
||
26 | |||
27 | import java.awt.BorderLayout; |
||
28 | import java.awt.FlowLayout; |
||
29 | import java.awt.GridBagConstraints; |
||
30 | import java.awt.GridBagLayout; |
||
31 | |||
32 | import javax.swing.JButton; |
||
33 | import javax.swing.JComboBox; |
||
34 | import javax.swing.JLabel; |
||
35 | import javax.swing.JPanel; |
||
36 | |||
37 | import org.cresques.io.data.RasterBuf; |
||
38 | import org.cresques.io.datastruct.Histogram; |
||
39 | import org.cresques.io.datastruct.Statistic; |
||
40 | import org.cresques.ui.raster.listener.HistogramPanelListener; |
||
41 | import org.cresques.util.Utilities; |
||
42 | import org.gvsig.gui.beans.BaseComponent; |
||
43 | import org.gvsig.gui.beans.graphic.GraphicChartPanel; |
||
44 | import org.gvsig.gui.beans.graphic.GraphicContainer; |
||
45 | import org.gvsig.gui.beans.table.TableContainer; |
||
46 | import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
||
47 | import org.gvsig.i18n.Messages; |
||
48 | |||
49 | /**
|
||
50 | * Interfaz de usuario para la representaci?n de histogramas.
|
||
51 | *
|
||
52 | * @author Diego Guerrero (diego.guerrero@uclm.es)
|
||
53 | *
|
||
54 | */
|
||
55 | |||
56 | public class HistogramPanel extends BaseComponent { |
||
57 | |||
58 | public static int MAXBANDS = 10; |
||
59 | private int HSUP = 60; |
||
60 | private int HTABLE = 105; |
||
61 | private int MARGIN = 12; |
||
62 | |||
63 | private JPanel pGeneral = null; |
||
64 | private JPanel pSupControl = null; |
||
65 | private GraphicContainer pHistogram = null; |
||
66 | private JPanel pTable = null; |
||
67 | private JComboBox jComboBoxOrigen = null; |
||
68 | private JComboBox jComboBoxTipo = null; |
||
69 | private JComboBox jComboBands = null; |
||
70 | private JButton jButtonClear = null; |
||
71 | private JButton jButtonBands = null; |
||
72 | private JButton bTable = null; |
||
73 | private TableContainer tableContainer = null; |
||
74 | private HistogramPanelListener listener = null; |
||
75 | |||
76 | private JPanel pButtons = null; |
||
77 | private int width, height; |
||
78 | private JPanel cbSup = null; |
||
79 | private JLabel lOrigin = null; |
||
80 | private JLabel lBands = null; |
||
81 | private JLabel lType = null; |
||
82 | /**
|
||
83 | * Objeto histograma para la gesti?n de procesos de histograma
|
||
84 | */
|
||
85 | private Histogram histogramObj = null; |
||
86 | /**
|
||
87 | * Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas
|
||
88 | * RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las
|
||
89 | * bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un elemento
|
||
90 | * por cada una.
|
||
91 | */
|
||
92 | public boolean[] showBands = {true, true, true}; |
||
93 | /**
|
||
94 | * Tipo de histograma
|
||
95 | * 0 = acumulado
|
||
96 | * 1 = No acumulado
|
||
97 | */
|
||
98 | private int type = 0; |
||
99 | /**
|
||
100 | * Tipo de fuente de datos para el histograma
|
||
101 | * 0 = Datos de la vista
|
||
102 | * 1 = extent de la vista y datos leidos desde la imagen
|
||
103 | * 2 = histograma de la imagen completa
|
||
104 | */
|
||
105 | private int histogramDataSource = 0; |
||
106 | |||
107 | private HistogramIncrement incrementPanel = null; |
||
108 | |||
109 | /**
|
||
110 | * ?ltimo histograma visualizado en el gr?fico
|
||
111 | */
|
||
112 | private int[][] lastHistogram = null; |
||
113 | /**
|
||
114 | * Tipo de dato de la petici?n. Si la petici?n del histograma es de la vista el tipo
|
||
115 | * de dato ser? byte aunque la imagen sea de 16 bits. Si la petici?n es de los datos
|
||
116 | * reales de la imagen entonces el tipo de dato de la petici?n coincide con el tipo
|
||
117 | * de datos de la imagen.
|
||
118 | */
|
||
119 | private int requestDataType = RasterBuf.TYPE_BYTE; |
||
120 | |||
121 | /**
|
||
122 | * This method initializes
|
||
123 | * @param histograms
|
||
124 | */
|
||
125 | public HistogramPanel(int w, int h){ |
||
126 | super();
|
||
127 | this.width = w;
|
||
128 | this.height = h;
|
||
129 | initialize(); |
||
130 | this.setComponentSize(width, height);
|
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * This method initializes
|
||
135 | *
|
||
136 | */
|
||
137 | public HistogramPanel() {
|
||
138 | super();
|
||
139 | initialize(); |
||
140 | this.setComponentSize(width, height);
|
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * This method initializes this
|
||
145 | *
|
||
146 | */
|
||
147 | private void initialize() { |
||
148 | listener = new HistogramPanelListener(this); |
||
149 | BorderLayout l = new BorderLayout(); |
||
150 | setLayout(l); |
||
151 | add(getCbSup(), l.NORTH); |
||
152 | add(getPHistogram(), l.CENTER); |
||
153 | add(getPTable(), l.SOUTH); |
||
154 | setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
||
155 | listener.setControlListeners(); |
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * This method initializes jPanel
|
||
160 | *
|
||
161 | * @return javax.swing.JPanel
|
||
162 | */
|
||
163 | private JPanel getPGeneral() { |
||
164 | if (pGeneral == null) { |
||
165 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
||
166 | gridBagConstraints2.gridx = 0;
|
||
167 | gridBagConstraints2.gridy = 2;
|
||
168 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
169 | gridBagConstraints1.gridx = 0;
|
||
170 | gridBagConstraints1.gridy = 1;
|
||
171 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
172 | gridBagConstraints.gridx = 0;
|
||
173 | gridBagConstraints.gridy = 0;
|
||
174 | pGeneral = new JPanel(); |
||
175 | pGeneral.setLayout(new GridBagLayout()); |
||
176 | //pGeneral.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
||
177 | pGeneral.add(getCbSup(), gridBagConstraints); |
||
178 | pGeneral.add(getPHistogram(), gridBagConstraints1); |
||
179 | pGeneral.add(getPTable(), gridBagConstraints2); |
||
180 | } |
||
181 | return pGeneral;
|
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * This method initializes jPanel
|
||
186 | *
|
||
187 | * @return javax.swing.JPanel
|
||
188 | */
|
||
189 | public GraphicContainer getPHistogram() {
|
||
190 | if (pHistogram == null) { |
||
191 | pHistogram = new GraphicContainer(width - MARGIN, height - HSUP - HTABLE, false); |
||
192 | //pHistogram.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
||
193 | } |
||
194 | return pHistogram;
|
||
195 | } |
||
196 | |||
197 | /**
|
||
198 | * This method initializes jPanel
|
||
199 | *
|
||
200 | * @return javax.swing.JPanel
|
||
201 | */
|
||
202 | private JPanel getPTable() { |
||
203 | if (pTable == null) { |
||
204 | pTable = new JPanel(); |
||
205 | //pTable.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
||
206 | |||
207 | FlowLayout flowlayout = new FlowLayout(); |
||
208 | flowlayout.setVgap(0);
|
||
209 | flowlayout.setHgap(0);
|
||
210 | flowlayout.setAlignment(java.awt.FlowLayout.LEFT); |
||
211 | |||
212 | pTable.setLayout(flowlayout); |
||
213 | pTable.add(getTable(), null);
|
||
214 | pTable.add(getBCreateTable(), null);
|
||
215 | } |
||
216 | return pTable;
|
||
217 | } |
||
218 | |||
219 | /**
|
||
220 | * Obtiene la tabla de estadisticas
|
||
221 | * @return
|
||
222 | */
|
||
223 | public TableContainer getTable(){
|
||
224 | if(tableContainer == null){ |
||
225 | String[] columnNames = {Messages.getText("banda"), Messages.getText("minimo"), Messages.getText("maximo"), Messages.getText("media"), Messages.getText("mediana"), Messages.getText("npixeles")}; |
||
226 | int[] columnWidths = {50, 65, 65, 65, 65, 115}; |
||
227 | tableContainer = new TableContainer(width - 200, HTABLE - 12, columnNames, columnWidths); |
||
228 | tableContainer.setControlVisible(false);
|
||
229 | tableContainer.setModel("ListModel");
|
||
230 | tableContainer.initialize(); |
||
231 | try{
|
||
232 | tableContainer.setEditable(false);
|
||
233 | }catch(NotInitializeException ex){
|
||
234 | System.out.println("Tabla no inicializada"); |
||
235 | } |
||
236 | } |
||
237 | return tableContainer;
|
||
238 | } |
||
239 | |||
240 | /**
|
||
241 | * This method initializes jPanel
|
||
242 | *
|
||
243 | * @return javax.swing.JPanel
|
||
244 | */
|
||
245 | private JPanel getCbSup() { |
||
246 | if (cbSup == null) { |
||
247 | lOrigin = new JLabel(); |
||
248 | lOrigin.setText(Messages.getText("origen")+":"); |
||
249 | lBands = new JLabel(); |
||
250 | lBands.setText(Messages.getText("bandas")+":"); |
||
251 | lType = new JLabel(); |
||
252 | lType.setText(Messages.getText("tipo")+":"); |
||
253 | |||
254 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
255 | gridBagConstraints.gridy = 0;
|
||
256 | gridBagConstraints.gridx = 0;
|
||
257 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
258 | gridBagConstraints1.insets = new java.awt.Insets(0,0,0,80); |
||
259 | gridBagConstraints1.gridy = 0;
|
||
260 | gridBagConstraints1.gridx = 1;
|
||
261 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
||
262 | gridBagConstraints2.gridy = 0;
|
||
263 | gridBagConstraints2.gridx = 3;
|
||
264 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
||
265 | gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0); |
||
266 | gridBagConstraints3.gridy = 1;
|
||
267 | gridBagConstraints3.gridx = 0;
|
||
268 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
||
269 | gridBagConstraints4.insets = new java.awt.Insets(2,0,0,80); |
||
270 | gridBagConstraints4.gridy = 1;
|
||
271 | gridBagConstraints4.gridx = 1;
|
||
272 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
||
273 | gridBagConstraints5.insets = new java.awt.Insets(2,0,0,0); |
||
274 | gridBagConstraints5.gridy = 1;
|
||
275 | gridBagConstraints5.gridx = 3;
|
||
276 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
||
277 | gridBagConstraints6.gridy = 0;
|
||
278 | gridBagConstraints6.gridx = 2;
|
||
279 | |||
280 | cbSup = new JPanel(); |
||
281 | //cbSup.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
||
282 | |||
283 | cbSup.setSize(new java.awt.Dimension(width - MARGIN, HSUP));
|
||
284 | cbSup.setPreferredSize(new java.awt.Dimension(height - MARGIN, HSUP));
|
||
285 | |||
286 | cbSup.setLayout(new GridBagLayout()); |
||
287 | cbSup.add(lOrigin, gridBagConstraints); |
||
288 | cbSup.add(getJComboBoxOrigen(), gridBagConstraints1); |
||
289 | |||
290 | cbSup.add(lBands, gridBagConstraints6); |
||
291 | |||
292 | cbSup.add(getJComboBands(), gridBagConstraints2); |
||
293 | cbSup.add(lType, gridBagConstraints3); |
||
294 | cbSup.add(getJComboBoxTipo(), gridBagConstraints4); |
||
295 | cbSup.add(getJButtonClear(), gridBagConstraints5); |
||
296 | } |
||
297 | return cbSup;
|
||
298 | } |
||
299 | |||
300 | /**
|
||
301 | * Obtiene el combo con la selecci?n de tipo de histograma, acumulado/no acumulado
|
||
302 | * @return javax.swing.JComboBox
|
||
303 | */
|
||
304 | public JComboBox getJComboBoxTipo() { |
||
305 | if (jComboBoxTipo == null) { |
||
306 | String lista [] = {Messages.getText("no_acumulado"),Messages.getText("acumulado")}; |
||
307 | jComboBoxTipo = new JComboBox(lista); |
||
308 | jComboBoxTipo.addActionListener(listener); |
||
309 | jComboBoxTipo.setPreferredSize(new java.awt.Dimension(150,25)); |
||
310 | } |
||
311 | return jComboBoxTipo;
|
||
312 | } |
||
313 | |||
314 | /**
|
||
315 | * Obtiene el combo con la selecci?n de la fuente de datos en el calculo del histograma,
|
||
316 | * datos de la vista, datos reales con el extent de la vista e imagen completa.
|
||
317 | * @return javax.swing.JComboBox
|
||
318 | */
|
||
319 | public JComboBox getJComboBoxOrigen() { |
||
320 | if (jComboBoxOrigen == null) { |
||
321 | String lista [] = {Messages.getText("datos_visualizados"),Messages.getText("vista_datasource"),Messages.getText("imagen_completa")}; |
||
322 | jComboBoxOrigen = new JComboBox(lista); |
||
323 | jComboBoxOrigen.addActionListener(listener); |
||
324 | jComboBoxOrigen.setPreferredSize(new java.awt.Dimension(150,25)); |
||
325 | } |
||
326 | return jComboBoxOrigen;
|
||
327 | } |
||
328 | |||
329 | /**
|
||
330 | *Asigna el combo "Origen" el valor de solo vista para el calculo del histograma. Esa opci?n es
|
||
331 | *utilizada para extensiones que necesitan histograma pero no pueden acceder a la fuente de datos.
|
||
332 | */
|
||
333 | public void setOnlyViewValue(){ |
||
334 | HistogramPanelListener.comboEventEnable = false;
|
||
335 | getJComboBoxOrigen().removeAllItems(); |
||
336 | getJComboBoxOrigen().addItem(Messages.getText("vista"));
|
||
337 | HistogramPanelListener.comboEventEnable = true;
|
||
338 | } |
||
339 | |||
340 | /**
|
||
341 | * This method initializes jButton
|
||
342 | *
|
||
343 | * @return javax.swing.JButton
|
||
344 | */
|
||
345 | public JButton getJButtonClear() { |
||
346 | if (jButtonClear == null) { |
||
347 | jButtonClear = new JButton(); |
||
348 | jButtonClear.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); |
||
349 | jButtonClear.setText(Messages.getText("limpiar"));
|
||
350 | jButtonClear.addActionListener(listener); |
||
351 | jButtonClear.setPreferredSize(new java.awt.Dimension(100,25)); |
||
352 | } |
||
353 | return jButtonClear;
|
||
354 | } |
||
355 | |||
356 | /**
|
||
357 | * This method initializes jButton
|
||
358 | *
|
||
359 | * @return javax.swing.JButton
|
||
360 | */
|
||
361 | public JButton getBCreateTable() { |
||
362 | if (bTable == null) { |
||
363 | bTable = new JButton(); |
||
364 | bTable.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); |
||
365 | bTable.setText(Messages.getText("crear_tabla"));
|
||
366 | bTable.addActionListener(listener); |
||
367 | bTable.setPreferredSize(new java.awt.Dimension(150,25)); |
||
368 | } |
||
369 | return bTable;
|
||
370 | } |
||
371 | |||
372 | /**
|
||
373 | * This method initializes jComboBox
|
||
374 | *
|
||
375 | * @return javax.swing.JComboBox
|
||
376 | */
|
||
377 | public JComboBox getJComboBands() { |
||
378 | if (jComboBands == null) { |
||
379 | String lista [] = {Messages.getText("todas")}; |
||
380 | jComboBands = new JComboBox(lista); |
||
381 | jComboBands.addActionListener(listener); |
||
382 | jComboBands.setPreferredSize(new java.awt.Dimension(100,25)); |
||
383 | } |
||
384 | return jComboBands;
|
||
385 | } |
||
386 | |||
387 | /**
|
||
388 | * Asigna el tama?o del componente
|
||
389 | * @param w Nuevo ancho del componente padre
|
||
390 | * @param h Nuevo alto del componente padre
|
||
391 | */
|
||
392 | public void setComponentSize(int w, int h){ |
||
393 | this.width = w;
|
||
394 | this.height = h;
|
||
395 | int margin_table = 200; |
||
396 | |||
397 | this.setPreferredSize(new java.awt.Dimension(width, height)); |
||
398 | getPHistogram().setComponentSize(width - MARGIN, height - HSUP - HTABLE); |
||
399 | getTable().setComponentSize(width - margin_table, HTABLE - MARGIN); |
||
400 | } |
||
401 | |||
402 | //*************************************************************
|
||
403 | //M?TODOS DEL CONTROL
|
||
404 | |||
405 | public void showHistogram(){ |
||
406 | switch(type){//Tipo noacumulado = 0, acumulado = 1 |
||
407 | case 0: switch(histogramDataSource){//Fte de datos vista = 0, extent = 1, completo =2 |
||
408 | case 0: requestDataType = RasterBuf.TYPE_BYTE; |
||
409 | calcHistogramFromView(showBands); |
||
410 | break;
|
||
411 | case 1: if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
||
412 | requestDataType = RasterBuf.TYPE_SHORT; |
||
413 | else
|
||
414 | requestDataType = RasterBuf.TYPE_BYTE; |
||
415 | calcHistogramFromDataSourceAndExtentView(showBands); |
||
416 | break;
|
||
417 | case 2: if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
||
418 | requestDataType = RasterBuf.TYPE_SHORT; |
||
419 | else
|
||
420 | requestDataType = RasterBuf.TYPE_BYTE; |
||
421 | calcFullHistogramFromDataSource(showBands); |
||
422 | break;
|
||
423 | } |
||
424 | break;
|
||
425 | case 1: switch(histogramDataSource){//Fte de datos vista = 0, extent = 1, completo =2 |
||
426 | case 0: requestDataType = RasterBuf.TYPE_BYTE; |
||
427 | calcAccumulatedHistogramFromView(showBands); |
||
428 | break;
|
||
429 | case 1: if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
||
430 | requestDataType = RasterBuf.TYPE_SHORT; |
||
431 | else
|
||
432 | requestDataType = RasterBuf.TYPE_BYTE; |
||
433 | calcHistogramFromDataSourceAndExtentView(showBands); |
||
434 | break;
|
||
435 | case 2: if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
||
436 | requestDataType = RasterBuf.TYPE_SHORT; |
||
437 | else
|
||
438 | requestDataType = RasterBuf.TYPE_BYTE; |
||
439 | calcFullAccumulatedHistogramFromDataSource(showBands); |
||
440 | break;
|
||
441 | } |
||
442 | break;
|
||
443 | } |
||
444 | } |
||
445 | |||
446 | |||
447 | /**
|
||
448 | * Calcula el histograma de la vista y solo con los datos de visualizaci?n
|
||
449 | * de las bandas R, G o B solicitadas
|
||
450 | * @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si
|
||
451 | * est? a true se visualizar? esa banda y si est? a false no se visualizar?
|
||
452 | */
|
||
453 | private void calcHistogramFromView(boolean[] bands){ |
||
454 | if(histogramObj != null){ |
||
455 | lastHistogram = histogramObj.calcHistogramFromView(bands); |
||
456 | showBands = bands; |
||
457 | setStatistic(Statistic.getBasicStatsFromHistogram( lastHistogram, |
||
458 | (int)getBoxesValues()[1], |
||
459 | (int)getBoxesValues()[0], |
||
460 | bands)); |
||
461 | GraphicChartPanel gcp = pHistogram.getPGraphic(); |
||
462 | |||
463 | String bandNames[] = new String[bands.length]; |
||
464 | for (int iBand = 0; iBand<bands.length; iBand++) |
||
465 | bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString(); |
||
466 | |||
467 | gcp.setNewChart(lastHistogram, bandNames); |
||
468 | } |
||
469 | } |
||
470 | |||
471 | /**
|
||
472 | * Calcula el histograma accumulado de la vista y solo con los datos de visualizaci?n
|
||
473 | * @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si
|
||
474 | * est? a true se visualizar? esa banda y si est? a false no se visualizar?
|
||
475 | */
|
||
476 | private void calcAccumulatedHistogramFromView(boolean[] bands){ |
||
477 | if(histogramObj != null){ |
||
478 | lastHistogram = histogramObj.calcAccumulatedHistogramFromView(bands); |
||
479 | showBands = bands; |
||
480 | setStatistic(Statistic.getBasicStatsFromHistogram( lastHistogram, |
||
481 | (int)getBoxesValues()[1], |
||
482 | (int)getBoxesValues()[0], |
||
483 | bands)); |
||
484 | GraphicChartPanel gcp = pHistogram.getPGraphic(); |
||
485 | |||
486 | String bandNames[] = new String[bands.length]; |
||
487 | for (int iBand = 0; iBand<bands.length; iBand++) |
||
488 | bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString(); |
||
489 | |||
490 | gcp.setNewChart(lastHistogram, bandNames); |
||
491 | } |
||
492 | } |
||
493 | |||
494 | /**
|
||
495 | * Calcula el histograma completo
|
||
496 | * @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si
|
||
497 | * est? a true se visualizar? esa banda y si est? a false no se visualizar?
|
||
498 | */
|
||
499 | private void calcHistogramFromDataSourceAndExtentView(boolean[] bands){ |
||
500 | if(histogramObj != null){ |
||
501 | incrementPanel = new HistogramIncrement(this); |
||
502 | if(histogramObj.calcHistogramFromRenderizerLimetedArea(bands))
|
||
503 | incrementPanel.showWindow(); |
||
504 | else
|
||
505 | readFullHistogramFromThread(); |
||
506 | } |
||
507 | } |
||
508 | |||
509 | /**
|
||
510 | * Calcula el histograma completo
|
||
511 | * @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si
|
||
512 | * est? a true se visualizar? esa banda y si est? a false no se visualizar?
|
||
513 | */
|
||
514 | private void calcFullHistogramFromDataSource(boolean[] bands){ |
||
515 | if(histogramObj != null){ |
||
516 | histogramObj.calcFullHistogram(bands); |
||
517 | incrementPanel = new HistogramIncrement(this); |
||
518 | incrementPanel.showWindow(); |
||
519 | } |
||
520 | } |
||
521 | |||
522 | /**
|
||
523 | * Calcula el histograma acumulado completo
|
||
524 | * @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si
|
||
525 | * est? a true se visualizar? esa banda y si est? a false no se visualizar?
|
||
526 | */
|
||
527 | private void calcFullAccumulatedHistogramFromDataSource(boolean[] bands){ |
||
528 | if(histogramObj != null){ |
||
529 | incrementPanel = new HistogramIncrement(this); |
||
530 | histogramObj.calcFullAccumulatedHistogram(bands); |
||
531 | incrementPanel.showWindow(); |
||
532 | } |
||
533 | } |
||
534 | |||
535 | |||
536 | /**
|
||
537 | * M?todo que ejecuta el thread que comprueba cuando se ha acabado de generar
|
||
538 | * el histograma. Al finalizar, se lee el histograma de la imagen completa
|
||
539 | * calculado y se muestra.
|
||
540 | */
|
||
541 | public void readFullHistogramFromThread(){ |
||
542 | if(type == 0) |
||
543 | lastHistogram = histogramObj.getFullHistogram(); |
||
544 | else if(type == 1) |
||
545 | lastHistogram = histogramObj.getFullAccumulatedHistogram(); |
||
546 | |||
547 | setStatistic(Statistic.getBasicStatsFromHistogram( lastHistogram, |
||
548 | (int)getBoxesValues()[1], |
||
549 | (int)getBoxesValues()[0], |
||
550 | showBands)); |
||
551 | //Si el histograma es grande lo recortamos para mostrarlo porque jfreeChart se vuelve
|
||
552 | //inestable al poner muchos elementos en las X
|
||
553 | |||
554 | int pos = lastHistogram[0].length; |
||
555 | int[][] newHistogram = lastHistogram; |
||
556 | boolean elem = true; |
||
557 | if(lastHistogram[0].length >= Utilities.MAX_SHORT_BIT_VALUE){ |
||
558 | for(int i = (lastHistogram[0].length - 1); i >= 0; i--){ |
||
559 | for(int iBand = 0; iBand < lastHistogram.length; iBand ++){ |
||
560 | if(lastHistogram[iBand][i] != 0) |
||
561 | elem = false;
|
||
562 | } |
||
563 | if(!elem){
|
||
564 | pos = i; |
||
565 | break;
|
||
566 | } |
||
567 | } |
||
568 | newHistogram = new int[lastHistogram.length][pos]; |
||
569 | for(int iBand = 0; iBand < lastHistogram.length; iBand ++){ |
||
570 | for(int i = 0; i < newHistogram[iBand].length; i ++){ |
||
571 | newHistogram[iBand][i] = lastHistogram[iBand][i]; |
||
572 | } |
||
573 | } |
||
574 | } |
||
575 | |||
576 | GraphicChartPanel gcp = pHistogram.getPGraphic(); |
||
577 | |||
578 | String bandNames[] = new String[lastHistogram.length]; |
||
579 | for (int iBand = 0; iBand<lastHistogram.length; iBand++) |
||
580 | bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString(); |
||
581 | |||
582 | gcp.setNewChart(newHistogram, bandNames); |
||
583 | } |
||
584 | |||
585 | /**
|
||
586 | * Asigna el n?mero de bandas al combobox
|
||
587 | * @param bands N?mero de bandas de la imagen
|
||
588 | */
|
||
589 | public void setBands(int bands){ |
||
590 | HistogramPanelListener.comboEventEnable = false;
|
||
591 | getJComboBands().removeAllItems(); |
||
592 | getJComboBands().addItem(Messages.getText("todas"));
|
||
593 | showBands = new boolean[bands]; |
||
594 | for(int i = 0; i < bands; i++){ |
||
595 | getJComboBands().addItem("Band "+String.valueOf(i)); |
||
596 | showBands[i] = true;
|
||
597 | } |
||
598 | HistogramPanelListener.comboEventEnable = true;
|
||
599 | } |
||
600 | |||
601 | |||
602 | /**
|
||
603 | * Asigna la estadistica a la tabla
|
||
604 | * @param stat
|
||
605 | */
|
||
606 | public void setStatistic(long[][] stat){ |
||
607 | if(stat == null) |
||
608 | return;
|
||
609 | try {
|
||
610 | getTable().removeAllRows(); |
||
611 | for(int iBand = 0; iBand < stat[0].length; iBand++){ |
||
612 | Object[] list = new Object[stat.length + 1]; |
||
613 | list[0] = new Integer(iBand); |
||
614 | for(int iStat = 1; iStat <= stat.length; iStat++) |
||
615 | list[iStat] = new Long(stat[iStat - 1][iBand]); |
||
616 | |||
617 | getTable().addRow(list); |
||
618 | list = null;
|
||
619 | } |
||
620 | } catch (NotInitializeException e) {
|
||
621 | // TODO Auto-generated catch block
|
||
622 | e.printStackTrace(); |
||
623 | } |
||
624 | } |
||
625 | |||
626 | /**
|
||
627 | * Resetea el control de bandas del panel con los valores RGB para
|
||
628 | * cuando se est? haciendo el histograma de la visualizaci?n en
|
||
629 | * vez del histograma con los datos
|
||
630 | *
|
||
631 | */
|
||
632 | public void setRGBInBandList(){ |
||
633 | HistogramPanelListener.comboEventEnable = false;
|
||
634 | boolean[] list = {true, true, true}; |
||
635 | showBands = list; |
||
636 | getJComboBands().removeAllItems(); |
||
637 | getJComboBands().addItem(Messages.getText("todas"));
|
||
638 | getJComboBands().addItem("R");
|
||
639 | getJComboBands().addItem("G");
|
||
640 | getJComboBands().addItem("B");
|
||
641 | HistogramPanelListener.comboEventEnable = true;
|
||
642 | } |
||
643 | |||
644 | /**
|
||
645 | * A?ade o elimina una banda de la visualizaci?n. Si la banda se est? visualizando
|
||
646 | * se elimina y si no entonces se muestra
|
||
647 | * @param band banda a visualizar o borrar del gr?fico
|
||
648 | */
|
||
649 | public void addOrRemoveGraphicBand(int band){ |
||
650 | if(band > showBands.length)
|
||
651 | return;
|
||
652 | showBands[band] = !showBands[band]; |
||
653 | } |
||
654 | |||
655 | /**
|
||
656 | * Limpia la gr?fica
|
||
657 | */
|
||
658 | public void cleanChart(){ |
||
659 | GraphicChartPanel gcp = pHistogram.getPGraphic(); |
||
660 | gcp.cleanChart(); |
||
661 | for(int i = 0; i < showBands.length; i++) |
||
662 | showBands[i] = false;
|
||
663 | } |
||
664 | |||
665 | /**
|
||
666 | * Asigna el objeto histograma para la gesti?n de procesos de histograma
|
||
667 | * @param histogramObj
|
||
668 | */
|
||
669 | public void setHistogram(Histogram histogramObj) { |
||
670 | this.histogramObj = histogramObj;
|
||
671 | listener.setHistogram(histogramObj); |
||
672 | } |
||
673 | |||
674 | /**
|
||
675 | * Obtiene el objeto histograma para la gesti?n de procesos de histograma
|
||
676 | * @return
|
||
677 | */
|
||
678 | public Histogram getHistogram() {
|
||
679 | return histogramObj;
|
||
680 | } |
||
681 | |||
682 | /**
|
||
683 | * Obtiene el tipo de datos de la fuente de la imagen
|
||
684 | * @return tipo de datos de la fuente de la imagen
|
||
685 | */
|
||
686 | public int getHistogramDataSource() { |
||
687 | return histogramDataSource;
|
||
688 | } |
||
689 | |||
690 | /**
|
||
691 | * Asigna el tipo de datos de la fuente de la imagen
|
||
692 | * @param histogramDataSource tipo de datos de la fuente de la imagen
|
||
693 | */
|
||
694 | public void setHistogramDataSource(int histogramDataSource) { |
||
695 | this.histogramDataSource = histogramDataSource;
|
||
696 | } |
||
697 | |||
698 | /**
|
||
699 | * Obtiene la lista de bandas que se muestran en el histograma
|
||
700 | * @return Lista de bandas donde cada elemento es un booleano. True si la banda
|
||
701 | * se muestra y false si no se muestra.
|
||
702 | */
|
||
703 | public boolean[] getBandListShowInChart(){ |
||
704 | return showBands;
|
||
705 | } |
||
706 | |||
707 | /**
|
||
708 | * Asigna la lista de bandas que se muestran en el histograma
|
||
709 | * @param Lista de bandas donde cada elemento es un booleano. True si la banda
|
||
710 | * se muestra y false si no se muestra.
|
||
711 | */
|
||
712 | public void setBandListShowInChart(boolean[] showBands) { |
||
713 | this.showBands = showBands;
|
||
714 | } |
||
715 | |||
716 | /**
|
||
717 | * Obtiene el tipo de histograma a mostrar
|
||
718 | * @return acumulado/no acumulado
|
||
719 | */
|
||
720 | public int getType() { |
||
721 | return type;
|
||
722 | } |
||
723 | |||
724 | /**
|
||
725 | * Asigna el tipo de histograma a mostrar
|
||
726 | * @param type acumulado/no acumulado
|
||
727 | */
|
||
728 | public void setType(int type) { |
||
729 | this.type = type;
|
||
730 | } |
||
731 | |||
732 | /**
|
||
733 | * Obtiene el valor de los controles en el rango 0-255. Los controles dan un rango en tanto por cien 0-100
|
||
734 | * pero para el calculo de estadisticas necesitamos un rango de valor de pixel.
|
||
735 | * @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha
|
||
736 | * y el segundo el de la izquierda.
|
||
737 | */
|
||
738 | public double[] getBoxesValues(){ |
||
739 | double[] v = new double[2]; |
||
740 | double[] currentValues = getPHistogram().getBoxesValues(); |
||
741 | switch(requestDataType){
|
||
742 | case RasterBuf.TYPE_BYTE: v[0] = (currentValues[0] * Utilities.MAX_BYTE_BIT_VALUE) / 100; |
||
743 | v[1] = (currentValues[1] * Utilities.MAX_BYTE_BIT_VALUE) / 100; |
||
744 | break;
|
||
745 | case RasterBuf.TYPE_SHORT: v[0] = (currentValues[0] * Utilities.MAX_SHORT_BIT_VALUE) / 100; |
||
746 | v[1] = (currentValues[1] * Utilities.MAX_SHORT_BIT_VALUE) / 100; |
||
747 | break;
|
||
748 | } |
||
749 | return v;
|
||
750 | } |
||
751 | |||
752 | /**
|
||
753 | * Obtiene el ?ltimo histograma visualizado
|
||
754 | * @return
|
||
755 | */
|
||
756 | public int[][] getLastHistogram() { |
||
757 | return lastHistogram;
|
||
758 | } |
||
759 | |||
760 | } // @jve:decl-index=0:visual-constraint="10,10" |