-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from svencc/feature/forest-cell-renderer-and-s…
…pacial-index Feature/forest cell renderer and spacial index
- Loading branch information
Showing
32 changed files
with
615 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ns/src/main/java/com/recom/commons/calculator/d8algorithm/D8AlgorithmForStructureMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.recom.commons.calculator.d8algorithm; | ||
|
||
|
||
import com.recom.commons.calculator.ARGBCalculator; | ||
import com.recom.commons.map.rasterizer.mapdesignscheme.MapDesignScheme; | ||
import com.recom.commons.model.DEMDescriptor; | ||
import com.recom.commons.model.maprendererpipeline.dataprovider.SpacialIndex; | ||
import com.recom.commons.model.maprendererpipeline.dataprovider.village.StructureItem; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public class D8AlgorithmForStructureMap { | ||
|
||
@NonNull | ||
private final ARGBCalculator colorCalculator = new ARGBCalculator(); | ||
private final int structureCellSizeInMeter; | ||
|
||
|
||
@NonNull | ||
public int[][] generateStructureMap( | ||
@NonNull final DEMDescriptor demDescriptor, | ||
@NonNull final SpacialIndex<StructureItem> spacialIndex, | ||
@NonNull final MapDesignScheme mapScheme | ||
) { | ||
final int demWidth = demDescriptor.getDemWidth(); | ||
final int demHeight = demDescriptor.getDemHeight(); | ||
|
||
final int[][] structureMap = new int[demWidth][demHeight]; | ||
for (int demX = 0; demX < demWidth; demX++) { | ||
for (int demY = 0; demY < demHeight; demY++) { | ||
structureMap[demX][demY] = calculateStructureFragment(demDescriptor, spacialIndex, mapScheme, demX, demY); | ||
} | ||
} | ||
|
||
return structureMap; | ||
} | ||
|
||
@NonNull | ||
private int calculateStructureFragment( | ||
@NonNull final DEMDescriptor demDescriptor, | ||
@NonNull final SpacialIndex<StructureItem> spacialIndex, | ||
@NonNull final MapDesignScheme mapScheme, | ||
final int demX, | ||
final int demY | ||
) { | ||
final int structureCellSizeSquared = structureCellSizeInMeter * structureCellSizeInMeter; | ||
double structureDensityThreshold = 1F / 100; // @TODO extract to conf | ||
|
||
final int spacialX = demX * demDescriptor.getStepSize(); | ||
final int spacialY = demY * demDescriptor.getStepSize(); | ||
|
||
final List<StructureItem> structureItemsInSpace = spacialIndex.getInSpace(spacialX, spacialY); | ||
final double StructureDensity = structureItemsInSpace.size() / (double) structureCellSizeSquared; | ||
|
||
int surroundingStructureNeighbourSpaces = 0; | ||
for (int direction = 0; direction < 8; direction++) { | ||
final double adjacentNeighborSpatialX = spacialX + (D8AspectMatrix.directionXComponentMatrix[direction] * demDescriptor.getStepSize()); // Calculate the X-coordinate of the adjacent neighbor. | ||
final double adjacentNeighborSpatialY = spacialY + (D8AspectMatrix.directionYComponentMatrix[direction] * demDescriptor.getStepSize()); // Calculate the Y-coordinate of the adjacent neighbor. | ||
|
||
if (adjacentNeighborSpatialX < 0 || adjacentNeighborSpatialX > demDescriptor.getMapWidthInMeter() || adjacentNeighborSpatialY < 0 || adjacentNeighborSpatialY > demDescriptor.getMapHeightInMeter()) { | ||
continue; | ||
} else { | ||
final List<StructureItem> structureItemsInNeighborCell = spacialIndex.getInSpace(adjacentNeighborSpatialX, adjacentNeighborSpatialY); | ||
|
||
double neighbourStructureDensity; | ||
if (!structureItemsInNeighborCell.isEmpty()) { | ||
neighbourStructureDensity = structureItemsInNeighborCell.size() / (double) structureCellSizeSquared; | ||
} else { | ||
neighbourStructureDensity = 0; | ||
} | ||
|
||
if (neighbourStructureDensity >= structureDensityThreshold) { | ||
surroundingStructureNeighbourSpaces++; | ||
} | ||
} | ||
} | ||
|
||
if (StructureDensity < structureDensityThreshold) { | ||
return mapScheme.getBaseColorStructureBackground(); | ||
} else if (StructureDensity >= structureDensityThreshold && surroundingStructureNeighbourSpaces >= 5) { | ||
return mapScheme.getBaseColorStructure(); | ||
} else { | ||
return colorCalculator.modifyTransparency(mapScheme.getBaseColorStructure(), 0.5); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.