def test_save_and_load_polydata(): l_ext = ["vtk", "fib", "ply", "xml"] fname = "temp-io" for ext in l_ext: with InTemporaryDirectory() as odir: data = np.random.randint(0, 255, size=(50, 3)) pd = vtk.vtkPolyData() pd.SetPoints(numpy_to_vtk_points(data)) fname_path = pjoin(odir, "{0}.{1}".format(fname, ext)) save_polydata(pd, fname_path) npt.assert_equal(os.path.isfile(fname_path), True) assert_greater(os.stat(fname_path).st_size, 0) out_pd = load_polydata(fname_path) out_data = numpy_support.vtk_to_numpy(out_pd.GetPoints().GetData()) npt.assert_array_equal(data, out_data) npt.assert_raises(IOError, save_polydata, vtk.vtkPolyData(), "test.vti") npt.assert_raises(IOError, save_polydata, vtk.vtkPolyData(), "test.obj") npt.assert_raises(IOError, load_polydata, "test.vti")
def test_save_and_load_options(): l_ext = ["ply", "vtk"] l_options = [{ 'color_array_name': 'horizon', }, { 'binary': True, }] fname = "temp-io" for ext, option in zip(l_ext, l_options): with InTemporaryDirectory() as odir: data = np.random.randint(0, 255, size=(50, 3)) pd = vtk.vtkPolyData() pd.SetPoints(numpy_to_vtk_points(data)) fname_path = pjoin(odir, "{0}.{1}".format(fname, ext)) save_polydata(pd, fname_path, **option) npt.assert_equal(os.path.isfile(fname_path), True) assert_greater(os.stat(fname_path).st_size, 0) out_pd = load_polydata(fname_path) out_data = numpy_support.vtk_to_numpy(out_pd.GetPoints().GetData()) npt.assert_array_equal(data, out_data) l_ext = ["stl", "obj"] l_options = [{}, { 'is_mni_obj': True, }] for ext, option in zip(l_ext, l_options): with InTemporaryDirectory() as odir: data = np.random.randint(0, 255, size=(50, 3)) pd = vtk.vtkPolyData() pd.SetPoints(numpy_to_vtk_points(data)) fname_path = pjoin(odir, "{0}.{1}".format(fname, ext)) save_polydata(pd, fname_path, **option) npt.assert_equal(os.path.isfile(fname_path), True) assert_greater(os.stat(fname_path).st_size, 0)
def select(self, disp_xy, sc, area=0): """ Select multiple objects using display coordinates Parameters ---------- disp_xy : tuple Display coordinates x, y. sc : Scene area : int or 2d tuple of ints Selection area around x, y coords. """ info_plus = {} self.hsel.SetRenderer(sc) if isinstance(area, int): picking_area = area, area else: picking_area = area try: self.hsel.SetArea(disp_xy[0] - picking_area[0], disp_xy[1] - picking_area[1], disp_xy[0] + picking_area[0], disp_xy[1] + picking_area[1]) res = self.hsel.Select() except OverflowError: return { 0: { 'node': None, 'vertex': None, 'face': None, 'actor': None } } num_nodes = res.GetNumberOfNodes() if num_nodes < 1: sel_node = None return { 0: { 'node': None, 'vertex': None, 'face': None, 'actor': None } } else: for i in range(num_nodes): sel_node = res.GetNode(i) info = { 'node': None, 'vertex': None, 'face': None, 'actor': None } if sel_node is not None: selected_nodes = set( np.floor( numpy_support.vtk_to_numpy( sel_node.GetSelectionList())).astype(int)) info['node'] = sel_node info['actor'] = \ sel_node.GetProperties().Get(sel_node.PROP()) if self.selected_type == 'faces': info['face'] = list(selected_nodes) if self.selected_type == 'vertex': info['vertex'] = list(selected_nodes) info_plus[i] = info return info_plus