关于SetViewPlaneNormal的tvtk中的AttributeError

时间:2013-10-20 12:42:30

标签: python vtk mayavi

注意:找到了一个临时解决方案:打开camera.py,使用pass并在函数_view_plane_normal_changed中注释内容,然后重新编译它。

我正在使用python(x,y)2.7.5.1。当我使用像mayavi这样的tvtk的一些软件包时,会引发一个AttributeError:SetViewPlaneNormal. 我知道这是因为vtk已弃用此方法。 有谁知道如何解决它? vtk的版本为5.10.1-3. 完整的引用包含一些像这样的块:

ERROR:traits:Exception occurred in traits notification handler for object:     vtkOpenGLCamera (06F89078)
    Debug: Off
    ...#There are too many lines here


Traceback (most recent call last):
    File "D:\Python27\lib\site-packages\traits\trait_notifiers.py", line 381, in call_3
        self.handler( object, old, new )
    File "D:\Python27\lib\site-packages\tvtk\tvtk_classes.zip\tvtk_classes\camera.py", line 82, in _view_plane_normal_changed
        self._do_change(self._vtk_obj.SetViewPlaneNormal,
AttributeError: SetViewPlaneNormal
Exception occurred in traits notification handler.

2 个答案:

答案 0 :(得分:1)

我面临同样的问题。任何mayavi代码都会导致AttributeError:SetViewPlaneNormal错误。

我的平台是Win 7 Pro x64,包含Python 2.7.5,VTK 5.10.1,Mayavi 4.3.0。

请注意,即使官方的python示例也会导致错误,但即使在控制台中不断打印错误,图形也会正确显示。

这是完整的堆栈跟踪:

, trait: view_plane_normal, old value: [ 0.57735027  0.57735027  0.57735027], new value: [     0.57735027  0.57735027  0.57735027]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\traits\trait_notifiers.py", line 381, in call_3
    self.handler( object, old, new )
  File "C:\Python27\lib\site-packages\tvtk\tvtk_classes.zip\tvtk_classes\camera.py", line 82, in     _view_plane_normal_changed
    self._do_change(self._vtk_obj.SetViewPlaneNormal,
AttributeError: SetViewPlaneNormal
Exception occurred in traits notification handler for object: vtkOpenGLCamera (092BF010)
  Debug: Off
  Modified Time: 890617
  Reference Count: 2
  Registered Events: 
    Registered Observers:
      vtkObserver (0A1AA3C8)
        Event: 33
        EventName: ModifiedEvent
        Command: 0A867210
        Priority: 0
        Tag: 1
  ClippingRange: (1.56289, 5.47286)
  DirectionOfProjection: (-0.57735, -0.57735, -0.57735)
  Distance: 3.29037
  EyeAngle: 2
  FocalDisk: 1
  FocalPoint: (1, 1, 1)
  ViewShear: (0, 0, 1)
  ParallelProjection: Off
  ParallelScale: 0.851612
  Position: (2.8997, 2.8997, 2.8997)
  Stereo: Off
  Left Eye: 1
  Thickness: 3.90998
  ViewAngle: 30
  UseHorizontalViewAngle: 0
  UserTransform: (none)
(none)
  ViewPlaneNormal: (0.57735, 0.57735, 0.57735)
  ViewUp: (0, 0, 1)
  WindowCenter: (0, 0)
  UseOffAxisProjection: (0)
  ScreenBottomLeft: (-0.5, -0.5, -0.5)
  ScreenBottomRight: (0.5, -0.5, -0.5)
  ScreenTopRight: (0.5, 0.5, -0.5)
  EyeSeparation: (0.06)
  WorldToScreenMatrix: (03996300
    Debug: Off
    Modified Time: 881548
    Reference Count: 1
    Registered Events: (none)
    Elements:
        1 0 0 0 
        0 1 0 0 
        0 0 1 0 
        0 0 0 1 
  )
  EyeTransformMatrix: (039954F0
    Debug: Off
    Modified Time: 881550
    Reference Count: 1
    Registered Events: (none)
    Elements:
        1 0 0 0 
        0 1 0 0 
        0 0 1 0 
        0 0 0 1 
  )
  ModelTransformMatrix: (039955E0
    Debug: Off
    Modified Time: 881552
    Reference Count: 1
    Registered Events: (none)
    Elements:
        1 0 0 0 
        0 1 0 0 
        0 0 1 0 
        0 0 0 1 
  )

, trait: view_plane_normal, old value: [ 0.57735027  0.57735027  0.57735027], new value: [     0.57735027  0.57735027  0.57735027]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\traits\trait_notifiers.py", line 381, in call_3
    self.handler( object, old, new )
  File "C:\Python27\lib\site-packages\tvtk\tvtk_classes.zip\tvtk_classes\camera.py", line 82, in     _view_plane_normal_changed
    self._do_change(self._vtk_obj.SetViewPlaneNormal,
AttributeError: SetViewPlaneNormal    

每次渲染都会打印多次上面的堆栈跟踪。如果我们移动相机导致FPS大幅下降,那就继续发生。

导致此错误的最简单代码示例:

from mayavi import mlab
mlab.points3d([1], [1], [1])

答案 1 :(得分:0)

我也遇到过使用python(x,y)(2.7.5.2)的问题,但是在Anaconda(1.8.0)发行版下,代码运行正常。

# code comes from mayavi docs shipped with python(x,y) 2.7.5.2
# Create the data.
from numpy import pi, sin, cos, mgrid
dphi, dtheta = pi/250.0, pi/250.0
[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
x = r*sin(phi)*cos(theta)
y = r*cos(phi)
z = r*sin(phi)*sin(theta)

# View it.
from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()