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

Annotation of /trunk/src/appl/parallel/test/AverageNeighborhoodTestTask_MultiGrid.java

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26