def test_polydata_lines(): colors = np.array([[1, 0, 0], [0, 0, 1.]]) line_1 = np.array([[0, 0, 0], [2, 2, 2], [3, 3, 3.]]) line_2 = line_1 + np.array([0.5, 0., 0.]) lines = [line_1, line_2] pd_lines, is_cmap = utils.lines_to_vtk_polydata(lines, colors) res_lines = utils.get_polydata_lines(pd_lines) npt.assert_array_equal(lines, res_lines) npt.assert_equal(is_cmap, False) res_colors = utils.get_polydata_colors(pd_lines) res_colors = np.unique(res_colors, axis=0) / 255 npt.assert_array_equal(colors, np.flipud(res_colors)) npt.assert_equal(utils.get_polydata_colors(vtk.vtkPolyData()), None)
def test_polydata_polygon(interactive=False): # Create a cube my_triangles = np.array([[0, 6, 4], [0, 2, 6], [0, 3, 2], [0, 1, 3], [2, 7, 6], [2, 3, 7], [4, 6, 7], [4, 7, 5], [0, 4, 5], [0, 5, 1], [1, 5, 7], [1, 7, 3]], dtype='i8') my_vertices = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 1.0, 1.0]]) colors = my_vertices * 255 my_polydata = vtk.vtkPolyData() utils.set_polydata_vertices(my_polydata, my_vertices) utils.set_polydata_triangles(my_polydata, my_triangles) npt.assert_equal(len(my_vertices), my_polydata.GetNumberOfPoints()) npt.assert_equal(len(my_triangles), my_polydata.GetNumberOfCells()) npt.assert_equal(utils.get_polydata_normals(my_polydata), None) res_triangles = utils.get_polydata_triangles(my_polydata) res_vertices = utils.get_polydata_vertices(my_polydata) npt.assert_array_equal(my_vertices, res_vertices) npt.assert_array_equal(my_triangles, res_triangles) utils.set_polydata_colors(my_polydata, colors) npt.assert_equal(utils.get_polydata_colors(my_polydata), colors) utils.update_polydata_normals(my_polydata) normals = utils.get_polydata_normals(my_polydata) npt.assert_equal(len(normals), len(my_vertices)) mapper = utils.get_polymapper_from_polydata(my_polydata) actor1 = utils.get_actor_from_polymapper(mapper) actor2 = utils.get_actor_from_polydata(my_polydata) scene = window.Scene() for actor in [actor1, actor2]: scene.add(actor) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr) npt.assert_equal(report.objects, 1)
[3, 5, 7]], dtype='i8') #good utils.set_polydata_vertices(my_polydata, my_vertices) utils.set_polydata_triangles(my_polydata, my_triangles) file_name = "my_star2D.vtk" save_polydata(my_polydata, file_name) print("Surface saved in " + file_name) star_polydata = load_polydata(file_name) star_vertices = utils.get_polydata_vertices(star_polydata) colors = star_vertices * 255 utils.set_polydata_colors(star_polydata, colors) print("new surface colors") print(utils.get_polydata_colors(star_polydata)) # get vtkActor star_actor = utils.get_actor_from_polydata(star_polydata) star_actor.GetProperty().BackfaceCullingOff() # Create a scene scene = window.Scene() scene.add(star_actor) scene.set_camera(position=(0, 0, 7), focal_point=(0, 0, 0)) scene.zoom(3) # display # window.show(scene, size=(1000, 1000), reset_camera=False) this allows the picture to be moved around window.record(scene, out_path='star2D.png', size=(600, 600))
print("Surface saved in " + file_name) ############################################################################### # Load the ``vtkPolyData`` cube_polydata = io_vtk.load_polydata(file_name) ############################################################################### # add color based on vertices position cube_vertices = ut_vtk.get_polydata_vertices(cube_polydata) colors = cube_vertices * 255 ut_vtk.set_polydata_colors(cube_polydata, colors) print("new surface colors") print(ut_vtk.get_polydata_colors(cube_polydata)) ############################################################################### # Visualize surfaces # get vtkActor cube_actor = ut_vtk.get_actor_from_polydata(cube_polydata) # renderer and scene renderer = window.Renderer() renderer.add(cube_actor) renderer.set_camera(position=(10, 5, 7), focal_point=(0.5, 0.5, 0.5)) renderer.zoom(3) # display # window.show(renderer, size=(600, 600), reset_camera=False)
], dtype='i8') utils.set_polydata_vertices(my_polydata, my_vertices) utils.set_polydata_triangles(my_polydata, my_triangles) file_name = "my_rhombicube.vtk" save_polydata(my_polydata, file_name) print("Surface saved in " + file_name) rhombicube_polydata = load_polydata(file_name) rhombicube_vertices = utils.get_polydata_vertices(rhombicube_polydata) colors = rhombicube_vertices * 255 utils.set_polydata_colors(rhombicube_polydata, colors) print("new surface colors") print(utils.get_polydata_colors(rhombicube_polydata)) # get vtkActor rhombicube_actor = utils.get_actor_from_polydata(rhombicube_polydata) rhombicube_actor.GetProperty().BackfaceCullingOff() #gets rid of the winding order issue (look at later and other algorithms that get rid of winding order) # Create a scene scene = window.Scene() scene.add(rhombicube_actor) scene.set_camera(position=(0, 0, 7), focal_point=(0, 0, 0)) scene.zoom(0) # display window.show(scene, size=(1000, 1000), reset_camera=False) #this allows the picture to be moved around window.record(scene, out_path='rhombicu.png', size=(600, 600))
print("Surface saved in " + file_name) ############################################################################### # Load the ``vtkPolyData`` cube_polydata = load_polydata(file_name) ############################################################################### # add color based on vertices position cube_vertices = utils.get_polydata_vertices(cube_polydata) colors = cube_vertices * 255 utils.set_polydata_colors(cube_polydata, colors) print("new surface colors") print(utils.get_polydata_colors(cube_polydata)) ############################################################################### # Visualize surfaces # get vtkActor cube_actor = utils.get_actor_from_polydata(cube_polydata) # Create a scene scene = window.Scene() scene.add(cube_actor) scene.set_camera(position=(10, 5, 7), focal_point=(0.5, 0.5, 0.5)) scene.zoom(3) # display # window.show(scene, size=(600, 600), reset_camera=False)