Skip to content

ENH: Add low-level VTK-to-USD facade and clarify API boundary#46

Merged
aylward merged 3 commits intoProject-MONAI:mainfrom
aylward:vtk_to_usd_cleanup
May 6, 2026
Merged

ENH: Add low-level VTK-to-USD facade and clarify API boundary#46
aylward merged 3 commits intoProject-MONAI:mainfrom
aylward:vtk_to_usd_cleanup

Conversation

@aylward
Copy link
Copy Markdown
Collaborator

@aylward aylward commented May 6, 2026

Add vtk_to_usd.convert_vtk_file() as the stable advanced file-conversion facade, while keeping ConvertVTKToUSD as the in-repo API for experiments, workflows, and tests.

Refactor VTK-to-USD tests to validate behavior through ConvertVTKToUSD, replace experiment diagnostics with ConvertVTKToUSD.inspect_file(), and update docs/API map to remove stale converter APIs.

Summary by CodeRabbit

  • New Features
    • Unified VTK→USD conversion workflow with a simple single-file conversion facade, improved time‑series and material handling, and a diagnostics-based VTK inspection tool.
  • Documentation
    • Major docs and examples updated: quickstart, API reference, tutorials, and usage patterns for time‑series, materials, and advanced settings.
  • Bug Fixes
    • Reader made more robust for empty/missing geometry.
  • Tests
    • Expanded test suite covering conversions, time‑series, materials, primvars, and unit scaling.

Add vtk_to_usd.convert_vtk_file() as the stable advanced file-conversion
facade, while keeping ConvertVTKToUSD as the in-repo API for experiments,
workflows, and tests.

Refactor VTK-to-USD tests to validate behavior through ConvertVTKToUSD,
replace experiment diagnostics with ConvertVTKToUSD.inspect_file(), and
update docs/API map to remove stale converter APIs.
Copilot AI review requested due to automatic review settings May 6, 2026 17:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@aylward has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 37 minutes and 3 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 885cd4a9-2be0-4e92-b6a2-3902a44edc8f

📥 Commits

Reviewing files that changed from the base of the PR and between 442fd57 and b0da21c.

📒 Files selected for processing (9)
  • README.md
  • docs/API_MAP.md
  • docs/api/index.rst
  • docs/api/usd/polymesh.rst
  • docs/api/usd/tetmesh.rst
  • docs/api/usd/vtk_conversion.rst
  • docs/api/utilities/index.rst
  • src/physiomotion4d/vtk_to_usd/README.md
  • tests/test_vtk_to_usd_library.py

Walkthrough

This PR replaces the prior VTK-to-USD converter surface with a new ConvertVTKToUSD-centered API and adds a low-level file facade convert_vtk_file(). It updates package exports, reader robustness, docs, examples, experiments, and introduces a substantial test suite validating single-file, time-series, material, primvar, and unit-scaling behavior.

Changes

VTK-to-USD API Refactor

