Add get_data_no_update to quick test
36
main.py
@@ -55,25 +55,25 @@ def main():
|
|||||||
|
|
||||||
entranceDirection = ["N", "S", "E", "W"]
|
entranceDirection = ["N", "S", "E", "W"]
|
||||||
|
|
||||||
for houses in rectangle_building:
|
# for houses in rectangle_building:
|
||||||
height = get_height_building_from_center(
|
# height = get_height_building_from_center(
|
||||||
center, (houses[0][0], houses[0][2]), length_world)
|
# center, (houses[0][0], houses[0][2]), length_world)
|
||||||
start = (houses[0][0] + origin[0], houses[0]
|
# start = (houses[0][0] + origin[0], houses[0]
|
||||||
[1], houses[0][2] + origin[1])
|
# [1], houses[0][2] + origin[1])
|
||||||
end = (houses[1][0] + origin[0], houses[1]
|
# end = (houses[1][0] + origin[0], houses[1]
|
||||||
[1] + height, houses[1][2] + origin[1])
|
# [1] + height, houses[1][2] + origin[1])
|
||||||
house = House(editor, start, end,
|
# house = House(editor, start, end,
|
||||||
entranceDirection[random.randint(0, 3)], blocks)
|
# entranceDirection[random.randint(0, 3)], blocks)
|
||||||
house.build()
|
# house.build()
|
||||||
|
|
||||||
for houses in rectangle_house_mountain:
|
# for houses in rectangle_house_mountain:
|
||||||
start = (houses[0][0] + origin[0], houses[0]
|
# start = (houses[0][0] + origin[0], houses[0]
|
||||||
[1], houses[0][2] + origin[1])
|
# [1], houses[0][2] + origin[1])
|
||||||
end = (houses[1][0] + origin[0], houses[1]
|
# end = (houses[1][0] + origin[0], houses[1]
|
||||||
[1], houses[1][2] + origin[1])
|
# [1], houses[1][2] + origin[1])
|
||||||
house = House(editor, start, end,
|
# house = House(editor, start, end,
|
||||||
entranceDirection[random.randint(0, 3)], blocks)
|
# entranceDirection[random.randint(0, 3)], blocks)
|
||||||
house.build()
|
# house.build()
|
||||||
|
|
||||||
|
|
||||||
def get_height_building_from_center(center, position, length_world):
|
def get_height_building_from_center(center, position, length_world):
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 717 B |
|
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -18,6 +18,17 @@ def get_data(world: World):
|
|||||||
return heightmap, watermap, treemap
|
return heightmap, watermap, treemap
|
||||||
|
|
||||||
|
|
||||||
|
def get_data_no_update():
|
||||||
|
print("[Data Analysis] Generating data...")
|
||||||
|
# heightmap, watermap, treemap = world.getData()
|
||||||
|
heightmap, watermap, treemap = handle_import_image(
|
||||||
|
'./world_maker/data/heightmap.png'), handle_import_image(
|
||||||
|
'./world_maker/data/watermap.png'), handle_import_image(
|
||||||
|
'./world_maker/data/treemap.png')
|
||||||
|
print("[Data Analysis] Data generated.")
|
||||||
|
return heightmap, watermap, treemap
|
||||||
|
|
||||||
|
|
||||||
def handle_import_image(image: str | Image.Image) -> Image.Image:
|
def handle_import_image(image: str | Image.Image) -> Image.Image:
|
||||||
if isinstance(image, str):
|
if isinstance(image, str):
|
||||||
return Image.open(image)
|
return Image.open(image)
|
||||||
@@ -68,29 +79,29 @@ def filter_sobel(image: str | Image.Image) -> Image.Image:
|
|||||||
for i in range(1, h - 1):
|
for i in range(1, h - 1):
|
||||||
for j in range(1, w - 1):
|
for j in range(1, w - 1):
|
||||||
horizontalGrad = (
|
horizontalGrad = (
|
||||||
(horizontal[0, 0] * gray_img[i - 1, j - 1])
|
(horizontal[0, 0] * gray_img[i - 1, j - 1])
|
||||||
+ (horizontal[0, 1] * gray_img[i - 1, j])
|
+ (horizontal[0, 1] * gray_img[i - 1, j])
|
||||||
+ (horizontal[0, 2] * gray_img[i - 1, j + 1])
|
+ (horizontal[0, 2] * gray_img[i - 1, j + 1])
|
||||||
+ (horizontal[1, 0] * gray_img[i, j - 1])
|
+ (horizontal[1, 0] * gray_img[i, j - 1])
|
||||||
+ (horizontal[1, 1] * gray_img[i, j])
|
+ (horizontal[1, 1] * gray_img[i, j])
|
||||||
+ (horizontal[1, 2] * gray_img[i, j + 1])
|
+ (horizontal[1, 2] * gray_img[i, j + 1])
|
||||||
+ (horizontal[2, 0] * gray_img[i + 1, j - 1])
|
+ (horizontal[2, 0] * gray_img[i + 1, j - 1])
|
||||||
+ (horizontal[2, 1] * gray_img[i + 1, j])
|
+ (horizontal[2, 1] * gray_img[i + 1, j])
|
||||||
+ (horizontal[2, 2] * gray_img[i + 1, j + 1])
|
+ (horizontal[2, 2] * gray_img[i + 1, j + 1])
|
||||||
)
|
)
|
||||||
|
|
||||||
newhorizontalImage[i - 1, j - 1] = abs(horizontalGrad)
|
newhorizontalImage[i - 1, j - 1] = abs(horizontalGrad)
|
||||||
|
|
||||||
verticalGrad = (
|
verticalGrad = (
|
||||||
(vertical[0, 0] * gray_img[i - 1, j - 1])
|
(vertical[0, 0] * gray_img[i - 1, j - 1])
|
||||||
+ (vertical[0, 1] * gray_img[i - 1, j])
|
+ (vertical[0, 1] * gray_img[i - 1, j])
|
||||||
+ (vertical[0, 2] * gray_img[i - 1, j + 1])
|
+ (vertical[0, 2] * gray_img[i - 1, j + 1])
|
||||||
+ (vertical[1, 0] * gray_img[i, j - 1])
|
+ (vertical[1, 0] * gray_img[i, j - 1])
|
||||||
+ (vertical[1, 1] * gray_img[i, j])
|
+ (vertical[1, 1] * gray_img[i, j])
|
||||||
+ (vertical[1, 2] * gray_img[i, j + 1])
|
+ (vertical[1, 2] * gray_img[i, j + 1])
|
||||||
+ (vertical[2, 0] * gray_img[i + 1, j - 1])
|
+ (vertical[2, 0] * gray_img[i + 1, j - 1])
|
||||||
+ (vertical[2, 1] * gray_img[i + 1, j])
|
+ (vertical[2, 1] * gray_img[i + 1, j])
|
||||||
+ (vertical[2, 2] * gray_img[i + 1, j + 1])
|
+ (vertical[2, 2] * gray_img[i + 1, j + 1])
|
||||||
)
|
)
|
||||||
|
|
||||||
newverticalImage[i - 1, j - 1] = abs(verticalGrad)
|
newverticalImage[i - 1, j - 1] = abs(verticalGrad)
|
||||||
@@ -318,6 +329,7 @@ def get_index_of_biggest_area_mountain(area_mountain: list[int], exception: list
|
|||||||
index = i
|
index = i
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
||||||
def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int) -> Position | None:
|
def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int) -> Position | None:
|
||||||
points = []
|
points = []
|
||||||
for y in range(len(mountain_map)):
|
for y in range(len(mountain_map)):
|
||||||
@@ -328,6 +340,7 @@ def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int)
|
|||||||
return None
|
return None
|
||||||
return choice(points)
|
return choice(points)
|
||||||
|
|
||||||
|
|
||||||
def get_center_of_area_mountain(mountain_map: list[list[int]], index: int) -> Position:
|
def get_center_of_area_mountain(mountain_map: list[list[int]], index: int) -> Position:
|
||||||
sum_x = 0
|
sum_x = 0
|
||||||
sum_y = 0
|
sum_y = 0
|
||||||
@@ -353,7 +366,8 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10,
|
|||||||
for y in range(image_heightmap.size[1]):
|
for y in range(image_heightmap.size[1]):
|
||||||
for x in range(image_heightmap.size[0]):
|
for x in range(image_heightmap.size[0]):
|
||||||
avg_height += image_heightmap.getpixel((x, y))
|
avg_height += image_heightmap.getpixel((x, y))
|
||||||
avg_height = int(avg_height / (image_heightmap.size[0] * image_heightmap.size[1]))
|
avg_height = int(
|
||||||
|
avg_height / (image_heightmap.size[0] * image_heightmap.size[1]))
|
||||||
print("[Data Analysis] Average height:", avg_height)
|
print("[Data Analysis] Average height:", avg_height)
|
||||||
|
|
||||||
mountain_map = [[-1 if image_heightmap.getpixel((x, y)) < (avg_height + height_threshold) else 0 for x in
|
mountain_map = [[-1 if image_heightmap.getpixel((x, y)) < (avg_height + height_threshold) else 0 for x in
|
||||||
@@ -375,13 +389,15 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10,
|
|||||||
if number_of_mountain < len(area_mountain):
|
if number_of_mountain < len(area_mountain):
|
||||||
index_mountain = []
|
index_mountain = []
|
||||||
for n in range(number_of_mountain):
|
for n in range(number_of_mountain):
|
||||||
index_mountain.append(get_index_of_biggest_area_mountain(area_mountain, index_mountain))
|
index_mountain.append(get_index_of_biggest_area_mountain(
|
||||||
|
area_mountain, index_mountain))
|
||||||
else:
|
else:
|
||||||
index_mountain = [i for i in range(len(area_mountain))]
|
index_mountain = [i for i in range(len(area_mountain))]
|
||||||
|
|
||||||
position_mountain = []
|
position_mountain = []
|
||||||
for i in range(len(index_mountain)):
|
for i in range(len(index_mountain)):
|
||||||
position_mountain.append(get_center_of_area_mountain(mountain_map, index_mountain[i]))
|
position_mountain.append(get_center_of_area_mountain(
|
||||||
|
mountain_map, index_mountain[i]))
|
||||||
|
|
||||||
return position_mountain
|
return position_mountain
|
||||||
|
|
||||||
@@ -408,7 +424,7 @@ def rectangle_2D_to_3D(rectangle: list[tuple[tuple[int, int], tuple[int, int]]],
|
|||||||
|
|
||||||
|
|
||||||
def transpose_form_heightmap(heightmap: str | Image.Image, coordinates, origin: tuple[int, int]) -> tuple[
|
def transpose_form_heightmap(heightmap: str | Image.Image, coordinates, origin: tuple[int, int]) -> tuple[
|
||||||
int, int, int]:
|
int, int, int]:
|
||||||
heightmap = handle_import_image(heightmap).convert('L')
|
heightmap = handle_import_image(heightmap).convert('L')
|
||||||
|
|
||||||
xMin, zMin = origin
|
xMin, zMin = origin
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from world_maker.World import World
|
from world_maker.World import World
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from world_maker.data_analysis import (get_data, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map,
|
from world_maker.data_analysis import (get_data, get_data_no_update, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map,
|
||||||
smooth_sobel_water, subtract_map, detect_mountain, filter_smooth, overide_map)
|
smooth_sobel_water, subtract_map, detect_mountain, filter_smooth, overide_map)
|
||||||
from world_maker.City import City
|
from world_maker.City import City
|
||||||
from world_maker.Position import Position
|
from world_maker.Position import Position
|
||||||
@@ -9,8 +9,10 @@ from world_maker.pack_rectangle import generate_building
|
|||||||
|
|
||||||
|
|
||||||
def world_maker():
|
def world_maker():
|
||||||
world = World()
|
# world = World()
|
||||||
heightmap, watermap, treemap = get_data(world)
|
# heightmap, watermap, treemap = get_data(world)
|
||||||
|
|
||||||
|
heightmap, watermap, treemap = get_data_no_update()
|
||||||
|
|
||||||
filter_sobel(
|
filter_sobel(
|
||||||
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')
|
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')
|
||||||
|
|||||||