Skip to content

Commit

Permalink
Added mesh simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Nov 25, 2024
1 parent f53a6fe commit 79edabc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy pylint opencv-python "osmnx<2.0.0" geopy trimesh rasterio tqdm types-tqdm pandas-stubs types-requests pytest pytest-cov
pip install mypy pylint opencv-python "osmnx<2.0.0" "fast-simplification" geopy trimesh rasterio tqdm types-tqdm pandas-stubs types-requests pytest pytest-cov
- name: Run mypy to generate cache
run: mypy maps4fs || true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /usr/src/app
COPY data /usr/src/app/data
COPY webui /usr/src/app/webui

RUN pip install "opencv-python" "pyproj" "folium" "geopy" "osmnx<2.0.0" "rasterio" "trimesh" "tqdm" "streamlit" "maps4fs"
RUN pip install "opencv-python" "pyproj" "folium" "geopy" "osmnx<2.0.0" "fast-simplification" "rasterio" "trimesh" "tqdm" "streamlit" "maps4fs"

EXPOSE 8501

Expand Down
1 change: 1 addition & 0 deletions dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pytest
pytest-cov
folium
geopy
fast-simplification
pyproj
7 changes: 6 additions & 1 deletion maps4fs/generator/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def preprocess(self) -> None:
tile_code=path_step.code,
auto_process=False,
blur_radius=self.kwargs.get("blur_radius"),
multiplier=300,
multiplier=1,
)

# Update the origin for the next tile.
Expand Down Expand Up @@ -168,6 +168,11 @@ def plane_from_np(self, dem_data: np.ndarray, save_path: str) -> None:

faces = np.array(faces) # type: ignore
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)

# Simplify the mesh to reduce the number of faces.
mesh = mesh.simplify_quadric_decimation(face_count=len(faces) // 10)
self.logger.debug("Mesh simplified to %s faces", len(mesh.faces))

mesh.export(save_path)
self.logger.info("Obj file saved: %s", save_path)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ folium
geopy
trimesh
pyproj
fast-simplification
maps4fs

0 comments on commit 79edabc

Please sign in to comment.