嵌入Mayavi时在vtkOutputWindow中禁用或捕获VTK警告 [英] Disable or Catch VTK warnings in vtkOutputWindow when embedding Mayavi

查看:498
本文介绍了嵌入Mayavi时在vtkOutputWindow中禁用或捕获VTK警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用VTK警告窗口,或者更好的是,捕获它们以使用我的应用程序的日志记录系统进行处理.我的应用程序正在使用嵌入式mayavi视图,并且我不希望弹出无法控制的错误窗口.以下代码演示了警告窗口.

I'd like to either disable the VTK warning window or, better yet, catch them to handle with my application's logging system. My application is using an embedded mayavi view, and I don't want error windows popping up that I have no control over. The following code demonstrates the warning window.

import numpy as np
from mayavi import mlab

x1 = np.array([1, 1, 2, 3])
y1 = np.array([1, 1, 4, 2])
z1 = np.array([1, 1, 5, 1])

mlab.plot3d(x1, y1, z1)

mlab.show()

好的,我做过一些研究,发现vtk.vtkObject.GlobalWarningDisplayOff()将完全禁用该窗口,这很好.更好的是,以下代码会将警告记录到文件中(找到它

Ok, I've done some research and discovered that vtk.vtkObject.GlobalWarningDisplayOff() will disable the window completely, which is nice. Better yet the followingcode will log the warnings to a file (found it here):

def redirect_vtk_messages ():
    """ Can be used to redirect VTK related error messages to a
    file."""
    import tempfile
    tempfile.template = 'vtk-err'
    f = tempfile.mktemp('.log')
    log = vtkpython.vtkFileOutputWindow()
    log.SetFlush(1)
    log.SetFileName(f)
    log.SetInstance(log)

因此,尽管这很好,但我仍然无法将警告直接传递到日志处理程序中.我宁可不必在常规日志文件旁边有一个vtk_log文件.另外,我可能想以某种方式处理GUI中的警告,或者为用户提供有关如何处理警告的选项,并不断观察日志文件中的更改似乎是一种糟糕的方法.

So while this is nice, I'm still unable to pipe the warnings directly into a logging handler. I'd rather not have to have a vtk_log file next to my regular log files. Also I might want to handle the warnings in my GUI somehow, or give the user options on how to handle them and constantly watching a log file for changes seems like a poor way to do that.

关于在嵌入mayavi/vtk的应用程序中处理vtk警告的强大pythonic方法的任何建议吗?

Any suggestions on a robust pythonic way to handle vtk warnings in an application which embeds mayavi/vtk?

推荐答案

我想这部分地回答了您的问题,但是您可以按照python

I guess this partially answer your question, but you could implement an error observer in python as explained here http://public.kitware.com/pipermail/vtkusers/2012-June/074703.html and add it to the vtk class you are interested.

在c ++中,我发现将输出重定向到stderr更为简单(此示例适用于Windows):

In c++ I find much simpler to redirect the output to stderr (this example is for windows):

vtkSmartPointer<vtkWin32OutputWindow> myOutputWindow = vtkSmartPointer<vtkWin32OutputWindow>::New(); 
myOutputWindow->SetSendToStdErr(true);
vtkOutputWindow::SetInstance(myOutputWindow);

在python中,我尝试过

In python I tried

ow = vtk.vtkOutputWindow()
ow.SendToStdErrOn()

它将错误发送到控制台,但是我仍然看到vtk窗口,并且它似乎并没有捕获到错误.

it sends the error to console, but I still see the vtk window and it doesn't really seem catching the errors.

另一个选择可能是在关闭VTK_USE_DISPLAY的情况下重新编译vtk( http://osdir.com/ml/python-enthought-devel/2009-11/msg00164.html ).我不会尝试此操作,因为我使用的是已经在paraview中编译的vtk发行版

Another option could be to recompile vtk with VTK_USE_DISPLAY turned off ( http://osdir.com/ml/python-enthought-devel/2009-11/msg00164.html). I am not going to try this because I am using the vtk distribution already compiled in paraview

这篇关于嵌入Mayavi时在vtkOutputWindow中禁用或捕获VTK警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