示例#1
0
    def test_image_convolve_kernel(self):
        """ Test that setting the kernels in ImageConvolve works
        """
        tvtk_filter = tvtk.ImageConvolve()
        expected = numpy.arange(9.)

        # Since VTK 6.x, ImageConvolve.GetKernel3x3
        # can take either no argument or an array
        # With that change in the API, kernel3x3
        # is a Trait (similarly for kernel3x3x3, ...)
        tvtk_filter.kernel3x3 = expected

        # Get it back
        result = numpy.empty(9)
        tvtk_filter._vtk_obj.GetKernel3x3(result)

        self.assertTrue(numpy.allclose(result, expected), True)

        # The shape is validated by Trait
        with self.assertRaises(TraitError):
            tvtk_filter.kernel3x3 = range(2)
示例#2
0
    def test_image_convolve_kernel(self):
        """ Test that setting the kernels in ImageConvolve works
        """
        tvtk_filter = tvtk.ImageConvolve()
        expected = numpy.arange(9.)

        if vtk_major_version < 6:
            # Before VTK 6, the ImageConvolve.GetKernel3x3
            # requires an array as argument

            # Set the kernel
            tvtk_filter.set_kernel3x3(expected)

            # Get it back
            result = numpy.empty(9)
            tvtk_filter.get_kernel3x3(result)

            self.assertTrue(numpy.allclose(result, expected), True)

            with self.assertRaises(TypeError):
                # VTK Set method raises the TypeError
                tvtk_filter.set_kernel3x3(range(2))

        else:
            # Since VTK 6.x, ImageConvolve.GetKernel3x3
            # can take either no argument or an array
            # With that change in the API, kernel3x3
            # is a Trait (similarly for kernel3x3x3, ...)
            tvtk_filter.kernel3x3 = expected

            # Get it back
            result = numpy.empty(9)
            tvtk_filter._vtk_obj.GetKernel3x3(result)

            self.assertTrue(numpy.allclose(result, expected), True)

            # The shape is validated by Trait
            with self.assertRaises(TraitError):
                tvtk_filter.kernel3x3 = range(2)