def test_eq(): camera = pyvista.Camera() other = pyvista.Camera() for camera_now in camera, other: for name, value, _ in configuration: setattr(camera_now, name, value) assert camera == other # check that changing anything will break equality for name, value, _ in configuration: original_value = getattr(other, name) if isinstance(value, bool): changed_value = not value elif isinstance(value, (int, float)): changed_value = 0 elif isinstance(value, tuple): changed_value = (0.5, 0.5, 0.5) else: changed_value = -value setattr(other, name, changed_value) assert camera != other setattr(other, name, original_value) # sanity check that we managed to restore the original state assert camera == other
def test_copy(): camera = pyvista.Camera() for name, value, _ in configuration: setattr(camera, name, value) deep = camera.copy() assert deep == camera
def test_camera(): camera = pyvista.Camera() position = np.random.random(3) camera.position = position assert np.all(camera.GetPosition() == position) assert np.all(camera.position == position) focal_point = np.random.random(3) camera.focal_point = focal_point assert np.all(camera.GetFocalPoint() == focal_point) assert np.all(camera.focal_point == focal_point) model_transform_matrix = np.random.random((4, 4)) camera.model_transform_matrix = model_transform_matrix assert np.all(camera.model_transform_matrix == model_transform_matrix) camera.distance == np.linalg.norm(focal_point - position, ord=2) thickness = np.random.random(1) camera.thickness = thickness assert camera.thickness == thickness parallel_scale = np.random.random(1) camera.parallel_scale = parallel_scale assert camera.parallel_scale == parallel_scale value = np.random.random(1) camera.zoom(value) vector = np.random.random(3) camera.up(vector) camera.up() camera.enable_parallel_projection() assert camera.GetParallelProjection() assert camera.is_parallel_projection camera.disable_parallel_projection() assert not camera.GetParallelProjection() assert not camera.is_parallel_projection near_point = np.random.random(1) far_point = near_point + np.random.random(1) points = (near_point, far_point) camera.clipping_range = points assert camera.GetClippingRange() == points assert camera.clipping_range == points with pytest.raises(ValueError): far_point = near_point - np.random.random(1) points = (near_point, far_point) camera.clipping_range = points
tm_vis = pv.make_tri_mesh(shape_model.V, shape_model.F) tm_vis.cell_arrays['vis'] = vis # ... and one with their difference. tm_vis_diff = pv.make_tri_mesh(shape_model.V, shape_model.F) tm_vis_diff.cell_arrays['diff'] = vis_f - vis # The keyword argument "shape=(1, 3)" indicates that we'll have a # row with three columns of subplots. # plotter = pvqt.BackgroundPlotter(window_size=(900, 400), shape=(1, 3)) plotter = pv.Plotter(window_size=(900, 400), shape=(1, 3)) # We want to use the same camera for each plot. We set it up here. V_ptp = shape_model.V.ptp(0) V_mean = shape_model.V.mean(0) camera = pv.Camera() camera.position = V_mean + np.array([0, 0, 2.2 * V_ptp[:2].mean()]) camera.focal_point = V_mean camera.up = np.array([1, 0, 0]) plotter.subplot(0, 0) plotter.add_text(f'From form factor matrix (eps = {eps_f})', font_size=12) plotter.add_mesh(tm_vis_f, lighting=False, cmap=cc.cm.fire) plotter.camera = camera plotter.subplot(0, 1) plotter.add_text(f'Raytracing (eps = {eps})', font_size=12) plotter.add_mesh(tm_vis, lighting=False, cmap=cc.cm.fire) plotter.camera = camera plotter.subplot(0, 2)
def camera(): return pyvista.Camera()
def test_invalid_init(): with pytest.raises(TypeError): pyvista.Camera(1)