[Mlab] VTK Warning

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Mlab] VTK Warning

Lionel-3
Hi,

In my application, when the user closes a scene, a save some attributes
of it to restore them later. This includes the camera, which is a simple
set of tuples in the vtkOpenGLCamera, and some other attributes.

As I want to save them all, I do:
saved_camera = copy.copy(scene.camera)

The scene is an MlabSceneModel.

This works perfectly fine, but I get an output in the console saying.

Warning: In /path/to/mylibs/python/VTK/Rendering/vtkCamera.cxx, line 946
vtkOpenGLCamera (0xfc5c0d0): SetViewPlaneNormal:  This method is
deprecated, the view plane normal is calculated automatically.

This does not affect the application, which runs fine. After some
research, I read that it is due to an update in VTK which caused the
setViewPlaneNormal function to be deprecated.

I don't really know what happens when I copy() the camera, but it might
be necessary to update it. I don't know if Mayavi is responsible for
this, or PyQt, or anything else.

Here are my specs:
i686 GNU/Linux
Mayavi 3.3.1.dev-r24690
VTK 5.4.2
Python 2.6.2
PyQt 4.5.4
Qt 4.5.0

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Gael Varoquaux
Hi,

A quick suggestion: you should be able to use the output of mlab.view()
and mlab.roll to save and restore the viewpoint:

# Save
view = mlab.view()
roll = mlab.roll()

# Restore
mlab.view(*view)
mlab.roll(roll)

Tell us if this solves your problem, or if you really need to copy the
camera.

Cheers,

Gaël

PS: I just realized that mlab.roll does not take a 'figure=' keyword
argument. This is a bug, I'll fix it ASAP.

On Thu, Apr 08, 2010 at 10:06:57AM +0200, Lionel wrote:
> In my application, when the user closes a scene, a save some attributes
> of it to restore them later. This includes the camera, which is a simple
> set of tuples in the vtkOpenGLCamera, and some other attributes.

> As I want to save them all, I do:
> saved_camera = copy.copy(scene.camera)

> The scene is an MlabSceneModel.

> This works perfectly fine, but I get an output in the console saying.

> Warning: In /path/to/mylibs/python/VTK/Rendering/vtkCamera.cxx, line 946
> vtkOpenGLCamera (0xfc5c0d0): SetViewPlaneNormal:  This method is
> deprecated, the view plane normal is calculated automatically.

> This does not affect the application, which runs fine. After some
> research, I read that it is due to an update in VTK which caused the
> setViewPlaneNormal function to be deprecated.

> I don't really know what happens when I copy() the camera, but it might
> be necessary to update it. I don't know if Mayavi is responsible for
> this, or PyQt, or anything else.

> Here are my specs:
> i686 GNU/Linux
> Mayavi 3.3.1.dev-r24690
> VTK 5.4.2
> Python 2.6.2
> PyQt 4.5.4
> Qt 4.5.0

> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

--
    Gael Varoquaux
    Research Fellow, INRIA
    Laboratoire de Neuro-Imagerie Assistee par Ordinateur
    NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
    ++ 33-1-69-08-78-35
    ++ 33-6-28-25-64-62
    http://gael-varoquaux.info
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Lionel-3
Gael Varoquaux wrote:

