def test1(): scene = load('test/data/gears.obj') bb = scene.bb print bb print bb.sphere_beam() print bb.center() print scene.views[0]
def test3(): def compute_normals(sc): out = len(sc.points) * [ [.0, .0, .0] ] triangle_normals = len(sc.faces) * [ [.0, .0, .0] ] def hash(p): return .11234 * p[0] + .35678 * p[1] + .67257 * p[2] from collections import defaultdict pt_table = defaultdict(list) for i, t in enumerate(sc.faces): p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] pt_table[hash(p1)].append( (i, p1, t[0]) ) pt_table[hash(p2)].append( (i, p2, t[1]) ) pt_table[hash(p3)].append( (i, p3, t[2]) ) normal = vcross(sub(p2, p1), sub(p3, p1)) normal = vnorm(normal) triangle_normals[i] = normal for key, value in pt_table.iteritems(): # we assume no collisions in the hash point_index = value[0][2] first_point = value[0][1] # compute the normal of each triangles around # TODO should be done just once for each triangle in pre-process normals = [] for t_index, p, _ in value: assert p == first_point normals.append(triangle_normals[t_index]) N = ( sum(n[0] for n in normals) / len(normals), sum(n[1] for n in normals) / len(normals), sum(n[2] for n in normals) / len(normals) ) # print N out[point_index] = N return out scene = load(sys.argv[1]) with benchmark('compute normals'): scene.normals = compute_normals(scene) scene.write(sys.argv[2])
def test3(): def compute_normals(sc): out = len(sc.points) * [[.0, .0, .0]] triangle_normals = len(sc.faces) * [[.0, .0, .0]] def hash(p): return .11234 * p[0] + .35678 * p[1] + .67257 * p[2] from collections import defaultdict pt_table = defaultdict(list) for i, t in enumerate(sc.faces): p1 = sc.points[t[0]] p2 = sc.points[t[1]] p3 = sc.points[t[2]] pt_table[hash(p1)].append((i, p1, t[0])) pt_table[hash(p2)].append((i, p2, t[1])) pt_table[hash(p3)].append((i, p3, t[2])) normal = vcross(sub(p2, p1), sub(p3, p1)) normal = vnorm(normal) triangle_normals[i] = normal for key, value in pt_table.iteritems(): # we assume no collisions in the hash point_index = value[0][2] first_point = value[0][1] # compute the normal of each triangles around # TODO should be done just once for each triangle in pre-process normals = [] for t_index, p, _ in value: assert p == first_point normals.append(triangle_normals[t_index]) N = (sum(n[0] for n in normals) / len(normals), sum(n[1] for n in normals) / len(normals), sum(n[2] for n in normals) / len(normals)) # print N out[point_index] = N return out scene = load(sys.argv[1]) with benchmark('compute normals'): scene.normals = compute_normals(scene) scene.write(sys.argv[2])
def main(): gears = join('test', 'data', 'gears.obj') fn = gears if len(sys.argv) > 1: fn = sys.argv[1] sc = load(fn) with benchmark('build octree'): octree = Octree(sc) ray = (octree.bb.min(), octree.bb.max()) with benchmark('ray octree'): print octree.intersect(ray) # debug if fn == gears: segment = ([6.0124801866126916, -0.51249832634225589, -9.7930512397503584], (5.9371910904864844, -0.50190367657896617, -10.093763375438117)) assert octree.intersect(segment) octree.write()
def load_file(self, fn, verbose = 0, procedural = False): # Currently immediate mode is way faster (3x) than Draw array mode # cause we have to build the arrays in memory from list objects. # We should use module array instead # # VBO are 3 to 4 times faster than display list (random test) self.do_immediate_mode = False # self.do_immediate_mode = False # TEST self.use_display_list = False self.do_immediate_mode = True self.do_vbo = not self.do_immediate_mode self.vbo_init = False # Style self.do_lighting = not self.show_wireframe from scene import load with benchmark('load from disk'): self.scene = load(fn, verbose) if not self.scene: return self.fn = fn if self.use_display_list: self.dl = [-1 for i in self.scene.objets] # Init quat self.trackball = Trackball() # highlight setup, for CPython only # setup(self.scene.points, self.scene.faces) # Grid setup if self.octree: setup_octree() return self.scene
def load_file(self, fn, verbose=0, procedural=False): # Currently immediate mode is way faster (3x) than Draw array mode # cause we have to build the arrays in memory from list objects. # We should use module array instead # # VBO are 3 to 4 times faster than display list (random test) self.do_immediate_mode = False # self.do_immediate_mode = False # TEST self.use_display_list = False self.do_immediate_mode = True self.do_vbo = not self.do_immediate_mode self.vbo_init = False # Style self.do_lighting = not self.show_wireframe from scene import load with benchmark('load from disk'): self.scene = load(fn, verbose) if not self.scene: return self.fn = fn if self.use_display_list: self.dl = [-1 for i in self.scene.objets] # Init quat self.trackball = Trackball() # highlight setup, for CPython only # setup(self.scene.points, self.scene.faces) # Grid setup if self.octree: setup_octree() return self.scene
def test5(): scene = load(sys.argv[1]) from geom_ops import compute_normals with benchmark('compute normals'): scene.normals, scene.faces_normals = compute_normals(scene) scene.write(sys.argv[2])
def test4(): scene = load(sys.argv[1]) scene.write(sys.argv[2])
def main(): sc = load( join('data', 'gears.obj') ) g = Grid(sc)
# # http://code.google.com/apis/chart/ # # http://chart.apis.google.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World # http://chart.apis.google.com/chart?cht=p3&chs=250x100&chd=t:53,46&chl=Index|Verts&chdl=40|60 base = 'http://chart.apis.google.com/chart?cht=p3' url = [base] title = 'chtt=%s %s' % (basename(fn), sizeof_fmt(getsize(fn))) url.append(title.replace(' ', '+')) url.append('chs=300x120') # Dimensions datas = ','.join('%d' % s for s in [index, verts]) url.append('chd=t:' + datas ) url.append('chl=Index|Verts') datas = '|'.join('%d%%' % s for s in [index, verts]) url.append('chdl=' + datas) webbrowser.open('&'.join(url)) return size N = 100 * 1000 fn = sys.argv[1] if len(sys.argv) > 1 else 'test/data/dragon.obj' print getsize(fn) / 1024, 'KB' sc = load(fn) size = write_bin(sc, fn) print size / 1024, 'KB'
loss = loss_fn(tile_output, target_output[y_off:y_off+y_tile, x_off:x_off+x_tile]) print(tile_output) print(target_output) print("Loss: {}".format(loss)) optimizer.zero_grad() loss.backward(retain_graph=False) optimizer.step() # current_model.update() if loss < 1e-14 and torch.sum(tile_output) > 0.0: break if __name__ == '__main__': from tracer import create_analytic, sphere_model import scene r1 = torch.tensor((3.0,), dtype=torch.float64, requires_grad=True) r2 = torch.tensor((6.0,), dtype=torch.float64, requires_grad=False) def sphere_1(position): return sphere_model(position, r1) def sphere_2(position): return sphere_model(position, r2) test_scene = scene.load('test.hdf5') renderer = ImageRenderer() inverse((create_analytic(test_scene, sphere_1), r1), (create_analytic(test_scene, sphere_2), r2), renderer)
def scene2c(): ao = ArgsOptions() options = [ao.options.fn, ao.options.verbose, ao.options.procedural] return load(*options)
def main(): sc = load(join('data', 'gears.obj')) g = Grid(sc)
# # http://code.google.com/apis/chart/ # # http://chart.apis.google.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World # http://chart.apis.google.com/chart?cht=p3&chs=250x100&chd=t:53,46&chl=Index|Verts&chdl=40|60 base = 'http://chart.apis.google.com/chart?cht=p3' url = [base] title = 'chtt=%s %s' % (basename(fn), sizeof_fmt(getsize(fn))) url.append(title.replace(' ', '+')) url.append('chs=300x120') # Dimensions datas = ','.join('%d' % s for s in [index, verts]) url.append('chd=t:' + datas) url.append('chl=Index|Verts') datas = '|'.join('%d%%' % s for s in [index, verts]) url.append('chdl=' + datas) webbrowser.open('&'.join(url)) return size N = 100 * 1000 fn = sys.argv[1] if len(sys.argv) > 1 else 'test/data/dragon.obj' print getsize(fn) / 1024, 'KB' sc = load(fn) size = write_bin(sc, fn) print size / 1024, 'KB'
dest="distance_as_color", default=False) parser.add_option("--dist_range", type="int", dest="dist_range", default=30) (options, args) = parser.parse_args() # print(options) with open(options.scene, 'r', encoding='utf8') as yaml_file: cfg = yaml.load(yaml_file) camera = camera.Camera() camera.load(cfg['camera']) camera.init() scene = scene.Scene(camera) scene.load(cfg['scene']) color_mode = utils.ColorModes.UNIFORM if options.normal_as_color is True: color_mode = utils.ColorModes.NORMAL elif options.distance_as_color is True: color_mode = utils.ColorModes.DISTANCE render = render.Render( np.array([options.resolution_x, options.resolution_y]), options.trace_depth, scene, color_mode, options.dist_range) render.render() # render.draw() render.save(options.output)