Skip to content

Commit

Permalink
Merge pull request #220 from dmsurti/fix-mask-input-points
Browse files Browse the repository at this point in the history
Fixes #165: Fix Glyph to handle masking of input points
  • Loading branch information
prabhuramachandran committed Jul 23, 2015
2 parents eebd33e + fd5254a commit 5110feb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mayavi/components/glyph.py
Expand Up @@ -271,8 +271,10 @@ def _mask_input_points_changed(self, value):
if value:
mask = self.mask_points
tvtk_common.configure_input(mask, inputs[0].outputs[0])
self.configure_connection(self.glyph, mask)
else:
self.configure_connection(self.glyph, inputs[0])
self.glyph.update()

def _glyph_type_changed(self, value):
if self.glyph_type == 'vector':
Expand Down
42 changes: 37 additions & 5 deletions mayavi/tests/test_glyph.py
Expand Up @@ -64,6 +64,7 @@ def setUp(self):
g.glyph.glyph_source.glyph_position = 'center'
g.glyph.glyph.vector_mode = 'use_normal'
g.glyph.glyph.scale_factor = 0.5
g.glyph.mask_points.on_ratio = 20
g.actor.property.line_width = 1.0

v = VectorCutPlane()
Expand Down Expand Up @@ -91,16 +92,30 @@ def tearDown(self):
self.e.stop()
return

def check(self):
"""Do the actual testing."""

s=self.scene
def check(self, mask=False, mask_random_mode=False):
"""Do the actual testing with and without masking. For masking,
both the presence and absence of random mode is also tested.
"""
s = self.scene
src = s.children[0]
g = src.children[0].children[1]
self.assertEqual(g.glyph.glyph_source.glyph_position,'center')
self.assertEqual(g.glyph.glyph.vector_mode,'use_normal')
self.assertEqual(g.glyph.glyph.scale_factor,0.5)
self.assertEqual(g.actor.property.line_width,1.0)
# Test masking
n_output_points = src.outputs[0].number_of_points
n_glyph_input_points = g.glyph.glyph.input.number_of_points
if mask:
self.assertNotEqual(n_glyph_input_points , 0)
if mask_random_mode:
self.assertLessEqual(n_glyph_input_points , n_output_points)
else:
on_ratio = g.glyph.mask_points.on_ratio
self.assertEqual(n_glyph_input_points,
n_output_points / on_ratio)
else:
self.assertEqual(n_glyph_input_points, n_output_points)

v = src.children[0].children[2]
glyph = v.glyph
Expand All @@ -118,11 +133,28 @@ def check(self):
self.assertEqual(numpy.allclose(v.implicit_plane.normal,
(0., 1., 0.)),True)


def test_glyph(self):
"Test if the test fixture works"
self.check()

def test_mask_input_points_with_random_mode(self):
"""Test if masking input points works with random mode.
Tests Issue #165"""
s = self.scene
src = s.children[0]
g = src.children[0].children[1]
g.glyph.mask_input_points = True
self.check(mask=True, mask_random_mode=True)

def test_mask_input_points_without_random_mode(self):
"""Test if masking input points works without random mode.
Tests Issue #165"""
s = self.scene
src = s.children[0]
g = src.children[0].children[1]
g.glyph.mask_points.random_mode = 0
g.glyph.mask_input_points = True
self.check(mask=True)

def test_components_changed(self):
""""Test if the modules respond correctly when the components
Expand Down

0 comments on commit 5110feb

Please sign in to comment.