> Hi,
>
> A quick suggestion: you should be able to use the output of mlab.view()
> and mlab.roll to save and restore the viewpoint:
>
> # Save
> view = mlab.view()
> roll = mlab.roll()
>
> # Restore
> mlab.view(*view)
> mlab.roll(roll)
>
> Tell us if this solves your problem, or if you really need to copy the
> camera.
>
> Cheers,
>
> Gaël
>
> PS: I just realized that mlab.roll does not take a 'figure=' keyword
> argument. This is a bug, I'll fix it ASAP.
>
> On Thu, Apr 08, 2010 at 10:06:57AM +0200, Lionel wrote:
>> In my application, when the user closes a scene, a save some attributes
>> of it to restore them later. This includes the camera, which is a simple
>> set of tuples in the vtkOpenGLCamera, and some other attributes.
>
>> As I want to save them all, I do:
>> saved_camera = copy.copy(scene.camera)
>
>> The scene is an MlabSceneModel.
>
>> This works perfectly fine, but I get an output in the console saying.
>
>> Warning: In /path/to/mylibs/python/VTK/Rendering/vtkCamera.cxx, line 946
>> vtkOpenGLCamera (0xfc5c0d0): SetViewPlaneNormal:  This method is
>> deprecated, the view plane normal is calculated automatically.
>
>> This does not affect the application, which runs fine. After some
>> research, I read that it is due to an update in VTK which caused the
>> setViewPlaneNormal function to be deprecated.
>
>> I don't really know what happens when I copy() the camera, but it might
>> be necessary to update it. I don't know if Mayavi is responsible for
>> this, or PyQt, or anything else.
>
>> Here are my specs:
>> i686 GNU/Linux
>> Mayavi 3.3.1.dev-r24690
>> VTK 5.4.2
>> Python 2.6.2
>> PyQt 4.5.4
>> Qt 4.5.0
>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

Hi Gaël,
I did a little (horrible) hack to test what you said, and tried the
following:
# Save
saved_camera = [scene.mlab.view(), scene.mlab.roll()]

# Restore
scene.mlab.view(self.camera[0])
scene.mlab.roll(self.camera[1])

However, the first scene.mlab.roll() raised:

File
"/path/to/ets/python26/lib/python2.6/site-packages/Mayavi-3.3.1.dev_r24690-py2.6-linux-i686.egg/enthought/mayavi/tools/camera.py",
line 66, in roll
     cam = get_engine().current_scene.scene._renderer.active_camera
AttributeError: 'NoneType' object has no attribute 'scene'

This looks related to the bug you were talking about, so I'll try again
later. Thanks a lot !

Lionel

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Gael Varoquaux
On Thu, Apr 08, 2010 at 11:38:00AM +0200, Lionel wrote:
> I did a little (horrible) hack to test what you said, and tried the
> following:
> # Save
> saved_camera = [scene.mlab.view(), scene.mlab.roll()]

> # Restore
> scene.mlab.view(self.camera[0])
> scene.mlab.roll(self.camera[1])

> However, the first scene.mlab.roll() raised:

> File
> "/path/to/ets/python26/lib/python2.6/site-packages/Mayavi-3.3.1.dev_r24690-py2.6-linux-i686.egg/enthought/mayavi/tools/camera.py",
> line 66, in roll
>      cam = get_engine().current_scene.scene._renderer.active_camera
> AttributeError: 'NoneType' object has no attribute 'scene'

> This looks related to the bug you were talking about,

I suspect that this is more related to the fact that the render window is
not yet initialized. See the warning at the following of the following
paragraph:

http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/building_applications.html#making-the-visualization-live

HTH,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Lionel-3
Gael Varoquaux wrote:

> On Thu, Apr 08, 2010 at 11:38:00AM +0200, Lionel wrote:
>> I did a little (horrible) hack to test what you said, and tried the
>> following:
>> # Save
>> saved_camera = [scene.mlab.view(), scene.mlab.roll()]
>
>> # Restore
>> scene.mlab.view(self.camera[0])
>> scene.mlab.roll(self.camera[1])
>
>> However, the first scene.mlab.roll() raised:
>
>> File
>> "/path/to/ets/python26/lib/python2.6/site-packages/Mayavi-3.3.1.dev_r24690-py2.6-linux-i686.egg/enthought/mayavi/tools/camera.py",
>> line 66, in roll
>>      cam = get_engine().current_scene.scene._renderer.active_camera
>> AttributeError: 'NoneType' object has no attribute 'scene'
>
>> This looks related to the bug you were talking about,
>
> I suspect that this is more related to the fact that the render window is
> not yet initialized. See the warning at the following of the following
> paragraph:
>
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/building_applications.html#making-the-visualization-live
>
> HTH,
>
> Gaël

