Skip to content

set opacity per-vertex #13679

Closed
Closed

Description

@drammock

Describe the new feature or enhancement

in a recent conversation, @jstout211 mentioned a missing feature: setting the opacity of distributed solutions per-vertex (something that e.g. AFNI can do for MRIs).

Describe your proposed implementation

IDK how easy/hard this would be given that vertices are the corners of triangles; simple approach is set whole triangle as mean opacity of each vertex.

Describe possible alternatives

If using mean of corners looks like garbage, we could consider Pineda's triangle-filling algorithm [1] to interpolate values within each tri (though how we would actually render that I don't know).

[1]: Pineda, J. 1988 A parallel algorithm for polygon rasterization. ACM SIGGRAPH Computer Graphics 22(4), 17-20. http://dx.doi.org/10.1145/378456.378457

Additional context

use case is to highlight areas of the distributed source solution that meet some criterion / threshold (could be an anatomical label, some statistical criterion, etc) while still showing the rest of the solution on the brain.

Activity

  1. larsoner commented on Feb 24, 2026

    @larsoner
    Member

    Currently our 3D meshes have color (R,G,B,A) set on a per-vertex basis. I wouldn't get too much into the weeds about how we interpolate over the triangle and just let VTK do its thing.

    And we currently have this:

    if self._opacity is not None:
    colors[:, 3] *= self._opacity

    I think to add support for this sort of thing we "just" need to add another *= statement, or (equvialently) allow self._opacity to be more than just a float but ndarray of shape (n_vertices,). To be tested, though...

  2. Aniketsy commented on Feb 25, 2026

    @Aniketsy
    Contributor

    Pineda (1988) focus on manually interpolating vertex values across triangles, but since VTK already handles this internally, implementing it ourselves would be redundant.

    Based on this, I think we can proceed with @larsoner’s suggestion of supporting per vertex opacity via the existing RGBA . If I’m misunderstanding anything here, please feel free to correct me, I’d also be happy to test this locally and verify the behavior.

  3. PragnyaKhandelwal commented on Feb 28, 2026

    @PragnyaKhandelwal
    Contributor

    Following @larsoner's suggestion, I have implemented support for per-vertex opacity by refactoring _3d_overlay.py. The self.opacity attribute now accepts an ndarray of shapes n{vertices}, alongside the existing float support. I have verified the broadcasting and 3D rendering behavior locally and have opened PR #13706 for formal review and CI checks. I look forward to your feedback on the implementation!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions