use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.
the class OmsDePitter method floodAndFlow.
private void floodAndFlow(int iteration, List<GridNode> nodesToCheck, double runningFloodValue, List<GridNode> allNodesOfPit, BitMatrix floodedPositions, WritableRandomIter pitIter) {
iteration++;
double currentRunningFloodValue = runningFloodValue + delta;
List<GridNode> nodesForNextRound = new ArrayList<>();
for (GridNode currentNode : nodesToCheck) {
// flood and grow the first surrounding
List<GridNode> currentSurroundingNodes = currentNode.getValidSurroundingNodes();
for (GridNode gridNode : currentSurroundingNodes) {
if (!floodedPositions.isMarked(gridNode.col, gridNode.row) && allNodesOfPit.contains(gridNode)) {
double newValue = 0;
if (gridNode.elevation <= runningFloodValue) {
newValue = currentRunningFloodValue;
} else {
// TODO check if it is enough or
newValue = gridNode.elevation + delta;
// better
// add delta
}
gridNode.setValueInMap(pitIter, newValue);
floodedPositions.mark(gridNode.col, gridNode.row);
nodesForNextRound.add(gridNode);
}
}
}
int size = nodesForNextRound.size();
if (size > 0) {
floodAndFlow(iteration, nodesForNextRound, currentRunningFloodValue, allNodesOfPit, floodedPositions, pitIter);
}
}
use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.
the class OmsDePitter method findConnectedOfSameHeight.
private void findConnectedOfSameHeight(GridNode node, BitMatrix allPitsPositions, List<GridNode> nodesInPit) {
double elev = node.elevation;
List<GridNode> checkNodes = new ArrayList<>();
checkNodes.add(node);
boolean oneAdded = true;
int startIndex = 0;
while (oneAdded) {
oneAdded = false;
int currentSize = checkNodes.size();
for (int i = startIndex; i < currentSize; i++) {
GridNode checkNode = checkNodes.get(i);
List<GridNode> tmpNodes = checkNode.getValidSurroundingNodes();
for (GridNode gridNode : tmpNodes) {
if (allPitsPositions.isMarked(gridNode.col, gridNode.row)) {
continue;
}
if (gridNode.elevation == elev) {
checkNodes.add(gridNode);
nodesInPit.add(gridNode);
allPitsPositions.mark(gridNode.col, gridNode.row);
oneAdded = true;
}
}
}
startIndex = currentSize;
}
}
use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.
the class OmsAspectIM method processCell.
@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
RandomIter elevIter = inRasterIterators.get(0);
Double novalue = inRasterNovalues.get(0);
GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
double aspect = OmsAspect.calculateAspect(node, radtodeg, doRound);
WritableRandomIter outDataIter = outRasterIterators.get(0);
outDataIter.setSample(writeCol, writeRow, 0, aspect);
}
use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.
the class OmsCurvaturesIM method processCell.
@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
RandomIter elevIter = inRasterIterators.get(0);
Double novalue = inRasterNovalues.get(0);
GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
OmsCurvatures.calculateCurvatures2(node, planTangProf);
if (outPlan != null)
outRasterIterators.get(0).setSample(writeCol, writeRow, 0, planTangProf[0]);
if (outTang != null)
outRasterIterators.get(1).setSample(writeCol, writeRow, 0, planTangProf[1]);
if (outProf != null)
outRasterIterators.get(2).setSample(writeCol, writeRow, 0, planTangProf[2]);
}
use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.
the class OmsSlope method process.
@Execute
public void process() {
if (!concatOr(outSlope == null, doReset)) {
return;
}
checkNull(inPit, inFlow);
HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit);
int nCols = regionMap.get(CoverageUtilities.COLS).intValue();
int nRows = regionMap.get(CoverageUtilities.ROWS).intValue();
double xRes = regionMap.get(CoverageUtilities.XRES);
double yRes = regionMap.get(CoverageUtilities.YRES);
double novalue = HMConstants.getNovalue(inPit);
RenderedImage elevationRI = inPit.getRenderedImage();
RandomIter elevationIter = RandomIterFactory.create(elevationRI, null);
RenderedImage flowRI = inFlow.getRenderedImage();
RandomIter flowIter = RandomIterFactory.create(flowRI, null);
WritableRaster slopeWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, doubleNovalue);
pm.beginTask(msg.message("slope.calculating"), nCols);
for (int r = 0; r < nRows; r++) {
for (int c = 0; c < nCols; c++) {
double flowValue = flowIter.getSampleDouble(c, r, 0);
GridNode node = new GridNode(elevationIter, nCols, nRows, xRes, yRes, c, r, novalue);
double value = calculateSlope(node, flowValue);
if (doHandleNegativeSlope && value < 0) {
value = Double.MIN_VALUE;
}
slopeWR.setSample(c, r, 0, value);
}
pm.worked(1);
}
pm.done();
outSlope = CoverageUtilities.buildCoverageWithNovalue("slope", slopeWR, regionMap, inPit.getCoordinateReferenceSystem(), doubleNovalue);
}
Aggregations