Skip to content

## Defensive Coding Improvements: batch_processor.py & feature_extractor.p#36

Open
agentksimha wants to merge 2 commits into
humanai-foundation:mainfrom
agentksimha:main
Open

## Defensive Coding Improvements: batch_processor.py & feature_extractor.p#36
agentksimha wants to merge 2 commits into
humanai-foundation:mainfrom
agentksimha:main

Conversation

@agentksimha

Copy link
Copy Markdown

Summary

Adds input validation, output safety guards, and fixes silent failure points across the PLY processing pipeline.


batch_processor.py

[High] Path & permission validation (_validate_path)
Introduces a _validate_path helper called at the top of validate_ply_file. Checks that the file exists, is a regular file, carries a .ply extension, and is readable before Open3D is ever invoked — replacing opaque internal errors with clear, early messages.

[High] File size validation (_check_file_size)
Rejects files under 80 bytes (corrupt/empty) as a hard error and warns on files exceeding 500 MB before any processing begins.

[Medium] Output path safety (preprocess_file)
Aborts if the resolved output path matches the input (preventing silent data loss) and verifies the output directory is writable before any mesh work is done.

[Medium] Zero-extent guard (normalize_mesh_scale)
Prevents a division-by-zero crash on degenerate meshes with zero bounding-box extent. Also validates that target_size is a positive number.


feature_extractor.py

[Refactor] PCA swap in compute_geometric_moments
Replaces manual np.cov + np.linalg.eigh with sklearn.decomposition.PCA, consistent with compute_surface_normal which already used PCA. No behaviour change.

[Medium] No in-place mutation (compute_surface_curvature)
Deep-copies the input point cloud before calling estimate_normals(), preventing silent permanent modification of the caller's object.

[Medium] JSON-serialisable boundary points (compute_boundary_features)
Converts boundary_points from a raw numpy array to a plain Python list, consistent with all other fields returned by this class and safe for json.dumps(). Tightens bare except to except Exception as e and surfaces the error string.

[Medium] KeyError-safe visualisation (visualize_surface_features)
Extends the existing surface guard to also check that features have been extracted before accessing fragment['features'][color][surface_idx], with a distinct message for each failure case. Adds a np.array() cast for boundary_points at the plot site since it is now stored as a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant