Statistics
| Revision:

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

History | View | Annotate | Download (3.71 KB)

1
/* 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.IBuffer;
23
import org.gvsig.raster.dataset.RasterDataset;
24
import org.gvsig.raster.dataset.RasterDriverException;
25
import org.gvsig.raster.dataset.RasterMultiDataset;
26
import org.gvsig.raster.util.DataClassList;
27
import org.gvsig.raster.util.Histogram;
28

    
29
/**
30
 * Clase para la gesti?n de histogramas de un raster formado por una lista de ficheros.
31
 * Para devolver un histograma pedir? el histograma a todos los ficheros que
32
 * componen el multifichero.
33
 * 
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class DatasetListHistogram {
37
        /**
38
         * clases en las que se divide el histograma
39
         */
40
        private DataClassList                                 classes = null;
41
        
42
        /**
43
         * Histograma de la imagen completa
44
         */
45
        private Histogram                                        histogram = null;
46
        /**
47
         * Dataset del cual se calcula el histograma
48
         */
49
        private RasterMultiDataset                        multiDataset = null;
50
        
51
        /**
52
         * Constructor
53
         * @param dataset
54
         */
55
        public DatasetListHistogram(RasterMultiDataset dataset){
56
                this.multiDataset = dataset;
57
        }
58
        
59
        /**
60
         * Asigna una lista de clases sobre la que se calcular? la petici?n de
61
         * histograma.
62
         * @param classes
63
         */
64
        public void setClasses(DataClassList classes){
65
                this.classes = classes;
66
                for (int iDataset = 0; iDataset < multiDataset.getDatasetCount(); iDataset++)
67
                        multiDataset.getDataset(iDataset).getHistogram().setClasses(classes);
68
        }
69
        
70
        /**
71
         * Obtiene el histograma. Pregunta a todos los datasets que forman el multidataset
72
         * por su histograma y luego los fusiona.
73
         * @return histograma 
74
         */
75
        public Histogram getHistogram()throws FileNotOpenException, RasterDriverException{
76
                if(multiDataset != null){
77
                        //Obtenemos los histogramas de cada dataset
78
                        int nBands = 0;
79
                        Histogram[] hList = new Histogram[multiDataset.getDatasetCount()];
80
                        for (int i = 0; i < hList.length; i++) {
81
                                multiDataset.getDataset(i).getHistogram().setClasses(classes);
82
                                hList[i] = multiDataset.getDataset(i).getHistogram().getHistogram();
83
                                nBands += hList[i].getNumBands();
84
                        }
85
                        
86
                        if(hList[0].getNumBands() == 0)
87
                                return null;
88
                        
89
                        histogram = new Histogram(nBands, hList[0].getNumValues());
90
                        //histogram = new long[nBands][hList[0][0].length];
91
                        int band = 0;
92
                        for (int iDataset = 0; iDataset < hList.length; iDataset++) {
93
                                for (int iBand = 0; iBand < hList[iDataset].getNumBands(); iBand++) {
94
                                        for (int iPxValue = 0; iPxValue < hList[iDataset].getBandLenght(iBand); iPxValue ++) {
95
                                                histogram.setHistogramValue(band, iPxValue, hList[iDataset].getHistogramValue(iBand, iPxValue));
96
                                        }
97
                                        band ++;
98
                                }        
99
                        }
100
                        
101
                        return histogram;
102
                }
103
                return null;
104
        }
105
        
106
        public int getPercent() {
107
                int percent = 0;
108
                for (int i = 0; i < multiDataset.getDatasetCount(); i++) {
109
                        percent += multiDataset.getDataset(i).getPercent();
110
                }
111
                percent = percent / multiDataset.getDatasetCount();
112
                return percent;
113
        }
114
}