Hello,
I would like to build a custom palette in pyanatomist that would include a transparency component (RGBA).
I have been playing with RGB palette following the nice tutorial http://brainvisa.info/pyanatomist/sphin ... orial.html, but I do not find examples for RGBA, is there any tuto or example for that anywhere?
Thanks for your help!
gui
RGBA palette in pyanatomist
-
- Posts: 44
- Joined: Wed Mar 15, 2006 10:29 am
- Location: Institut des Neurosciences de la Timone
- Contact:
Re: RGBA palette in pyanatomist
Maybe I found the solution, but please confirm:
in http://brainvisa.info/anatomist-4.6/dev ... mands.html
I see the color_mode parameter that can be set to "RGB" or "RGBA"
I tried to set in my code:
colors = []
colors.extend([128,128,0,0])
colors.extend([128,128,0,255])
customPalette.setColors(colors=colors, color_mode='RGBA')
and I can see the changes... now I'm playing with the transparency to really understand how it works
in http://brainvisa.info/anatomist-4.6/dev ... mands.html
I see the color_mode parameter that can be set to "RGB" or "RGBA"
I tried to set in my code:
colors = []
colors.extend([128,128,0,0])
colors.extend([128,128,0,255])
customPalette.setColors(colors=colors, color_mode='RGBA')
and I can see the changes... now I'm playing with the transparency to really understand how it works
- riviere
- Site Admin
- Posts: 1361
- Joined: Tue Jan 06, 2004 12:21 pm
- Location: CEA NeuroSpin, Saint Aubin, France
- Contact:
Re: RGBA palette in pyanatomist
Hi Guillaume,
Yes normally you are right, except that... there is a bug. The transparency status of the palette is not updated when calling customPalette.setColors(...).
I'm fixing this.
In the meantime, you can call manually, after setColors():
Note also that depending on the texturing mode applied to the displayed object, transparency may not be used. See the texturing parameters on the object in Anatomist GUI. On a volume for instance the default mode is "decal", which does not render transparently. Use "replace" or "geometric" instead. You can setup this mode in a script using the TexturingParams command.
Yes normally you are right, except that... there is a bug. The transparency status of the palette is not updated when calling customPalette.setColors(...).
I'm fixing this.
In the meantime, you can call manually, after setColors():
Code: Select all
customPalette.update()
-
- Posts: 44
- Joined: Wed Mar 15, 2006 10:29 am
- Location: Institut des Neurosciences de la Timone
- Contact:
Re: RGBA palette in pyanatomist
Hi Denis,
almost everything works.
The only remaining difficulty is with texturing mode.
I tried with TexturingParams without success.
I manage to do it manually (through the Anatomist GUI) by setting the 'mapping mode' in the 'fusion 2D control' panel of the fused object to 'Linear / A if B is not opaque'.
To do it in python, I tried to set it using the two possible commands:
a.execute("Fusion2DParams", object=fus, mode="linear_A_if_B_transparent")
and
a.execute("TexturingParams", object=fus, mode="linear_A_if_B_transparent")
but it didn't work.
I also tried mode="linear_A_if_B_not_opaque" which did not work neither.
Thanks for your help!
gui
almost everything works.
The only remaining difficulty is with texturing mode.
I tried with TexturingParams without success.
I manage to do it manually (through the Anatomist GUI) by setting the 'mapping mode' in the 'fusion 2D control' panel of the fused object to 'Linear / A if B is not opaque'.
To do it in python, I tried to set it using the two possible commands:
a.execute("Fusion2DParams", object=fus, mode="linear_A_if_B_transparent")
and
a.execute("TexturingParams", object=fus, mode="linear_A_if_B_transparent")
but it didn't work.
I also tried mode="linear_A_if_B_not_opaque" which did not work neither.
Thanks for your help!
gui
- riviere
- Site Admin
- Posts: 1361
- Joined: Tue Jan 06, 2004 12:21 pm
- Location: CEA NeuroSpin, Saint Aubin, France
- Contact:
Re: RGBA palette in pyanatomist
Hi Guillaume,
I guess what is missing is an extra parameter "texture_index=1" in the TexturingParams command: actually a Fusion2D has 2 textures, and the mixing mode you want to apply here is when merging the 2nd texture (index 1) with the previous one, thus the merging textue index is 1.
I see also that there is an update issue there. You may need to add 2 lines until I fix it:
(this should be done automatically but it does not seem to be currently)
Denis
I guess what is missing is an extra parameter "texture_index=1" in the TexturingParams command: actually a Fusion2D has 2 textures, and the mixing mode you want to apply here is when merging the 2nd texture (index 1) with the previous one, thus the merging textue index is 1.
I see also that there is an update issue there. You may need to add 2 lines until I fix it:
Code: Select all
fusion.setChanged()
fusion.notifyObservers()
Denis
-
- Posts: 44
- Joined: Wed Mar 15, 2006 10:29 am
- Location: Institut des Neurosciences de la Timone
- Contact:
Re: RGBA palette in pyanatomist
Yessssssssss it finally works!
I used the texture_index, and also fixed one mistake:
I was using object=fus which is not correct and should be replaced by objects=[fus].
So at the end, the following works fine:
Thank you Denis!
gui
I used the texture_index, and also fixed one mistake:
I was using object=fus which is not correct and should be replaced by objects=[fus].
So at the end, the following works fine:
Code: Select all
customPalette=a.createPalette("maPalette")
customPalette.setColors(colors=colors, color_mode='RGBA')
customPalette.update()
a.setObjectPalette(avol1, customPalette)
fus=a.fusionObjects([ aT1vol, avol1 ], 'Fusion2DMethod')
a.execute("TexturingParams", objects=[fus], mode="linear_A_if_B_transparent", texture_index=1, rate=0)
fus.setChanged()
fus.notifyObservers()
gui
- riviere
- Site Admin
- Posts: 1361
- Joined: Tue Jan 06, 2004 12:21 pm
- Location: CEA NeuroSpin, Saint Aubin, France
- Contact:
Re: RGBA palette in pyanatomist
Right
By the way I fixed the update bug in anatomist sources (bug_fix branch, version 4.6.1).
Denis
By the way I fixed the update bug in anatomist sources (bug_fix branch, version 4.6.1).
Denis