Skip to content

Commit

Permalink
DEM validation
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot authored Jan 26, 2025
1 parent d28bab9 commit fd83ebf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions maps4fs/generator/component/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def process(self) -> None:

if not self.map.custom_background_path:
self.dem.process()
self.validate_np_for_mesh(self.dem.dem_path, self.map_size)

shutil.copyfile(self.dem.dem_path, self.not_substracted_path)
self.save_map_dem(self.dem.dem_path, save_path=self.not_resized_path)
Expand Down
21 changes: 15 additions & 6 deletions maps4fs/generator/component/base/component_mesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Base class for all components that primarily used to work with meshes."""

import os

import cv2
import numpy as np
import trimesh
Expand All @@ -17,24 +19,31 @@ def validate_np_for_mesh(image_path: str, map_size: int) -> None:
"""Checks if the given image is a valid for mesh generation.
Arguments:
image_path (str): The path to the custom background image.
image_path (str): The path to the background image.
map_size (int): The size of the map.
Raises:
ValueError: If the custom background image does not meet the requirements.
FileNotFoundError: If the background image is not found.
ValueError: If the background image does not meet the requirements.
"""
if not os.path.isfile(image_path):
raise FileNotFoundError(f"Can't find the background DEM image at {image_path}.")

image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
if image is None:
raise ValueError(f"Can't read the background DEM image at {image_path}.")

if image.shape[0] != image.shape[1]:
raise ValueError("The custom background image must be a square.")
raise ValueError("The background image must be a square.")

if image.shape[0] != map_size + Parameters.BACKGROUND_DISTANCE * 2:
raise ValueError("The custom background image must have the size of the map + 4096.")
raise ValueError("The background image must have the size of the map + 4096.")

if len(image.shape) != 2:
raise ValueError("The custom background image must be a grayscale image.")
raise ValueError("The background image must be a grayscale image.")

if image.dtype != np.uint16:
raise ValueError("The custom background image must be a 16-bit grayscale image.")
raise ValueError("The background image must be a 16-bit grayscale image.")

@staticmethod
def mesh_to_stl(mesh: trimesh.Trimesh, save_path: str) -> None:
Expand Down

0 comments on commit fd83ebf

Please sign in to comment.