trenchfoot 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of trenchfoot might be problematic. Click here for more details.

Files changed (69) hide show
  1. trenchfoot/Dockerfile +5 -0
  2. trenchfoot/README.md +125 -0
  3. trenchfoot/__init__.py +67 -0
  4. trenchfoot/generate_scenarios.py +667 -0
  5. trenchfoot/gmsh_sloped_trench_mesher.py +508 -0
  6. trenchfoot/plot_mesh.py +126 -0
  7. trenchfoot/render_colors.py +59 -0
  8. trenchfoot/scenarios/S01_straight_vwalls/meshes/trench_scene_culled.obj +46 -0
  9. trenchfoot/scenarios/S01_straight_vwalls/metrics.json +35 -0
  10. trenchfoot/scenarios/S01_straight_vwalls/point_clouds/culled/resolution0p050.pth +0 -0
  11. trenchfoot/scenarios/S01_straight_vwalls/point_clouds/full/resolution0p050.pth +0 -0
  12. trenchfoot/scenarios/S01_straight_vwalls/preview.png +0 -0
  13. trenchfoot/scenarios/S01_straight_vwalls/preview_oblique.png +0 -0
  14. trenchfoot/scenarios/S01_straight_vwalls/preview_side.png +0 -0
  15. trenchfoot/scenarios/S01_straight_vwalls/preview_top.png +0 -0
  16. trenchfoot/scenarios/S01_straight_vwalls/scene.json +30 -0
  17. trenchfoot/scenarios/S01_straight_vwalls/trench_scene.obj +46 -0
  18. trenchfoot/scenarios/S01_straight_vwalls/volumetric/trench_volume.msh +1017 -0
  19. trenchfoot/scenarios/S02_straight_slope_pipe/meshes/trench_scene_culled.obj +60 -0
  20. trenchfoot/scenarios/S02_straight_slope_pipe/metrics.json +38 -0
  21. trenchfoot/scenarios/S02_straight_slope_pipe/point_clouds/culled/resolution0p050.pth +0 -0
  22. trenchfoot/scenarios/S02_straight_slope_pipe/point_clouds/full/resolution0p050.pth +0 -0
  23. trenchfoot/scenarios/S02_straight_slope_pipe/preview.png +0 -0
  24. trenchfoot/scenarios/S02_straight_slope_pipe/preview_oblique.png +0 -0
  25. trenchfoot/scenarios/S02_straight_slope_pipe/preview_side.png +0 -0
  26. trenchfoot/scenarios/S02_straight_slope_pipe/preview_top.png +0 -0
  27. trenchfoot/scenarios/S02_straight_slope_pipe/scene.json +39 -0
  28. trenchfoot/scenarios/S02_straight_slope_pipe/trench_scene.obj +14404 -0
  29. trenchfoot/scenarios/S02_straight_slope_pipe/volumetric/trench_volume.msh +2389 -0
  30. trenchfoot/scenarios/S03_L_slope_two_pipes_box/meshes/trench_scene_culled.obj +87 -0
  31. trenchfoot/scenarios/S03_L_slope_two_pipes_box/metrics.json +42 -0
  32. trenchfoot/scenarios/S03_L_slope_two_pipes_box/point_clouds/culled/resolution0p050.pth +0 -0
  33. trenchfoot/scenarios/S03_L_slope_two_pipes_box/point_clouds/full/resolution0p050.pth +0 -0
  34. trenchfoot/scenarios/S03_L_slope_two_pipes_box/preview.png +0 -0
  35. trenchfoot/scenarios/S03_L_slope_two_pipes_box/preview_oblique.png +0 -0
  36. trenchfoot/scenarios/S03_L_slope_two_pipes_box/preview_side.png +0 -0
  37. trenchfoot/scenarios/S03_L_slope_two_pipes_box/preview_top.png +0 -0
  38. trenchfoot/scenarios/S03_L_slope_two_pipes_box/scene.json +68 -0
  39. trenchfoot/scenarios/S03_L_slope_two_pipes_box/trench_scene.obj +28803 -0
  40. trenchfoot/scenarios/S03_L_slope_two_pipes_box/volumetric/trench_volume.msh +4463 -0
  41. trenchfoot/scenarios/S04_U_slope_multi_noise/meshes/trench_scene_culled.obj +150 -0
  42. trenchfoot/scenarios/S04_U_slope_multi_noise/metrics.json +46 -0
  43. trenchfoot/scenarios/S04_U_slope_multi_noise/preview.png +0 -0
  44. trenchfoot/scenarios/S04_U_slope_multi_noise/preview_oblique.png +0 -0
  45. trenchfoot/scenarios/S04_U_slope_multi_noise/preview_side.png +0 -0
  46. trenchfoot/scenarios/S04_U_slope_multi_noise/preview_top.png +0 -0
  47. trenchfoot/scenarios/S04_U_slope_multi_noise/scene.json +79 -0
  48. trenchfoot/scenarios/S04_U_slope_multi_noise/trench_scene.obj +49402 -0
  49. trenchfoot/scenarios/S04_U_slope_multi_noise/volumetric/trench_volume.msh +7610 -0
  50. trenchfoot/scenarios/S05_wide_slope_pair/metrics.json +42 -0
  51. trenchfoot/scenarios/S05_wide_slope_pair/preview_oblique.png +0 -0
  52. trenchfoot/scenarios/S05_wide_slope_pair/preview_side.png +0 -0
  53. trenchfoot/scenarios/S05_wide_slope_pair/preview_top.png +0 -0
  54. trenchfoot/scenarios/S05_wide_slope_pair/scene.json +71 -0
  55. trenchfoot/scenarios/S05_wide_slope_pair/trench_scene.obj +28803 -0
  56. trenchfoot/scenarios/S06_bumpy_wide_loop/metrics.json +43 -0
  57. trenchfoot/scenarios/S06_bumpy_wide_loop/preview_oblique.png +0 -0
  58. trenchfoot/scenarios/S06_bumpy_wide_loop/preview_side.png +0 -0
  59. trenchfoot/scenarios/S06_bumpy_wide_loop/preview_top.png +0 -0
  60. trenchfoot/scenarios/S06_bumpy_wide_loop/scene.json +82 -0
  61. trenchfoot/scenarios/S06_bumpy_wide_loop/trench_scene.obj +35084 -0
  62. trenchfoot/scenarios/SUMMARY.json +159 -0
  63. trenchfoot/scene_spec_example.json +74 -0
  64. trenchfoot/trench_scene_generator_v3.py +798 -0
  65. trenchfoot-0.1.0.dist-info/METADATA +104 -0
  66. trenchfoot-0.1.0.dist-info/RECORD +69 -0
  67. trenchfoot-0.1.0.dist-info/WHEEL +4 -0
  68. trenchfoot-0.1.0.dist-info/entry_points.txt +3 -0
  69. trenchfoot-0.1.0.dist-info/licenses/LICENSE +661 -0
