def make_wf_hat(hat, pv, nodes_per_hemi = 100): """ Makes wireframe hat consisting of base, bill and light sensors. """ global correction_matrix scale = 50 # Make untransformed base, bill and lightSensor wireframes. base = wf.Wireframe() bill = wf.Wireframe() lightSensors = wf.Wireframe() hat_center = hat.position bill_center = 1 * hat_center ls_center = 1 * hat_center ls_center[1] += scale bill_center[0] += hat.billOffset * scale * np.cos(hat.theta) bill_center[2] += hat.billOffset * scale * np.sin(hat.theta) bill_radius = hat.billDiam / 2 * scale base_radius = hat.diam / 2 * scale lightSensors.make_circle(ls_center, base_radius, len(hat.lightSensors)) lightSensors.clearEdges() bill.make_dense_circle(bill_center, bill_radius, nodes_per_hemi) bill.edges[:] = [x for x in bill.edges if (np.linalg.norm(bill.nodes[x[0]][0:3] - hat_center) > base_radius and np.linalg.norm(bill.nodes[x[1]][0:3] - hat_center) > base_radius)] base.make_sphere(hat_center, base_radius, nodes_per_hemi, 1 * np.pi, 20, 11) # Transform wireframes to viewing angle. center = np.hstack((hat_center, 1)) base.nodes = base.nodes - center bill.nodes = bill.nodes - center lightSensors.nodes = lightSensors.nodes - center rotateXMatrix = wf.rotateXMatrix(pv.viewing_angle) rotateYMatrix = wf.rotateYMatrix(pv.viewing_angle) rotateMatrix = np.dot(rotateYMatrix, rotateXMatrix) rotateMatrix = 1 * rotateXMatrix # Update correction matrix. correction_matrix = np.dot(np.linalg.inv(rotateMatrix), correction_matrix) bill.nodes = np.dot(bill.nodes, rotateMatrix) base.nodes = np.dot(base.nodes, rotateMatrix) lightSensors.nodes = np.dot(lightSensors.nodes, rotateMatrix) bill.nodes = bill.nodes + center base.nodes = base.nodes + center lightSensors.nodes = lightSensors.nodes + center return wf.WireframeHat(base, bill, lightSensors)
def view_projection(modelpath, testpath): pv = ProjectionViewer(1600, 1200,modelpath,modelpath) arm = wireframe.Wireframe() arm.addNodes([(0, 0, 0), (100, 0, 0)]) arm.addEdges([(0, 1)]) arm2 = wireframe.Wireframe() arm2.addNodes([(0,0,0), (100,00,0)]) arm2.addEdges([(0,1)]) pv.addWireframe('model', arm2) pv.addWireframe('arm', arm) pv.run()
def __init__(self, width, height, name="Wireframe Viewer"): self.width = width self.height = height self.screen = pygame.display.set_mode((width, height)) pygame.display.set_caption(name) self.wireframes = {} self.wireframe_colours = {} self.object_to_update = [] self.displayNodes = False self.displayEdges = True self.displayFaces = True self.perspective = False #300. self.eyeX = self.width / 2 self.eyeY = 100 self.view_vector = np.array([0, 0, -1]) self.light = wf.Wireframe() self.light.addNodes([[0, -1, 0]]) self.min_light = 0.02 self.max_light = 1.0 self.light_range = self.max_light - self.min_light self.background = (10, 10, 50) self.nodeColour = (250, 250, 250) self.nodeRadius = 4 self.control = 0
def Spheroid(a, b, resolution=10): """ Returns a wireframe spheroid centred on (x,y,z) with a radii of (rx,ry,rz) in the respective axes. """ (x,y,z) = a (rx, ry, rz) = b spheroid = wf.Wireframe() latitudes = [n*np.pi/resolution for n in range(1,resolution)] longitudes = [n*2*np.pi/resolution for n in range(resolution)] # Add nodes except for poles spheroid.addNodes([(x + rx*np.sin(n)*np.sin(m), y - ry*np.cos(m), z - rz*np.cos(n)*np.sin(m)) for m in latitudes for n in longitudes]) # Add square faces to whole spheroid but poles num_nodes = resolution*(resolution-1) spheroid.addFaces([(m+n, (m+resolution)%num_nodes+n, (m+resolution)%resolution**2+(n+1)%resolution, m+(n+1)%resolution) for n in range(resolution) for m in range(0,num_nodes-resolution,resolution)]) # Add poles and triangular faces around poles spheroid.addNodes([(x, y+ry, z),(x, y-ry, z)]) spheroid.addFaces([(n, (n+1)%resolution, num_nodes+1) for n in range(resolution)]) start_node = num_nodes-resolution spheroid.addFaces([(num_nodes, start_node+(n+1)%resolution, start_node+n) for n in range(resolution)]) return spheroid
def Cuboid(a, b): (x,y,z) = a (w,h,d) = b """ Return a wireframe cuboid starting at (x,y,z) with width, w, height, h, and depth, d. """ cuboid = wf.Wireframe() cuboid.addNodes(np.array([[nx,ny,nz] for nx in (x,x+w) for ny in (y,y+h) for nz in (z,z+d)])) cuboid.addFaces([(0,1,3,2), (7,5,4,6), (4,5,1,0), (2,3,7,6), (0,2,6,4), (5,7,3,1)]) return cuboid
def main(args): # Filepaths config_file = utils.data("wireframe.yaml") model_file = utils.data("pretrained_lcnn.pth.tar") w = wireframe.Wireframe(config_file, model_file, "") if not w.setup(): print(w.error) else: print("w is setup successfully") save_wireframe_records(args.project_directory, w)
def chunk(depth, height, width, size, coords): cubes = [] x0, y0, z0 = coords for d in range(depth): for w in range(width): for h in range(height): cube = wf.Wireframe() cubes.append(cube) coords = (x0+w*size,y0+h*size,z0+d*size) cube.addNodes(np.array(cubeNodes(size,coords))) cube.addEdges(cubeEdges) return cubes
def HorizontalGrid(a, b, c): """ Returns a nx by nz wireframe grid that starts at (x,y,z) with width dx.nx and depth dz.nz. """ (x,y,z) = a (dx,dz) = b (nx,nz) = c grid = wf.Wireframe() grid.addNodes([[x+n1*dx, y, z+n2*dz] for n1 in range(nx+1) for n2 in range(nz+1)]) grid.addEdges([(n1*(nz+1)+n2,n1*(nz+1)+n2+1) for n1 in range(nx+1) for n2 in range(nz)]) grid.addEdges([(n1*(nz+1)+n2,(n1+1)*(nz+1)+n2) for n1 in range(nx) for n2 in range(nz+1)]) return grid
def FractalLandscape( origin=(0, 0, 0), dimensions=(400, 400), iterations=4, height=40): import random def midpoint(nodes): m = 1.0 / len(nodes) x = m * sum(n[0] for n in nodes) y = m * sum(n[1] for n in nodes) z = m * sum(n[2] for n in nodes) return [x, y, z] (x, y, z) = origin (dx, dz) = dimensions nodes = [[x, y, z], [x + dx, y, z], [x + dx, y, z + dz], [x, y, z + dz]] edges = [(0, 1), (1, 2), (2, 3), (3, 0)] size = 2 for i in range(iterations): # Add nodes midway between each edge for (n1, n2) in edges: nodes.append(midpoint([nodes[n1], nodes[n2]])) # Add nodes to the centre of each square squares = [(x + y * size, x + y * size + 1, x + (y + 1) * size + 1, x + (y + 1) * size) for y in range(size - 1) for x in range(size - 1)] for (n1, n2, n3, n4) in squares: nodes.append(midpoint([nodes[n1], nodes[n2], nodes[n3], nodes[n4]])) # Sort in order of grid nodes.sort(key=lambda node: (node[2], node[0])) size = size * 2 - 1 # Horizontal edge edges = [(x + y * size, x + y * size + 1) for y in range(size) for x in range(size - 1)] # Vertical edges edges.extend([(x + y * size, x + (y + 1) * size) for x in range(size) for y in range(size - 1)]) # Shift node heights scale = height / 2**(i * 0.8) for node in nodes: node[1] += (random.random() - 0.5) * scale grid = wf.Wireframe(nodes) grid.addEdges(edges) return grid
def testWireframe(): """ Example of how to create wireframes node by node, and by using the basicShape module. Creates a triangle and cuboid wireframe and outputs their node, edge and face values. """ # Create a triangle by explictly passing the nodes and edges print "\nTriangle" triangle = wf.Wireframe([[100, 200, 10], [200, 200, 10], [125, 100, 500]]) triangle.addEdges([(0, 1), (1, 2), (2, 0)]) triangle.output() # Create a cuboid using the basicShape module print "\nCuboid" cuboid = shape.Cuboid((100, 100, 10), (20, 30, 40)) cuboid.output()
def initializeCube(): block = wf.Wireframe() block_nodes = [(x, y, z) for x in (-1.5, 1.5) for y in (-1, 1) for z in (-0.1, 0.1)] node_colors = [(255, 255, 255)] * len(block_nodes) block.addNodes(block_nodes, node_colors) block.outputNodes() faces = [(0, 2, 6, 4), (0, 1, 3, 2), (1, 3, 7, 5), (4, 5, 7, 6), (2, 3, 7, 6), (0, 1, 5, 4)] colors = [(255, 0, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 255, 255), (255, 255, 0)] block.addFaces(faces, colors) block.outputFaces() return block
def main(args): try: images, reconstruction = setup_project_data(args.project_directory) except Exception as e: print("An exception occurred while trying to load project data: {}".format(e)) return # Filepaths config_file = utils.data("wireframe.yaml") model_file = utils.data("pretrained_lcnn.pth.tar") w = wireframe.Wireframe(config_file, model_file, args.device) if not w.setup(): print(w.error) else: print("w is setup successfully") records = wireframe.project.generate_wireframe_records(args.project_directory, w, force=args.recompute) if args.reconstruction >= 0: reconstruction = [reconstruction[args.reconstruction]] wpcs = [] for r in reconstruction: for imname, iminfo in r['shots'].items(): print("Processing {}...".format(imname)) wpc = wireframe.WireframePointCloud(args.project_directory, imname, records[imname], iminfo, r['cameras'], line_inlier_thresh=args.l_thresh, color_inliers=args.color_inliers, threshold=args.score_thresh) wpcs.append(wpc) wpc.write_line_point_clouds() return wpcs, records
def __init__(self): w = Window(800,400) self.dr = DataReader() self.wfv = WireframeViewer((0.4,0.1,0.5,0.8),self.dr) self.wfv.addWireframe('sphere', Sphere((0.5,0.5, 0.5), 0.4, resolution=24), displayNodes=False) dwf = wf.Wireframe() self.wfv.addWireframe('sphere_points', dwf, displayEdges=True) StokesCalculator(self.dr,dwf) """ owf = wf.Wireframe() self.wfv.addWireframe('target', owf, nodeColor=(200,0,200)) #TODO: add target node (need Stokes parameters of target node) s1 = 0.93 s2 = -0.36 s3 = 0 (x,y,z), r = (0.5,0.5, 0.5), 0.4 l = np.sqrt(s1**2+s2**2+s3**2) owf.addNodes([(x + r*s1/l, y + r*s3/l, z + r*s2/l )]) """ osc = Oscilloscope((0.05, 0.1, 0.3, 0.8), self.dr) w.add(osc) w.add(self.wfv) w.connect('mouse-motion', self.on_mouse_motion) w.connect('mouse-button-down', self.on_mouse_button_down) w.connect('quit', self.on_quit) w.run()
def main(args): # Filepaths config_file = utils.data("wireframe.yaml") model_file = utils.data("pretrained_lcnn.pth.tar") w = wireframe.Wireframe(config_file, model_file, "") if not w.setup(): print(w.error) else: print("w is setup successfully") # Controls how small the minimum connected component can be desired_edges = 2 for imname in args.image: im, g, subgraphs = w.get_filtered_subgraphs(imname, desired_edges) g.plot_graph(g.g, im) print("\n\nFound {} subgraphs".format(len(subgraphs))) for s in subgraphs: print("\n\n===================\n\n") g.plot_graph(s, im) print("\n\nReduced subgraphs to {} graphs".format(len(subgraphs)))
pygame.draw.aaline(self.screen, self.edgeColour, (edge.start.x, edge.start.y), (edge.stop.x, edge.stop.y), 1) if self.displayNodes: for node in wireframe.nodes: pygame.draw.circle(self.screen, self.nodeColour, (int(node.x), int(node.y)), self.nodeRadius, 0) def translateAll(self, axis, d): """ Translate all wireframes along a given axis by d units. """ for wireframe in self.wireframes.itervalues(): wireframe.translate(axis, d) def scaleAll(self, scale): """ Scale all wireframes by a given scale, centred on the centre of the screen. """ centre_x = self.width/2 centre_y = self.height/2 for wireframe in self.wireframes.itervalues(): wireframe.scale((centre_x, centre_y), scale) if __name__ == '__main__': pv = ProjectionViewer(400, 300) cube = wireframe.Wireframe() cube.addNodes([(x,y,z) for x in (50,250) for y in (50,250) for z in (50,250)]) cube.addEdges([(n,n+4) for n in range(0,4)]+[(n,n+1) for n in range(0,8,2)]+[(n,n+2) for n in (0,1,4,5)]) pv.addWireframe('cube', cube) pv.run()
centre_x = self.width / 2 centre_y = self.height / 2 for wireframe in self.wireframes.itervalues(): wireframe.scale((centre_x, centre_y), scale) def rotateAll(self, axis, theta): """ Rotate all wireframe about their centre, along a given axis by a given angle. """ rotateFunction = 'rotate' + axis for wireframe in self.wireframes.itervalues(): centre = wireframe.findCentre() getattr(wireframe, rotateFunction)(centre, theta) if __name__ == '__main__': pv = ProjectionViewer(400, 300) cube = wf.Wireframe() cube_nodes = [(x, y, z) for x in (50, 250) for y in (50, 250) for z in (50, 250)] cube.addNodes(np.array(cube_nodes)) cube.addEdges([(n, n + 4) for n in range(0, 4)] + [(n, n + 1) for n in range(0, 8, 2)] + [(n, n + 2) for n in (0, 1, 4, 5)]) pv.addWireframe('cube', cube) pv.run()
from projectionViewer import ProjectionViewer import wireframe import numpy as np cube = wireframe.Wireframe() cube2 = wireframe.Wireframe() cube3 = wireframe.Wireframe() cube_nodes = [(x, y, z) for x in (50, 250) for y in (50, 250) for z in (50, 250)] cube_nodes2 = [(x, y, z) for x in (250, 400) for y in (250, 400) for z in (250, 400)] cube_nodes3 = [(x, y, z) for x in (1, 800) for y in (400, 401) for z in (1, 800)] cube.addNodes(np.array(cube_nodes)) cube.addEdges([(n, n + 4) for n in range(0, 4)]) cube.addEdges([(n, n + 1) for n in range(0, 8, 2)]) cube.addEdges([(n, n + 2) for n in (0, 1, 4, 5)]) cube2.addNodes(np.array(cube_nodes2)) cube2.addEdges([(n, n + 4) for n in range(0, 4)]) cube2.addEdges([(n, n + 1) for n in range(0, 8, 2)]) cube2.addEdges([(n, n + 2) for n in (0, 1, 4, 5)]) cube3.addNodes(np.array(cube_nodes3)) cube3.addEdges([(n, n + 4) for n in range(0, 4)]) cube3.addEdges([(n, n + 1) for n in range(0, 8, 2)]) cube3.addEdges([(n, n + 2) for n in (0, 1, 4, 5)]) pv = ProjectionViewer(1200, 1000) pv.addWireframe('cube', cube) pv.addWireframe('cube2', cube2)
if node[2] > -self.perspective: z = self.perspective/ (self.perspective + node[2]) x = 0.5 + z*(node[0] - 0.5) y = 0.5 + z*(node[1] - 0.5) pygame.draw.circle(surface, color, (int(x*w), int(y*h)), wireframe.nodeRadius, 0) else: pygame.draw.circle(surface, color, (int(node[0]*w), int(node[1]*h)), wireframe.nodeRadius, 0) #Sphere from http://www.petercollingridge.co.uk/pygame-3d-graphics-tutorial def Sphere((x,y,z), r, resolution=10): """ Returns a wireframe spheroid centred on (x,y,z) with a radii of (rx,ry,rz) in the respective axes. """ spheroid = wf.Wireframe() latitudes = [n*np.pi/resolution for n in range(1,resolution)] longitudes = [n*2*np.pi/resolution for n in range(resolution)] # Add nodes except for poles spheroid.addNodes([(x + r*np.sin(n)*np.sin(m), y - r*np.cos(m), z - r*np.cos(n)*np.sin(m)) for m in latitudes for n in longitudes]) # Add square faces to whole spheroid but poles num_nodes = resolution*(resolution-1) spheroid.addFaces([(m+n, (m+resolution)%num_nodes+n, (m+resolution)%resolution**2+(n+1)%resolution, m+(n+1)%resolution) for n in range(resolution) for m in range(0,num_nodes-resolution,resolution)]) # Add poles and triangular faces around poles spheroid.addNodes([(x, y+r, z),(x, y-r, z)]) spheroid.addFaces([(n, (n+1)%resolution, num_nodes+1) for n in range(resolution)]) start_node = num_nodes-resolution spheroid.addFaces([(num_nodes, start_node+(n+1)%resolution, start_node+n) for n in range(resolution)])
rotateFunction = "rotate" + axis for wireframe in self.wireframes.itervalues(): center = wireframe.findCenter() getattr(wireframe, rotateFunction)(center, theta) def clearAll(self): self.wireframes = {} pv = ProjectionViewer(800, 600) """for i in range(0,5): placeCube((300+200*i,300),pv)""" tesseract = wireframe.Wireframe() tesseract.addNodes([(x,y,z) for x in (150,350) for y in (100,300) for z in (150,350)]+[(x,y,z) for x in (200,300) for y in (150,250) for z in (200,300)]) #Basic edges for the two cubes tesseract.addEdges([(n,n+4) for n in range(0,4)]+[(n,n+1) for n in range(0,8,2)]+[(n,n+2) for n in (0,1,4,5)]+[(n+8,n+12) for n in range(0,4)]+[(n+8,n+9) for n in range(0,8,2)]+[(n+8,n+10) for n in (0,1,4,5)]) #Edges for connecting the cubes tesseract.addEdges([n,n+8]for n in range(0,8)) rectangle = wireframe.Wireframe() rectangle.addNodes([(x,y,z) for x in (150,450) for y in (350,550) for z in (150,350)]) rectangle.addEdges([(n,n+4) for n in range(0,4)]+[(n,n+1) for n in range(0,8,2)]+[(n,n+2) for n in (0,1,4,5)]) prism = wireframe.Wireframe() prism.addNodes([(100,100,100),(200,100,100),(200,100,200),(125,200,125)]) prism.addEdges([(0,1),(0,2),(1,2)] + [(x,3) for x in range(0,3)]) pv.addWireframe("prism", prism)
R = m.affine(m.rotX(0.1 * np.pi), np.array([0, 0, 0])) if (axis == 'y'): R = m.affine(m.rotY(0.05 * np.pi), np.array([0, 0, 0])) if (axis == 'z'): R = m.affine(m.rotZ(0.05 * np.pi), np.array([0, 0, 0])) if (axis == 'x-'): R = m.affine(m.rotX(-0.05 * np.pi), np.array([0, 0, 0])) if (axis == 'y-'): R = m.affine(m.rotY(-0.05 * np.pi), np.array([0, 0, 0])) if (axis == 'z-'): R = m.affine(m.rotZ(-0.05 * np.pi), np.array([0, 0, 0])) for wireframe in self.wireframes.values(): wireframe.nodes[node].rotate(R) if __name__ == '__main__': pv = ProjectionViewer(1600, 1200) arm = wireframe.Wireframe() arm.addNodes([(0, 0, 0), (100, 0, 0)]) arm.addEdges([(0, 1)]) arm2 = wireframe.Wireframe() arm2.addNodes([(0, 0, 0), (100, 00, 0)]) arm2.addEdges([(0, 1)]) pv.addWireframe('model', arm2) pv.addWireframe('arm', arm) pv.run()
def placeCube(loc,viewer): cube = wireframe.Wireframe() cube.addNodes([(x,y,z) for x in (loc[0]-100,loc[0]+100) for y in (loc[1]-100,loc[1]+100) for z in (loc[0]-100,loc[0]+100)]) cube.addEdges([(n,n+4) for n in range(0,4)]+[(n,n+1) for n in range(0,8,2)]+[(n,n+2) for n in (0,1,4,5)]) viewer.addWireframe(str(len(viewer.wireframes)),cube)
CENTER_X = WIDTH / 2 CENTER_Y = HEIGHT / 2 print("Creating cubes...") cube_nodes = [(x,y,z) for x in (CENTER_X-200, CENTER_X-100) \ for y in (CENTER_Y-50, CENTER_Y+50) \ for z in (-50, 50)] cube_faces = [(0,2,6,WINE), (0,6,4,WINE), \ (7,3,1,WINE), (1,5,7,WINE), \ (4,6,7,AUSTIN), (7,5,4,AUSTIN), \ (0,1,2,AUSTIN), (3,2,1,AUSTIN), \ (0,4,1,SALMON), (1,4,5,SALMON), \ (2,3,7,SALMON), (2,7,6,SALMON)] cube1 = wireframe.Wireframe(cube_nodes, cube_faces) cube1.rotate_y(0.785398) cube1.rotate_x(-0.523599) cube_nodes = [(x,y,z) for x in (CENTER_X+100, CENTER_X+200) \ for y in (CENTER_Y-50, CENTER_Y+50) \ for z in (-50, 50)] cube_faces = [(0,2,6,SEA), (0,6,4,SEA), \ (7,3,1,SEA), (1,5,7,SEA), \ (4,6,7,LIME), (7,5,4,LIME), \ (0,1,2,LIME), (3,2,1,LIME), \ (0,4,1,OLIVE), (1,4,5,OLIVE), \ (2,3,7,OLIVE), (2,7,6,OLIVE)] cube2 = wireframe.Wireframe(cube_nodes, cube_faces)
node2d[1] <= -radius or node2d[1] >= self.height+radius): continue pygame.draw.circle(self.screen, color, node2d, radius ) def perspective(self, incl, az): return ( int(self.halfWidth + self.camDist*np.sin(incl)*np.cos(az)), int(self.halfHeight + self.camDist*np.sin(incl)*np.sin(az)) ) if __name__ == '__main__': cube = wireframe.Wireframe() cube.addNodes(np.array([(x,y,z) for x in (-10,10) for y in (-10,10) for z in (100,120)])) cube.addEdges([(n,n+4) for n in range(4)]+[(n,n+1) for n in range(0,7,2)]+[(n,n+2) for n in (0,1,4,5)]) cube2 = wireframe.Wireframe() cube2.addNodes(np.array([(x,y,z) for x in (-10,10) for y in (10,30) for z in (100,120)])) cube2.addEdges([(n,n+4) for n in range(4)]+[(n,n+1) for n in range(0,7,2)]+[(n,n+2) for n in (0,1,4,5)]) dots = wireframe.Wireframe() dots.addNodes(np.array([(x,y,z) for x in range(0,100,20) for y in range(0,100,20) for z in range(0,300,20)])) pv = ProjectionViewer(800, 600) pv.addWireframe('cube', cube) pv.addWireframe('cube2', cube2) pv.addWireframe('dots', dots) pv.run()
def drawRect(rect,viewer): rectangle = wireframe.Wireframe() rectangle.addNodes([(x,y,z) for x in (rect[0],rect[0]+rect[2]) for y in (rect[1],rect[1]+rect[3]) for z in (rect[0],rect[0]+rect[2])]) rectangle.addEdges([(n,n+4) for n in range(0,4)]+[(n,n+1) for n in range(0,8,2)]+[(n,n+2) for n in (0,1,4,5)]) viewer.addWireframe(str(len(viewer.wireframes)),rectangle)
import numpy as np import wireframe as wf def Cuboid((x, y, z), (w, h, d)): """ Return a wireframe cuboid starting at (x,y,z) with width, w, height, h, and depth, d. """ cuboid = wf.Wireframe() cuboid.addNodes( np.array([[nx, ny, nz] for nx in (x, x + w) for ny in (y, y + h) for nz in (z, z + d)])) cuboid.addFaces([(0, 1, 3, 2), (7, 5, 4, 6), (4, 5, 1, 0), (2, 3, 7, 6), (0, 2, 6, 4), (5, 7, 3, 1)]) return cuboid def Spheroid((x, y, z), (rx, ry, rz), resolution=10): """ Returns a wireframe spheroid centred on (x,y,z) with a radii of (rx,ry,rz) in the respective axes. """ spheroid = wf.Wireframe() latitudes = [n * np.pi / resolution for n in range(1, resolution)] longitudes = [n * 2 * np.pi / resolution for n in range(resolution)] # Add nodes except for poles spheroid.addNodes([(x + rx * np.sin(n) * np.sin(m), y - ry * np.cos(m), z - rz * np.cos(n) * np.sin(m)) for m in latitudes for n in longitudes])
""" Translate all wireframes along a given axis by d units. """ for wireframe in self.wireframes.itervalues(): wireframe.translate(axis, d) def scaleAll(self, scale): """ Scale all wireframes by a given scale, centred on the centre of the screen. """ centre_x = self.width/2 centre_y = self.height/2 for wireframe in self.wireframes.itervalues(): wireframe.scale((centre_x, centre_y), scale) def rotateAll(self, axis, theta): """ Rotate all wireframe about their centre, along a given axis by a given angle. """ rotateFunction = 'rotate' + axis for wireframe in self.wireframes.itervalues(): centre = wireframe.findCentre() getattr(wireframe, rotateFunction)(centre, theta) if __name__ == '__main__': pv = ProjectionViewer(900, 600) #size of window terrain = wireframe.Wireframe() pv.addWireframe('terrain', terrain) pv.run() ##runs the main loop
import numpy as np import wireframe import ProjectionViewer as pview import tools from interpol import idw_mesh if __name__ == '__main__': points = tools.center(tools.rescale(tools.parse_file('../resources/demo5.mod1'))) print(points) points = np.vstack([points, tools.gen_borders(0, 2, 0, 2)]) res = idw_mesh(points, 100, 0.6) wr = wireframe.Wireframe() wr.addNodes(res) pv = pview.ProjectionViewerNP(800, 800) pv.addWireframe(wr) pv.run()
save = args['data_save'] save_pos = args['pos_save'] # this is the folder where our # images are saved if not os.path.exists('./imgs_bmp'): os.mkdir('imgs_bmp') p = Projector(256, 256, fps, save, save_pos, step) cube_nodes = [[x, y, z] for x in (0, 100) for y in (0, 100) for z in (0, 100)] cube_nodes = np.array(cube_nodes) cube_faces = [[0, 1, 3, 2], [7, 5, 4, 6], [4, 5, 1, 0], [2, 3, 7, 6], [0, 2, 6, 4], [5, 7, 3, 1]] cube_faces = np.array(cube_faces) cube_colors = [[255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 255, 0], [255, 0, 255], [0, 255, 255]] cube_colors = np.array(cube_colors) cube_node_colors = [[0, 255, 0], [255, 255, 0], [0, 255, 255], [150, 150, 255], [255, 0, 0], [0, 100, 255], [255, 200, 255], [255, 255, 255]] cube_node_colors = np.array(cube_node_colors) cube = wf.Wireframe(cube_nodes, cube_node_colors, cube_faces, cube_colors) p.add_wireframe('cube1', cube) p.run(test_npy=test) ''' Resources / Credits: http://www.petercollingridge.co.uk/pygame-3d-graphics-tutorial/projecting-3d-objects '''