Repository navigation
v2: harden interface, add field integral, parallel time-series, tests/CI - #1
Conversation
Interface & robustness: - Implement the long-form flags that were documented but silently ignored (--res, --data, --batch, --out, --view, --threads). - Reject unknown options and malformed/zero view vectors instead of swallowing them; wrap main in try/catch so bad input gives a clean "Error: ..." and exit 1 rather than an abort/std::terminate crash. - Report data-file size mismatches with mesh vertex/face counts. Generic analysis: - Add the area integral of the field (sum value*pixel_area) alongside average/min/max. This is domain-agnostic: a radiance field yields radiant intensity, pressure yields force, etc. Exposed in text and JSON output; JSON now also carries resolution, width/height, min/max, image, and emits null for non-finite numbers so pipelines don't break. Performance / time-series: - Separate the scalar field from the read-only mesh and process batch timesteps across a standard-library thread pool (one renderer per worker, output kept in view order). A fixed -d field loads once and is shared; per-timestep field files stream on demand, so peak memory is O(threads) not O(timesteps). Field parsing switched to strtod. - ~1000 changing-view/changing-field timesteps on the 70k-triangle bunny now run in ~1.5s. - Resolve relative batch data-file paths against the batch file's directory so a case folder is portable across working directories. Build (dependency-free / airgapped): - Add a one-line Makefile and document a single-compiler-invocation build; link Threads in CMake (required by std::thread). Examples, tests, CI: - Rewrite generate_field.py to be standard-library only (no numpy/pyvista) and emit a portable time-series case; drop the stale cases.txt that referenced missing data. - Commit a small ready-to-run timeseries_demo and add a dependency-free test suite (bash+awk) covering geometry, the integral, and interface errors, plus a GitHub Actions workflow building with GCC/Clang and CMake. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
There was a problem hiding this comment.
Code Review
This pull request refactors FlatLand into a multi-threaded C++17 utility for projected-area and scalar field analysis of 3D meshes, introducing parallel batch processing, area integral calculations, and a dependency-free test suite. Feedback on these changes suggests validating vertex indices in the OBJ loader to prevent potential out-of-bounds memory access, and including to ensure portable floating-point parsing across different system locales.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (mesh.vertices.empty()) throw std::runtime_error("mesh '" + filename + "' contains no vertices"); | ||
| if (mesh.faces.empty()) throw std::runtime_error("mesh '" + filename + "' contains no faces"); |
There was a problem hiding this comment.
The OBJ loader does not validate that vertex indices in the face definitions are within the bounds of the loaded vertices. If an OBJ file contains invalid or out-of-bounds indices, it will lead to undefined behavior or crashes during rendering. Adding a validation check here prevents out-of-bounds memory access.
if (mesh.vertices.empty()) throw std::runtime_error("mesh '" + filename + "' contains no vertices");
if (mesh.faces.empty()) throw std::runtime_error("mesh '" + filename + "' contains no faces");
for (const auto& f : mesh.faces) {
if (f.v0_idx < 0 || f.v0_idx >= (int)mesh.vertices.size() ||
f.v1_idx < 0 || f.v1_idx >= (int)mesh.vertices.size() ||
f.v2_idx < 0 || f.v2_idx >= (int)mesh.vertices.size()) {
throw std::runtime_error("mesh '" + filename + "' contains out-of-bounds vertex index");
}
}| #include <cstdlib> | ||
| #include <stdexcept> |
Address review feedback on PR #1: - Validate that every face references an in-range vertex index when loading an OBJ, throwing a clear error instead of letting process_view read out of bounds on a malformed file. - Call setlocale(LC_ALL, "C") at startup so strtod/sscanf always treat '.' as the decimal separator regardless of the environment locale. - Add a test covering rejection of an out-of-bounds vertex index. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
A batch line of the form "<nx> <ny> <nz> <data_file>" (data file with the default resolution) previously dropped the data file: the parser only read a data file after a numeric resolution token, so a non-numeric token failed the numeric extraction and was ignored. Sniff each trailing token instead -- a pure number is a resolution, anything else is a data-file path -- so resolution and data file may appear independently. Add a regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
Reduce input clunk across all three surfaces, backward-compatibly: Meshes: - Add STL support (binary + ASCII), auto-detected by extension with a robust size-based binary/ASCII discriminator. Unified load_mesh dispatches OBJ/STL and runs the shared empty/index validation. Field files: - Treat a field file as a matrix: one row per entity, one column per timestep, so an entire time series fits in a single file. A data token may select a column via a trailing '@<col>' (default 0). One-value-per-line files remain the single-column case. Node-vs-face is inferred from the row count, with a new --field-mode node|face|auto to force it. - Load each distinct field file once into a shared, read-only cache; workers extract their column concurrently, so a shared matrix is parsed once rather than once per thread. Views: - Accept azimuth/elevation angles via -a/--angle and an 'a <az> <el>' batch line form, alongside raw direction vectors. Batch parsing: - Fix silent data-file drop: resolution and data file are now order-independent (a pure number is a resolution, anything else a path), so a view can attach data without restating the resolution. Examples & tests: - Regenerate the committed demo as a single matrix file + angle batch (two files instead of 24); rewrite generate_field.py to match. - Extend the suite to 25 checks (STL ASCII/binary, matrix column select and out-of-range, angle views, field-mode override and mismatch). Update README and help text. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
Overview
A v2 pass focused on the three stated goals — reliable, fast, dependency-free analysis — with most attention on the interface and the time-dependent batch workflow. The math core (projected area, edge-function rasterization, Z-buffer) is unchanged in behavior; everything around it is hardened.
Interface & robustness
--helpbut silently ignored (--res,--data,--batch,--out,--view,--threads). Previously--res 0.1ran at the default resolution.mainin try/catch so bad input produces a cleanError: ...and exit 1, rather than anstd::terminate/abort crash (was exit 134 on a missing file).Generic analysis
∫ f dA = Σ(value · pixel_area), alongside average/min/max. Domain-agnostic: a radiance field gives radiant intensity, pressure gives force, etc.resolution,width/height,min/max,image, and emitsnullfor non-finite numbers so downstream parsers don't break.Performance / time-series (1000-timestep goal)
-dfield loads once and is shared; per-timestep field files stream on demand, so peak memory isO(threads), notO(timesteps). Field parsing switched tostrtod.Build (dependency-free / airgapped)
Makefileand document a single-compiler-invocation build (c++ -std=c++17 -O2 -pthread src/main.cpp -o flatland).Threadsin CMake (now required bystd::thread).Examples, tests, CI
generate_field.pyto be standard-library only (no numpy/pyvista) and emit a portable time-series case; drop the stalecases.txtthat referenced missing data.examples/with_fields/timeseries_demo/.bash+awk, 14 checks) covering geometry (cube area = 1, sphere = π), the field integral, and every interface-error path.Validation
makeand CMake binaries.-oPPM output and double precision exercised.🤖 Generated with Claude Code
Generated by Claude Code