I’m using (C++) vtkIntersectionPolyDataFilter to perfrom boolean operations (union, intersection, difference) on geometric bodies such as spheres and cylinders. For instance, if 2 bodies do not touch or overlap in any manner, when I execute the code I see the following error messages / warnings (regardless of the boolean operation) and NO objects are rendered on screen:
2022-06-06 16:25:36.780 ( 0.334s) [ 3FD38A00] vtkPointLocator.cxx:845 ERR| vtkPointLocator (0x1147620): No points to subdivide 2022-06-06 16:25:36.781 ( 0.334s) [ 3FD38A00] vtkIntersectionPolyData:2410 WARN| No Intersection between objects 2022-06-06 16:25:36.781 ( 0.335s) [ 3FD38A00]vtkDistancePolyDataFilt:81 ERR| vtkDistancePolyDataFilter (0x1041fd0): No points/cells to operate on 2022-06-06 16:25:36.781 ( 0.335s) [ 3FD38A00]vtkDistancePolyDataFilt:81 ERR| vtkDistancePolyDataFilter (0x1041fd0): No points/cells to operate on
Now, the error messages are certainly informative to me as a developer, but they will probably confuse my users and have them asking “What went wrong?” when they mess up.
I would like to handle messages like those shown above in a more robust way in my code, but I can’t figure out how to do that from vtkBooleanOperationPolyDataFilter’s paucity of error codes. The fact that this filter inherits quite a lot from other filters is also a factor and seems to add complexity to the issue.
I’m not against subclassing vtkBooleanOperationPolyDataFilter and inserting my own codes and / or messages, but I’m not sure how to proceed considering that some of the messages are so deep into the inheritance chain.
Certainly, this is not the first time this issue has surfaced. Can anyone offer a solution? Did the vtk developers even consider a situation such as this?
There is the vtkErrorObserver class you can attach to a vtkObject. AFAIK, there’s no way to squelch messages not attached to them without silencing the level they make noise at.
Ah, I keep forgetting that it’s a Python wrapper around vtkCommand. You can search for vtkTest::ErrorObserver in the repo to see how it is done there; the class is part of VTK::TestingCore, so not really intended for generic use.
First, the vtkObjec::GlobalWarningDisplayOff() does indeed turn the messages off. Much thanks fort that. However, it doesn’t let me know that there is a problem so that I can handle it internally.
However, when I set it up according to the example on the vtkIntersectionPolyDataFilter object, it didn’t work. And, it didn’t work on any other object / filter that I tried the vtkObserver on. So, I’m lost of this one. Is it suppose to catch errors / warnings from inherited classses?
Sorry. I don’t see how this F3DObjectFactory code can help me at all. There is just not enough context of what is going on with it for to relate it to what I want to do.
Maybe I should have phrased the original question a little differently. I’ll try again.
How can one know if a function like vtkBooleanOperationPolyDataFilter is successful and has valid results to use vs it being unsuccessful and the results aren’t valid?
I would’ve hoped with a return code, but perhaps there is some function to query for this?
I could try that. Have never done it. Still learning about how to approach things using VTK.
Do you have a specific example in mind that catches exceptions? I can try and look in the examples section, but not sure if there is something there that does what you suggest – but, it sounds good!
The try / catch doesn’t catch the errors and warnings that are generated by vtkBooleanOperationPolyDataFilter.
I believe that the filters aren’t throwing exceptions. They don’t like the data they are given. Are unsuccessful in working with the data. Print out the warnings and errors. What they should do is give me a return value that I can work with.
It’s more likely that the exceptions are being swallowed. I suggest putting a break-point where the warning is being generated and then working backwards to the offending code.
@BlueKnight7@toddy : VTK does not throw exceptions, there is literally nothing to catch.
The errors you mentions (I should have checked earlier) actually do not do anything else than printing something. It does not error out, so the boolean you get is true.
Reading the code is sometimes the simplest way forward.
IMO this is an issue. A filter should not print an error and not return an error and this should be fixed.
In any case if you want to makje this work with VTK, you need the object factory to “catch” the error printing.
I agree about fixing the filter regarding the printed error messages.
I’ll take a stab at the factory approach, but I don’t have experience with it. For me, the code for the F3D factory was a little vague. I just don’t understand the principles needed for implementation. There was not enough code supporting it to understand what is needed to make it work. And, looking at (digging through) another major application to figure this out was not how I envisioned learning how to do this.
I see from the documentation that the vtkObjectFactory is an aid in writing a subclass. All of the examples mentioned at https://vtk.org/doc/nightly/html/classvtkObjectFactory.html
use the vtkObjectFactory. h header file, but do not directly use vtkObjectFactory. So, this is a bit confusing and leaves me wondering how to use the factory class.
But, the bigger issue is that I don’t know how to write the subclass at this point because the filters that vtkBooleanOperationPolyDataFilter use may or may not return any useful information from which I can create the code I need.
In essence, writing a subclass is basically fixing the problem that the developers created by not having the function make the right checks to begin with. At this point I don’t know enough about what these other routines return or make available for one to work with. This will take some digging on my part with the biggest concern is that I don’t know when the pipeline is making things available and what those things might be.