Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetListHistogram.java @ 11067

History | View | Annotate | Download (4.17 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.DataClassList;
25
import org.gvsig.raster.util.Histogram;
26
27
/**
28
 * Clase para la gesti?n de histogramas de un raster formado por una lista de ficheros.
29
 * Para devolver un histograma pedir? el histograma a todos los ficheros que
30
 * componen el multifichero.
31
 *
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class DatasetListHistogram {
35
        /**
36
         * clases en las que se divide el histograma
37
         */
38 11067 bsanchez
        private DataClassList                         classes = null;
39 10996 bsanchez
40 10939 nacho
        /**
41
         * Histograma de la imagen completa
42
         */
43 11067 bsanchez
        private Histogram                                                histogram = null;
44 10939 nacho
        /**
45
         * Dataset del cual se calcula el histograma
46
         */
47 11067 bsanchez
        private RasterMultiDataset        multiDataset = null;
48 10939 nacho
49
        /**
50 11067 bsanchez
         * Variable para saber si se ha parado el proceso
51
         */
52
        private boolean                                                        canceled = false;
53
54
        /**
55 10939 nacho
         * Constructor
56
         * @param dataset
57
         */
58
        public DatasetListHistogram(RasterMultiDataset dataset){
59
                this.multiDataset = dataset;
60
        }
61
62
        /**
63
         * Asigna una lista de clases sobre la que se calcular? la petici?n de
64
         * histograma.
65
         * @param classes
66
         */
67
        public void setClasses(DataClassList classes){
68
                this.classes = classes;
69
                for (int iDataset = 0; iDataset < multiDataset.getDatasetCount(); iDataset++)
70
                        multiDataset.getDataset(iDataset).getHistogram().setClasses(classes);
71
        }
72
73
        /**
74
         * Obtiene el histograma. Pregunta a todos los datasets que forman el multidataset
75
         * por su histograma y luego los fusiona.
76
         * @return histograma
77
         */
78
        public Histogram getHistogram()throws FileNotOpenException, RasterDriverException{
79
                if(multiDataset != null){
80
                        //Obtenemos los histogramas de cada dataset
81
                        int nBands = 0;
82
                        Histogram[] hList = new Histogram[multiDataset.getDatasetCount()];
83
                        for (int i = 0; i < hList.length; i++) {
84 11067 bsanchez
                                if (canceled) return null;
85 10939 nacho
                                multiDataset.getDataset(i).getHistogram().setClasses(classes);
86
                                hList[i] = multiDataset.getDataset(i).getHistogram().getHistogram();
87
                                nBands += hList[i].getNumBands();
88
                        }
89
90
                        if(hList[0].getNumBands() == 0)
91
                                return null;
92
93
                        histogram = new Histogram(nBands, hList[0].getNumValues());
94
                        //histogram = new long[nBands][hList[0][0].length];
95
                        int band = 0;
96
                        for (int iDataset = 0; iDataset < hList.length; iDataset++) {
97
                                for (int iBand = 0; iBand < hList[iDataset].getNumBands(); iBand++) {
98
                                        for (int iPxValue = 0; iPxValue < hList[iDataset].getBandLenght(iBand); iPxValue ++) {
99 11067 bsanchez
                                                if (isCanceled()) return null;
100 10939 nacho
                                                histogram.setHistogramValue(band, iPxValue, hList[iDataset].getHistogramValue(iBand, iPxValue));
101
                                        }
102
                                        band ++;
103
                                }
104
                        }
105
106
                        return histogram;
107
                }
108
                return null;
109
        }
110 11065 bsanchez
111
        public void resetPercent() {
112
                for (int i = 0; i < multiDataset.getDatasetCount(); i++) {
113
                        multiDataset.getDataset(i).resetPercent();
114
                }
115
        }
116
117 10996 bsanchez
        public int getPercent() {
118
                int percent = 0;
119
                for (int i = 0; i < multiDataset.getDatasetCount(); i++) {
120
                        percent += multiDataset.getDataset(i).getPercent();
121
                }
122
                percent = percent / multiDataset.getDatasetCount();
123
                return percent;
124
        }
125 11067 bsanchez
126
        /**
127
         * Metodo para poder cancelar el proceso.
128
         */
129
        public void cancel() {
130
                canceled = true;
131
        }
132
133
        /**
134
         * Metodo para saber si se ha cancelado un proceso
135
         * @return boolean
136
         */
137
        public boolean isCanceled() {
138
                return canceled;
139
        }
140 10939 nacho
}