Layer / File(s) Summary
Data Shapes & DTOs
src/physiomotion4d/vtk_to_usd/...
New/public data structures referenced across docs and code: ConversionSettings, MaterialData, MeshData are introduced to shape conversion inputs (documented in README and CLAUDE.md).
Core Facade Implementation
src/physiomotion4d/vtk_to_usd/converter.py
Adds convert_vtk_file(...) — a file-based facade that reads VTK, creates a USD stage, configures meters/up-axis, initializes MaterialManager, delegates to UsdMeshConverter, saves and returns the stage.
High-Level Class API
src/physiomotion4d/convert_vtk_to_usd.py
ConvertVTKToUSD gains inspect_file() classmethod for diagnostics; module-level imports expanded to include cell_type_name_for_vertex_count, read_vtk_file, and validate_time_series_topology.
Reader Robustness
src/physiomotion4d/vtk_to_usd/vtk_reader.py
Safer geometry extraction: guards for missing/empty vtkPoints, returning empty arrays when appropriate.
Package Exports / Facade
src/physiomotion4d/vtk_to_usd/__init__.py
Public docstring rewritten; convert_vtk_file imported from .converter and added to __all__ under a File facade section.
Tests
tests/test_vtk_to_usd_library.py
New comprehensive test module with helpers/fixtures and multiple test classes exercising ConvertVTKToUSD.from_files() and conversion behavior (single-file, static merge, time-series, materials, primvars, meters/unit scaling, normals).
Documentation & Guides
docs/..., README.md, src/physiomotion4d/vtk_to_usd/README.md, CLAUDE.md
Extensive doc updates to reflect new ConvertVTKToUSD and convert_vtk_file APIs: quickstart, examples, API docs, developer guides, architecture, and new usage patterns (ConversionSettings, MaterialData, time-series examples).
Examples & Experiments
experiments/Convert_VTK_To_USD/*, docs/examples.rst, docs/quickstart.rst
Experiment scripts and examples updated to use ConvertVTKToUSD.inspect_file() and ConvertVTKToUSD.from_files() workflows; removed low-level read_vtk_file / numpy inspection usages.
API Map / Inventory
docs/API_MAP.md
API entries added for convert_vtk_file, ConvertVTKToUSD public methods, and new helper functions referenced by tests/examples.

Sequence Diagram

sequenceDiagram
    participant User
    participant HighLevel as ConvertVTKToUSD<br/>(High-Level)
    participant Facade as converter.py<br/>(convert_vtk_file)
    participant VTK as VTK Reader
    participant Material as MaterialManager
    participant USD as USD Stage

    User->>HighLevel: from_files(data_basename, vtk_files, time_codes...)
    activate HighLevel
    HighLevel->>VTK: read VTK files (read_vtk_file)
    VTK-->>HighLevel: mesh data / arrays
    HighLevel->>HighLevel: prepare mesh/time sampling, materials
    HighLevel-->>User: configured converter instance
    deactivate HighLevel

    User->>HighLevel: convert(output_usd_file)
    activate HighLevel
    HighLevel->>USD: create stage, set metadata (meters/upAxis)
    HighLevel->>Material: ensure/create material
    Material-->>HighLevel: material prim
    HighLevel->>USD: create mesh prim(s), write primvars/time samples
    HighLevel->>USD: save stage
    USD-->>HighLevel: stage saved
    HighLevel-->>User: USD stage
    deactivate HighLevel

    alt Direct file facade
    User->>Facade: convert_vtk_file(vtk_file, output_usd_file, ...)
    activate Facade
    Facade->>VTK: read_vtk_file(vtk_file)
    VTK-->>Facade: mesh data
    Facade->>Material: prepare/ensure material
    Material-->>Facade: material prim
    Facade->>USD: create stage and mesh prim, write, save
    USD-->>Facade: stage
    Facade-->>User: USD stage
    deactivate Facade
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

A rabbit hops through files anew,
Where VTK and USD meet view—
Facades and classes leap in tune,
Tests ensure the shapes commune;
Convert and inspect, then run the show 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a low-level VTK-to-USD facade function and clarifying the API boundary between public and internal APIs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 57.89474% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.11%. Comparing base (54d1d5e) to head (b0da21c).

Files with missing lines Patch % Lines
src/physiomotion4d/vtk_to_usd/converter.py 25.80% 23 Missing ⚠️
src/physiomotion4d/vtk_to_usd/vtk_reader.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #46      +/-   ##
==========================================
+ Coverage   20.06%   22.11%   +2.04%     
==========================================
  Files          45       46       +1     
  Lines        6214     6268      +54     
==========================================
+ Hits         1247     1386     +139     
+ Misses       4967     4882      -85     
Flag Coverage Δ
integration-tests 22.11% <57.89%> (?)
unittests 21.72% <57.89%> (+1.66%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add vtk_to_usd.convert_vtk_file() as the stable advanced low-level
single-file conversion facade while keeping ConvertVTKToUSD as the in-repo
API for experiments, workflows, and tests.

Add ConvertVTKToUSD.inspect_file() for public diagnostics, update experiments
to use it, refactor tests to exercise conversion through ConvertVTKToUSD, and
refresh docs/API map to remove stale converter APIs. Handle empty mesh
inspection without raising.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/api/usd/tetmesh.rst (1)

1-21: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

All three files—polymesh.rst, tetmesh.rst, and vtk_conversion.rst—document the same class with duplicate .. autoclass:: ConvertVTKToUSD directives.

This causes Sphinx to emit duplicate object description warnings. Additionally, only vtk_conversion.rst is listed in index.rst toctree; polymesh.rst and tetmesh.rst are orphaned from the main navigation.

Consolidate API documentation in one location. Either:

  • Delete polymesh.rst and tetmesh.rst, keep only vtk_conversion.rst
  • Or replace autoclass directives in polymesh.rst and tetmesh.rst with a single-sentence note + :doc: link to vtk_conversion.rst for backwards compatibility
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/api/usd/tetmesh.rst` around lines 1 - 21, The three files (polymesh.rst,
tetmesh.rst, vtk_conversion.rst) all declare the same autoclass ConvertVTKToUSD
causing duplicate-object warnings; fix by consolidating docs: either delete
polymesh.rst and tetmesh.rst and keep the canonical vtk_conversion.rst, or edit
polymesh.rst and tetmesh.rst to remove the autoclass:: ConvertVTKToUSD block and
replace it with a single-sentence notice that points readers to
vtk_conversion.rst via a :doc: link (and if you keep the stub files, ensure
index.rst/toctree includes them for navigation).
🧹 Nitpick comments (1)
tests/test_vtk_to_usd_library.py (1)

38-42: 💤 Low value

check_valve4d_data() appears unused in this file.

It's defined alongside check_kcl_heart_data() but isn't referenced by any fixture or test in this module. If it was intentionally kept for parity with the experiment scripts or anticipated valve4d tests, please add a brief comment; otherwise consider removing it to keep the test helpers tight.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_vtk_to_usd_library.py` around lines 38 - 42, The helper function
check_valve4d_data() is unused in the test module; either remove it to keep
helpers minimal or document why it’s retained (e.g., placeholder for future
Valve4D tests) and ensure it is correct if kept — fix the variable name bug
(alterra_dir vs alterra_dir/alterra typo) inside check_valve4d_data() and add a
one-line comment above it explaining its purpose if you choose to keep it,
otherwise delete the function; reference: check_valve4d_data() and
check_kcl_heart_data().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 351-356: The example uses ConversionSettings with
meters_per_unit=1.0 but doesn't clarify units; update the snippet so it either
keeps the library default (meters_per_unit=0.001) to reflect the mm→m
conversion, or keep 1.0 but change the inline comment to explicitly state
"source mesh authored in meters (no scaling)" — adjust the example around
ConversionSettings and the meters_per_unit parameter accordingly so users won't
accidentally scale typical medical (mm) meshes 1000×.

In `@src/physiomotion4d/vtk_to_usd/README.md`:
- Around line 12-17: The README currently claims "VTK point and cell arrays as
USD primvars" while the low-level API (ConversionSettings.preserve_cell_arrays)
is still unimplemented; update the README entry to only advertise supported
functionality: change the line to indicate only VTK point arrays are exported as
USD primvars and either remove or explicitly mark cell-array primvars as "not
yet supported / coming soon." Reference the symbol
ConversionSettings.preserve_cell_arrays to guide future enabling of the feature
once implemented and keep the Materials/Coordinates lines unchanged.

---

Outside diff comments:
In `@docs/api/usd/tetmesh.rst`:
- Around line 1-21: The three files (polymesh.rst, tetmesh.rst,
vtk_conversion.rst) all declare the same autoclass ConvertVTKToUSD causing
duplicate-object warnings; fix by consolidating docs: either delete polymesh.rst
and tetmesh.rst and keep the canonical vtk_conversion.rst, or edit polymesh.rst
and tetmesh.rst to remove the autoclass:: ConvertVTKToUSD block and replace it
with a single-sentence notice that points readers to vtk_conversion.rst via a
:doc: link (and if you keep the stub files, ensure index.rst/toctree includes
them for navigation).

---

Nitpick comments:
In `@tests/test_vtk_to_usd_library.py`:
- Around line 38-42: The helper function check_valve4d_data() is unused in the
test module; either remove it to keep helpers minimal or document why it’s
retained (e.g., placeholder for future Valve4D tests) and ensure it is correct
if kept — fix the variable name bug (alterra_dir vs alterra_dir/alterra typo)
inside check_valve4d_data() and add a one-line comment above it explaining its
purpose if you choose to keep it, otherwise delete the function; reference:
check_valve4d_data() and check_kcl_heart_data().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 097c7242-279b-4060-9e15-7b0479d6b9ae

📥 Commits

Reviewing files that changed from the base of the PR and between 54d1d5e and 442fd57.

📒 Files selected for processing (20)
  • README.md
  • docs/API_MAP.md
  • docs/api/usd/index.rst
  • docs/api/usd/polymesh.rst
  • docs/api/usd/tetmesh.rst
  • docs/developer/architecture.rst
  • docs/developer/extending.rst
  • docs/developer/usd_generation.rst
  • docs/examples.rst
  • docs/quickstart.rst
  • experiments/Convert_VTK_To_USD/convert_chop_alterra_valve_to_usd.py
  • experiments/Convert_VTK_To_USD/convert_chop_tpv25_valve_to_usd.py
  • experiments/Convert_VTK_To_USD/convert_vtk_to_usd_using_class.py
  • src/physiomotion4d/convert_vtk_to_usd.py
  • src/physiomotion4d/vtk_to_usd/CLAUDE.md
  • src/physiomotion4d/vtk_to_usd/README.md
  • src/physiomotion4d/vtk_to_usd/__init__.py
  • src/physiomotion4d/vtk_to_usd/converter.py
  • src/physiomotion4d/vtk_to_usd/vtk_reader.py
  • tests/test_vtk_to_usd_library.py

Comment thread README.md
Comment on lines +351 to 356
# Advanced: custom settings and material
settings = ConversionSettings(
triangulate_meshes=True,
compute_normals=True,
meters_per_unit=0.001, # mm to meters
meters_per_unit=1.0, # coordinates are authored in meters
times_per_second=60.0,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Clarify the unit-scaling example before users copy it.

ConversionSettings.meters_per_unit is the VTK→USD scale factor, and the library’s default path is the mm→m conversion validated by tests/test_vtk_to_usd_library.py. Setting this to 1.0 here without explicitly saying the source mesh is already in meters will make typical medical meshes 1000× too large. Either keep the default 0.001 in the example or call out that 1.0 is only for meter-authored inputs.

📝 Suggested doc tweak
 settings = ConversionSettings(
     triangulate_meshes=True,
     compute_normals=True,
-    meters_per_unit=1.0,  # coordinates are authored in meters
+    meters_per_unit=0.001,  # typical VTK medical meshes are authored in millimeters
     times_per_second=60.0,
 )

Or, if you want to keep 1.0, make the comment explicit:

-    meters_per_unit=1.0,  # coordinates are authored in meters
+    meters_per_unit=1.0,  # only when the source VTK coordinates are already in meters
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Advanced: custom settings and material
settings = ConversionSettings(
triangulate_meshes=True,
compute_normals=True,
meters_per_unit=0.001, # mm to meters
meters_per_unit=1.0, # coordinates are authored in meters
times_per_second=60.0,
settings = ConversionSettings(
triangulate_meshes=True,
compute_normals=True,
meters_per_unit=0.001, # typical VTK medical meshes are authored in millimeters
times_per_second=60.0,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 351 - 356, The example uses ConversionSettings with
meters_per_unit=1.0 but doesn't clarify units; update the snippet so it either
keeps the library default (meters_per_unit=0.001) to reflect the mm→m
conversion, or keep 1.0 but change the inline comment to explicitly state
"source mesh authored in meters (no scaling)" — adjust the example around
ConversionSettings and the meters_per_unit parameter accordingly so users won't
accidentally scale typical medical (mm) meshes 1000×.

Comment thread src/physiomotion4d/vtk_to_usd/README.md
Remove duplicate ConvertVTKToUSD API pages, clean stale navigation links,
clarify VTK-to-USD scaling and primvar documentation, and remove an unused
Valve4D test helper.
@aylward aylward merged commit b1af1c1 into Project-MONAI:main May 6, 2026
13 of 14 checks passed
@aylward aylward deleted the vtk_to_usd_cleanup branch May 6, 2026 19:47
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