Skip to content

Conversation

Copy link

Copilot AI commented Nov 18, 2025

Please check the following before creating the pull request (PR):

  • Did you run automatic tests?
  • Did you run manual tests?
  • Is the code provided in the PR still backwards compatible to previous SIMPA versions?

List any specific code review questions

None - straightforward loop restructuring to fix boundary condition check.

List any special testing requirements

None beyond existing test suite.

Additional context (e.g. papers, documentation, blog posts, ...)

The issue manifests when vessel start coordinates exactly equal tissue dimensions (e.g., y=16mm for a 16mm volume). Before fix, only ~11% of expected vessel volume was generated. After fix, vessels at boundaries generate correctly at ~100% of expected volume.

Provide issue / feature request fixed by this PR

Fixes #<ISSUE_NUMBER_TO_BE_FILLED>


Problem

Vessels starting exactly at tissue boundaries fail to generate proper tube structures. Instead of creating a full vessel (~271 voxels), only a degenerate stub is created (~30 voxels).

Root Cause

calculate_vessel_samples() checked bounds before loop entry:

while torch.all(position < volume_dimensions) and torch.all(0 <= position):

When position[i] == volume_dimensions[i] (e.g., voxel 32 for 16mm at 0.5mm spacing), the condition 32 < 32 fails immediately, preventing vessel generation.

Changes

VesselStructure.py

  • Restructured loop to check bounds after position update rather than before loop entry
  • Ensures initial position is always added, even at boundaries
  • New position is validated before being added to the vessel path

test_vesseltree.py

  • Added test_vessel_starting_at_boundary() regression test
  • Validates boundary vessels generate ≥80% of expected volume compared to interior vessels

Verification

Before: Boundary vessel = 30 voxels (11% of expected)
After: Boundary vessel = 276 voxels (102% of expected, within random variation)

All existing tests pass. CodeQL security scan: 0 alerts.

Original prompt

This section details on the original issue you should resolve

<issue_title>define_vessel_structure_settings does not create vessels starting from boundary </issue_title>
<issue_description>Describe the bug
Sometimes, if a vessel is created starting on a tissue boundary, the vessel does not assume a tube structure.

Specify a priority (low, medium, high)
medium

To Reproduce
Define a homogeneous tissue of size 16 x 16 x 10 mm, spacing = 0.5mm and define a single vessel with the following vessel dictionary:

vessel_dictionary = sp.define_vessel_structure_settings(vessel_start_mm=[10, 16, 0.2],
                                                            vessel_direction_mm=[-1, -1, 0.0],
                                                            molecular_composition=sp.TISSUE_LIBRARY.blood(0.7),
                                                            radius_mm=2.0,
                                                            curvature_factor=0.0,
                                                            radius_variation_factor=1.0,
                                                            bifurcation_length_mm=1000.0,
                                                            priority=5,
                                                            consider_partial_volume=True,
                                                            adhere_to_deformation=True)

Then run any MCX simulation and acquire the semantic map. Aggregate by the z-Dimension to get the vessel area viewed from above the tissue.

Current Behavior
The vessel only occupies a small area:
image

Expected behavior
With these parameters, the vessel should have a tube structure like this:
image

This image was created by changing the start position to [10, 15.99, 0.2].
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix vessel structure creation for boundary starting point Fix vessel structure generation at tissue boundaries Nov 18, 2025
Copilot AI requested a review from jgroehl November 18, 2025 18:26
Copy link
Collaborator

@jgroehl jgroehl left a comment

Choose a reason for hiding this comment

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

This is how I would have implemented the change as well, not too bad!

@jgroehl jgroehl marked this pull request as ready for review November 18, 2025 20:57
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.

2 participants