/[xulu]/trunk/src/appl/parallel/test/AverageNeighborhoodTestTask.java
ViewVC logotype

Contents of /trunk/src/appl/parallel/test/AverageNeighborhoodTestTask.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 114 - (show annotations)
Mon Jul 11 11:31:25 2011 UTC (13 years, 5 months ago) by mojays
File size: 2642 byte(s)
SCHMITZM library updated to current version (2.6-SNAPSHOT)
Added gt-xsd-filter.jar, gt-xsd-gml2.jar, picocontainer.jar and xsd.jar from Geotools 2.6.5
1 package appl.parallel.test;
2
3 import java.awt.Rectangle;
4
5 import appl.parallel.spmd.AbstractSPMDTask;
6 import appl.parallel.spmd.SPMDServerInterface;
7 import appl.util.RasterUtil;
8 import de.schmitzm.geotools.data.WritableGrid;
9
10 /**
11 * @author Dominik Appl
12 */
13 public class AverageNeighborhoodTestTask extends AbstractSPMDTask {
14
15 /**
16 *
17 */
18 private static final long serialVersionUID = 13L;
19
20 /* (non-Javadoc)
21 * @see appl.parallel.spmd.SPMDTask#run()
22 */
23 public Object run(Object...parameters) {
24
25 SPMDServerInterface controller = getSPMDServerController();
26 WritableGrid gridInput = (WritableGrid) controller
27 .getPartition("inputGrid");
28 WritableGrid gridOutput = (WritableGrid) controller
29 .getPartition("outputGrid");
30 int neighborhoodRange = (Integer) parameters[0];
31 /********************** START REMOTE ALGORITHM *********************
32 * start the calculation (notice that only the outer loop variables have changed)
33 * *****************************************************************/
34 float overallSum = 0;
35 Rectangle partition = controller.getLocalBounds();
36 //System.out.println("290,64: " + gridInput.getRasterSampleAsFloat(controller.getLocalCalcMinX()+289,64));
37 for (int y = controller.getLocalCalcMinY(); y < controller
38 .getLocalCalcMaxY() + 1; y++)
39 for (int x = controller.getLocalCalcMinX(); x < controller
40 .getLocalCalcMaxX() + 1; x++) {
41 float tmp = gridInput.getRasterSampleAsFloat(x,y);
42 if(!Float.isNaN(tmp))
43 overallSum += tmp;
44 //the local sum is simply the sum over all elements in the neighborhood
45 float localSum = 0;
46 //number of cells over which the sum is calculated
47 int noOfCells = 0;
48 //for each cell: calculate the sum of all neighbors
49 for (int y2 = y - neighborhoodRange; y2 <= y
50 + neighborhoodRange; y2++)
51 for (int x2 = x - neighborhoodRange; x2 <= x
52 + neighborhoodRange; x2++)
53 //check if the coordinates are valid (inside the grid and not NaN)
54 if (partition.contains(x2, y2))
55 if (!Float.isNaN(gridInput
56 .getRasterSampleAsFloat(x2, y2))) {
57 localSum += gridInput.getRasterSampleAsFloat(
58 x2, y2);
59 noOfCells++;
60 }
61 gridOutput.setRasterSample(localSum / (float) (noOfCells), x,y);
62
63 }
64 //copy values into results from output to input (for next step)
65 RasterUtil.copyInto(gridOutput, gridInput);
66 return overallSum;
67 }
68
69 /* (non-Javadoc)
70 * @see appl.parallel.spmd.AbstractSPMDTask#init()
71 */
72 @Override
73 public void init() {
74 // TODO Auto-generated method stub
75
76 }
77
78
79
80 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26