root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetListHistogram.java @ 11196
History | View | Annotate | Download (4.11 KB)
1 | 10939 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. 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 | package org.gvsig.raster.dataset.properties; |
||
20 | |||
21 | import org.gvsig.raster.dataset.FileNotOpenException; |
||
22 | import org.gvsig.raster.dataset.RasterDriverException; |
||
23 | import org.gvsig.raster.dataset.RasterMultiDataset; |
||
24 | import org.gvsig.raster.util.Histogram; |
||
25 | |||
26 | /**
|
||
27 | * Clase para la gesti?n de histogramas de un raster formado por una lista de ficheros.
|
||
28 | * Para devolver un histograma pedir? el histograma a todos los ficheros que
|
||
29 | * componen el multifichero.
|
||
30 | *
|
||
31 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
32 | */
|
||
33 | public class DatasetListHistogram { |
||
34 | /**
|
||
35 | * Histograma de la imagen completa
|
||
36 | */
|
||
37 | 11067 | bsanchez | private Histogram histogram = null; |
38 | 10939 | nacho | /**
|
39 | * Dataset del cual se calcula el histograma
|
||
40 | */
|
||
41 | 11067 | bsanchez | private RasterMultiDataset multiDataset = null; |
42 | 10939 | nacho | |
43 | /**
|
||
44 | * Constructor
|
||
45 | * @param dataset
|
||
46 | */
|
||
47 | public DatasetListHistogram(RasterMultiDataset dataset){
|
||
48 | this.multiDataset = dataset;
|
||
49 | } |
||
50 | |||
51 | /**
|
||
52 | * Obtiene el histograma. Pregunta a todos los datasets que forman el multidataset
|
||
53 | * por su histograma y luego los fusiona.
|
||
54 | * @return histograma
|
||
55 | */
|
||
56 | public Histogram getHistogram()throws FileNotOpenException, RasterDriverException{ |
||
57 | 11182 | bsanchez | if (multiDataset != null) { |
58 | 10939 | nacho | //Obtenemos los histogramas de cada dataset
|
59 | Histogram[] hList = new Histogram[multiDataset.getDatasetCount()]; |
||
60 | 11182 | bsanchez | double max = Double.MIN_VALUE; |
61 | double min = Double.MAX_VALUE; |
||
62 | 10939 | nacho | for (int i = 0; i < hList.length; i++) { |
63 | hList[i] = multiDataset.getDataset(i).getHistogram().getHistogram(); |
||
64 | 11182 | bsanchez | if (max < multiDataset.getDataset(i).getHistogram().getMaximum())
|
65 | max = multiDataset.getDataset(i).getHistogram().getMaximum(); |
||
66 | if (min > multiDataset.getDataset(i).getHistogram().getMinimum())
|
||
67 | min = multiDataset.getDataset(i).getHistogram().getMinimum(); |
||
68 | 11113 | nacho | if (isCanceled() || (hList[i] == null)) |
69 | return null; |
||
70 | 10939 | nacho | } |
71 | 11182 | bsanchez | |
72 | if (hList[0].getNumBands() == 0) |
||
73 | 10939 | nacho | return null; |
74 | |||
75 | 11182 | bsanchez | histogram = new Histogram(multiDataset.getBandCount(), hList[0].getNumValues(), min, max); |
76 | 11113 | nacho | |
77 | 10939 | nacho | int band = 0; |
78 | for (int iDataset = 0; iDataset < hList.length; iDataset++) { |
||
79 | for (int iBand = 0; iBand < hList[iDataset].getNumBands(); iBand++) { |
||
80 | for (int iPxValue = 0; iPxValue < hList[iDataset].getBandLenght(iBand); iPxValue ++) { |
||
81 | 11113 | nacho | if (isCanceled())
|
82 | return null; |
||
83 | 11182 | bsanchez | histogram.setHistogramValueByPos(band, iPxValue, (long) hList[iDataset].getHistogramValueByPos(iBand, iPxValue));
|
84 | 10939 | nacho | } |
85 | band ++; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return histogram;
|
||
90 | } |
||
91 | return null; |
||
92 | } |
||
93 | 11065 | bsanchez | |
94 | public void resetPercent() { |
||
95 | for (int i = 0; i < multiDataset.getDatasetCount(); i++) { |
||
96 | multiDataset.getDataset(i).resetPercent(); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | 10996 | bsanchez | public int getPercent() { |
101 | int percent = 0; |
||
102 | for (int i = 0; i < multiDataset.getDatasetCount(); i++) { |
||
103 | percent += multiDataset.getDataset(i).getPercent(); |
||
104 | } |
||
105 | percent = percent / multiDataset.getDatasetCount(); |
||
106 | return percent;
|
||
107 | } |
||
108 | 11067 | bsanchez | |
109 | /**
|
||
110 | * Metodo para poder cancelar el proceso.
|
||
111 | */
|
||
112 | 11068 | bsanchez | public void setCanceled(boolean value) { |
113 | for (int i = 0; i < multiDataset.getDatasetCount(); i++) { |
||
114 | multiDataset.getDataset(i).setCanceled(value); |
||
115 | } |
||
116 | 11067 | bsanchez | } |
117 | |||
118 | /**
|
||
119 | * Metodo para saber si se ha cancelado un proceso
|
||
120 | * @return boolean
|
||
121 | */
|
||
122 | public boolean isCanceled() { |
||
123 | 11068 | bsanchez | boolean cancel = false; |
124 | for (int i = 0; i < multiDataset.getDatasetCount(); i++) { |
||
125 | if (multiDataset.getDataset(i).isCanceled()) {
|
||
126 | cancel = true;
|
||
127 | break;
|
||
128 | } |
||
129 | } |
||
130 | return cancel;
|
||
131 | 11067 | bsanchez | } |
132 | 10939 | nacho | } |