root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridCalculus / generateRandomBernoulli / GenerateRandomBernoulliAlgorithm.java @ 59
History | View | Annotate | Download (2.05 KB)
1 |
package es.unex.sextante.gridCalculus.generateRandomBernoulli; |
---|---|
2 |
|
3 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
4 |
import es.unex.sextante.core.GeoAlgorithm; |
5 |
import es.unex.sextante.core.Sextante; |
6 |
import es.unex.sextante.dataObjects.IRasterLayer; |
7 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
8 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
9 |
|
10 |
public class GenerateRandomBernoulliAlgorithm |
11 |
extends
|
12 |
GeoAlgorithm { |
13 |
|
14 |
public static final String RESULT = "RESULT"; |
15 |
public static final String PROB = "PROB"; |
16 |
|
17 |
private IRasterLayer m_Result;
|
18 |
|
19 |
|
20 |
@Override
|
21 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
22 |
|
23 |
int x, y;
|
24 |
int iNX, iNY;
|
25 |
int iValue;
|
26 |
double dValue;
|
27 |
|
28 |
final double dProb = m_Parameters.getParameterValueAsDouble(PROB) / 100.; |
29 |
|
30 |
m_Result = getNewRasterLayer(RESULT, Sextante.getText("New_layer"), IRasterLayer.RASTER_DATA_TYPE_INT);
|
31 |
|
32 |
iNX = m_Result.getWindowGridExtent().getNX(); |
33 |
iNY = m_Result.getWindowGridExtent().getNY(); |
34 |
|
35 |
for (y = 0; y < iNY; y++) { |
36 |
for (x = 0; x < iNX; x++) { |
37 |
dValue = Math.random();
|
38 |
if (dValue < dProb) {
|
39 |
iValue = 1;
|
40 |
} |
41 |
else {
|
42 |
iValue = 0;
|
43 |
} |
44 |
m_Result.setCellValue(x, y, iValue); |
45 |
} |
46 |
} |
47 |
|
48 |
return !m_Task.isCanceled();
|
49 |
|
50 |
} |
51 |
|
52 |
|
53 |
@Override
|
54 |
public void defineCharacteristics() { |
55 |
|
56 |
setName(Sextante.getText("Random_grid__Bernouilli"));
|
57 |
setGroup(Sextante.getText("Raster_creation_tools"));
|
58 |
setUserCanDefineAnalysisExtent(true);
|
59 |
|
60 |
try {
|
61 |
m_Parameters.addNumericalValue(PROB, Sextante.getText("Probability__%"),
|
62 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE, 50, 0, 100); |
63 |
addOutputRasterLayer(RESULT, Sextante.getText("Probability"));
|
64 |
} |
65 |
catch (final RepeatedParameterNameException e) { |
66 |
Sextante.addErrorToLog(e); |
67 |
} |
68 |
|
69 |
} |
70 |
|
71 |
} |