def test_regular_sampler(self): sam = RegularSampler(2, 2, 1.0, 1) sam.create_shader() sam.prepare_standalone() sample = sam.generate_sample() self._check_result(sample, -0.5, -0.5, 0.5, 0.5, 0, 0, 1) sample = sam.generate_sample() self._check_result(sample, 0.5, -0.5, 0.5, 0.5, 1, 0, 1) sample = sam.generate_sample() self._check_result(sample, -0.5, 0.5, 0.5, 0.5, 0, 1, 1) sample = sam.generate_sample() self._check_result(sample, 0.5, 0.5, 0.5, 0.5, 1, 1, 1) sample = sam.generate_sample() self.assertFalse(sample)
def draw_samples(sampler, spp=None, fname=None, grid=False, resolution=None): if resolution is None: resolution = 10 else: resolution = int(resolution) if spp is None: spp = 16 else: spp = int(spp) if sampler == 'regular': sam = RegularSampler(width=resolution, height=resolution) elif sampler == 'random': sam = RandomSampler(width=resolution, height=resolution, nsamples=spp) elif sampler == 'jittered': sam = JitteredSampler(width=resolution, height=resolution, nsamples=spp) else: raise ValueError("Unknown sampler %s" % sampler) sam_gen = SamplerGenerator(sam) # sam.create_shader() # sam.prepare_standalone() ppx = 32 width = sam._width * ppx height = sam._height * ppx img = ImageRGBA(width, height) draw_white_rect(img) #beacuse of jpeg format if grid: draw_grid(img, ppx) while True: if not sam.has_more_samples(): break while True: sample = sam_gen.generate_sample() if sample is False: break x = sample.ix * ppx + int(sample.px * ppx) y = sample.iy * ppx + int(sample.py * ppx) img.set_pixel(x, y, 255, 0, 0) sam.increment_pass() if not sam.has_more_samples(): break if fname: save_image(fname, img) else: save_image("sampling.png", img)
def draw_samples(sampler, spp=None, fname=None, grid=False, resolution=None): if resolution is None: resolution = 10 else: resolution = int(resolution) if spp is None: spp = 16 else: spp = int(spp) if sampler == "regular": sam = RegularSampler(width=resolution, height=resolution) elif sampler == "random": sam = RandomSampler(width=resolution, height=resolution, nsamples=spp) elif sampler == "jittered": sam = JitteredSampler(width=resolution, height=resolution, nsamples=spp) else: raise ValueError("Unknown sampler %s" % sampler) sam_gen = SamplerGenerator(sam) # sam.create_shader() # sam.prepare_standalone() ppx = 32 width = sam._width * ppx height = sam._height * ppx img = ImageRGBA(width, height) draw_white_rect(img) # beacuse of jpeg format if grid: draw_grid(img, ppx) while True: if not sam.has_more_samples(): break while True: sample = sam_gen.generate_sample() if sample is False: break x = sample.ix * ppx + int(sample.px * ppx) y = sample.iy * ppx + int(sample.py * ppx) img.set_pixel(x, y, 255, 0, 0) sam.increment_pass() if not sam.has_more_samples(): break if fname: save_image(fname, img) else: save_image("sampling.png", img)