This is strange, because this code (when I save the camera) is exactly
called when the event 'closing' (not the 'closed') of the scene is
fired. The renderer window should still be available, shoudln't it ?

Lionel

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Gael Varoquaux
On Thu, Apr 08, 2010 at 12:37:07PM +0200, Lionel wrote:
> This is strange, because this code (when I save the camera) is exactly
> called when the event 'closing' (not the 'closed') of the scene is
> fired. The renderer window should still be available, shoudln't it ?

Correct, so I agree with your analysis that it is probably realted to the
bug I found.

I won't be able to work on it too soon, be you can easily work around it:
the code of mlab.roll is trivial

def roll(roll=None):
    """ Sets or returns the absolute roll angle of the camera.
   
    **See also**

    :mlab.view: control the position and direction of the camera
    """
    cam = get_engine().current_scene.scene._renderer.active_camera
    if roll is not None:
        cam.set_roll(roll)
        get_engine().current_scene.render()
    return cam.get_roll()

Just replace the 'get_engine().current_scene' by your scene.

HTH,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

List of WeakRef

Giraudon Cyril
In reply to this post by Lionel-3
Hello,

I 'd like to maintain a list of elements thanks to a WeakRef list as
shown in the following snippet :

import unittest
from enthought.traits.api import (HasTraits, Str, List,  WeakRef)

class Child(HasTraits):
    name = Str

class ParentWeakRefList(HasTraits):
    name = Str
    children_list = List(WeakRef("Child"))

class Test(unittest.TestCase):
    def test_parent_weak_list(self):
        c1 = Child(name="honey")
        c2 = Child(name="pot")
        pwrl = ParentWeakRefList(name="dad")
        pwrl.children_list.append(c1)
        pwrl.children_list.append(c2)
        self.assertEqual(2, len(pwrl.children_list))
        self.assertEqual("honey", pwrl.children_list[0].name)
        self.assertEqual("pot", pwrl.children_list[1].name)
        c1 = None
        self.assertEqual(2, len(pwrl.children_list))
        self.assertEqual("honey", pwrl.children_list[0].name)
        self.assertEqual("pot", pwrl.children_list[1].name)


I don't understand why the test succeeds after c1 = None.
I thought pwrl.children_list[0] = None but the list keeps a reference to c1.

Isn't it possible to use weakref with List ?

Thanks a lot,

Regards,

Cyril.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: List of WeakRef

Robert Kern
On Fri, Apr 9, 2010 at 10:58 AM, Giraudon Cyril <[hidden email]> wrote:

> Hello,
>
> I 'd like to maintain a list of elements thanks to a WeakRef list as
> shown in the following snippet :
>
> import unittest
> from enthought.traits.api import (HasTraits, Str, List,  WeakRef)
>
> class Child(HasTraits):
>    name = Str
>
> class ParentWeakRefList(HasTraits):
>    name = Str
>    children_list = List(WeakRef("Child"))
>
> class Test(unittest.TestCase):
>    def test_parent_weak_list(self):
>        c1 = Child(name="honey")
>        c2 = Child(name="pot")
>        pwrl = ParentWeakRefList(name="dad")
>        pwrl.children_list.append(c1)
>        pwrl.children_list.append(c2)
>        self.assertEqual(2, len(pwrl.children_list))
>        self.assertEqual("honey", pwrl.children_list[0].name)
>        self.assertEqual("pot", pwrl.children_list[1].name)
>        c1 = None
>        self.assertEqual(2, len(pwrl.children_list))
>        self.assertEqual("honey", pwrl.children_list[0].name)
>        self.assertEqual("pot", pwrl.children_list[1].name)
>
>
> I don't understand why the test succeeds after c1 = None.
> I thought pwrl.children_list[0] = None but the list keeps a reference to c1.
>
> Isn't it possible to use weakref with List ?