trenchfoot/Dockerfile ADDED
@@ -0,0 +1,5 @@
1
+ FROM python:3.11-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends gmsh && rm -rf /var/lib/apt/lists/*
3
+ RUN pip install --no-cache-dir gmsh meshio numpy matplotlib
4
+ WORKDIR /work
5
+ COPY . /work
trenchfoot/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # Trenchfoot: synthetic trench generator
2
+
3
+ This bundle generates semi-realistic, synthetic mesh datasets of trenches with pipes and objects **inside** them, cut into a consistent **ground surface**.
4
+
5
+ **Included:**
6
+ - `trench_scene_generator_v3.py` — surface generator (polyline trenches, **sloped walls**, **ground plane**, pipes/boxes/spheres, noise, **multi‑angle previews**).
7
+ - `gmsh_sloped_trench_mesher.py` — **volumetric** mesher (Gmsh) with ground-aware sloped‑wall loft and conformal pipes.
8
+ - `generate_scenarios.py` — creates 4 scenarios from simple → complex (and generates OBJ/metrics/previews).
9
+ - `scene_spec_example.json` — example with a `ground` section.
10
+ - `Dockerfile` — recommended for volumetric meshing.
11
+
12
+ ---
13
+
14
+ ## Quick start
15
+
16
+ ### Surface (OBJ)
17
+ ```bash
18
+ python trench_scene_generator_v3.py --spec scene_spec_example.json --out ./out --preview
19
+ # outputs: trench_scene.obj, metrics.json, preview_top.png, preview_side.png, preview_oblique.png
20
+ ```
21
+
22
+ ### Volumetric (Gmsh)
23
+ ```bash
24
+ pip install gmsh meshio numpy
25
+ python gmsh_sloped_trench_mesher.py --spec scene_spec_example.json --out ./vol --lc 0.3
26
+ # outputs: vol/trench_volume.msh with Physical Volumes: "TrenchAir", "Pipe*"
27
+ ```
28
+
29
+ ### Docker (recommended for volumetric)
30
+ ```bash
31
+ # build
32
+ docker build -t trench-mesher .
33
+ # run volumetric mesher for Scenario 3
34
+ docker run --rm -v $PWD:/work trench-mesher python gmsh_sloped_trench_mesher.py --spec scenarios/S03_L_slope_two_pipes_box/scene.json --out /work/vol --lc 0.3
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Scene JSON schema (added **ground**)
40
+
41
+ ```jsonc
42
+ {
43
+ "path_xy": [[0,0],[6,0],[6,4]],
44
+ "width": 1.2,
45
+ "depth": 1.8,
46
+ "wall_slope": 0.15,
47
+ "ground_margin": 1.0, // legacy; still used if you disable ground_surface
48
+ "ground": { // NEW: consistent ground plane
49
+ "z0": 0.0, // base elevation
50
+ "slope": [0.0, 0.0], // dz/dx, dz/dy (0,0 = flat)
51
+ "size_margin": 4.0 // how far the rectangular ground_surface extends past trench
52
+ },
53
+ "pipes": [
54
+ {"radius": 0.15, "length": 8.0, "angle_deg": 0, "s_center": 0.35, "z": -1.0, "offset_u": 0.0}
55
+ ],
56
+ "boxes": [{"along": 0.8, "across": 0.5, "height": 0.4, "s": 0.55, "offset_u": 0.0}],
57
+ "spheres": [{"radius": 0.25, "s": 0.85, "offset_u": -0.2}],
58
+ "noise": {
59
+ "enable": true, "amplitude": 0.01, "corr_length": 0.5,
60
+ "octaves": 2, "gain": 0.5, "seed": 7,
61
+ "apply_to": ["trench_walls","trench_bottom"]
62
+ }
63
+ }
64
+ ```
65
+
66
+ ### Behavior
67
+ - The trench **top ring** lies on the ground plane (`z = z0 + sx*x + sy*y`), bottom ring at `ground(x,y) - depth`.
68
+ - Objects (pipes/boxes/spheres) are **clamped** so they fit entirely inside the sloped cross‑section at their depth (with small clearance).
69
+ - Previews: `preview_top.png`, `preview_side.png`, `preview_oblique.png`.
70
+
71
+ **Tip:** To keep the legacy narrow ground strips (instead of a single rectangular `ground_surface`), set `"ground": {"size_margin": 0}`.
72
+
73
+ ---
74
+
75
+ ## Python SDK
76
+
77
+ Import the package to work in memory without touching disk:
78
+
79
+ ```python
80
+ import json
81
+
82
+ from trenchfoot import (
83
+ SceneSpec,
84
+ scene_spec_from_dict,
85
+ generate_surface_mesh,
86
+ generate_trench_volume,
87
+ gmsh_available,
88
+ )
89
+
90
+ with open("scene_spec_example.json", "r", encoding="utf-8") as fh:
91
+ spec_dict = json.load(fh)
92
+
93
+ scene = scene_spec_from_dict(spec_dict)
94
+ surface = generate_surface_mesh(scene)
95
+ surface.persist("./out/surface")
96
+
97
+ if gmsh_available():
98
+ volume = generate_trench_volume(spec_dict, lc=0.3, persist_path="./out/vol/trench_volume.msh")
99
+ print("Physical groups:", [pg.name for pg in volume.physical_groups])
100
+ ```
101
+
102
+ `SurfaceMeshResult.groups` contains the per-object vertex/face arrays (useful for direct NumPy workflows), while `VolumeMeshResult` exposes raw nodes/elements plus the adaptive clearance diagnostics consumed by the CLI.
103
+
104
+ ## Scenarios
105
+
106
+ Run:
107
+ ```bash
108
+ python -m trenchfoot.generate_scenarios
109
+ # Creates ./scenarios/S01..S04 with OBJ/metrics + previews
110
+ ```
111
+ You can directly use those `scene.json` files with the volumetric mesher.
112
+
113
+ ### Tips
114
+ - Set `TRENCHFOOT_SCENARIO_OUT_ROOT=/path/to/scratch` before running the CLI to keep regenerated assets out of the repository tree; override with `--out` when needed.
115
+ - Each volumetric run records per-pipe clearance diagnostics in `SUMMARY.json["scenarios"][i]["pipe_clearances"]`. The mesher adapts the guard band based on the pipe radius and wall slope (minimum 50 mm) and warns or aborts before Gmsh hits a PLC failure.
116
+ - Add an optional `"clearance_scale"` to individual pipe specs to tighten/loosen the adaptive guard band (values > 1.0 widen the buffer; < 1.0 allow closer geometry when safe).
117
+ - Previews require `matplotlib`. If missing, install it or run `uv pip install matplotlib`.
118
+ - Run `uv run pytest -rs` to exercise the surface generator, the volumetric mesher (including all default presets), and the CLI entry point.
119
+ - The scenario CLI accepts `--gallery path.md` to emit a Markdown table of previews, `--scratch` to spill results into a temporary directory (handy for CI), and `--include-prebuilt` to copy the shipped assets into the output directory before regeneration.
120
+ - Preview renders now use color-coded materials (trench surfaces in copper/beige, pipes/boxes/spheres in distinct accent palettes) for quicker visual inspection.
121
+ - Install `plotly` via the `[viz]` extra and use `trenchfoot-plot path/to/trench_scene.obj --open` to generate interactive HTML mesh previews.
122
+
123
+ ---
124
+
125
+ © 2025-10-03 Synthetic Trench Bundle
trenchfoot/__init__.py ADDED
@@ -0,0 +1,67 @@
1
+ """Trenchfoot public API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict
6
+
7
+ from .trench_scene_generator_v3 import (
8
+ BoxSpec,
9
+ GroundSpec,
10
+ NoiseSpec,
11
+ PipeSpec,
12
+ SceneSpec,
13
+ SphereSpec,
14
+ SurfaceMeshFiles,
15
+ SurfaceMeshResult,
16
+ build_scene,
17
+ generate_surface_mesh,
18
+ load_scene_spec_from_json,
19
+ scene_spec_from_dict,
20
+ )
21
+ from .generate_scenarios import (
22
+ RunReport,
23
+ ScenarioDefinition,
24
+ default_scenarios,
25
+ generate_scenarios,
26
+ gmsh_available,
27
+ )
28
+
29
+ try: # optional gmsh dependency
30
+ from .gmsh_sloped_trench_mesher import (
31
+ VolumeMeshResult,
32
+ build_trench_volume_from_spec,
33
+ generate_trench_volume,
34
+ )
35
+ except Exception as _gmsh_exc: # pragma: no cover - triggered when gmsh unavailable
36
+
37
+ def generate_trench_volume(*args: Any, **kwargs: Dict[str, Any]) -> "VolumeMeshResult":
38
+ raise ImportError("gmsh is required for volumetric mesh generation") from _gmsh_exc
39
+
40
+ def build_trench_volume_from_spec(*args: Any, **kwargs: Dict[str, Any]) -> str:
41
+ raise ImportError("gmsh is required for volumetric mesh generation") from _gmsh_exc
42
+
43
+ VolumeMeshResult = None # type: ignore
44
+
45
+
46
+ __all__ = [
47
+ "BoxSpec",
48
+ "GroundSpec",
49
+ "NoiseSpec",
50
+ "PipeSpec",
51
+ "SceneSpec",
52
+ "SphereSpec",
53
+ "SurfaceMeshFiles",
54
+ "SurfaceMeshResult",
55
+ "build_scene",
56
+ "generate_surface_mesh",
57
+ "load_scene_spec_from_json",
58
+ "scene_spec_from_dict",
59
+ "RunReport",
60
+ "ScenarioDefinition",
61
+ "default_scenarios",
62
+ "generate_scenarios",
63
+ "gmsh_available",
64
+ "VolumeMeshResult",
65
+ "generate_trench_volume",
66
+ "build_trench_volume_from_spec",
67
+ ]