[vtkusers] Python observer handling
David Gobbi
david.gobbi at gmail.com
Wed Jan 9 14:09:45 EST 2013
Hi Willi,
You can capture errors globally and send them to a log file,
by using e.g. vtkFileOutputWindow. Or you can write a custom
OutputWindow class that pops up a modal dialog box and
requires your customers to press "Okay" or "Cancel" before
proceeding.
- David
On Wed, Jan 9, 2013 at 11:56 AM, Willi Huber <w.huber at ymail.com> wrote:
> Hey David,
>
> yeah it was the right problem you are assuming.
> Is there a way to catch errors like this or do I have to tell my
> "customers" to copy what they can read (if they can read it) in the popup
> window?
> In my opinion this kind of error handling ain't a good solution if
> wrapping is a feature VTK offers. Can it be stopped that my app is going to
> be killed in such a harsh way?
>
> Cheers,
> Willi
>
> ------------------------------
> * From: * David Gobbi <david.gobbi at gmail.com>;
> * To: * Willi Huber <surfersparadise85-vtk at yahoo.com>;
> * Cc: * vtkusers at vtk.org <vtkusers at vtk.org>;
> * Subject: * Re: [vtkusers] Python observer handling
> * Sent: * Wed, Jan 9, 2013 6:15:34 PM
>
> Hi Willi,
>
> I quickly ran your python code (on my Mac), and saw an error like this
> in the console:
>
> ERROR: In vtkDemandDrivenPipeline.cxx, line 816
> vtkStreamingDemandDrivenPipeline (0x1044d38a0): Input for connection
> index 0 on input port index 0 for algorithm
> vtkPainterPolyDataMapper(0x1044cf970) is of type vtkImageData, but a
> vtkPolyData is required.
>
> So in my case, it wasn't the mapper that generated this error: it was
> the mapper's executive, which is a different object. Also, many of
> the VTK mappers delegate to other VTK mappers, and because these
> delegate mappers are created internally you will not be able to add
> observers to them. I'm not saying this is a good thing... it is a bad
> thing, obviously, but ErrorObservers cannot always be used
> successfully with mappers. On the positive side, ErrorObservers work
> nicely with readers.
>
> For your code specifically, I'm guessing that you are seeing an error
> because you are using an image as input to a vtkPolyDataMapper.
>
> - David
>
>
> On Wed, Jan 9, 2013 at 9:20 AM, Willi Huber
> <surfersparadise85-vtk at yahoo.com> wrote:
> > Hello all,
> >
> > I know exception handling in VTK has been discussed quite a while so I
> don't
> > want to add insult to an injury.
> >
> > Since David Gobbi very often posted his code:
> >
> > ==== python code ====
> > import vtk
> >
> > class ErrorObserver:
> >
> > def __init__(self):
> > self.__ErrorOccurred = False
> > self.__ErrorMessage = None
> > self.CallDataType = 'string0'
> >
> > def __call__(self, obj, event, message):
> > self.__ErrorOccurred = True
> > self.__ErrorMessage = message
> >
> > def ErrorOccurred(self):
> > occ = self.__ErrorOccurred
> > self.__ErrorOccurred = False
> > return occ
> >
> > def ErrorMessage(self):
> > return self.__ErrorMessage
> >
> > e = ErrorObserver()
> >
> > a = vtk.vtkImageReader()
> > a.AddObserver('ErrorEvent', e)
> >
> > print "doing update"
> > a.Update()
> > if e.ErrorOccurred():
> > print e.ErrorMessage()
> >
> > ==== python code ====
> >
> >
> > Unfortunately it is not working as intended. I tried this code which
> > obviously had to fail:
> >
> > ==== python code ====
> >
> > mapper = vtk.vtkPolyDataMapper()
> > mapper.AddObserver('ErrorEvent', e)
> > mapper.SetInputConnection(reader.GetOutputPort()) #reader is of type
> > vtkMetaImageReader
> > mapper.Update()
> >
> > if e.ErrorOccurred():
> > print e.ErrorMessage()
> > else:
> > print "No Error"
> >
> > ==== python code ====
> >
> > but it didn't. Now I know about this error but I am still curious why it
> was
> > not working as intended.
> >
> > Shouldn't it print the cause of the error rather than "No Error"?
> >
> >
> > Everytime I tried this code a vtk warning window poped up which can't be
> > read since the whole application dies with some Windows failure handling.
> > Therefore I was not able to read the error message in the window and had
> a
> > tough time finding out about the problem.
> > Uncommenting renWin.Render() let me read the error.
> >
> > Any suggestions what I am doing wrong?
> >
> >
> > Cheers,
> >
> > Willi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130109/f5431ba2/attachment.htm>
More information about the vtkusers
mailing list