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 / buffer / BufferHistogramComputer.java @ 1081
History | View | Annotate | Download (5.13 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.buffer; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
26 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
27 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
28 |
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl; |
29 |
import org.gvsig.raster.impl.process.RasterTask; |
30 |
import org.gvsig.raster.impl.process.RasterTaskQueue; |
31 |
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram; |
32 |
|
33 |
|
34 |
/**
|
35 |
* This class computes the histogram for a <code>Buffer</code>
|
36 |
*
|
37 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
38 |
*/
|
39 |
public class BufferHistogramComputer implements HistogramComputer { |
40 |
private BufferHistogram histogram = null; |
41 |
private Buffer buffer = null; |
42 |
protected int progressHistogram = 0; |
43 |
private double[] limits = null; |
44 |
private boolean refresh = false; |
45 |
|
46 |
/**
|
47 |
* Constructor
|
48 |
* @param dataset
|
49 |
*/
|
50 |
public BufferHistogramComputer(Buffer buffer) { |
51 |
this.buffer = buffer;
|
52 |
} |
53 |
|
54 |
/*
|
55 |
* (non-Javadoc)
|
56 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#getBufferHistogram()
|
57 |
*/
|
58 |
public BufferHistogram getBufferHistogram()
|
59 |
throws ProcessInterruptedException, HistogramException {
|
60 |
if(histogram == null || refresh) { |
61 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
62 |
progressHistogram = 0;
|
63 |
double[][] limits = buffer.getAllBandsLimits(); |
64 |
|
65 |
BufferHistogramImpl hist = new BufferHistogramImpl(buffer.getBandCount(), limits[0], limits[1], buffer.getDataType()); |
66 |
|
67 |
for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) { |
68 |
for (int row = 0; row < buffer.getHeight(); row++) { |
69 |
switch(buffer.getDataType()) {
|
70 |
case Buffer.TYPE_BYTE: |
71 |
for (int col = 0; col < buffer.getWidth(); col++) |
72 |
hist.incrementPxValue(iBand, (double)(buffer.getElemByte(row, col, iBand)));
|
73 |
break;
|
74 |
case Buffer.TYPE_SHORT: |
75 |
for (int col = 0; col < buffer.getWidth(); col++) |
76 |
hist.incrementPxValue(iBand, (double)(buffer.getElemShort(row, col, iBand)));
|
77 |
break;
|
78 |
case Buffer.TYPE_INT: |
79 |
for (int col = 0; col < buffer.getWidth(); col++) |
80 |
hist.incrementPxValue(iBand, (double)(buffer.getElemInt(row, col, iBand)));
|
81 |
break;
|
82 |
case Buffer.TYPE_FLOAT: |
83 |
for (int col = 0; col < buffer.getWidth(); col++) |
84 |
hist.incrementPxValue(iBand, (double)buffer.getElemFloat(row, col, iBand));
|
85 |
break;
|
86 |
case Buffer.TYPE_DOUBLE: |
87 |
for (int col = 0; col < buffer.getWidth(); col++) |
88 |
hist.incrementPxValue(iBand, buffer.getElemDouble(row, col, iBand)); |
89 |
break;
|
90 |
} |
91 |
|
92 |
if (task.getEvent() != null) |
93 |
task.manageEvent(task.getEvent()); |
94 |
|
95 |
progressHistogram = ((iBand * buffer.getHeight() + row) * 100) /(buffer.getHeight() * buffer.getBandCount());
|
96 |
} |
97 |
} |
98 |
progressHistogram = 100;
|
99 |
histogram = hist; |
100 |
} |
101 |
return histogram;
|
102 |
} |
103 |
|
104 |
/*
|
105 |
* (non-Javadoc)
|
106 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#resetPercent()
|
107 |
*/
|
108 |
public void resetPercent() { |
109 |
progressHistogram = 0;
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#getPercent()
|
115 |
*/
|
116 |
public int getPercent() { |
117 |
return progressHistogram;
|
118 |
} |
119 |
|
120 |
/*
|
121 |
* (non-Javadoc)
|
122 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#getMinimum()
|
123 |
*/
|
124 |
public double getMinimum() { |
125 |
if(limits == null) |
126 |
try {
|
127 |
limits = buffer.getLimits(); |
128 |
} catch (ProcessInterruptedException e) {
|
129 |
return 0; |
130 |
} |
131 |
return limits[0]; |
132 |
} |
133 |
|
134 |
/*
|
135 |
* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#getMaximum()
|
137 |
*/
|
138 |
public double getMaximum() { |
139 |
if(limits == null) |
140 |
try {
|
141 |
limits = buffer.getLimits(); |
142 |
} catch (ProcessInterruptedException e) {
|
143 |
return 0; |
144 |
} |
145 |
return limits[1]; |
146 |
} |
147 |
|
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.fmap.dal.coverage.store.props.HistogramComputer#refreshHistogram()
|
151 |
*/
|
152 |
public void refreshHistogram() { |
153 |
refresh = true;
|
154 |
} |
155 |
|
156 |
public String getLog() { |
157 |
return null; |
158 |
} |
159 |
|
160 |
public boolean isCancelable() { |
161 |
return true; |
162 |
} |
163 |
|
164 |
public boolean isPausable() { |
165 |
return false; |
166 |
} |
167 |
|
168 |
public void setPercent(int value) { |
169 |
progressHistogram = value; |
170 |
} |
171 |
} |