Add remove tree

This commit is contained in:
2024-06-16 19:09:53 +02:00
parent b3aba8a97c
commit 7c59b04ec3
16 changed files with 61 additions and 3 deletions

10
main.py
View File

@@ -5,6 +5,7 @@ import gdpc.exceptions
from world_maker.world_maker import *
from world_maker.data_analysis import transpose_form_heightmap
from world_maker.Skeleton import Skeleton, simplify_coordinates
from world_maker.terraforming import remove_trees
from networks.geometry.Point3D import Point3D
from networks.roads_2.Road import Road
from networks.legacy_roads import roads
@@ -20,9 +21,12 @@ def main():
buildArea = editor.getBuildArea()
origin = ((buildArea.begin).x, (buildArea.begin).z)
set_roads(skeleton_mountain, origin)
set_roads(skeleton_highway, origin)
set_roads_grids(road_grid, origin)
remove_trees('./world_maker/data/heightmap.png',
'./world_maker/data/treemap.png', './world_maker/data/smooth_sobel_watermap.png')
# set_roads(skeleton_mountain, origin)
# set_roads(skeleton_highway, origin)
# set_roads_grids(road_grid, origin)
# roads.setRoads(skeleton_mountain)
# roads.setRoads(skeleton_highway)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 387 B

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 942 B

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 817 B

After

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 359 B

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -0,0 +1,54 @@
from typing import Union
import numpy as np
from gdpc import Editor, Block, geometry
from PIL import Image
from skimage import morphology
from world_maker.data_analysis import handle_import_image
def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask: Union[str, Image], ):
editor = Editor(buffering=True)
build_area = editor.getBuildArea()
build_rectangle = build_area.toRect()
start = build_rectangle.begin
distance = (max(build_rectangle.end[0], build_rectangle.begin[0]) - min(build_rectangle.end[0], build_rectangle.begin[0]), max(
build_rectangle.end[1], build_rectangle.begin[1]) - min(build_rectangle.end[1], build_rectangle.begin[1]))
heightmap = handle_import_image(heightmap).convert('L')
treesmap = handle_import_image(treesmap).convert('L')
mask = handle_import_image(mask)
removed_treesmap = Image.new("RGB", distance, 0)
removed = []
for x in range(0, distance[0]):
for z in range(0, distance[1]):
if mask.getpixel((x, z)) == 255 and treesmap.getpixel((x, z)) > 0 and (x, z) not in removed:
treeArea = morphology.flood(treesmap, (z, x), tolerance=1)
blend = Image.blend(Image.fromarray(treeArea).convert(
'RGB'), removed_treesmap.convert('RGB'), 0.5)
array = np.array(blend.convert('L'))
bool_array = array > 1
removed_treesmap = Image.fromarray(bool_array)
removed.append((x, z))
print(x, z)
removed_treesmap.save('./world_maker/data/removed_treesmap.png')
for x in range(0, distance[0]):
for z in range(0, distance[1]):
print("removing tree in ", start[0] + x, start[1] + z)
if removed_treesmap.getpixel((x, z)) != 0:
y = heightmap.getpixel((x, z))
y_top = removed_treesmap.getpixel((x, z))
geometry.placeLine(
editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air'))