Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / properties / MosaicDataStoreHistogram.java @ 186

History | View | Annotate | Download (4.39 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.store.properties;
23

    
24
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
25
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
26
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
27
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
28
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
29
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
30
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
31
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
32
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl;
33

    
34
/**
35
 * Clase para la gesti?n de histogramas de un raster formado por una lista de ficheros.
36
 * Para devolver un histograma pedir? el histograma a todos los ficheros que
37
 * componen el multifichero.
38
 * 
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class MosaicDataStoreHistogram implements Histogram {
42
        /**
43
         * Histograma de la imagen completa
44
         */
45
        private BufferHistogram                       histogram   = null;
46
        private Histogram[]                           multihistog = null;
47
        private RasterDataStore                       dataset     = null;
48
        
49
        /**
50
         * Constructor
51
         * @param dataset
52
         */
53
        public MosaicDataStoreHistogram(Histogram[] h, RasterDataStore dataset){
54
                this.multihistog = h;
55
                this.dataset = dataset;
56
        }
57
        
58
        /**
59
         * Gets the histogram. Builds the histogram of each dataset and join these
60
         * @return histograma 
61
         */
62
        public BufferHistogram getBufferHistogram()
63
                throws HistogramException, ProcessInterruptedException {
64
                if(histogram == null) {
65
                        BufferHistogram[] pres = new BufferHistogram[multihistog.length];
66
                        for (int i = 0; i < multihistog.length; i++) {
67
                                pres[i] = multihistog[i].getBufferHistogram();
68
                        }
69

    
70
                        Statistics stats = ((RasterDataStore)dataset).getStatistics();
71
                        try {
72
                                stats.calculate();
73
                        } catch (FileNotOpenException e) {
74
                                throw new HistogramException("");
75
                        } catch (RasterDriverException e) {
76
                                throw new HistogramException("");
77
                        }
78
                        BufferHistogram res = new BufferHistogramImpl(((RasterDataStore)dataset).getBandCount(), stats.getMin(), stats.getMax(), ((RasterDataStore)dataset).getDataType()[0]);
79

    
80
                        for (int i = 0; i < multihistog.length; i++)
81
                                res.union(pres[i]);
82
                }
83
                return histogram;
84
        }
85

    
86
        /**
87
         * Pone a cero el porcentaje de progreso del proceso de calculo de histograma
88
         */
89
        public void resetPercent() {
90
                for (int i = 0; i < multihistog.length; i++)
91
                        multihistog[i].resetPercent();
92
        }
93

    
94
        /**
95
         * Obtiene el porcentaje de proceso en la construcci?n del histograma,
96
         * @return porcentaje de progreso
97
         */
98
        public int getPercent() {
99
                //TODO: Calculo del porcentaje
100
                return 100;
101
        }
102

    
103
        /*
104
         * (non-Javadoc)
105
         * @see org.gvsig.fmap.dal.coverage.dataset.Histogram#getMaximum()
106
         */
107
        public double getMaximum() {
108
                double max = 0;
109
                try {
110
                        for (int i = 0; i < getBufferHistogram().getNumBands(); i++) {
111
                                double m = getBufferHistogram().getMax(i);
112
                                if(m > max)
113
                                        max = m;
114
                        }
115
                } catch (HistogramException e) {
116
                        return 0;
117
                } catch (ProcessInterruptedException e) {
118
                        return 0;
119
                }
120
                return max;
121
                
122
        }
123

    
124
        /*
125
         * (non-Javadoc)
126
         * @see org.gvsig.fmap.dal.coverage.dataset.Histogram#getMinimum()
127
         */
128
        public double getMinimum() {
129
                double min = Double.POSITIVE_INFINITY;
130
                try {
131
                        for (int i = 0; i < getBufferHistogram().getNumBands(); i++) {
132
                                double m = getBufferHistogram().getMin(i);
133
                                if(m < min)
134
                                        min = m;
135
                        }
136
                } catch (HistogramException e) {
137
                        return 0;
138
                } catch (ProcessInterruptedException e) {
139
                        return 0;
140
                }
141
                return min;
142
        }
143
}