Revision 14719
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.algorithm/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.roimask.algorithm.ROIMaskAlgorithmLibrary |
|
0 | 2 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.algorithm/src/main/java/org/gvsig/raster/roimask/algorithm/ROIMaskAlgorithmLibrary.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.algorithm; |
|
2 |
|
|
3 |
import org.gvsig.i18n.Messages; |
|
4 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
5 |
import org.gvsig.tools.library.AbstractLibrary; |
|
6 |
import org.gvsig.tools.library.LibraryException; |
|
7 |
|
|
8 |
/** |
|
9 |
* Initialization of ROIMaskAlgorithmLibrary library. |
|
10 |
*/ |
|
11 |
public class ROIMaskAlgorithmLibrary extends AbstractLibrary { |
|
12 |
public static final String PROCESS_LABEL = "ROIMaskProcess"; |
|
13 |
|
|
14 |
@Override |
|
15 |
protected void doInitialize() throws LibraryException { |
|
16 |
// Nothing to do |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void doPostInitialize() throws LibraryException { |
|
21 |
//Registers the process and its parameters |
|
22 |
RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, ROIMaskProcess.class); |
|
23 |
ROIMaskProcess.registerParameters(); |
|
24 |
|
|
25 |
Messages.addResourceFamily( |
|
26 |
"org.gvsig.raster.roimask.algorithm", |
|
27 |
ROIMaskAlgorithmLibrary.class.getClassLoader(), |
|
28 |
ROIMaskAlgorithmLibrary.class.getClass().getName()); |
|
29 |
//registerGeoProcess(new RasterReprojectAlgorithmLibrary()); |
|
30 |
|
|
31 |
Messages.addResourceFamily("org.gvsig.raster.roimask.algorithm.i18n.text", |
|
32 |
ROIMaskAlgorithmLibrary.class.getClassLoader(), |
|
33 |
ROIMaskAlgorithmLibrary.class.getClass().getName()); |
|
34 |
} |
|
35 |
} |
|
0 | 36 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.algorithm/src/main/java/org/gvsig/raster/roimask/algorithm/ROIMaskException.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.algorithm; |
|
2 |
|
|
3 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* This exception is thrown if happen problems processing data with this algorithm. |
|
8 |
*/ |
|
9 |
public class ROIMaskException extends ProcessException { |
|
10 |
private static final long serialVersionUID = -3022090543908771484L; |
|
11 |
|
|
12 |
public ROIMaskException(String msg){ |
|
13 |
super(msg); |
|
14 |
} |
|
15 |
|
|
16 |
public ROIMaskException(String msg, Throwable e){ |
|
17 |
super(msg, e); |
|
18 |
} |
|
19 |
} |
|
0 | 20 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.algorithm/src/main/java/org/gvsig/raster/roimask/algorithm/ROIMaskProcess.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.algorithm; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
|
|
5 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
6 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
7 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
8 |
import org.gvsig.fmap.dal.coverage.dataset.BufferParam; |
|
9 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
10 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
11 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
12 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
13 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
14 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
15 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
16 |
import org.gvsig.i18n.Messages; |
|
17 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
18 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
19 |
import org.gvsig.raster.roi.ROI; |
|
20 |
|
|
21 |
/** |
|
22 |
* Process |
|
23 |
*/ |
|
24 |
public class ROIMaskProcess extends DataProcess { |
|
25 |
public static String RASTER_STORE1 = "RasterStore1"; |
|
26 |
public static String BUFFER = "Buffer"; |
|
27 |
public static String PATH = "Path"; |
|
28 |
public static String FILENAME = "FileName"; |
|
29 |
public static String ROIS = "Rois"; |
|
30 |
public static String INVERSE = "Inverse"; |
|
31 |
public static String ALPHA = "Alpha"; |
|
32 |
public static String ALPHA_BAND = "AlphaBand"; |
|
33 |
public static String NODATA = "NoData"; |
|
34 |
|
|
35 |
private RasterDataStore store = null; |
|
36 |
private String filename = null; |
|
37 |
|
|
38 |
private ROI[] rois = null; |
|
39 |
private boolean inverse = false; |
|
40 |
private int alpha = 0; |
|
41 |
private NoData nodata = null; |
|
42 |
|
|
43 |
private double noDataResult = 0; |
|
44 |
|
|
45 |
/** |
|
46 |
* This buffer is just to test |
|
47 |
*/ |
|
48 |
private Buffer bufferForTest = null; |
|
49 |
|
|
50 |
public static void registerParameters() { |
|
51 |
registerInputParameter(RASTER_STORE1, RasterDataStore.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
52 |
registerInputParameter(PATH, String.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
53 |
registerInputParameter(ROIS, ROI[].class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
54 |
registerInputParameter(INVERSE, Boolean.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
55 |
registerInputParameter(ALPHA, Integer.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
56 |
registerInputParameter(NODATA, NoData.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
57 |
|
|
58 |
registerOutputParameter(FILENAME, String.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
59 |
registerOutputParameter(ALPHA_BAND, Buffer.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
60 |
registerOutputParameter(BUFFER, Buffer.class, ROIMaskAlgorithmLibrary.PROCESS_LABEL); |
|
61 |
} |
|
62 |
|
|
63 |
public void init() { |
|
64 |
store = getParam(RASTER_STORE1) != null ? (RasterDataStore)getParam(RASTER_STORE1) : null; |
|
65 |
filename = getStringParam(PATH); |
|
66 |
inverse = getBooleanParam(INVERSE); |
|
67 |
alpha = getIntParam(ALPHA); |
|
68 |
|
|
69 |
nodata = getParam(NODATA) != null ? (NoData)getParam(NODATA) : null; |
|
70 |
rois = getParam(ROIS) != null ? (ROI[])getParam(ROIS) : null; |
|
71 |
|
|
72 |
switch (store.getDataType()[0]) { |
|
73 |
case Buffer.TYPE_BYTE: |
|
74 |
if(nodata.getValue() != null) |
|
75 |
noDataResult = nodata.getValue().byteValue(); |
|
76 |
else |
|
77 |
noDataResult = RasterLibrary.defaultByteNoDataValue; |
|
78 |
break; |
|
79 |
case Buffer.TYPE_SHORT: |
|
80 |
if(nodata.getValue() != null) |
|
81 |
noDataResult = nodata.getValue().shortValue(); |
|
82 |
else |
|
83 |
noDataResult = RasterLibrary.defaultShortNoDataValue; |
|
84 |
break; |
|
85 |
case Buffer.TYPE_INT: |
|
86 |
if(nodata.getValue() != null) |
|
87 |
noDataResult = nodata.getValue().intValue(); |
|
88 |
else |
|
89 |
noDataResult = RasterLibrary.defaultIntegerNoDataValue; |
|
90 |
break; |
|
91 |
case Buffer.TYPE_FLOAT: |
|
92 |
if(nodata.getValue() != null) |
|
93 |
noDataResult = nodata.getValue().floatValue(); |
|
94 |
else |
|
95 |
noDataResult = RasterLibrary.defaultFloatNoDataValue; |
|
96 |
break; |
|
97 |
case Buffer.TYPE_DOUBLE: |
|
98 |
if(nodata.getValue() != null) |
|
99 |
noDataResult = nodata.getValue().doubleValue(); |
|
100 |
else |
|
101 |
noDataResult = RasterLibrary.defaultDoubleNoDataValue; |
|
102 |
break; |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
107 |
insertLineLog(Messages.getText("applying_mask")); |
|
108 |
try { |
|
109 |
if (store == null) |
|
110 |
throw new ROIMaskException("Store not found"); |
|
111 |
|
|
112 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
|
113 |
|
|
114 |
Extent windowExtent = getExtentResult(getOutputWindow(), null, store); |
|
115 |
Rectangle2D sourcePxBBox = null; |
|
116 |
if(isOutputRescaled()) { |
|
117 |
sourcePxBBox = new Rectangle2D.Double(0, 0, getOutputWidth(), getOutputHeight()); |
|
118 |
query.setSupersamplingOption(true); |
|
119 |
} else { |
|
120 |
sourcePxBBox = getSourcePxBox(windowExtent, store); |
|
121 |
query.setSupersamplingOption(false); |
|
122 |
} |
|
123 |
double cellSize = windowExtent.width() / sourcePxBBox.getWidth(); |
|
124 |
|
|
125 |
if(isForPreviews()) { |
|
126 |
query.setReadOnly(false); |
|
127 |
query.forceRGBRequest(); |
|
128 |
query.setDrawableBands(store.getRender().getRenderColorInterpretation().buildRenderBands()); |
|
129 |
} else { |
|
130 |
query.setAllDrawableBands(); |
|
131 |
query.setReadOnly(true); |
|
132 |
} |
|
133 |
|
|
134 |
int w = (int)sourcePxBBox.getWidth(); |
|
135 |
int h = (int)sourcePxBBox.getHeight(); |
|
136 |
|
|
137 |
query.setAreaOfInterest(windowExtent, w, h); |
|
138 |
Buffer sourceBuffer = null; |
|
139 |
try { |
|
140 |
sourceBuffer = store.query(query); |
|
141 |
sourceBuffer.setDataExtent(windowExtent.toRectangle2D()); |
|
142 |
} catch (QueryException e) { |
|
143 |
throw new ROIMaskException("Error reading data", e); |
|
144 |
} |
|
145 |
|
|
146 |
bufferForTest = sourceBuffer; |
|
147 |
ColorInterpretation ci = store.getColorInterpretation(); |
|
148 |
int ouputAlphaBandNumber = -1; |
|
149 |
|
|
150 |
if(rois != null && rois.length > 0) { |
|
151 |
nodata.setNoDataTransparent(false); |
|
152 |
if(ci.isRGBA()) { |
|
153 |
bufferForTest = processRGB(windowExtent, sourceBuffer, w, h, cellSize, ci.getAlphaBand()); |
|
154 |
ouputAlphaBandNumber = bufferForTest.getBandCount() - 1; |
|
155 |
ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(ColorInterpretation.ARGB); |
|
156 |
} else if(ci.isRGB()) { |
|
157 |
bufferForTest = processRGB(windowExtent, sourceBuffer, w, h, cellSize, -1); |
|
158 |
ouputAlphaBandNumber = bufferForTest.getBandCount() - 1; |
|
159 |
ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(ColorInterpretation.ARGB); |
|
160 |
} else { |
|
161 |
bufferForTest = processMDT(windowExtent, sourceBuffer, cellSize); |
|
162 |
ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(ColorInterpretation.GRAYSCALE); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
if(!isForPreviews()) { |
|
167 |
super.exportRaster(filename, |
|
168 |
bufferForTest, |
|
169 |
ci, |
|
170 |
windowExtent, |
|
171 |
nodata, |
|
172 |
store.getProjection()); |
|
173 |
addOutputValue(FILENAME, filename); |
|
174 |
} else { |
|
175 |
addOutputValue(BUFFER, bufferForTest); |
|
176 |
} |
|
177 |
|
|
178 |
addOutputValue(ALPHA_BAND, ouputAlphaBandNumber); |
|
179 |
} catch (ROIMaskException e) { |
|
180 |
if (incrementableTask != null) |
|
181 |
incrementableTask.processFinalize(); |
|
182 |
messageBoxError("Error in mask process", this, e); |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
private Buffer processRGB(Extent extent, Buffer sourceBuffer, int w, int h, double cellsize, int inputAlphaBandNumber) throws ProcessInterruptedException, ProcessException { |
|
187 |
BufferParam params = RasterLocator.getManager().getBufferFactory().createBufferParams( |
|
188 |
w, h, 4, store.getDataType()[0], true); |
|
189 |
Buffer outputBuffer = null; |
|
190 |
try { |
|
191 |
outputBuffer = RasterLocator.getManager().getBufferFactory().createBuffer(params); |
|
192 |
} catch (Exception e) { |
|
193 |
throw new ProcessException("Error creating buffer", e); |
|
194 |
} |
|
195 |
|
|
196 |
for (int row = 0; row < h; row++) { |
|
197 |
for (int col = 0; col < w; col++) { |
|
198 |
double wcX = extent.minX() + ((((double) col) * extent.width()) / ((double) w)); |
|
199 |
double wcY = extent.minY() + ((((double) (h - (row))) * extent.height()) / ((double) h)); |
|
200 |
|
|
201 |
for (int iBand = 0; iBand < 3; iBand++) { |
|
202 |
outputBuffer.setElem(row, col, iBand, sourceBuffer.getElemByte(row, col, iBand)); |
|
203 |
} |
|
204 |
|
|
205 |
boolean insideRoi = false; |
|
206 |
for (int i = 0; i < rois.length; i++) { |
|
207 |
if (((ROI) rois[i]).isInside(wcX, wcY, cellsize, cellsize)) { |
|
208 |
if (inverse) { |
|
209 |
if(inputAlphaBandNumber != -1) |
|
210 |
outputBuffer.setElem(row, col, 3, sourceBuffer.getElemByte(row, col, inputAlphaBandNumber)); |
|
211 |
else |
|
212 |
outputBuffer.setElem(row, col, 3, (byte) 255); |
|
213 |
} else { |
|
214 |
outputBuffer.setElem(row, col, 3, (byte) (255 - alpha)); |
|
215 |
} |
|
216 |
insideRoi = true; |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
if(!insideRoi) { |
|
221 |
if (inverse) { |
|
222 |
outputBuffer.setElem(row, col, 3, (byte) (255 - alpha)); |
|
223 |
} else { |
|
224 |
if(inputAlphaBandNumber != -1) |
|
225 |
outputBuffer.setElem(row, col, 3, sourceBuffer.getElemByte(row, col, inputAlphaBandNumber)); |
|
226 |
else |
|
227 |
outputBuffer.setElem(row, col, 3, (byte) 255); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
updatePercent(row, h); |
|
232 |
} |
|
233 |
return outputBuffer; |
|
234 |
} |
|
235 |
|
|
236 |
private Buffer processMDT(Extent extent, Buffer inputBuffer, double cellsize) throws ProcessInterruptedException, ProcessException { |
|
237 |
int w = inputBuffer.getWidth(); |
|
238 |
int h = inputBuffer.getHeight(); |
|
239 |
Buffer outputBuffer = null; |
|
240 |
|
|
241 |
BufferParam params = RasterLocator.getManager().getBufferFactory().createBufferParams( |
|
242 |
w, h, inputBuffer.getBandCount(), inputBuffer.getDataType(), true); |
|
243 |
try { |
|
244 |
outputBuffer = RasterLocator.getManager().getBufferFactory().createBuffer(params); |
|
245 |
} catch (Exception e) { |
|
246 |
throw new ProcessException("Error creating buffer", e); |
|
247 |
} |
|
248 |
|
|
249 |
for (int row = 0; row < h; row++) { |
|
250 |
for (int col = 0; col < w; col++) { |
|
251 |
for (int nband = 0; nband < inputBuffer.getBandCount(); nband++) { |
|
252 |
double wcX = extent.minX() + ((((double) col) * extent.width()) / ((double) w)); |
|
253 |
double wcY = extent.minY() + ((((double) (h - (row))) * extent.height()) / ((double) h)); |
|
254 |
boolean insideRoi = false; |
|
255 |
for (int i = 0; i < rois.length; i++) { |
|
256 |
if (((ROI) rois[i]).isInside(wcX, wcY, cellsize, cellsize)) { |
|
257 |
if (inverse) |
|
258 |
writePixel(inputBuffer, outputBuffer, col, row, nband); |
|
259 |
else |
|
260 |
writeNoData(outputBuffer, col, row, nband); |
|
261 |
insideRoi = true; |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
if(!insideRoi) { |
|
266 |
if (inverse) |
|
267 |
writeNoData(outputBuffer, col, row, nband); |
|
268 |
else { |
|
269 |
writePixel(inputBuffer, outputBuffer, col, row, nband); |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
updatePercent(row, h); |
|
275 |
} |
|
276 |
return outputBuffer; |
|
277 |
} |
|
278 |
|
|
279 |
private void writePixel(Buffer inputBuffer, Buffer outputBuffer, int col, int row, int nband) { |
|
280 |
switch (inputBuffer.getDataType()) { |
|
281 |
case Buffer.TYPE_BYTE: |
|
282 |
outputBuffer.setElem(row, col, nband, inputBuffer.getElemByte(row, col, nband)); |
|
283 |
break; |
|
284 |
case Buffer.TYPE_SHORT: |
|
285 |
outputBuffer.setElem(row, col, nband, inputBuffer.getElemShort(row, col, nband)); |
|
286 |
break; |
|
287 |
case Buffer.TYPE_INT: |
|
288 |
outputBuffer.setElem(row, col, nband, inputBuffer.getElemInt(row, col, nband)); |
|
289 |
break; |
|
290 |
case Buffer.TYPE_FLOAT: |
|
291 |
outputBuffer.setElem(row, col, nband, inputBuffer.getElemFloat(row, col, nband)); |
|
292 |
break; |
|
293 |
case Buffer.TYPE_DOUBLE: |
|
294 |
outputBuffer.setElem(row, col, nband, inputBuffer.getElemDouble(row, col, nband)); |
|
295 |
break; |
|
296 |
} |
|
297 |
} |
|
298 |
|
|
299 |
private void writeNoData(Buffer outputBuffer, int col, int row, int nband) { |
|
300 |
switch (outputBuffer.getDataType()) { |
|
301 |
case Buffer.TYPE_BYTE: |
|
302 |
outputBuffer.setElem(row, col, nband, (byte)noDataResult); |
|
303 |
break; |
|
304 |
case Buffer.TYPE_SHORT: |
|
305 |
outputBuffer.setElem(row, col, nband, (short)noDataResult); |
|
306 |
break; |
|
307 |
case Buffer.TYPE_INT: |
|
308 |
outputBuffer.setElem(row, col, nband, (int)noDataResult); |
|
309 |
break; |
|
310 |
case Buffer.TYPE_FLOAT: |
|
311 |
outputBuffer.setElem(row, col, nband, (float)noDataResult); |
|
312 |
break; |
|
313 |
case Buffer.TYPE_DOUBLE: |
|
314 |
outputBuffer.setElem(row, col, nband, (double)noDataResult); |
|
315 |
break; |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
public String getTitle() { |
|
320 |
return Messages.getText("mask_process"); |
|
321 |
} |
|
322 |
} |
|
0 | 323 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.algorithm/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.roimask.algorithm</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.roimask.algorithm</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.roimask</artifactId> |
|
10 |
<version>2.2.144</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.algorithm</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.i18n</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.ui</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
36 |
<scope>compile</scope> |
|
37 |
</dependency> |
|
38 |
<dependency> |
|
39 |
<groupId>org.gvsig</groupId> |
|
40 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
41 |
<scope>compile</scope> |
|
42 |
</dependency> |
|
43 |
<dependency> |
|
44 |
<groupId>org.gvsig</groupId> |
|
45 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
46 |
<scope>compile</scope> |
|
47 |
</dependency> |
|
48 |
|
|
49 |
<dependency> |
|
50 |
<groupId>org.gvsig</groupId> |
|
51 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
<!-- |
|
55 |
<dependency> |
|
56 |
<groupId>org.gvsig</groupId> |
|
57 |
<artifactId>org.gvsig.fmap.geometry.generalpath</artifactId> |
|
58 |
<scope>runtime</scope> |
|
59 |
</dependency> |
|
60 |
--> |
|
61 |
<dependency> |
|
62 |
<groupId>org.gvsig</groupId> |
|
63 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
64 |
<scope>compile</scope> |
|
65 |
</dependency> |
|
66 |
<dependency> |
|
67 |
<groupId>org.gvsig</groupId> |
|
68 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
69 |
<scope>compile</scope> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>org.gvsig</groupId> |
|
73 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
74 |
<scope>compile</scope> |
|
75 |
</dependency> |
|
76 |
<dependency> |
|
77 |
<groupId>org.gvsig</groupId> |
|
78 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
79 |
<scope>runtime</scope> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.gvsig</groupId> |
|
83 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
84 |
<scope>compile</scope> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>org.gvsig</groupId> |
|
88 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
89 |
<scope>compile</scope> |
|
90 |
</dependency> |
|
91 |
<dependency> |
|
92 |
<groupId>org.gvsig</groupId> |
|
93 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
94 |
<scope>compile</scope> |
|
95 |
</dependency> |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
99 |
<scope>compile</scope> |
|
100 |
</dependency> |
|
101 |
</dependencies> |
|
102 |
</project> |
|
0 | 103 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.roimask.lib.impl</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.roimask.lib.impl</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.roimask.lib</artifactId> |
|
10 |
<version>2.2.144</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.roimask.lib.api</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
36 |
<scope>compile</scope> |
|
37 |
</dependency> |
|
38 |
<dependency> |
|
39 |
<groupId>org.gvsig</groupId> |
|
40 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
41 |
<scope>runtime</scope> |
|
42 |
</dependency> |
|
43 |
<dependency> |
|
44 |
<groupId>org.gvsig</groupId> |
|
45 |
<artifactId>org.gvsig.ui</artifactId> |
|
46 |
<scope>compile</scope> |
|
47 |
</dependency> |
|
48 |
</dependencies> |
|
49 |
</project> |
|
0 | 50 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/src/main/java/org/gvsig/raster/roimask/lib/impl/ROIMaskDefaultImplLibrary.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.lib.impl; |
|
2 |
|
|
3 |
import org.gvsig.raster.roimask.lib.ROIMaskLibrary; |
|
4 |
import org.gvsig.raster.roimask.lib.ROIMaskLocator; |
|
5 |
import org.gvsig.raster.roimask.lib.impl.regionalpha.RegionAlphaListManager; |
|
6 |
import org.gvsig.tools.library.AbstractLibrary; |
|
7 |
import org.gvsig.tools.library.LibraryException; |
|
8 |
|
|
9 |
/** |
|
10 |
* Library for default implementation initialization and configuration. |
|
11 |
* |
|
12 |
* @author gvSIG team |
|
13 |
* @version $Id$ |
|
14 |
*/ |
|
15 |
public class ROIMaskDefaultImplLibrary extends AbstractLibrary { |
|
16 |
|
|
17 |
public ROIMaskDefaultImplLibrary() { |
|
18 |
registerAsImplementationOf(ROIMaskLibrary.class); |
|
19 |
} |
|
20 |
|
|
21 |
protected void doInitialize() throws LibraryException { |
|
22 |
//Register the default GeometryManager |
|
23 |
ROIMaskLocator.registerManager(DefaultROIMaskManager.class); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected void doPostInitialize() throws LibraryException { |
|
28 |
RegionAlphaListManager.register(); |
|
29 |
} |
|
30 |
|
|
31 |
} |
|
0 | 32 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/src/main/java/org/gvsig/raster/roimask/lib/impl/DefaultROIMaskManager.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.lib.impl; |
|
2 |
|
|
3 |
import org.gvsig.raster.roimask.lib.ROIMaskManager; |
|
4 |
import org.slf4j.Logger; |
|
5 |
import org.slf4j.LoggerFactory; |
|
6 |
|
|
7 |
/** |
|
8 |
* Default {@link ROIMaskManager} implementation. |
|
9 |
* |
|
10 |
* @author gvSIG Team |
|
11 |
* @version $Id$ |
|
12 |
*/ |
|
13 |
public class DefaultROIMaskManager implements ROIMaskManager { |
|
14 |
private static DefaultROIMaskManager internalInstance = new DefaultROIMaskManager(); |
|
15 |
private static final Logger logger = LoggerFactory.getLogger(DefaultROIMaskManager.class); |
|
16 |
|
|
17 |
/** |
|
18 |
* Gets an instance of this object for internal use. |
|
19 |
* @return DefaultRasterManager |
|
20 |
*/ |
|
21 |
public static DefaultROIMaskManager getInstance() { |
|
22 |
return internalInstance; |
|
23 |
} |
|
24 |
} |
|
0 | 25 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/src/main/java/org/gvsig/raster/roimask/lib/impl/regionalpha/RegionAlphaUI.java | ||
---|---|---|
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.roimask.lib.impl.regionalpha; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.EventObject; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import javax.swing.JCheckBox; |
|
32 |
import javax.swing.JLabel; |
|
33 |
import javax.swing.JPanel; |
|
34 |
import javax.swing.event.ChangeEvent; |
|
35 |
import javax.swing.event.ChangeListener; |
|
36 |
import javax.swing.event.TableModelEvent; |
|
37 |
import javax.swing.event.TableModelListener; |
|
38 |
|
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
41 |
import org.gvsig.fmap.dal.coverage.grid.FilterUIListener; |
|
42 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
|
43 |
import org.gvsig.gui.beans.table.TableContainer; |
|
44 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
45 |
import org.gvsig.i18n.Messages; |
|
46 |
import org.gvsig.raster.roi.ROI; |
|
47 |
/** |
|
48 |
* Es el interfaz gr?fico que contiene el filtro de regiones de interes. |
|
49 |
* En el se muestra una tabla con las posibles Rois a seleccionar y tambi?n |
|
50 |
* un Checkbox para definir si la seleccion es normal o invertida. |
|
51 |
* |
|
52 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
53 |
*/ |
|
54 |
public class RegionAlphaUI extends JPanel implements RegistrableFilterListener, TableModelListener, ChangeListener { |
|
55 |
private static final long serialVersionUID = 4525736825113598035L; |
|
56 |
private TableContainer tableContainer = null; |
|
57 |
private JLabel warning = null; |
|
58 |
//private List<ROI> roiList = null; |
|
59 |
private JCheckBox negative = null; |
|
60 |
private boolean lastInv = false; |
|
61 |
protected Params loadedParams = null; |
|
62 |
private ArrayList<FilterUIListener> |
|
63 |
actionCommandListeners = new ArrayList<FilterUIListener>(); |
|
64 |
|
|
65 |
/** |
|
66 |
* Constructor de un RegionAlphaUI |
|
67 |
*/ |
|
68 |
public RegionAlphaUI() { |
|
69 |
init(null); |
|
70 |
} |
|
71 |
|
|
72 |
public void init(Object obj) { |
|
73 |
setLayout(new BorderLayout()); |
|
74 |
add(getTableContainer(), BorderLayout.CENTER); |
|
75 |
add(getWarning(), BorderLayout.NORTH); |
|
76 |
add(getInverse(), BorderLayout.SOUTH); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Obtiene el contenedor con la tabla. |
|
81 |
* @return |
|
82 |
*/ |
|
83 |
private TableContainer getTableContainer() { |
|
84 |
if (tableContainer == null) { |
|
85 |
String[] columnNames = {" ", "Nombre", ""}; |
|
86 |
int[] columnWidths = {22, 334, 0}; |
|
87 |
tableContainer = new TableContainer(columnNames, columnWidths); |
|
88 |
tableContainer.setPreferredSize(new Dimension(0, 130)); |
|
89 |
tableContainer.setModel("CheckBoxModel"); |
|
90 |
tableContainer.initialize(); |
|
91 |
tableContainer.setControlVisible(false); |
|
92 |
tableContainer.setMoveRowsButtonsVisible(false); |
|
93 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(22); |
|
94 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(22); |
|
95 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMinWidth(0); |
|
96 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMaxWidth(0); |
|
97 |
tableContainer.getModel().addTableModelListener(this); |
|
98 |
} |
|
99 |
return tableContainer; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Obtiene el checkbox que informa de si selecciona lo que contiene las Rois |
|
104 |
* o su inversa. |
|
105 |
* @return JCheckBox |
|
106 |
*/ |
|
107 |
private JCheckBox getInverse() { |
|
108 |
if (negative == null) { |
|
109 |
negative = new JCheckBox(); |
|
110 |
negative.setText(Messages.getText("inversa")); |
|
111 |
negative.addChangeListener(this); |
|
112 |
} |
|
113 |
return negative; |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Obtiene el mensaje de aviso de que no hay rois en la lista. Esta etiqueta solo |
|
118 |
* es mostrada en caso en que la capa no tenga ROIs asociadas. |
|
119 |
* @return JLabel Etiqueta con el mensaje de aviso. |
|
120 |
*/ |
|
121 |
public JLabel getWarning() { |
|
122 |
if(warning == null) { |
|
123 |
warning = new JLabel(Messages.getText("rois_needed")); |
|
124 |
warning.setVisible(false); |
|
125 |
} |
|
126 |
return warning; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* Asigna la capa. |
|
131 |
* @param layer |
|
132 |
*/ |
|
133 |
public void setROIList(List<ROI> roiList) { |
|
134 |
//this.roiList = roiList; |
|
135 |
if(roiList == null || roiList.size() == 0) |
|
136 |
getWarning().setVisible(true); |
|
137 |
|
|
138 |
if (roiList != null) { |
|
139 |
for (int i = 0; i < roiList.size(); i++) { |
|
140 |
ROI roi = (ROI) roiList.get(i); |
|
141 |
|
|
142 |
Object row[] = {"", "", ""}; |
|
143 |
|
|
144 |
boolean active = false; |
|
145 |
|
|
146 |
if (roiList != null) { |
|
147 |
for (int r = 0; r < roiList.size(); r++) { |
|
148 |
if (((ROI) roiList.get(r)) == roi) { |
|
149 |
active = true; |
|
150 |
break; |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
row[0] = new Boolean(active); |
|
156 |
row[1] = roi.getName(); |
|
157 |
row[2] = new Integer(i); |
|
158 |
try { |
|
159 |
getTableContainer().addRow(row); |
|
160 |
} catch (NotInitializeException e) { |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Obtiene la lista de ROIs seleccionadas |
|
168 |
* @return ArrayList con la lista de ROIs |
|
169 |
*/ |
|
170 |
/*private List<ROI> getSelectedROIs() { |
|
171 |
List<ROI> selected = new ArrayList<ROI>(); |
|
172 |
if (roiList != null) { |
|
173 |
for (int i = 0; i < roiList.size(); i++) { |
|
174 |
try { |
|
175 |
if (((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue()) { |
|
176 |
selected.add(roiList.get(i)); |
|
177 |
} |
|
178 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
179 |
//Entra aqu? si se han a?adido ROIs con el cuadro abierto. Pasamos de hacer nada |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
return selected; |
|
184 |
}*/ |
|
185 |
|
|
186 |
private boolean[] getPositionSelectedROIs() { |
|
187 |
boolean[] selectedROIs = new boolean[tableContainer.getModel().getRowCount()]; |
|
188 |
|
|
189 |
for (int i = 0; i < tableContainer.getModel().getRowCount(); i++) { |
|
190 |
try { |
|
191 |
selectedROIs[i] = ((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue(); |
|
192 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
193 |
//Entra aqu? si se han a?adido ROIs con el cuadro abierto. Pasamos de hacer nada |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
return selectedROIs; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* Sobrecargamos el m?todo getParams para que siempre devuelva |
|
202 |
* algo. |
|
203 |
*/ |
|
204 |
public Params getParams() { |
|
205 |
Params params = null; |
|
206 |
if(loadedParams != null) { |
|
207 |
params = loadedParams; |
|
208 |
loadedParams = null; |
|
209 |
return params; |
|
210 |
} |
|
211 |
params = RasterLocator.getManager().createParams( |
|
212 |
"selected_roi", |
|
213 |
getPositionSelectedROIs(), |
|
214 |
-1, |
|
215 |
null); |
|
216 |
params.setParam("inverse", |
|
217 |
new Boolean(getInverse().isSelected()), |
|
218 |
-1, |
|
219 |
null); |
|
220 |
return params; |
|
221 |
} |
|
222 |
|
|
223 |
public void setParams(Params params) { |
|
224 |
this.loadedParams = params; |
|
225 |
} |
|
226 |
|
|
227 |
public void tableChanged(TableModelEvent e) { |
|
228 |
callStateChanged(); |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Cambio de estado para el check de inversa |
|
233 |
* @param e |
|
234 |
*/ |
|
235 |
public void stateChanged(ChangeEvent e) { |
|
236 |
if (e.getSource().equals(getInverse())) { |
|
237 |
if (((JCheckBox) e.getSource()).isSelected() != lastInv) { |
|
238 |
callStateChanged(); |
|
239 |
lastInv = ((JCheckBox) e.getSource()).isSelected(); |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
244 |
public void addFilterUIListener(FilterUIListener listener) { |
|
245 |
if (!actionCommandListeners.contains(listener)) |
|
246 |
actionCommandListeners.add(listener); |
|
247 |
} |
|
248 |
|
|
249 |
public void callStateChanged() { |
|
250 |
Iterator<FilterUIListener> acIterator = actionCommandListeners.iterator(); |
|
251 |
while (acIterator.hasNext()) { |
|
252 |
FilterUIListener listener = (FilterUIListener) acIterator.next(); |
|
253 |
listener.actionValuesCompleted(new EventObject(this)); |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
public void removeStateChangedListener(FilterUIListener listener) { |
|
258 |
actionCommandListeners.remove(listener); |
|
259 |
} |
|
260 |
} |
|
0 | 261 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/src/main/java/org/gvsig/raster/roimask/lib/impl/regionalpha/RegionAlphaFilter.java | ||
---|---|---|
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.roimask.lib.impl.regionalpha; |
|
23 |
|
|
24 |
import java.util.List; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
27 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
28 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
29 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
30 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
|
31 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
|
32 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
33 |
import org.gvsig.raster.roi.ROI; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
38 |
*/ |
|
39 |
public class RegionAlphaFilter extends BaseRasterFilter { |
|
40 |
public static String[] names = new String[] { "regionalpha" }; |
|
41 |
private RegionAlphaUI regionAlphaUI = null; |
|
42 |
private List<ROI> roiList = null; |
|
43 |
protected boolean[] selectedROI = null; |
|
44 |
protected int alpha = 255; |
|
45 |
protected boolean inverse = false; |
|
46 |
|
|
47 |
/* Variables que hacen falta en el process */ |
|
48 |
protected double cellsize = 0D; |
|
49 |
protected Extent bufferExtent = null; |
|
50 |
|
|
51 |
/** |
|
52 |
* Constructor |
|
53 |
*/ |
|
54 |
public RegionAlphaFilter() { |
|
55 |
super(); |
|
56 |
setName(names[0]); |
|
57 |
} |
|
58 |
|
|
59 |
public String getGroup() { |
|
60 |
return "mascaras"; |
|
61 |
} |
|
62 |
|
|
63 |
public String[] getNames() { |
|
64 |
return names; |
|
65 |
} |
|
66 |
|
|
67 |
public Params getUIParams(String nameFilter) { |
|
68 |
Params params = RasterLocator.getManager().createParams( |
|
69 |
"Panel", getRegionAlphaUI(), -1, null); |
|
70 |
params.setParam("FilterName", nameFilter, -1, null); |
|
71 |
params.setParam("Alpha", |
|
72 |
new Integer(alpha), |
|
73 |
Params.SLIDER, |
|
74 |
new String[]{ "0", "255", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
|
75 |
|
|
76 |
return params; |
|
77 |
} |
|
78 |
|
|
79 |
private RegionAlphaUI getRegionAlphaUI() { |
|
80 |
if (regionAlphaUI == null) { |
|
81 |
regionAlphaUI = new RegionAlphaUI(); |
|
82 |
regionAlphaUI.setROIList(getROIList()); |
|
83 |
} |
|
84 |
return regionAlphaUI; |
|
85 |
} |
|
86 |
|
|
87 |
@SuppressWarnings("unchecked") |
|
88 |
protected List<ROI> getROIList() { |
|
89 |
if(roiList == null) |
|
90 |
roiList = (List<ROI>)getEnv().get("SrcROI"); |
|
91 |
return roiList; |
|
92 |
} |
|
93 |
|
|
94 |
public void pre() throws FilterAddException { |
|
95 |
super.pre(); |
|
96 |
|
|
97 |
Boolean inverseBoolean = (Boolean) params.get("inverse"); |
|
98 |
if (inverseBoolean != null) |
|
99 |
inverse = inverseBoolean.booleanValue(); |
|
100 |
|
|
101 |
alpha = ((Integer) params.get("alpha")).intValue(); |
|
102 |
selectedROI = (boolean[]) params.get("selected_roi"); |
|
103 |
|
|
104 |
if(raster.getDataExtent() == null) |
|
105 |
throw new FilterAddException("Buffer extension cannot be null"); |
|
106 |
|
|
107 |
bufferExtent = RasterLocator.getManager().getDataStructFactory().createExtent(raster.getDataExtent()); |
|
108 |
cellsize = raster.getDataExtent().getWidth() / raster.getWidth(); |
|
109 |
|
|
110 |
if(hasInputTransparency()) |
|
111 |
createBufferResult(raster.getDataType(), raster.getBandCount()); |
|
112 |
else |
|
113 |
createBufferResult(raster.getDataType(), raster.getBandCount() + 1); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Gets the result of this filter |
|
118 |
*/ |
|
119 |
public Object getResult(String name) { |
|
120 |
if (name.equals(RESULT_TRANSPARENCY)) { |
|
121 |
String[] values = new String[rasterResult.getBandCount()]; |
|
122 |
for (int i = 0; i < values.length; i++) { |
|
123 |
values[i] = ColorInterpretation.UNDEF_BAND; |
|
124 |
} |
|
125 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(values); |
|
126 |
ci.setColorInterpValue(rasterResult.getBandCount() - 1, ColorInterpretation.ALPHA_BAND); |
|
127 |
transparency.setColorInterpretation(ci); |
|
128 |
transparency.activeTransparency(); |
|
129 |
return transparency; |
|
130 |
} |
|
131 |
|
|
132 |
return super.getResult(name); |
|
133 |
} |
|
134 |
|
|
135 |
public void post() { |
|
136 |
} |
|
137 |
|
|
138 |
public void process(int x, int y) { |
|
139 |
} |
|
140 |
|
|
141 |
public int getInRasterDataType() { |
|
142 |
return Buffer.TYPE_BYTE; |
|
143 |
} |
|
144 |
|
|
145 |
public int getOutRasterDataType() { |
|
146 |
return Buffer.TYPE_BYTE; |
|
147 |
} |
|
148 |
} |
|
0 | 149 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.144/org.gvsig.raster.roimask.lib/org.gvsig.raster.roimask.lib.impl/src/main/java/org/gvsig/raster/roimask/lib/impl/regionalpha/RegionAlphaListManager.java | ||
---|---|---|
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.roimask.lib.impl.regionalpha; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
|
29 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
|
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
|
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
|
32 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
|
33 |
|
|
34 |
public class RegionAlphaListManager extends AbstractRasterFilterManager { |
|
35 |
public static String ID = "RegionAlpha"; |
|
36 |
|
|
37 |
/** |
|
38 |
* Default constructor. Sets the filter list. |
|
39 |
* @param filterList |
|
40 |
*/ |
|
41 |
public RegionAlphaListManager(RasterFilterList filterList) { |
|
42 |
super(filterList); |
|
43 |
} |
|
44 |
|
|
45 |
public static void register() { |
|
46 |
AbstractRasterFilterManager.register(ID, RegionAlphaListManager.class, RegionAlphaUI.class); |
|
47 |
} |
Also available in: Unified diff