def draw_frames(self, ik_index=None): """Returns the frames of the reachability map. Parameters ---------- ik_index : int, optional If passed, returns only the reachable frames at a given IK index. For a 6-axis industrial robot this index reaches from 0 to 7 (8 solutions). Returns ------- list[System.Guid] The GUIDs of the created Rhino objects. """ if ik_index is None: xframes = [] for frames in self.reachability_map.frames: xframes.append([]) for frame in frames: xframes[-1].extend( FrameArtist(frame, layer=self.layer, scale=self.scale).draw()) return xframes else: frames, _ = self.reachability_map.reachable_frames_and_configurations_at_ik_index( ik_index) return [ FrameArtist(f, layer=self.layer, scale=self.scale).draw() for f in frames ]
def draw_interface_frames(self): """Draw the frames of the interfaces. """ layer = "{}::Interfaces::Frames".format( self.layer) if self.layer else None compas_rhino.clear_layer(layer) guids = [] for edge in self.assembly.edges(): interface = self.assembly.edge_attribute(edge, 'interface') artist = FrameArtist(interface.frame, layer=layer) guids += artist.draw() return guids
def draw_edge_rhino(edge): # ============================================================================== # Use a frame artist to visualize the boundary frame. # ============================================================================== artist = FrameArtist(edge['frames'][0], layer=edge['layer'] + "::Frame", scale=0.3) artist.clear_layer() artist.draw() # ============================================================================== # Use a frame artist to visualize the frame of the intersection points. # ============================================================================== artist = FrameArtist(edge['frames'][1], layer=edge['layer'] + "::Frame", scale=0.3) artist.clear_layer() artist.draw() # ============================================================================== # Use a point artist to visualize the intersection points. # ============================================================================== PointArtist.draw_collection(edge['intersections'], layer=edge['layer'] + "::Intersections", clear=True) # ============================================================================== # Use a mesh artist to visualize beams # ============================================================================== artist = MeshArtist(None, layer=edge['layer'] + "::BBox") artist.clear_layer() for mesh in edge['meshes']: artist = MeshArtist(mesh, layer=edge['layer'] + "::BBox") artist.draw_mesh()
from compas.geometry import Transformation from compas.geometry import Box from compas.datastructures import Mesh from compas_rhino.artists import FrameArtist from compas_rhino.artists import MeshArtist # Box in the world coordinate system frame = Frame([1, 0, 0], [-0.45, 0.1, 0.3], [1, 0, 0]) width, length, height = 1, 1, 1 box = Box(frame, width, length, height) # Frame F representing a coordinate system F = Frame([2, 2, 2], [0.978, 0.010, -0.210], [0.090, 0.882, 0.463]) # Get transformation between frames and apply transformation on box. T = Transformation.from_frame_to_frame(Frame.worldXY(), F) box_transformed = box.transformed(T) print("Box frame transformed", box_transformed.frame) # create artists artist1 = FrameArtist(Frame.worldXY()) artist2 = MeshArtist(Mesh.from_shape(box)) artist3 = FrameArtist(F) artist4 = MeshArtist(Mesh.from_shape(box_transformed)) # draw artist1.draw() artist2.draw_faces() artist3.draw() artist4.draw_faces()
from compas_rhino.artists import FrameArtist, PlaneArtist from compas.datastructures import Mesh # Define a Frame, which is not in the origin and a bit tilted to the world frame frame = Frame.from_plane(Plane([20, 40, 60], [0, 1, 1])) p = Plane(Point(0, 0, 0), [0, 0, 1]) d = 1, 0, 1 # Create a Box with that frame box = Box(frame, 10, 15, 20) # Create a Projection (can be orthogonal, parallel or perspective) P = Projection.from_plane_and_direction(p, d) # P = matrix_from_parallel_projection(p, d) # Create a Mesh from the Box mesh = Mesh.from_shape(box) ## Apply the Projection onto the mesh mesh_projected = mesh.transformed(P) # Create artists artist1 = BoxArtist(box) artist2 = MeshArtist(mesh_projected) artist3 = FrameArtist(frame) # Draw artist1.draw() artist2.draw_edges(color="#00ff00") artist3.draw()
axes = [] for joint in joints: frame = joint.origin.transformed(transformations[joint.name]) frame.name = joint.name frames.append(frame) axis = joint.axis.transformed(transformations[joint.name]) axis.name = joint.name axes.append(axis) # Visualization for frame in frames: artist = FrameArtist(frame, scale=0.3, layer="Frames::{}".format(frame.name)) artist.clear_layer() artist.draw() for a, b in pairwise(frames): line = Line(a.point, b.point) artist = LineArtist(line, layer="Links::{}".format(a.name)) artist.draw() tpl = Cylinder(Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 0.05), 0.2) for frame, axis in zip(frames, axes): point = frame.point normal = Vector(axis.x, axis.y, axis.z) plane = Plane(point, normal) frame = Frame.from_plane(plane)
-2, 2, 1)) # parallel projection P5 = Projection.from_plane_and_point(planexy, Point(3, -3, -1)) # perspective Projection # Create a Mesh from the Box mesh = Mesh.from_shape(box) # Apply the Projection onto the mesh mesh_projected3 = mesh.transformed(P3) mesh_projected4 = mesh.transformed(P4) mesh_projected5 = mesh.transformed(P5) # Create artists artist1 = BoxArtist(box) artist2 = FrameArtist(frame) artist3 = MeshArtist(mesh_projected3, layer="P3") artist4 = MeshArtist(mesh_projected4, layer="P4") artist5 = MeshArtist(mesh_projected5, layer="P5") #clear layers artistl = [artist1, artist2, artist3, artist4, artist5] for arty in artistl: arty.clear_layer() # Draw artist1.draw() artist2.draw() artist3.draw_edges(color="#00ffa0") artist4.draw_edges(color=(200, 0, 0)) artist5.draw_edges(color=(200, 100, 0))
bbox = bounding_box_xy(points) bbox = offset_polygon(bbox, -PADDING) bbox = transform_points(bbox, X.inverse()) # ============================================================================== # Convert the box to a mesh for visualisation. # ============================================================================== bbox = Mesh.from_vertices_and_faces(bbox, [[0, 1, 2, 3]]) # ============================================================================== # Use a frame artist to visualize the boundary frame. # ============================================================================== artist = FrameArtist(frame, layer="SOUTH::Frame", scale=0.3) artist.clear_layer() artist.draw() # ============================================================================== # Use a point artist to visualize the intersection points. # ============================================================================== PointArtist.draw_collection(intersections, layer="SOUTH::Intersections", clear=True) # ============================================================================== # Use a frame artist to visualize the frame of the intersection points. # ==============================================================================
frames = [] axes = [] for joint in robot.iter_joints(): frame = joint.origin.transformed(transformations[joint.name]) frame.name = joint.name frames.append(frame) axis = joint.axis.transformed(transformations[joint.name]) axis.name = joint.name axes.append(axis) for frame in frames: artist = FrameArtist(frame, scale=0.3, layer="Frames::{}".format(frame.name)) artist.clear_layer() artist.draw() tpl = Cylinder(Circle(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 0.05), 0.2) for frame, axis in zip(frames, axes): point = frame.point normal = Vector(axis.x, axis.y, axis.z) plane = Plane(point, normal) frame = Frame.from_plane(plane) X = Transformation.from_frame(frame) cylinder = tpl.transformed(X) artist = CylinderArtist(cylinder, layer="Axes::{}".format(axis.name)) artist.clear_layer() artist.draw()
x = Transformation.from_frame_to_frame(frame_1, Frame.worldXY()) points2 = transform_points(points, x) bbox = bounding_box_xy(points2) bbox = offset_polygon(bbox, -PADDING) bbox = transform_points(bbox, x.inverse()) all_vertices.extend(bbox) all_faces.append([i * 4, i * 4 + 1, i * 4 + 2, i * 4 + 3]) bbox = Mesh.from_vertices_and_faces(all_vertices, all_faces) # ============================================================================== # Visualization # ============================================================================== artist = FrameArtist(frame, layer="SOUTH::Frame", scale=0.3) artist.clear_layer() artist.draw() artist = FrameArtist(frame_1, layer="SOUTH::Frame_1", scale=0.3) artist.clear_layer() artist.draw() artist = MeshArtist(bbox, layer="SOUTH::Bbox1") artist.clear_layer() artist.draw_faces(join_faces=True, color=(0, 255, 255)) PointArtist.draw_collection(intersections, layer="SOUTH::intersections", clear=True)
from compas.robots import LocalPackageMeshLoader from compas.robots import RobotModel from compas_rhino.artists import FrameArtist from compas_rhino.artists import RobotModelArtist loader = LocalPackageMeshLoader('models', 'ur_description') model = RobotModel.from_urdf_file(loader.load_urdf('ur5.urdf')) model.load_geometry(loader) joints = dict(shoulder_pan_joint=0, shoulder_lift_joint=0, elbow_joint=0, wrist_1_joint=0, wrist_2_joint=0, wrist_3_joint=0) frame = model.forward_kinematics(joints) artist = FrameArtist(frame, layer='COMPAS::Robot Viz') artist.clear_layer() artist.draw() artist = RobotModelArtist(model, layer='COMPAS::Robot Viz') artist.update(joints) artist.draw_visual()
point = [0, 0, 0] normal = [0, 0, -1] plane = Plane(point, normal) direction = [2, -2, 1] P = Projection.from_plane_and_direction(plane, direction) # Create a Mesh from the Box mesh = Mesh.from_shape(box) tmesh = Mesh.from_shape(box_transformed) # Apply the Projection onto the mesh mesh_projected = tmesh.transformed(P) # clear layer artist = BoxArtist(box, layer="Default") artist.clear_layer() # defining Artists artist1 = BoxArtist(box) artist2 = BoxArtist(box_transformed) artist3 = MeshArtist(mesh_projected) artist4 = FrameArtist(frame, scale=1.0) artist5 = FrameArtist(frame1, scale=1.0) # Draw artist1.draw() artist2.draw() artist3.draw_edges(color="#00ffff") artist4.draw() artist5.draw()