Esempio n. 1
0
scene.add_object(xy, name="xy")
scene.add_object(yz, name="yz")
scene.add_object(xz, name="xz")

x_transl = 0
y_transl = 0
z_transl = 15

camera_pos = hl.IDENTITY4


def rotate(theta, axis):
    return np.matmul(camera_pos, hl.rotate_3(theta, axis))


translate = np.matmul(camera_pos, hl.translate_3(x_transl, y_transl, z_transl))

'''scene.render_scene(x_range=(-25, 25),
                   y_range=(-25, 25),
                   camera_position=camera_pos,
                   resolution=50,
                   projection_type="weak",
                   style='line',
                   region_params={'a_spacing': 0.5,
                                  'b_spacing': 0.5},
                   foreground=hl.WHITE,
                   background=hl.BLACK,
                   display=True)'''

rps = 1 / 3
period = 1/rps
Esempio n. 2
0
    def frame(self,
              camera_position=(0, 0, 0),
              projection_type=Projections.WEAK,
              styles=Styles.UNIFORM,
              densities=1):
        if not type(styles) == dict:
            styles_val = styles
            styles = {}
            for obj in self.objects:
                styles[obj] = styles_val

        if not type(densities) == dict:
            densities_val = densities
            densities = {}
            for obj in self.objects:
                densities[obj] = densities_val
        points = []
        lines = []
        endpoints1 = []
        endpoints2 = []
        scene_position = np.matmul(
            hl.translate_3(tuple(i * -1 for i in camera_position)),
            hl.IDENTITY4)

        if projection_type == Projections.ORTHO:
            projection_matrix = hl.ORTHO_PROJECT
        elif projection_type == Projections.WEAK:
            projection_matrix = hl.weak_project()
        else:  # no projection
            projection_matrix = hl.IDENTITY4

        transform = np.matmul(projection_matrix, scene_position)

        # TODO group objects
        objects = self.objects.items()
        render_objects = []
        for obj in objects:
            if isinstance(obj[1], hl.Group):
                for component in obj[1].components:
                    render_objects.append((obj[0], component))
            else:
                render_objects.append(obj)
        #print(render_objects)
        for name, obj in render_objects:
            obj_points = obj.region(densities[name])
            #print(obj_points)
            if styles[name] == Styles.UNIFORM:
                obj_points = hl.reshape_array(obj_points)
                transformed_obj_points = np.matmul(obj.position, obj_points)
                if len(points) == 0:
                    points = transformed_obj_points
                else:
                    points = np.concatenate((points, transformed_obj_points),
                                            axis=1)
            elif styles[name] == Styles.WIREFRAME:
                # TODO 2d case
                if obj.region_type == 'path':
                    print('wireframe not implemented for path objects')
                    return
                h1 = obj_points[:, :, 1:]
                h2 = obj_points[:, :, :-1]
                v1 = obj_points[:, 1:, :]
                v2 = obj_points[:, :-1, :]
                h1 = hl.reshape_array(h1)
                h2 = hl.reshape_array(h2)
                v1 = hl.reshape_array(v1)
                v2 = hl.reshape_array(v2)

                new_endpoints1 = np.concatenate((h1, v1), axis=1)
                new_endpoints2 = np.concatenate((h2, v2), axis=1)
                new_endpoints1, new_endpoints2 = hl.apply_transforms(
                    transforms=(obj.position, ),
                    arrays=(new_endpoints1, new_endpoints2))

                if len(endpoints1) == 0:
                    endpoints1 = new_endpoints1
                    endpoints2 = new_endpoints2
                else:
                    endpoints1 = np.concatenate((endpoints1, new_endpoints1),
                                                axis=1)
                    endpoints2 = np.concatenate((endpoints2, new_endpoints2),
                                                axis=1)

        if len(endpoints1) > 0:
            endpoints1, endpoints2 = hl.apply_transforms(
                (transform, ), (endpoints1, endpoints2))
            endpoints1 = np.divide(endpoints1, endpoints1[-1])
            endpoints2 = np.divide(endpoints2, endpoints2[-1])
            lines = np.array((endpoints1, endpoints2))
            lines = lines.transpose()
            lines = np.swapaxes(lines, 1, 2)
        if len(points) > 0:
            shape = np.shape(points)
            if shape[0] == 3:
                points = np.vstack((points, np.ones(shape[1])))

            points = np.matmul(transform, points)
            points = np.divide(points, points[-1])
            points = points.transpose()

        return points, lines
Esempio n. 3
0
                        polarization=(-1, 0, 0),
                        start_time=random.uniform(0, 5))

for i in range(num_drops):
    start_time = random.uniform(i/3, 10)
    x_location = random.uniform(-5, 5)
    y_location = random.uniform(-5, 5)
    surface.add_more_disturbances(disturbance=disturbance,
                                  init_pos=(x_location, y_location),
                                  polarization=(-1, 0, 0),
                                  start_time=start_time)

scene.add_object(surface, name="basin")

camera_pos = hl.IDENTITY4
camera_pos = np.matmul(camera_pos, hl.translate_3(-5, 0, -15))
camera_pos = np.matmul(camera_pos, hl.rotate_3(math.pi / 3, axis=(0, 1, 0)))


rotation_per_timestep = hl.rotate_3(math.pi / 20, axis=(1, 0, 0))


hl.parallel_video(frame_func=lambda t: scene.render_scene(params={'basin': {'t': t}},
                                                          x_range=(-25, 25),
                                                          y_range=(-25, 25),
                                                          camera_position=camera_pos,
                                                          resolution=50,
                                                          projection_type="weak",
                                                          style='line',
                                                          region_params={'a_spacing': 0.15,
                                                                         'b_spacing': 0.15,
Esempio n. 4
0
 def translate(self, t):
     return self.transform(hl.translate_3(t))
Esempio n. 5
0
sys.path.append('../hallucinator')
import hallucinator as hl
import numpy as np
import math

scene = hl.MonochromeScene()

scene.add_object(hl.box(10, 10, 10), name='box')
scene.add_object(hl.box(10, 10, 10, p0=(0, 20, 20)), name='box2')
scene.add_object(hl.box(10, 10, 10, p0=(20, 0, 20)), name='box3')
scene.add_object(hl.box(10, 10, 10, p0=(0, 0, 40)), name='box4')

#scene.render_scene(x_range=(-40, 80), y_range=(-40, 80), display=True, resolution=10)

scene = scene.transform(hl.translate_3(-20, -20, 50))

scene.render_scene(x_range=(-40, 40),
                   y_range=(-40, 40),
                   projection_type='weak',
                   display=True,
                   resolution=15)

camera_position = hl.IDENTITY4

scene.render_scene(x_range=(-40, 40),
                   y_range=(-40, 40),
                   camera_position=camera_position,
                   projection_type='weak',
                   display=True,
                   resolution=15)
Esempio n. 6
0
 def translate(self, tx=0, ty=0, tz=0):
     return self.transform(hallucinator.translate_3(tx, ty, tz))