def __init__(self): self.backup = BackUp("screen") self.stdscr = curses.initscr() self.MAX_Y, self.MAX_X = self.stdscr.getmaxyx() self.window = self.stdscr.subwin(self.MAX_Y, self.MAX_X, 0, 0) self.main_window = self.window.subwin(self.MAX_Y - 2, self.MAX_X - MENU_W - 3, 1, 1) self.menu_window = self.window.subwin(self.MAX_Y - 2, MENU_W, 1, self.MAX_X - MENU_W - 2) self._max_y = self.MAX_Y - 4 self._max_x = self.MAX_X - MENU_W - 6 self.screen = {} """创建【时标】 """ self.TS = TimeScale() """创建【资源】 """ self.R = resource.Resource(self._max_x, self._max_y) self.loadData() """创建【对象】 """ self.Obj = [] for _i in range(5): self.Obj.append( obj.Obj("%d" % _i, 0, 0, obj_pattern[_i % len(obj_pattern)], (_i % 7) + 1))
def main(): rgb_vermelho_grena = [140 / 255, 23 / 255, 23 / 255] material = obj.Material(rgb_vermelho_grena, rgb_vermelho_grena, [0.8, 0.8, 0.8], 2) d = 0.00001 window_height = 10 window_width = 10 pixels_height = 300 pixels_width = 300 objects = [] cube = obj.Obj().import_obj('../objects/cube.obj') cube.apply_material(material) # s = t.get_scale_matrix([3., 0.1, 4., 1]) # floor = copy.deepcopy(cube) # floor.apply_transformation(s) # objects.append(floor) # T = t.get_translation_matrix([1, 0, 2]) # cube2 = copy.deepcopy(cube) # cube2.apply_material(obj.Material([0, 0, 0], [0, 0, 0], [0, 0, 0], 1)) # cube2.apply_transformation(T) objects.append(cube) # punctual_light = PunctualLightSource(intensity=[1., 1., 1.], position=[1.5, 1.2, 0.1]) po = [0.5, 0.5, 2.5, 1.0] look_at = [0.5, 0.5, 0.5, 1.0] a_vup = [0.5, 2, 0.5, 1.0] p = "PERSPECTIVE" ob = "OBLIQUE" cb = "CABINET" cv = "CAVALIER" ort = "ORTHOGRAPHIC" projection_type = ob scenario = Scenario(objects=objects, light_sources=[], po=po, look_at=look_at, a_vup=a_vup, background_color=[0.1, 0.1, 0.1], ambient_light=[0.8, 0.8, 0.8]) window = Window(window_width, window_height, d, pixels_width, pixels_height) scenario.render(window, threads=True, shadow=False, projection_type=projection_type, oblique_angle=45, oblique_factor=1)
def __init__( self, func, priority=0.5, mem=None, deps=None, net=None, source="unknown", error=None, ): self.func = func self.name = self.func.__name__ self.priority = priority self.deps = deps or set() self.mem = mem or obj.Obj() self.net = net or obj.Obj() self.status = TaskStatus.Initial.Ready self.source = source self.error = error self._gen = None
def load(self, filename, trans, rot, scale, whereami, lookat): model = obj.Obj(filename) vertices = [] t_vertices = [] n_vertices = [] for face in model.vfaces: vcount = len(face) if vcount >= 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f1t = face[0][1] - 1 f2t = face[1][1] - 1 f3t = face[2][1] - 1 f1n = face[0][2] - 1 f2n = face[1][2] - 1 f3n = face[2][2] - 1 vertices.append(model.vertices[f1]) vertices.append(model.vertices[f2]) vertices.append(model.vertices[f3]) try: t_vertices.append(glm.vec2(*model.tvertices[f1t])) t_vertices.append(glm.vec2(*model.tvertices[f2t])) t_vertices.append(glm.vec2(*model.tvertices[f3t])) except TypeError: t_vertices.append(glm.vec3(*model.tvertices[f1t])) t_vertices.append(glm.vec3(*model.tvertices[f2t])) t_vertices.append(glm.vec3(*model.tvertices[f3t])) n_vertices.append((glm.vec3(*model.normals[f1n]))) n_vertices.append((glm.vec3(*model.normals[f2n]))) n_vertices.append((glm.vec3(*model.normals[f3n]))) self.vertices = iter( self.transform(vertices, trans, rot, scale, whereami, lookat)) self.t_vertices = iter(t_vertices) self.normals = iter(n_vertices)
# #'CIFAR10': real_functions.CIFAR10(), # #'KISSGP': real_functions.KISSGP()} # objective_func = obj_func_dict[obj_func_name] # dim = int(objective_func._dim) # num_initial_points = int(objective_func._num_init_pts) os.system("rm -rf work") os.system("mkdir work") argv = sys.argv[1:] conf = toml.load(argv[0]) obj_func_name = "MyFunc" job_id = 0 objective_func = obj.Obj(np.array(conf["bounds"]), conf["num_init"], conf["var_name"]) dim = objective_func._dim num_fidelity = objective_func._num_fidelity num_initial_points = int(objective_func._num_init_pts) num_to_sample = conf["batch_size"] num_iteration = conf["max_iter"] os.system("rm -rf work") os.system("mkdir work") for i in xrange(conf["batch_size"]): copy_cmd = "cp -r ./circuit work/%d" % i os.system(copy_cmd) inner_search_domain = pythonTensorProductDomain([ ClosedInterval(objective_func._search_domain[i, 0], objective_func._search_domain[i, 1])
def loadModel(self, filename, translate=(0, 0, 0), scale=(1, 1, 1), rotate=(0, 0, 0)): model = Obj.Obj(filename) modelMatrix = self.createModelMatrix(translate, scale, rotate) rotationMatrix = self.createRotationMatrix(rotate) for face in model.faces: vertCount = len(face) v0 = model.vertices[face[0][0] - 1] v1 = model.vertices[face[1][0] - 1] v2 = model.vertices[face[2][0] - 1] if vertCount > 3: v3 = model.vertices[face[3][0] - 1] v0 = self.transform(v0, modelMatrix) v1 = self.transform(v1, modelMatrix) v2 = self.transform(v2, modelMatrix) if vertCount > 3: v3 = self.transform(v3, modelMatrix) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = (vt0[0], vt0[1]) vt1 = (vt1[0], vt1[1]) vt2 = (vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = (vt3[0], vt3[1]) else: vt0 = (0, 0) vt1 = (0, 0) vt2 = (0, 0) vt3 = (0, 0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] vn0 = self.transform(vn0, rotationMatrix) vn1 = self.transform(vn1, rotationMatrix) vn2 = self.transform(vn2, rotationMatrix) if vertCount > 3: vn3 = model.normals[face[3][2] - 1] vn3 = self.transform(vn3, rotationMatrix) self.triangle_bc(v0, v1, v2, texcoords=(vt0, vt1, vt2), normals=(vn0, vn1, vn2)) if vertCount > 3: #asumamos que 4, un cuadrado self.triangle_bc(v0, v2, v3, texcoords=(vt0, vt2, vt3), normals=(vn0, vn2, vn3))
dtype=np.int32), np.array(uvsamp.getVals(), dtype=np.float32)), meshsmooth.FVarChannel("normals", normal_indices, normal_values), ] # ] vertice_channel = meshsmooth.FVarChannel("verts", face_indices, vertices) mesh = meshsmooth.Mesh(face_counts, vertice_channel, channels) refiner = meshsmooth.TopologyRefiner(mesh) level = 2 # refiner.refine_uniform(level) m = refiner.refine_uniform(level) # print np.array(m.vertices) # print np.array(m.face_counts) # print np.array(m.fvchannels[1].values) out_obj = obj.Obj() out_obj.vertices = np.array(m.vertices.values) out_obj.normals = np.array(m.fvchannels[1].values) out_obj.uvs = np.array(m.fvchannels[0].values) out_obj.face_sizes = np.array(m.face_counts) out_obj.face_indices = np.array(m.vertices.indices) out_obj.normal_indices = np.array(m.fvchannels[1].indices) out_obj.uv_indices = np.array(m.fvchannels[0].indices) out_obj.write(os.path.join(os.path.dirname(__file__), "monekeyabc_smooth.obj"), True)
def asptask(name, code, source="unknown"): """ Takes a name and a string (full of ASP predicates and/or constraints) and returns a Task object (setting the Tasks's source if given or using 'unknown' as the default source). The returned Task does the following when run: 1. Gathers ASP source code from the following locations: a: The code passed as an argument to this function, stored in the task's local memory at mem.code. b: Any universal code for the task's network, in net.mem.code.universal. c: The current story state for the task's network, in net.mem.code.story. d: The entire contents of local memory *except* mem.code, converted into predicates of the form: mem("memory.address.of.key", "value"). e: The entire contents of global memory *except* the net.mem.code subtree, converted into predicates of the form: glmem("memory.address.of.key", "value"). 2. Combines any source code found into a single ASP problem and solves it by calling `clingo` (see the asp module). 3. Scans the resulting answer set for the following predicates and behaves accordingly, updating the code in net.mem.code.story and yielding an appropriate status: <story predicate> See the story_schemas variable. Predicates matching any of these schemata will be used as part of the current story going onwards. error(<predicate>) If any error predicates are generated, an exception will be raised and none of the other predicates in this list will be heeded. status(completed|failed|inprogress|blocked) The task will yield the given status. If either "completed" or "failed" is the result, it will automatically be removed from the active tasks list. If multiple status() predicates are detected an error is generated. local_mem(<address>, <predicate>) The given local memory address will be set to the given predicate. global_mem(<address>, <predicate>) The given (network-) global memory address will be set to the given predicate. spawn_task(<id>, <task-name>) A copy of the named task will be spawned on the current task's network after it completes. Arguments can be passed using the task_arg predciate structure. task_arg(<id>, <key>, <value>) Passes an argument to the task with the given id. This will set mem.args.<key> to <value> (which can be a predicate structure) in the spawned task. run_code(<code>) Runs the given Python code (the code must be quoted). Several useful local variables are available (and editing them affects continued operation): status: The current return status (a TaskStatus symbol) as specified by a 'status' predicate. This can be modified to change the status yielded by the current execution cycle. task: The current Task object. This can be used to access both local and global memory as normal. story_predicates: A set of predicate objects that will overwrite the current story. lmemlist: A list of Address, Value objects that are about to be set in local memory. gmemlist: A list of Address, Value objects that are about to be set in (network-) global memory. """ def gen(t): nonlocal name, code, source if not t.mem.code: raise ASPTaskError( "Task '{}' has no code (missing t.mem.code)!".format(name)) if type(t.net.mem.code.story) == obj.EmptyObj: raise ASPTaskError( "No story found (missing t.net.mem.code.story)!") if type(t.net.mem.code.universal) == obj.EmptyObj: raise ASPTaskError( "No universal constraints object (missing t.net.mem.code.universal)!" ) problem = assemble_problem(t) predicates = asp.solve(problem) # print("Predicates:") # for p in predicates: # print(p) errors = [] status = None story_predicates = set() to_run = [] to_spawn = {} lmemlist = [] gmemlist = [] for (schema, binding) in ans.bindings(story_schemas, predicates): story_predicates.add(binding[schema]) for (schema, binding) in ans.bindings(active_schemas, predicates): if schema == "error": print("Error in Clingo output!") errors.append(dequote(str(binding["error.Message"]))) elif schema == "status": s = dequote(str(binding["status.String"])) if status == None: status = s else: status = status + " and " + s elif schema == "local_mem": lmemlist.append( (dequote(str(binding["local_mem.Address"].name)), binding["local_mem.Value"])) elif schema == "global_mem": gmemlist.append((dequote(str(binding["global_mem.Address"])), binding["global_mem.Value"])) elif schema == "spawn_task": tid = str(binding["spawn_task.Id"]) tname = dequote(str(binding["spawn_task.TaskName"])) if tid not in to_spawn: to_spawn[tid] = { "name": "<unknown>", "args": {}, } to_spawn[tid]["name"] = tname elif schema == "task_arg": tid = str(binding["task_arg.Id"]) tkey = dequote(str(binding["task_arg.Key"])) tval = dequote(str(binding["task_arg.Value"])) if tid not in to_spawn: to_spawn[tid] = { "name": "<unknown>", "args": {}, } to_spawn[tid]["args"][tkey] = tval elif schema == "run_code": to_run.append(unquote(binding["run_code.QuotedCode"])) if errors: raise ASPTaskError("Error(s) while resolving answer set task:\n" + '\n'.join(errors)) if status in tn.TaskStatus.aliases: status = tn.TaskStatus.aliases[status] elif status == None: status = tn.TaskStatus.Final.Completed else: raise ASPTaskError( "Error: answer set produced invalid status '{}'.".format( status)) # Run code blocks before additions and removals are processed: for code in to_run: code_locals = { "status": status, "task": t, "story_predicates": story_predicates, "lmemlist": lmemlist, "gmemlist": gmemlist, } compiled = compile( code, "<snippet from ASP task '{}' in {}>".format(name, source), 'exec') exec(compiled, {}, code_locals) status = code_locals["status"] story_predicates = code_locals["story_predicates"] lmemlist = code_locals["lmemlist"] gmemlist = code_locals["gmemlist"] # Process the new story and memory elements: t.set_story(story_predicates) for (addr, val) in lmemlist: t.mem[addr] = val for (addr, val) in gmemlist: t.net.mem[addr] = val # Spawn tasks: for id in to_spawn: spawn_task(t.net, to_spawn[id]["name"], **to_spawn[id]["args"]) # We're finally done, so yield the indicated status: yield status # end of gen function gen.__name__ = name mem = obj.Obj() mem.code = ans.ruleset(ans.parse_asp(code)) return StoryTask(gen, mem=mem, source=source)
os.system("rm -rf work") os.system("mkdir work") for i in xrange(batch_size): copy_cmd = "cp -r ./circuit work/%d" % i os.system(copy_cmd) dim = len(var_name) domain = [] for i in xrange(dim): domain.append({ 'name': 'var1', 'type': 'continuous', 'domain': (bounds[i][0], bounds[i][1]) }) obj_f = obj.Obj(bounds, num_init, var_name) def obj_func(id, x): return obj_f.evaluate(id, x) def obj_func_batch(xs): ys = Parallel(n_jobs=batch_size)(delayed(obj_func)(id % batch_size, x) for id, x in enumerate(xs)) # ys = [] # for id, x in enumerate(xs): # ys.append(obj_f.evaluate(id % batch_size, x)) return np.array(ys)
glutSpecialFunc(specialKeyPressed) # Register the function called when the mouse is pressed. glutMouseFunc(mouse) # Register the function called when the mouse is moved. glutMotionFunc(mouseMove) # Initialize our window. InitGL(windowSizeX, windowSizeY) # Start Event Processing Engine glutMainLoop() # Print message to console, and kick off the main to get it rolling. print "Hit ESC key to quit." print "To increase subdivision count press Shift and + buttons" print "To rotate object clockwise press Shift and left arrow keys or Alt key and left mouse click" print "To rotate object counterclockwise press Shift and right arrow keys or Alt key and left mouse click" print "To make zoom press Alt key and right mouse click" print "To resetting the view press F key " objFile = obj.Obj() if len(sys.argv) > 1: objFile.load(sys.argv[1]) else: objFile.load("ecube.obj") # objFile.load("tori.obj") # python assignment3.py tori.obj main()
def __init__(self, active=None, finished=None, mem=None): self.last = None self.active = active or [] self.finished = finished or [] self.mem = mem or obj.Obj()