Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetListHistogram.java @ 15948

History | View | Annotate | Download (3.52 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.IRasterDataSource;
23
import org.gvsig.raster.dataset.RasterDriverException;
24
import org.gvsig.raster.datastruct.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
        private Histogram                                                histogram = null;
38
        /**
39
         * Dataset del cual se calcula el histograma
40
         */
41
        private IRasterDataSource               raster = null;
42
        
43
        /**
44
         * Constructor
45
         * @param dataset
46
         */
47
        public DatasetListHistogram(IRasterDataSource raster){
48
                this.raster = raster;
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()
57
                throws FileNotOpenException, RasterDriverException, InterruptedException {
58
                if (raster != null) {
59
                        //Obtenemos los histogramas de cada dataset
60
                        Histogram[] hList = new Histogram[raster.getDatasetCount()];
61
                        double max = Double.NEGATIVE_INFINITY;
62
                        double min = Double.MAX_VALUE;
63
                        for (int i = 0; i < hList.length; i++) {
64
                                hList[i] = raster.getDataset(i)[0].getHistogram().getHistogram();
65
                                if (max < raster.getDataset(i)[0].getHistogram().getMaximum())
66
                                        max = raster.getDataset(i)[0].getHistogram().getMaximum();
67
                                if (min > raster.getDataset(i)[0].getHistogram().getMinimum())
68
                                        min = raster.getDataset(i)[0].getHistogram().getMinimum();
69
                                if (hList[i] == null) 
70
                                        return null;
71
                        }
72

    
73
                        if (hList[0].getNumBands() == 0)
74
                                return null;
75
                        
76
                        histogram = new Histogram(raster.getBandCount(), hList[0].getNumValues(), min, max);
77
                        
78
                        int band = 0;
79
                        for (int iDataset = 0; iDataset < hList.length; iDataset++) {
80
                                for (int iBand = 0; iBand < hList[iDataset].getNumBands(); iBand++) {
81
                                        for (int iPxValue = 0; iPxValue < hList[iDataset].getBandLenght(iBand); iPxValue ++) {
82
                                                histogram.setHistogramValueByPos(band, iPxValue, (long) hList[iDataset].getHistogramValueByPos(iBand, iPxValue));
83
                                        }
84
                                        band ++;
85
                                }        
86
                        }
87
                        
88
                        return histogram;
89
                }
90
                return null;
91
        }
92

    
93
        public void resetPercent() {
94
                for (int i = 0; i < raster.getDatasetCount(); i++) {
95
                        raster.getDataset(i)[0].resetPercent();
96
                }
97
        }
98

    
99
        public int getPercent() {
100
                int percent = 0;
101
                for (int i = 0; i < raster.getDatasetCount(); i++) {
102
                        percent += raster.getDataset(i)[0].getPercent();
103
                }
104
                percent = percent / raster.getDatasetCount();
105
                return percent;
106
        }
107
}