def test_warp_by_vector(): # Test when inplace=False (default) data = examples.load_sphere_vectors() warped = data.warp_by_vector() assert data.n_points == warped.n_points assert not np.allclose(data.points, warped.points) warped = data.warp_by_vector(factor=3) assert data.n_points == warped.n_points assert not np.allclose(data.points, warped.points) # Test when inplace=True foo = examples.load_sphere_vectors() warped = foo.warp_by_vector() foo.warp_by_vector(inplace=True) assert np.allclose(foo.points, warped.points)
""" Warping by Vectors ~~~~~~~~~~~~~~~~~~ This example applies the ``warp_by_vector`` filter to a sphere mesh that has 3D displacement vectors defined at each node. """ ############################################################################### # We first compare the unwarped sphere to the warped sphere. import pyvista as pv from pyvista import examples sphere = examples.load_sphere_vectors() warped = sphere.warp_by_vector() p = pv.Plotter(shape=(1, 2)) p.subplot(0, 0) p.add_text("Before warp") p.add_mesh(sphere, color='white') p.subplot(0, 1) p.add_text("After warp") p.add_mesh(warped, color='white') p.show() ############################################################################### # We then use several values for the scale factor applied to the warp # operation. Applying a warping factor that is too high can often lead to # unrealistic results.