listen for ctf otf changes with traits in mayavi v

2019-08-15 05:56发布

问题:

I would like to listen to changes in the transfer function in how the color and opacity (ctf/otf) of my data is represented.

Listening to sensible-sounding traits such as mayavi.modules.volume.Volume._ctf does not trigger my callback.

I would expect this to be changed by the user either through the "standard" mayavi pipeline display (as part of EngineRichView) or through including the Volume object's view directly. No such luck either way.

It is maybe telling that when you press the big red "record" button, the recorder also does not seem to notice user changes to the ctf.

回答1:

You are going to wade into dangerous territory. As you noted the recorder has idosyncratic behavior -- what that really means is that it uses features to programatically "disable" the trait notifications while it is doing things.

You can probably figure out a way to do it that way, but most likely you'll have to dig deeply into the code that assigns the vtk modules.

What would probably make the most sense, is for you to write a GUI that does exactly what you want. That is, instead of listening to something like Volume._ctf, and then opening up the menu and changing the color, you can make a GUI and add a button that says "Change volume color" that when clicked brings the user to a color wheel. Then it's just a matter of listening to the GUI elements that you explicitly code for.