def __init__(self): GpaphicBlueprint.__init__(self) self.kind = 'zylinder' self._color = [0.5, 0.5, 0.5] oldMesh = create_cylinder(10, 10) self._mesh = Mesh(oldMesh.get_vertices(), oldMesh.get_faces()) self.buildProgram()
def __init__(self, radius, length, rows=16, cols=16, vertex_colors=None, face_colors=None, color=(0.5, 0.5, 1, 1), edge_color=None, **kwargs): mesh_data = create_cylinder(rows, cols, radius, length, offset=False) self._mesh = MeshVisual( mesh_data.get_vertices() + np.array([0, 0, -length * 0.5]), mesh_data.get_faces(), vertex_colors, face_colors, color) if edge_color: self._border = MeshVisual(mesh_data.get_vertices() + np.array([0, 0, -length * 0.5]), mesh_data.get_faces(), color=edge_color, mode='lines') else: self._border = MeshVisual() CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs) self.mesh.set_gl_state(polygon_offset_fill=True, polygon_offset=(1, 1), depth_test=True)
def __init__(self, h): self.h = h app.Canvas.__init__(self, keys='interactive', size=(800, 550)) hcyl = mplcyl.TruncatedCone() print('1') #plot_tc(p0=np.array([1, 3, 2]), p1=np.array([8, 5, 9]), R=[5.0, 2.0]) verts, edges = h.get_geometry() self.meshes = [] self.rotation = MatrixTransform() sec_ids = [] s = 1.0 x, y = 0., 0. for edge in edges: ends = verts['pos'][edge] # xyz coordinate of one end [x,y,z] dia = verts['dia'][edge] # diameter at that end sec_id = verts['sec_index'][edge[0]] # save the section index dif = ends[1]-ends[0] # distance between the ends length = (dif**2).sum() ** 0.5 # print length # print dia #C, T, B = hcyl.make_truncated_cone(p0=ends[0], p1=ends[1], R=[dia[0]/2., dia[1]/2.]) mesh_verts = create_cylinder(8, 8, radius=[dia[0]/2., dia[1]/2.], length=length, offset=False) #mesh_verts = create_grid_mesh(C[0], C[1], C[2]) # sec_id_array = np.empty(mesh_verts.shape[0]*3, dtype=int) # # sec_id_array[:] = sec_id # meshes.append(mesh_verts) # sec_ids.append(sec_id_array) self.meshes.append(visuals.MeshVisual(meshdata=mesh_verts, color='r')) # transform = ChainTransform([STTransform(translate=(x, y), # scale=(s, s, s)), # self.rotation]) # # for i, mesh in enumerate(self.meshes): # # x = 800. * (i % grid[0]) / grid[0] + 40 # mesh.transform = transform # mesh.transforms.scene_transform = STTransform(scale=(1, 1, 0.01)) gloo.set_viewport(0, 0, *self.physical_size) gloo.clear(color='white', depth=True) for mesh in self.meshes: mesh.draw() print('running') self.show() if sys.flags.interactive != 1: app.run()
def generate_cylinder_geometry(first_vertex_coordinate, second_vertex_coordinate, cylinder_rows, cylinder_cols, cylinder_radius, sphere_radius): middle_point = (first_vertex_coordinate + second_vertex_coordinate) / 2 distance_between_vertices = np.linalg.norm(first_vertex_coordinate - second_vertex_coordinate) normalized_vector = (second_vertex_coordinate - first_vertex_coordinate) / distance_between_vertices cylinder_length = distance_between_vertices - 1.75 * sphere_radius cylinder = geometry.create_cylinder( cylinder_rows, cylinder_cols, radius=[cylinder_radius, cylinder_radius], length=cylinder_length) vertices = cylinder.get_vertices() vertices += (0, 0, -cylinder_length / 2) rotation_matrix = get_rotation_matrix(start_point=np.array((0, 0, 1), np.float32), end_point=normalized_vector) vertices = np.dot(vertices, rotation_matrix) vertices += middle_point cylinder.set_vertices(vertices) return cylinder
def create_axes(self): self.axes = {} coords = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] names = ["x", "y", "z"] colors = ["red", "green", "blue"] for coord, color, name in zip(coords, colors, names): mdata = geometry.create_cylinder(128, 128, radius=[0.1, 0.1], length=5, offset=False) axis = scene.visuals.Mesh(meshdata=mdata, shading="flat", color=color) t = visuals.transforms.MatrixTransform() t.rotate(90, coord) axis.transform = t self.view.add(axis) self.axes[name] = axis axis.visible = False
def create_axes(self): self.axes = {} coords = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] names = ["x", "y", "z"] colors = ["red", "green", "blue"] for coord, color, name in zip(coords, colors, names): mdata = geometry.create_cylinder(128, 128, radius=[0.1, 0.1], length=5, offset=False) axis = scene.visuals.Mesh(meshdata=mdata, shading='flat', color=color) t = visuals.transforms.MatrixTransform() t.rotate(90, coord) axis.transform = t self.view.add(axis) self.axes[name] = axis axis.visible = False
def test_cylinder(): """Test cylinder function""" md = create_cylinder(10, 20, radius=[10, 10]) radii = np.sqrt((md.get_vertices()[:, :2]**2).sum(axis=1)) assert_allclose(radii, np.ones_like(radii) * 10)
def test_cylinder(): """Test cylinder function""" md = create_cylinder(10, 20, radius=[10, 10]) radii = np.sqrt((md.get_vertices()[:, :2] ** 2).sum(axis=1)) assert_allclose(radii, np.ones_like(radii) * 10)