Skip to content

Commit

Permalink
Include zeros in background fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Jan 5, 2025
1 parent 321b1cf commit fa0efe6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions maps4fs/generator/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def generate_obj_files(self) -> None:
self.logger.debug("Generating obj file in path: %s", save_path)

dem_data = cv2.imread(self.dem.dem_path, cv2.IMREAD_UNCHANGED) # pylint: disable=no-member
self.plane_from_np(dem_data, save_path) # type: ignore
self.plane_from_np(dem_data, save_path, create_preview=True) # type: ignore

# pylint: disable=too-many-locals
def cutout(self, dem_path: str, save_path: str | None = None) -> str:
Expand Down Expand Up @@ -232,13 +232,15 @@ def plane_from_np(
dem_data: np.ndarray,
save_path: str,
include_zeros: bool = True,
create_preview: bool = False,
) -> None:
"""Generates a 3D obj file based on DEM data.
Arguments:
dem_data (np.ndarray) -- The DEM data as a numpy array.
save_path (str) -- The path where the obj file will be saved.
include_zeros (bool, optional) -- If True, the mesh will include the zero height values.
create_preview (bool, optional) -- If True, a simplified mesh will be saved as an STL.
"""
resize_factor = 1 / self.map.background_settings.resize_factor
dem_data = cv2.resize( # pylint: disable=no-member
Expand Down Expand Up @@ -278,7 +280,10 @@ def plane_from_np(
bottom_left = top_left + cols
bottom_right = bottom_left + 1

if ground in [z[i, j], z[i, j + 1], z[i + 1, j], z[i + 1, j + 1]]:
if (
ground in [z[i, j], z[i, j + 1], z[i + 1, j], z[i + 1, j + 1]]
and not include_zeros
):
skipped += 1
continue

Expand All @@ -304,7 +309,7 @@ def plane_from_np(
mesh.export(save_path)
self.logger.debug("Obj file saved: %s", save_path)

if include_zeros:
if create_preview:
# Simplify the preview mesh to reduce the size of the file.
mesh = mesh.simplify_quadric_decimation(face_count=len(mesh.faces) // 2**7)

Expand Down

0 comments on commit fa0efe6

Please sign in to comment.