[vtk-developers] Two "major" changes in VTK

Andy Cedilnik Andy.Cedilnik at kitware.com
Fri Dec 28 09:06:00 EST 2001


Hello all,

Yesterday, I made a change in VTK's error and warning handling. Two of them 
actually.

Currently if you are writing application using VTK and want to disable 
VTK's error and
warning reporting, you have to subclass vtkOutputWindow to do what you want.

I added ErrorEvent and WarningEvent to vtkCommand. Also, I modified 
vtkErrorMacro
and so that they first check if there is observer on ErrorEvent. If there 
is observer for
ErrorEvent, it will execute the vtkCommand associated with it. Otherwise it 
will
popup the error message as it did so far. Similar concept is with 
vtkWarningMacro,
which will be affected by WarningEvent. I also added two more macros called
vtkErrrorMacroWithObject, which takes pointer to vtkObject as an argument.
This way you can use this instead of vtkGenericWarningMacro. As an example
of use, here is vtkErrrorMacro:

#define vtkErrorMacro(x) \
      vtkErrorMacroWithObject(this, x)

The use of vtkGenericWarningMacro is therefore obsolete and should be 
deprecated in
the scope of VTK classes, since vtkWarningMacroWithObject has the option of 
using our
own callbacks for reporting errors and warnings. I hope people will modify 
VTK classes
and change all vtkGenericWarningMacro to vtkWarningMacroWithObject.
vtkGenericWarningMacro can still be used where we do not have access to any 
vtkObject.
I will try to change this in some places, but I would appreciate some help.
Important note here is that if you use vtkErrorMacro, vtkWarningMacro, and 
so on, with
observers, make sure that callbacks are thread safe, since the errors and 
warnings
can happen in threads.

The second major change is to do with readers (and potentially with all 
other objects).
Currently reader has no way of reporting error when reading file. I added 
class
vtkErrorCode and I added to the vtkSource ivar ErrorCode and of course 
public method
GetErrorCode and protected method SetErrorCode. The reason why I added this to
vtkSource is that vtkSource is the first superclass of all readers. This 
way after performing
some operation on file with any reader (or potentially on any object), you 
can get the error
code. An example somewhere in your application, you would say:

vtkStructuredPointsReader *r = vtkStructuredPointsReader::New();
r->SetFileName("test.vtk");
r->Update();
cout << "Error code: " << vtkErrorCode::GetStringFromErrorCode( 
r->GetErrorCode() ) << endl;

Currently only vtkDataReader and vtkStructuredPointsReader set ErrorCode. I 
think all reader
writers should from now on set this error codes and maybe add new ones. 
These are current
error code:

     NoError = 0,
     FileNotFoundError,
     CannotOpenFileError,
     UnrecognizedFileTypeError,
     PrematureEndOfFileError,
     FileFormatError,
     NoFileNameError,
     UnknownError,
     UserError = 1000

I suggest the error handling should be extended to all vtkObjects 
derivatives, so that the
application developer has a full control over error handling.

Both changes should not impact any of existing projects.

Thank you.

						Andy Cedilnik




More information about the vtk-developers mailing list