Skip to content

unified color interface - #1054

Open
tontyoutoure wants to merge 2 commits into
OpenGATE:masterfrom
tontyoutoure:unified_color_interface
Open

tontyoutoure wants to merge 2 commits into
OpenGATE:masterfrom
tontyoutoure:unified_color_interface

Conversation

@tontyoutoure

Copy link
Copy Markdown
Contributor
  1. unified color interface in c++ and python
  2. volume color can take color name now, like "red", "blue"

I'm not sure whether this is necessary, since there is only that much visualization in Gate 9. But this surely conforms the DRY principle better.

@dsarrut

dsarrut commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Hi @tontyoutoure,

Thank you for this PR. Having named colors for volumes (vol.color = "red") is indeed a welcome improvement and simplifies user scripts nicely.

There is just one bug to fix in opengate/geometry/volumes.py where self.color[3] is accessed directly:

        self.g4_vis_attributes.SetColor(
            *validate_color(self.color, f"Color error for volume {self.name}: ")
        )
        self.g4_vis_attributes.SetVisibility(bool(self.color[3]))

If a user specifies a short color name like "red", self.color[3] raises an IndexError: string index out of range (it only worked for "magenta" in the test because len("magenta") > 3).

Please store the result of validate_color in a local variable:

        color = validate_color(self.color, f"Color error for volume {self.name}: ")
        self.g4_vis_attributes.SetColor(*color)
        self.g4_vis_attributes.SetVisibility(bool(color[3]))

Also, in GateHelpersDict.cpp, DictGetColourVec appears to be an undeclared alias for DictGetVecColour that can be removed.

Once these points are addressed, this is good to merge.

David (review made with AI)

2. volume color can take color name now, like "red"
@dsarrut
dsarrut force-pushed the unified_color_interface branch from a79c6ae to fb606a7 Compare October 6, 2026 18:20
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