Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make text appear and disappear again #28

Closed
m-albert opened this issue Jun 12, 2019 · 7 comments
Closed

Make text appear and disappear again #28

m-albert opened this issue Jun 12, 2019 · 7 comments

Comments

@m-albert
Copy link

Hi, thanks for such a great tool!

I'm trying to have changing text in an animation and don't manage to properly make it appear and disappear. Consider this example:

from vtkplotter import Text, screenshot, Plotter

vp = Plotter(axes=0, interactive=0)

for i in [1,2,3]:
    text = Text('%03d' %i)
    # vp.actors = [text] # this produces different results
    vp.add(text)
    vp.show()
    screenshot('test_%03d.png' %i)
    vp.remove(text)

Output: test_000.png shows 001 instead of 002...

Thanks a lot!

@marcomusy
Copy link
Owner

Hi @quakberto
thanks!
i cannot reproduce the problem.. are you running the latest version? try
pip install -U vtkplotter
Also, you cannot have a test_000 with i in the range of [1,2,3].
This gives me the expected output:

from vtkplotter import Text, screenshot, Plotter

vp = Plotter(axes=0, interactive=0)

for i in [0,1,2,3]:
    text = Text('%03d' %i, c='white')
    vp += text
    # vp += more objects..
    vp.show()
    screenshot('htest_%03d.png' %i)
    vp.remove(text)

image

Let me know if it still does not work for you,
cheers
Marco

@m-albert
Copy link
Author

Hi Marco,

thanks for the quick look!

i cannot reproduce the problem.. are you running the latest version? try
pip install -U vtkplotter

Indeed I was one release behind, however the behaviour I get remains the same.

Your code gives me this output (I just increased the text size ...,s=10)):
image

Also, you cannot have a test_000 with i in the range of [1,2,3].

Sorry, of course you're right, I meant test_002.png. Here's the output of the code I posted above:

image

Notice also the difference in text color.

Let me know if I can give you any info about my environment. In any case, I guess this could well be a problem outside of vtkplotter.

Cheers

@marcomusy
Copy link
Owner

that's funny... it must be something related to your python (?). In my ubuntu system with either python 2,3 your script gives the expected output.
Try maybe Text(str(i), c='white') and screenshot(str(i)+'.png')

The color difference is caused by the fact the first time the rendering window does not yet exist, so vtkplotter makes it a default grey, This is fixed by explicitly setting c='white'.

@m-albert
Copy link
Author

The color difference is caused by the fact the first time the rendering window does not yet exist, so vtkplotter makes it a default grey,

Okay, that explains the grey. Still it's a bit strange that the second screenshot is also grey, as the rendering window already existed in the second iteration.

Yeah, must be something in my environment which is clearly a bit strange. For example, despite it being a clean anaconda installation on a fresh MacOS, executing the same code above with ipython gives me a segfault (in the screenshot command). Without screenshot, the rendering window is not displayed. In any case I'll try to reproduce the problem on another system soon.

Thanks for the help and I'll write here if I find out anything new in case anyone else stumbles upon a similar problem :)

@marcomusy
Copy link
Owner

Hi again, I tried on my mac and YES, i can reproduce the issue! i´ll investigate that, thanks for spotting the issue, and get back to you asap.

@marcomusy marcomusy added the bug label Jun 13, 2019
@marcomusy
Copy link
Owner

@quakberto
I think I fixed the issue... give it a try:

git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter
pip install .

then:

from vtkplotter import *

#this is needed when using ipython or from jupyter:
#embedWindow(False) 

vp = Plotter(axes=0, interactive=0)

for i in [1,2,3]:
    text = Text('%03d' %i, c='white')
    vp += text
    vp += Sphere(c=i).x(i)
    vp.show()
    screenshot('test_%03d.png' %i)
    vp.remove(text)

image

Let me know if the issue persists,
Cheers, M.

@m-albert
Copy link
Author

Hi Marco,

nice, after updating to your new version I get the same output as you!

As your comment says, embedWindow(False) is needed on ipython or jupyter. Also the normal python console seems to be fine with it.

Thanks a lot for following up on the issue!

Cheers,
Marvin

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

No branches or pull requests

2 participants