Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "_p_void" values in TVTK with VTK 6.x #370

Merged
merged 25 commits into from May 13, 2016

Conversation

kitchoi
Copy link
Contributor

@kitchoi kitchoi commented Apr 29, 2016

I have tested this with VTK 6.2 and 6.3 on Ubuntu 12, and VTK 6.3 on OSX 10.11

Things seem to work but since this is a fundamental change, I would prefer sitting on it for a bit longer. Review and comments are very much appreciated.

Most of these changes are tested by the existing TVTK test for initialising all classes, but I think I could also add more tests to make it more robust.

To compare the bahaviour, try the following with the master branch and with this one:

from tvtk.api import tvtk
obj = tvtk.ViewTheme()
obj.configure_traits()

@codecov-io
Copy link

codecov-io commented Apr 29, 2016

Current coverage is 45.53%

Merging #370 into master will decrease coverage by -<.01%

@@             master       #370   diff @@
==========================================
  Files           258        258          
  Lines         22909      23011   +102   
  Methods           0          0          
  Messages          0          0          
  Branches       3030       3036     +6   
==========================================
+ Hits          10451      10476    +25   
- Misses        11729      11805    +76   
- Partials        729        730     +1   
  1. File ...ayavi/core/engine.py (not in diff) was modified. more

Powered by Codecov. Last updated by 10f5db9...c1e1f46

@kitchoi
Copy link
Contributor Author

kitchoi commented Apr 29, 2016

Should fix #357 and #360

@@ -272,6 +274,11 @@ class TVTKBase(traits.HasStrictTraits):
# The wrapped VTK object.
_vtk_obj = traits.Trait(None, None, vtk.vtkObjectBase())

# Stores the names of the traits whose VTK Get methods may return
# invalid values (e.g. reference to a point) or uninitialised values
# We would try to update but allow it to failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"allow it to fail" :)

@kitchoi kitchoi changed the title Fix "_p_void" values in TVTK with VTK 6.x [WIP] Fix "_p_void" values in TVTK with VTK 6.x May 4, 2016
@stefanoborini
Copy link
Contributor

This is too much code to review without being told more.

@kitchoi
Copy link
Contributor Author

kitchoi commented May 4, 2016

If you try to run the new tvtk test case with the master branch + VTK 6.3, you should see a bunch of failures: https://gist.github.com/kitchoi/8e92ad08e44334133360536ce3d5bdff
These are what this PR is fixing, plus a bunch of refactoring.

@stefanoborini
Copy link
Contributor

The problem now is that it's very hard to differentiate between what you changed for the fix and what you refactored.

@stefanoborini
Copy link
Contributor

I think it's time we ditch codecov until they fix this unexpected changes problem.

@kitchoi
Copy link
Contributor Author

kitchoi commented May 4, 2016

If you want less of the refactoring changes, try git diff the master and this commit: 7a30bdd

@stefanoborini
Copy link
Contributor

Try pushing a dummy change. I disabled codecov

if klass.__name__ == 'vtkCubeAxesActor2D' and \
name == 'inertia':
# VTK bug. Inconsistent API!
rng = (float(rng[0]), float(rng[1]))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the special handling of 'vtkCubeAxesActor2D.inertia' here because from what I have researched on the VTK API, inertia is indeed an int and there is no inconsistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite possible this was a bug with VTK 4.x or so which is not relevant anymore so this is fine.

@stefanoborini
Copy link
Contributor

apparently the codecov yaml file did not solve for this branch

@kitchoi
Copy link
Contributor Author

kitchoi commented May 5, 2016

I think the "codecov/project" captures the increase in coverage after we added VTK 6.3 and VTK 7 in the test matrix, it raises a red flag because it did not expect those changes (who knows how they decide what they should expect).

@@ -295,7 +294,8 @@ def get_other_methods(self):
"""
return self.other_meths

def get_method_signature(self, method):
@staticmethod
def get_method_signature(method):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many occurrence of parser = VTKMethodParser(); parser.get_method_signature(...) in wrapper_gen and in tests (and possibly some other places I have not touched), could do with a separately cleanup PR in order to move this function out of the class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave it as is. not top priority. If you want, open a issue tagged refactoring.

self._write_trait(out, name, t_def, vtk_set_meth, mapped=False)

def _write_hardware_selector_prop_color_value(self, klass, out,
vtk_attr_name='PropColorValue'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that you have to pass a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have to. But I think it acts as a form of documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the intent, but it's deceiving. When I see that, I don't expect it to be documentation.
You already enforce the value in the content. When I see that I assume that the method can be called without any passed vtk_attr_name for some reason, and you are "fixing" that behavior with the only acceptable value, but the vtk_attr_name is always passed, only in this routine must be one and only one value, otherwise there's a programming error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the default value now. Unfortunately I have to keep the signature consistent, so vtk_attr_name is kept there.

@stefanoborini
Copy link
Contributor

Review ready. Merge when done (they are mostly minor).

@stefanoborini
Copy link
Contributor

stefanoborini commented May 5, 2016

How is this related to issue #385 ? did you skip the test?

@kitchoi
Copy link
Contributor Author

kitchoi commented May 5, 2016

What is issue #907?

@stefanoborini
Copy link
Contributor

Fixed. I pasted the wrong content.

# e.g. x = numpy.empty(9); ImageConvolve.GetKernel3x3(x)
# FIXME: we could try harder in retrieving these values
# in TVTKBase.update_traits
del updateable_traits[name]
Copy link
Contributor Author

@kitchoi kitchoi May 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change del updateable_traits[name] to allow_update_failure.add(name), the difference in behaviour is not only that TVTKBase.update_traits will have more updating to do while those updating will almost certainly fail with TraitError, but I will also get these traits visible on the UI.
E.g. with del updateable_traits[name]
obj = tvtk.ImageConvolve(); obj.configure_traits()
del_updateable

E.g. replace with allow_update_failure.add(name)
allow

Question is, which one do we want. The bahaviour on the interactive interpreter is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corran suggested using TextEditor for these arrays. Unfortunately I am preoccupied at the moment. I think I would attack this problem in a separate PR if and after this one is merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Maybe adding an issue for that would be good so we don't forget.

@kitchoi
Copy link
Contributor Author

kitchoi commented May 5, 2016

How is this related to issue #385 ? did you skip the test?

I did not do anything about #385, the error is still there (look at VTK 6.3 and VTK 7)
https://travis-ci.org/enthought/mayavi/jobs/128037832#L1208

def test_spider_plot_actor(self):
""" Test SpiderPlotActor Get/SetAxisLabel works
"""
actor = tvtk.SpiderPlotActor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if there were a comment as to why this object is tested that would be helpful.

@kitchoi
Copy link
Contributor Author

kitchoi commented May 12, 2016

Note to self
TODO:

  • Test with Python 3

return 'traits.Array', '', kwargs

elif type_ is bool:
return 'traits.Bool', '', kwargs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self, return 'traits.Bool', str(value), kwargs


if vtk_attr_name != 'PropColorValue':
raise RuntimeError("Not sure why you ask for me! "
"I only deal with PropColorValue. Panicking.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to prevent this method being used with vtk_attr_name other than PropColorValue. This may be unnecessary given the method is private and is used internally.

@prabhuramachandran
Copy link
Member

Thanks for this, it looks nice and the code looks a lot cleaner than before! I will merge this for now.

@prabhuramachandran prabhuramachandran merged commit 904204d into master May 13, 2016
@kitchoi kitchoi deleted the fix/357-360-tvtk-with-undefined-traits branch June 29, 2016 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants