Revision 2438 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/filter/convolution/ConvolutionFloatFilter.java
ConvolutionFloatFilter.java | ||
---|---|---|
22 | 22 |
package org.gvsig.raster.impl.grid.filter.convolution; |
23 | 23 |
|
24 | 24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
|
25 | 26 |
import org.gvsig.raster.impl.DefaultRasterManager; |
26 | 27 |
import org.gvsig.raster.impl.buffer.RasterBuffer; |
27 | 28 |
import org.gvsig.raster.impl.datastruct.Kernel; |
... | ... | |
33 | 34 |
* */ |
34 | 35 |
public class ConvolutionFloatFilter extends ConvolutionFilter { |
35 | 36 |
|
36 |
public ConvolutionFloatFilter(){ |
|
37 |
public ConvolutionFloatFilter() {
|
|
37 | 38 |
super(); |
38 | 39 |
} |
39 | 40 |
|
... | ... | |
41 | 42 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como |
42 | 43 |
* parametro el kernel se pretende aplicar. |
43 | 44 |
* **/ |
44 |
public ConvolutionFloatFilter(Kernel k){ |
|
45 |
public ConvolutionFloatFilter(Kernel k) {
|
|
45 | 46 |
super(); |
46 |
super.kernel=k;
|
|
47 |
super.kernel = k;
|
|
47 | 48 |
} |
48 | 49 |
|
49 |
public void pre(){ |
|
50 |
public void pre() throws FilterAddException {
|
|
50 | 51 |
super.pre(); |
51 | 52 |
rasterResult = DefaultRasterManager.getInstance().createBuffer(Buffer.TYPE_FLOAT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
52 | 53 |
} |
... | ... | |
56 | 57 |
|
57 | 58 |
int lado= kernel.getLado(); |
58 | 59 |
int semiLado = (lado - 1) >> 1; |
59 |
double ventana[][]= new double[lado][lado]; |
|
60 |
double resultConvolution=0;
|
|
61 |
for (int band = 0; band < raster.getBandCount(); band++) {
|
|
60 |
double ventana[][] = new double[lado][lado];
|
|
61 |
double resultConvolution = 0;
|
|
62 |
for (int band = 0; band < numberOfBandsToProcess(); band++) {
|
|
62 | 63 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)){ |
63 | 64 |
for (int j = -semiLado; j <= semiLado; j++) |
64 | 65 |
for (int i = -semiLado; i <= semiLado; i++) |
65 | 66 |
ventana[i + semiLado][j + semiLado] = raster.getElemFloat(line + j, col + i, band);; |
66 |
Kernel Kventana= new Kernel(ventana); |
|
67 |
resultConvolution=kernel.convolution(Kventana);
|
|
68 |
if(resultConvolution>Float.MAX_VALUE)
|
|
69 |
resultConvolution=Float.MAX_VALUE;
|
|
67 |
Kernel Kventana = new Kernel(ventana);
|
|
68 |
resultConvolution = kernel.convolution(Kventana);
|
|
69 |
if(resultConvolution > Float.MAX_VALUE)
|
|
70 |
resultConvolution = Float.MAX_VALUE;
|
|
70 | 71 |
else if (resultConvolution<0) |
71 | 72 |
resultConvolution = 0; |
72 | 73 |
rasterResult.setElem(line, col, band,(float)resultConvolution); |
73 | 74 |
} |
74 | 75 |
else rasterResult.setElem(line, col,band,raster.getElemFloat(line,col,band)); |
75 | 76 |
} |
76 |
|
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
/** |
... | ... | |
89 | 89 |
public int getOutRasterDataType() { |
90 | 90 |
return RasterBuffer.TYPE_FLOAT; |
91 | 91 |
} |
92 |
|
|
93 |
/** |
|
94 |
* @return buffer resultante tras aplicar el filtro |
|
95 |
* */ |
|
96 |
public Object getResult(String name) { |
|
97 |
if (name.equals("raster")) |
|
98 |
return this.rasterResult; |
|
99 |
return null; |
|
100 |
} |
|
101 | 92 |
|
102 | 93 |
} |
Also available in: Unified diff