def timer_callback(_obj, _event): global apply_force, fpss cnt = next(counter) showm.render() if cnt % 1 == 0: fps = scene.frame_rate fpss = np.append(fpss, fps) tb.message = "Avg. FPS: " + str(np.round(np.mean(fpss), 0)) + \ "\nSim Steps: " + str(cnt) # Get the position and orientation of the first domino. domino1_pos, domino1_orn = p.getBasePositionAndOrientation(dominos[0]) # Apply force on the First Domino (domino) above the Center of Mass. if apply_force: # Apply the force. p.applyExternalForce(dominos[0], -1, forceObj=[100, 0, 0], posObj=domino1_pos + np.array([0, 0, 1.7]), flags=p.WORLD_FRAME) apply_force = False # Updating the position and orientation of individual dominos. for idx, domino in enumerate(dominos): sync_domino(idx, domino) utils.update_actor(domino_actor) # Simulate a step. p.stepSimulation() # Exit after 300 steps of simulation. if cnt == 300: showm.exit()
def timer_callback(_obj, _event): global pts, time, incre_time, coor_1 time += incre_time cnt = next(counter) x = initial_velocity*time + 0.5*acc*(time**2) y = np.sin(10*angular_frq*time + phase_angle) z = np.cos(10*angular_frq*time + phase_angle) pts = np.array([[x, y, z]]) vertices[:] = initial_vertices + \ np.repeat(pts, no_vertices_per_point, axis=0) utils.update_actor(charge_actor) # Plotting the path followed by the particle coor_2 = np.array([x, y, z]) coors = np.array([coor_1, coor_2]) coors = [coors] line_actor = actor.line(coors, window.colors.cyan, linewidth=3) scene.add(line_actor) coor_1 = coor_2 showm.render() # to end the animation if cnt == end: showm.exit()
def _timer(_obj, _event): nonlocal counter, framesPerSecond counter += 1 framesPerSecond.append(scene.frame_rate) centers_geometry[:] = np.repeat(positions, centers_length, axis=0) verts_geometry[:] = verts_geometryOrig + centers_geometry edges_positions = vtknp.vtk_to_numpy( lines_actor.GetMapper().GetInput().GetPoints().GetData()) edges_positions[::2] = positions[edges_list[:, 0]] edges_positions[1::2] = positions[edges_list[:, 1]] lines_actor.GetMapper().GetInput().GetPoints().GetData().Modified() lines_actor.GetMapper().GetInput().ComputeBounds() vtk_verts_geometry.Modified() vtk_centers_geometry.Modified() update_actor(nodes_actor) if (selected_node is not None): selected_actor.SetPosition(positions[selected_node]) nodes_actor.GetMapper().GetInput().GetPoints().GetData().Modified() nodes_actor.GetMapper().GetInput().ComputeBounds() selected_actor.GetMapper().GetInput().ComputeBounds() selected_actor.GetMapper().GetInput().GetPoints().GetData().Modified() showm.scene.ResetCameraClippingRange() showm.render() if counter >= max_iterations: showm.exit()
def timer_callback(_obj, _event): cnt = next(counter) global t, fpss showm.render() t += 1. / freq_sim if cnt % 1 == 0: fps = showm.frame_rate fpss = np.append(fpss, fps) tb.message = "Avg. FPS: " + str(np.round(np.mean(fpss), 0)) + \ "\nSim Steps: " + str(cnt) # some trajectory ux = amplitude_x * np.sin(2 * np.pi * freq * t) uy = amplitude_y * np.cos(2 * np.pi * freq * t) # move base around pivot = [3 * ux, uy, 2] orn = p.getQuaternionFromEuler([0, 0, 0]) p.changeConstraint(root_robe_c, pivot, jointChildFrameOrientation=orn, maxForce=500) # Sync base and chain. sync_actor(base_actor, rope) sync_joints(rope_actor, rope) utils.update_actor(rope_actor) # Simulate a step. p.stepSimulation() # Exit after 2000 steps of simulation. if cnt == 130: showm.exit()
def _timer(_obj, _event): nonlocal counter, pos counter += 1 if mode == 0: iterate(1) else: pos[:] += (np.random.random(pos.shape) - 0.5) * 1.5 spheres_positions = vertices_from_actor(sphere_actor) spheres_positions[:] = sphere_geometry + \ np.repeat(pos, geometry_length, axis=0) edges_positions = vertices_from_actor(lines_actor) edges_positions[::2] = pos[edges_list[:, 0]] edges_positions[1::2] = pos[edges_list[:, 1]] update_actor(lines_actor) compute_bounds(lines_actor) update_actor(sphere_actor) compute_bounds(lines_actor) showm.scene.reset_clipping_range() showm.render() if counter >= max_iterations: showm.exit()
def update_path(act, counter_step): if counter_step < act.num_total_steps: x, y, z = act.position[counter_step - 1] x += norm.rvs(scale=act.delta**2 * act.time_step) y += norm.rvs(scale=act.delta**2 * act.time_step) z += norm.rvs(scale=act.delta**2 * act.time_step) act.position[counter_step:] = [x, y, z] act.vertices[:] = act.initial_vertices + \ np.repeat(act.position, act.no_vertices_per_point, axis=0) utils.update_actor(act)
def update_path(self, counter_step): if counter_step < self.num_total_steps: x, y, z = self.position[counter_step - 1] x += norm.rvs(scale=self.delta**2 * self.time_step) y += norm.rvs(scale=self.delta**2 * self.time_step) z += norm.rvs(scale=self.delta**2 * self.time_step) self.position[counter_step:] = [x, y, z] self.vertices[:] = self.initial_vertices + \ np.repeat(self.position, self.no_vertices_per_point, axis=0) utils.update_actor(self.path_actor)
def timer_callback(_obj, _event): global xyz cnt = next(counter) tb.message = "Let's count up to 1000 and exit :" + str(cnt) xyz = xyz + vel * dt collision() vertices[:] = initial_vertices + \ np.repeat(xyz, no_vertices_per_sphere, axis=0) utils.update_actor(sphere_actor) scene.reset_clipping_range() showm.render() if cnt == steps: showm.exit()
def left_click_callback(obj, event): # Get the event position on display and pick event_pos = pickm.event_position(showm.iren) picked_info = pickm.pick(event_pos, showm.scene) vertex_index = picked_info['vertex'] # Calculate the objects index object_index = np.int(np.floor((vertex_index / num_vertices) * num_objects)) # Find how many vertices correspond to each object sec = np.int(num_vertices / num_objects) if not selected[object_index]: scale = 6/5 color_add = np.array([30, 30, 30], dtype='uint8') selected[object_index] = True else: scale = 5/6 color_add = np.array([-30, -30, -30], dtype='uint8') selected[object_index] = False # Update vertices positions vertices[object_index * sec: object_index * sec + sec] = scale * \ (vertices[object_index * sec: object_index * sec + sec] - centers[object_index]) + centers[object_index] # Update colors vcolors[object_index * sec: object_index * sec + sec] += color_add # Tell actor that memory is modified utils.update_actor(fury_actor) face_index = picked_info['face'] # Show some info text = 'Object ' + str(object_index) + '\n' text += 'Vertex ID ' + str(vertex_index) + '\n' text += 'Face ID ' + str(face_index) + '\n' text += 'World pos ' + str(np.round(picked_info['xyz'], 2)) + '\n' text += 'Actor ID ' + str(id(picked_info['actor'])) text_block.message = text showm.render()
def timer_callback(_obj, _event): global xyz, time time += dt cnt = next(counter) # updating the colors and vertices of the triangles used to form the # surfaces for surf in surfaces: xyz, colors = update_surface(x, y, equation=surf.equation, cmap_name=surf.cmap_name) utils.update_surface_actor_colors(surf, colors) surf.vertices[:] = surf.initial_vertices + \ np.repeat(xyz, surf.no_vertices_per_point, axis=0) utils.update_actor(surf) showm.render() # to end the animation if cnt == end: showm.exit()
def timer_callback(_obj, _event): global verts3D, angle cnt = next(counter) verts3D = rotate4D(verts4D) if not wireframe: point_verts[:] = initial_verts + \ np.repeat(verts3D, no_vertices, axis=0) utils.update_actor(points) lines = connect_points(verts3D) lines_verts[:] = initial_lines + \ np.reshape(lines, (-1, 3)) utils.update_actor(edges) showm.render() angle += dtheta if cnt == end: showm.exit()
def hover_callback(_obj, _event): event_pos = selm.event_position(showm.iren) # updates rectangular box around mouse texa.SetPosition(event_pos[0] - 200 // 2, event_pos[1] - 100 // 2) # defines selection region and returns information from selected objects info = selm.select(event_pos, showm.scene, (200 // 2, 100 // 2)) for node in info.keys(): if info[node]['face'] is not None: if info[node]['actor'] is cube_actor: for face_index in info[node]['face']: # generates an object_index to help with coloring # by dividing by the number of faces of each cube (6 * 2) object_index = face_index // 12 sec = int(num_vertices / num_objects) color_change = np.array([150, 0, 0, 255], dtype='uint8') vcolors[object_index * sec: object_index * sec + sec] \ = color_change utils.update_actor(cube_actor) showm.render()
def timer_callback(_obj, _event): global pts, pts2, time, time_incre, angular_frq, phase_angle, wavenumber time += incre_time cnt = next(counter) x, y, z = update_coordinates(wavenumber, angular_frq, phase_angle, time) pts = np.array([(a, b, c) for (a, b, c) in zip(x, y, z)]) vertices[:] = initial_vertices + \ np.repeat(pts, no_vertices_per_point, axis=0) utils.update_actor(wave_actor1) xx, zz, yy = update_coordinates(wavenumber, angular_frq, phase_angle, time) pts2 = np.array([(a, b, c) for (a, b, c) in zip(xx, yy, zz)]) vertices2[:] = initial_vertices2 + \ np.repeat(pts2, no_vertices_per_point2, axis=0) utils.update_actor(wave_actor2) showm.render() # to end the animation if cnt == end: showm.exit()
def timer_callback(_obj, _event): global apply_force, fpss cnt = next(counter) showm.render() if cnt % 1 == 0: fps = scene.frame_rate fpss = np.append(fpss, fps) tb.message = "Avg. FPS: " + str(np.round(np.mean(fpss), 0)) + \ "\nSim Steps: " + str(cnt) # Get the position and orientation of the ball. ball_pos, ball_orn = p.getBasePositionAndOrientation(ball) # Apply force for 5 times for the first step of simulation. if apply_force: # Apply the force. p.applyExternalForce(ball, -1, forceObj=[-10000, 0, 0], posObj=ball_pos, flags=p.WORLD_FRAME) apply_force = False # Set position and orientation of the ball. sync_actor(ball_actor, ball) # Updating the position and orientation of each individual brick. for idx, brick in enumerate(bricks): sync_brick(idx, brick) utils.update_actor(brick_actor) # Simulate a step. p.stepSimulation() # Exit after 2000 steps of simulation. if cnt == 130: showm.exit()
def timer_callback(_obj, _event): global apply_force, fpss cnt = next(counter) showm.render() if cnt % 1 == 0: fps = showm.frame_rate fpss = np.append(fpss, fps) tb.message = "Avg. FPS: " + str(np.round(np.mean(fpss), 0)) + \ "\nSim Steps: " + str(cnt) # Updating the position and orientation of each individual brick. for idx, brick in enumerate(bricks): sync_brick(idx, brick) pos, _ = p.getBasePositionAndOrientation(rope) if apply_force: p.applyExternalForce(rope, -1, forceObj=[-500, 0, 0], posObj=pos, flags=p.WORLD_FRAME) apply_force = False pos = p.getLinkState(rope, p.getNumJoints(rope) - 1)[4] ball_actor.SetPosition(*pos) sync_chain(rope_actor, rope) utils.update_actor(brick_actor) utils.update_actor(rope_actor) # Simulate a step. p.stepSimulation() if cnt == 130: showm.exit()
def test_update_actor(): size = (15, 15) test_bounds = [0.0, 15, 0.0, 15, 0.0, 0.0] points = vtk.vtkPoints() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(size[0], 0, 0) points.InsertNextPoint(size[0], size[1], 0) points.InsertNextPoint(0, size[1], 0) # Create the polygon polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(4) # make a quad polygon.GetPointIds().SetId(0, 0) polygon.GetPointIds().SetId(1, 1) polygon.GetPointIds().SetId(2, 2) polygon.GetPointIds().SetId(3, 3) # Add the polygon to a list of polygons polygons = vtk.vtkCellArray() polygons.InsertNextCell(polygon) # Create a PolyData polygonPolyData = vtk.vtkPolyData() polygonPolyData.SetPoints(points) polygonPolyData.SetPolys(polygons) # Create a mapper and actor mapper = vtk.vtkPolyDataMapper2D() mapper = set_input(mapper, polygonPolyData) actor = vtk.vtkActor2D() actor.SetMapper(mapper) compute_bounds(actor) npt.assert_equal(actor.GetMapper().GetInput().GetBounds(), test_bounds) updated_size = (35, 35) points.SetPoint(0, 0, 0, 0.0) points.SetPoint(1, updated_size[0], 0, 0.0) points.SetPoint(2, updated_size[0], updated_size[1], 0.0) points.SetPoint(3, 0, updated_size[1], 0.0) polygonPolyData.SetPoints(points) test_bounds = [0.0, 35.0, 0.0, 35.0, 0.0, 0.0] compute_bounds(actor) npt.assert_equal(None, update_actor(actor)) npt.assert_equal(test_bounds, actor.GetMapper().GetInput().GetBounds())
def update_colors(color_array): for _, figure in figure_dict.items(): vcolors = utils.colors_from_actor(figure) vcolors[:] = color_array utils.update_actor(figure)
def toggle_color(radio): vcolors = utils.colors_from_actor(sphere) color = options[radio.checked_labels[0]] vcolors[:] = np.array(color) utils.update_actor(sphere)
def update_track(positions_planet, planet_track, planet_orbit_actor): positions_planet[:] = np.array(planet_track) utils.update_actor(planet_orbit_actor)