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
Upgrading to new pipeline #114
Changes from 24 commits
16074af
fb7d034
a80f36c
1d84a15
6990bc7
0962b1f
34f9294
51e6cff
9507555
4ec242c
eb4e341
c49c6c4
a32ca8f
b4456c0
6655191
8185cb9
6408e7a
af9faae
741ae92
23aeb81
d32b64b
a6f22d3
be70e14
d6137bd
3c2b0e0
70bfec9
c210d60
b1bd084
2aabef9
25c3e57
89e4c6e
62ad693
89e9ba2
e36ae0b
651e549
4e361ad
352a64e
9530de4
df72e9a
dab2862
bcc2e66
3b9e4e0
0f7b9ae
91091e2
4528e59
1878216
a2ca82e
77dac31
e618a7e
46b47ab
80cb4e3
0a513c2
416bc83
074f76a
5bfa118
19f9b31
269d7cd
4216fc4
ef292e0
72dc9f2
f1d8417
d4880ea
7c5b7d2
e15651b
66a3957
5a403f4
7b47efb
d8fcbdd
6b3163c
edf6ae9
6c99e25
025760a
58376eb
0a58b33
2558b21
c492d0a
3580b18
da306a1
ae4ec93
74bec8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
# Local imports. | ||
from mayavi.core.component import Component | ||
from mayavi.core.source import Source | ||
|
||
from mayavi.core.common import is_old_pipeline | ||
|
||
###################################################################### | ||
# `Actor` class. | ||
|
@@ -133,7 +133,10 @@ def _mapper_changed(self, old, new): | |
self.set_lut(old.lookup_table) | ||
# Setup the inputs to the mapper. | ||
if (len(self.inputs) > 0) and (len(self.inputs[0].outputs) > 0): | ||
new.input = self.inputs[0].outputs[0] | ||
if self.inputs[0].has_output_port(): | ||
new.input_connection = self.inputs[0].get_output_object() | ||
else: | ||
new.input = self.inputs[0].outputs[0] | ||
# Setup the actor's mapper. | ||
actor = self.actor | ||
if actor is not None: | ||
|
@@ -191,8 +194,12 @@ def _can_object_give_image_data(self, source): | |
|
||
def _change_texture_input(self): | ||
if self._can_object_give_image_data(self.texture_source_object): | ||
img_data = self.texture_source_object.outputs[0] | ||
self.texture.input = img_data | ||
if self.texture_source_object.has_output_port(): | ||
output_port = self.texture_source_object.get_output_object() | ||
self.texture.input_connection = output_port | ||
else: | ||
img_data = self.texture_source_object.outputs[0] | ||
self.texture.input = img_data | ||
self.actor.texture = self.texture | ||
else: | ||
self.texture_source_object = None | ||
|
@@ -211,11 +218,13 @@ def _texture_source_object_changed(self,old,new): | |
else: | ||
self.actor.texture = None | ||
self.texture.input = None | ||
self.texture.input_connection = None | ||
|
||
def _texture_changed(self,value): | ||
# Setup the actor's texture. | ||
actor = self.actor | ||
if actor is not None and value.input is not None: | ||
if actor is not None and (value.input is not None | ||
or value.input_connection is not None): | ||
actor.texture = value | ||
self.texture.on_trait_change(self.render) | ||
|
||
|
@@ -226,21 +235,32 @@ def _tcoord_generator_mode_changed(self, value): | |
if (len(inp) == 0) or \ | ||
(len(inp[0].outputs) == 0): | ||
return | ||
input = inp[0].outputs[0] | ||
old_tg = self.tcoord_generator | ||
if old_tg is not None: | ||
old_tg.on_trait_change(self.render, remove=True) | ||
if value == 'none': | ||
self.tcoord_generator = None | ||
self.mapper.input = input | ||
if inp[0].has_output_port(): | ||
self.mapper.input_connection = inp[0].get_output_object() | ||
else: | ||
if is_old_pipeline(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? The logic for this seems rather complex. Can't this block be wrapped into one reusable function which takes care of setting the input/input_connection from the appropriate output depending on the object being given? i.e. something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will look into relevant similar pieces of code and refactor them. Kept these as is, as would refactor these only after mayavi module is also updated for VTK 6, so that the refactor is once and for all. |
||
self.mapper.input = inp[0].get_output_object() | ||
else: | ||
self.mapper.set_input_data(inp[0].get_output_object()) | ||
else: | ||
tg_dict = {'cylinder': tvtk.TextureMapToCylinder, | ||
'sphere': tvtk.TextureMapToSphere, | ||
'plane': tvtk.TextureMapToPlane} | ||
tg = tg_dict[value]() | ||
self.tcoord_generator = tg | ||
tg.input = input | ||
self.mapper.input = tg.output | ||
if inp[0].has_output_port(): | ||
tg.input_connection = inp[0].get_output_object() | ||
else: | ||
tg.input = inp[0].get_output_object() | ||
if inp[0].has_output_port(): | ||
self.mapper.input_connection = inp[0].get_output_object() | ||
else: | ||
self.mapper.input = inp[0].get_output_object() | ||
tg = self.tcoord_generator | ||
if tg is not None: | ||
tg.on_trait_change(self.render) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
# Local imports. | ||
from mayavi.core.component import Component | ||
from mayavi.core.common import error | ||
from mayavi.core.common import error, is_old_pipeline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
from mayavi.components.common \ | ||
import get_module_source, convert_to_poly_data | ||
|
||
|
@@ -189,6 +189,14 @@ def update_data(self): | |
# Propagage the data changed event. | ||
self.data_changed = True | ||
|
||
def has_output_port(self): | ||
""" The contour filter has an output port.""" | ||
return True | ||
|
||
def get_output_object(self): | ||
""" Returns the output port.""" | ||
return self.contour_filter.output_port | ||
|
||
###################################################################### | ||
# Non-public methods. | ||
###################################################################### | ||
|
@@ -297,7 +305,18 @@ def _set_contour_input(self): | |
cf = self.contour_filter | ||
if self.filled_contours: | ||
inp = convert_to_poly_data(inp) | ||
cf.input = inp | ||
if is_old_pipeline(): | ||
cf.input = inp | ||
else: | ||
cf.set_input_data(inp) | ||
else: | ||
if self.inputs[0].has_output_port(): | ||
cf.input_connection = self.inputs[0].get_output_object() | ||
else: | ||
if is_old_pipeline(): | ||
cf.input = self.inputs[0].get_output_object() | ||
else: | ||
cf.set_input_data(self.inputs[0].outputs[0]) | ||
cf.update() | ||
return cf | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,10 @@ def update_pipeline(self): | |
error(msg) | ||
raise TypeError, msg | ||
|
||
plane.input = input | ||
if self.inputs[0].has_output_port(): | ||
plane.input_connection = self.inputs[0].get_output_object() | ||
else: | ||
plane.input = self.inputs[0].get_output_object() | ||
self.plane = plane | ||
self._update_limits() | ||
self._update_voi() | ||
|
@@ -143,6 +146,54 @@ def update_data(self): | |
# Propagate the data_changed event. | ||
self.data_changed = True | ||
|
||
def has_output_port(self): | ||
""" The contour filter has an output port.""" | ||
return True | ||
|
||
def get_output_object(self): | ||
""" Returns the output port.""" | ||
return self.plane.output_port | ||
|
||
###################################################################### | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these relevant for the custom_grid_plane? This seems to be incorrect. I mean all the additions below this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these are incorrect. (BAD: these most likely ended up when I did copy/paste from contour vim buffer). Reverting. |
||
# Non-public methods. | ||
###################################################################### | ||
def _contours_items_changed(self, list_event): | ||
if self.auto_contours or not self._has_input(): | ||
return | ||
cf = self.contour_filter | ||
added, removed, index = (list_event.added, list_event.removed, | ||
list_event.index) | ||
if len(added) == len(removed): | ||
cf.set_value(index, added[0]) | ||
cf.update() | ||
self.data_changed = True | ||
else: | ||
self._contours_changed(self.contours) | ||
|
||
def _contours_changed(self, values): | ||
if self.auto_contours or not self._has_input(): | ||
return | ||
cf = self.contour_filter | ||
cf.number_of_contours = len(values) | ||
for i, x in enumerate(values): | ||
cf.set_value(i, x) | ||
cf.update() | ||
self.data_changed = True | ||
|
||
def _update_ranges(self): | ||
# Here we get the module's source since the input of this | ||
# component may not in general represent the entire object. | ||
if not self.auto_update_range: | ||
return | ||
src = get_module_source(self.inputs[0]) | ||
sc = src.outputs[0].point_data.scalars | ||
if sc is not None: | ||
sc_array = sc.to_array() | ||
has_nan = numpy.isnan(sc_array).any() | ||
if has_nan: | ||
rng = (float(numpy.nanmin(sc_array)), | ||
float(numpy.nanmax(sc_array))) | ||
|
||
###################################################################### | ||
# Non-public methods. | ||
###################################################################### | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
# Local imports. | ||
from mayavi.core.component import Component | ||
from mayavi.core.common import is_old_pipeline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
|
||
|
||
###################################################################### | ||
|
@@ -50,7 +51,13 @@ def update_pipeline(self): | |
if (len(self.inputs) == 0) or (len(self.inputs[0].outputs) == 0): | ||
return | ||
c = self.cutter | ||
c.input = self.inputs[0].outputs[0] | ||
if self.inputs[0].has_output_port(): | ||
c.input_connection = self.inputs[0].get_output_object() | ||
else: | ||
if is_old_pipeline(): | ||
c.input = self.inputs[0].get_output_object() | ||
else: | ||
c.set_input_data(self.inputs[0].get_output_object()) | ||
self.outputs = [c.output] | ||
|
||
def update_data(self): | ||
|
@@ -62,6 +69,14 @@ def update_data(self): | |
""" | ||
self.data_changed = True | ||
|
||
def has_output_port(self): | ||
""" The contour filter has an output port.""" | ||
return True | ||
|
||
def get_output_object(self): | ||
""" Returns the output port.""" | ||
return self.cutter.output_port | ||
|
||
###################################################################### | ||
# `Cutter` interface | ||
###################################################################### | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
from mayavi.core.component import Component | ||
from mayavi.core.module import Module | ||
from mayavi.components import glyph_source | ||
from mayavi.core.common import is_old_pipeline | ||
|
||
|
||
###################################################################### | ||
|
@@ -209,14 +210,28 @@ def stop(self): | |
self.glyph_source.stop() | ||
super(Glyph, self).stop() | ||
|
||
def has_output_port(self): | ||
""" The filter has an output port.""" | ||
return True | ||
|
||
def get_output_object(self): | ||
""" Returns the output port.""" | ||
return self.glyph.output_port | ||
|
||
###################################################################### | ||
# Non-public methods. | ||
###################################################################### | ||
def _update_source(self): | ||
self.glyph.source = self.glyph_source.outputs[0] | ||
if is_old_pipeline(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
self.glyph.source = self.glyph_source.outputs[0] | ||
else: | ||
self.glyph.set_source_data(self.glyph_source.outputs[0]) | ||
|
||
def _glyph_source_changed(self, value): | ||
self.glyph.source = value.outputs[0] | ||
if is_old_pipeline(): | ||
self.glyph.source = value.outputs[0] | ||
else: | ||
self.glyph.set_source_data(value.outputs[0]) | ||
|
||
def _color_mode_changed(self, value): | ||
if len(self.inputs) == 0: | ||
|
@@ -261,10 +276,23 @@ def _mask_input_points_changed(self, value): | |
return | ||
if value: | ||
mask = self.mask_points | ||
mask.input = inputs[0].outputs[0] | ||
self.glyph.input = mask.output | ||
if is_old_pipeline(): | ||
mask.input = inputs[0].outputs[0] | ||
self.glyph.input = mask.output | ||
else: | ||
if inputs[0].has_output_port(): | ||
mask.input_connection = inputs[0].get_output_object() | ||
else: | ||
mask.input = inputs[0].outputs[0] | ||
self.glyph.input_connection = mask.output_port | ||
else: | ||
self.glyph.input = inputs[0].outputs[0] | ||
if is_old_pipeline(): | ||
self.glyph.input = inputs[0].outputs[0] | ||
else: | ||
if inputs[0].has_output_port(): | ||
self.glyph.input_connection = inputs[0].get_output_object() | ||
else: | ||
self.glyph.input = inputs[0].get_output_object() | ||
|
||
def _glyph_type_changed(self, value): | ||
if self.glyph_type == 'vector': | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work with older pipelines? vtk-5.10.1 or 5.6 should work I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this will work with vtk 5.10.1 and 5.6.