コード例 #1
0
 def step(self, step_t):
     t = self.c.get_current_time()
     print 'Simulation time:', t
     T = time.time()
     self.update_levelset(t, t + step_t)
     print 'Update Leveset Time:', time.time() - T
     T = time.time()
     self.c.step(step_t)
     print 'Step Time:', time.time() - T
     image_buffer = tc_core.Array2DVector3(self.video_manager.width,
                                           self.video_manager.height,
                                           Vector(0, 0, 0.0))
     particles = self.c.get_render_particles()
     particles.write(self.directory + '/particles%05d.bin' % self.frame)
     res = map(float, self.resolution)
     camera = Camera('pinhole',
                     origin=(0, res[1] * 0.4, res[2] * 1.4),
                     look_at=(0, -res[1] * 0.5, 0),
                     up=(0, 1, 0),
                     fov=90,
                     width=10,
                     height=10)
     self.particle_renderer.set_camera(camera)
     self.particle_renderer.render(image_buffer, particles)
     img = image_buffer_to_ndarray(image_buffer)
     img = LDRDisplay(exposure=2.0, adaptive_exposure=False).process(img)
     show_image('Vis', img)
     self.video_manager.write_frame(img)
     self.frame += 1
コード例 #2
0
 def step(self, step_t):
     t = self.c.get_current_time()
     print('Simulation time:', t)
     T = time.time()
     self.c.step(step_t)
     print('Time:', time.time() - T)
     image_buffer = tc_core.Array2DVector3(self.video_manager.width,
                                           self.video_manager.height,
                                           Vector(0, 0, 0.0))
     particles = self.c.get_render_particles()
     particles.write(
         self.get_output_path('particles%05d.bin' % self.step_counter))
     camera = Camera('pinhole',
                     origin=(0, 0, 50),
                     look_at=(0, 0, 0),
                     up=(0, 1, 0),
                     fov=70,
                     width=self.video_manager.width,
                     height=self.video_manager.height)
     self.particle_renderer.set_camera(camera)
     self.particle_renderer.render(image_buffer, particles)
     img = image_buffer_to_ndarray(image_buffer)
     # img = LDRDisplay(exposure=1, adaptive_exposure=False).process(img)
     show_image('Vis', img)
     self.video_manager.write_frame(img)
     self.step_counter += 1
コード例 #3
0
 def step(self, step_t):
     t = self.c.get_current_time()
     print 'Simulation time:', t
     T = time.time()
     self.c.step(step_t)
     print 'Time:', time.time() - T
     image_buffer = tc_core.Array2DVector3(self.video_manager.width,
                                           self.video_manager.height,
                                           Vector(0, 0, 0.0))
     particles = self.c.get_render_particles()
     particles.write(self.directory + '/particles%05d.bin' % self.frame)
     res = map(float, self.resolution)
     radius = res[0] * 2.5
     theta = 0
     camera = Camera('pinhole',
                     origin=(0, res[1], res[2] * 5),
                     look_at=(0, 0, 0),
                     up=(0, 1, 0),
                     fov=70,
                     width=10,
                     height=10)
     self.particle_renderer.set_camera(camera)
     self.particle_renderer.render(image_buffer, particles)
     img = image_buffer_to_ndarray(image_buffer)
     img = LDRDisplay(exposure=0.1).process(img)
     show_image('Vis', img)
     self.video_manager.write_frame(img)
     self.frame += 1
コード例 #4
0
 def view(self, frame, camera):
     particles = tc_core.RenderParticles()
     ret = particles.read(self.input_directory + 'particles%05d.bin' % frame)
     if not ret:
         print 'read file failed'
         return False
     image_buffer = tc_core.Array2DVector3(self.video_manager.width, self.video_manager.height, Vector(0, 0, 0.0))
     self.particle_renderer.set_camera(camera)
     self.particle_renderer.render(image_buffer, particles)
     img = image_buffer_to_ndarray(image_buffer)
     #img = LDRDisplay(exposure=1, adaptive_exposure=False).process(img)
     show_image('Vis', img)
     self.video_manager.write_frame(img)
     return True
コード例 #5
0
ファイル: mpm.py プロジェクト: ckatrycz/Spray
 def step(self, step_t, camera=None):
     t = self.c.get_current_time()
     print('* Current t: %.3f' % t)
     self.update_levelset(t, t + step_t)
     T = time.time()
     if not self.start_simulation_time:
         self.start_simulation_time = T
     if not self.simulation_total_time:
         self.simulation_total_time = 0
     self.c.step(step_t)
     self.simulation_total_time += time.time() - T
     print('* Step Time: %.2f [tot: %.2f per frame %.2f]' %
           (time.time() - T, time.time() - self.start_simulation_time,
            self.simulation_total_time / (self.c.frame + 1)))
     image_buffer = tc_core.Array2DVector3(
         Vectori(self.video_manager.width, self.video_manager.height),
         Vector(0, 0, 0.0))
     '''
 particles = self.c.get_render_particles()
 try:
   os.mkdir(self.directory + '/particles')
 except:
   pass
 particles.write(self.directory + '/particles/%05d.bin' % self.c.frame)
 '''
     res = list(map(float, self.res))
     r = res[0]
     if not camera:
         camera = Camera('pinhole',
                         origin=(0, r * 0.4, r * 1.4),
                         look_at=(0, -r * 0.5, 0),
                         up=(0, 1, 0),
                         fov=90,
                         res=(10, 10))
     if False:
         self.particle_renderer.set_camera(camera)
         self.particle_renderer.render(image_buffer, particles)
         img = image_buffer_to_ndarray(image_buffer)
         img = LDRDisplay(exposure=2.0,
                          adaptive_exposure=False).process(img)
         show_image('Vis', img)
         self.video_manager.write_frame(img)
コード例 #6
0
from taichi.gui.image_viewer import show_image

if __name__ == '__main__':
    resolution = [64] * 3
    resolution[1] *= 2

    particle_renderer = ParticleRenderer('shadow_map',
                                         shadow_map_resolution=0.5, alpha=0.6, shadowing=0.07, ambient_light=0.3,
                                         light_direction=(1, 3, 1))

    smoke = Smoke3(resolution=tuple(resolution),
                   simulation_depth=resolution[2], delta_x=1.0 / resolution[0], gravity=(0, 0, 0),
                   advection_order=1, cfl=0.5, smoke_alpha=80.0, smoke_beta=800,
                   temperature_decay=0.05, pressure_tolerance=1e-6, density_scaling=2, initial_speed=(0, 0, 0),
                   tracker_generation=20, perturbation=0, pressure_solver='mgpcg', num_threads=2, open_boundary=True,
                   maximum_pressure_iterations=200)

    for i in range(600):
        smoke.step(0.03)
        particles = smoke.c.get_render_particles()
        width, height = 512, 1024
        image_buffer = tc_core.Array2DVector3(width, height, Vector(0, 0, 0.0))
        radius = resolution[0] * 4
        camera = Camera('pinhole', origin=(0, radius * 0.3, radius),
                        look_at=(0, 0, 0), up=(0, 1, 0), fov=70,
                        width=width, height=height)
        particle_renderer.set_camera(camera)
        particle_renderer.render(image_buffer, particles)
        img = image_buffer_to_ndarray(image_buffer)
        show_image('Vis', img)