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 @ 162

History | View | Annotate | Download (4.45 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.MosaicRasterStore;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
32
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
33
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl;
34

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

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

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

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

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

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

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