[vtkusers] Python observer handling
David Gobbi
david.gobbi at gmail.com
Wed Jan 9 13:15:34 EST 2013
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
More information about the vtkusers
mailing list