Not in the way you are thinking, no. The container object needs to be
specially written; you can't use a regular list object.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Mlab] VTK Warning

Gael Varoquaux
In reply to this post by Gael Varoquaux
On Thu, Apr 08, 2010 at 12:40:24PM +0200, Gael Varoquaux wrote:
> On Thu, Apr 08, 2010 at 12:37:07PM +0200, Lionel wrote:
> > This is strange, because this code (when I save the camera) is exactly
> > called when the event 'closing' (not the 'closed') of the scene is
> > fired. The renderer window should still be available, shoudln't it ?

> I won't be able to work on it too soon, be you can easily work around it:
> the code of mlab.roll is trivial

I got stuck in a train for a while, so I had time to fix this issue: rev
25464.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: List of WeakRef

Giraudon Cyril
In reply to this post by Robert Kern
Thank you Robert for your response,

May I understand there is no "Traits" way to maintain a list /
dictionary of WeakRef ? A new container WeakRefList (for instance) has
to be written ?

I'm not sure to get the connection with python weak reference  (
http://docs.python.org/library/weakref.html ) which come with weak
reference container.

Regards,

Cyril.


Le 09/04/2010 18:53, Robert Kern a écrit :

> On Fri, Apr 9, 2010 at 10:58 AM, Giraudon Cyril <[hidden email]> wrote:
>  
>> Hello,
>>
>> I 'd like to maintain a list of elements thanks to a WeakRef list as
>> shown in the following snippet :
>>
>> import unittest
>> from enthought.traits.api import (HasTraits, Str, List,  WeakRef)
>>
>> class Child(HasTraits):
>>    name = Str
>>
>> class ParentWeakRefList(HasTraits):
>>    name = Str
>>    children_list = List(WeakRef("Child"))
>>
>> class Test(unittest.TestCase):
>>    def test_parent_weak_list(self):
>>        c1 = Child(name="honey")
>>        c2 = Child(name="pot")
>>        pwrl = ParentWeakRefList(name="dad")
>>        pwrl.children_list.append(c1)
>>        pwrl.children_list.append(c2)
>>        self.assertEqual(2, len(pwrl.children_list))
>>        self.assertEqual("honey", pwrl.children_list[0].name)
>>        self.assertEqual("pot", pwrl.children_list[1].name)
>>        c1 = None
>>        self.assertEqual(2, len(pwrl.children_list))
>>        self.assertEqual("honey", pwrl.children_list[0].name)
>>        self.assertEqual("pot", pwrl.children_list[1].name)
>>
>>
>> I don't understand why the test succeeds after c1 = None.
>> I thought pwrl.children_list[0] = None but the list keeps a reference to c1.
>>
>> Isn't it possible to use weakref with List ?
>>    
> Not in the way you are thinking, no. The container object needs to be
> specially written; you can't use a regular list object.
>
>  

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: List of WeakRef

Robert Kern
On Wed, Apr 14, 2010 at 4:18 AM, Giraudon Cyril <[hidden email]> wrote:
> Thank you Robert for your response,
>
> May I understand there is no "Traits" way to maintain a list /
> dictionary of WeakRef ? A new container WeakRefList (for instance) has
> to be written ?
>
> I'm not sure to get the connection with python weak reference  (
> http://docs.python.org/library/weakref.html ) which come with weak
> reference container.

The WeakRef trait uses a weakref.ref() underneath, but handles the
dereferencing for you (so you don't have to call the ref object to get
the real object). We do not have traitsified containers to correspond
with weakref.WeakKeyDictionary or weakref.WeakValueDictionary, but you
can put either into an Any trait. You just won't get the *_items event
notifications when something is added to or removed from them. The
weakref module has no weak list implementation at all. It would be
difficult to do so, and there are few use cases for it that the
WeakKeyDictionary does not solve (or the WeakSet coming in 2.7).

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev