示例#1
0
def create_random_lf_cameras(num_to_create,
                             look_from_radii,
                             max_look_to_origin=1.0,
                             interspatial_distance=1.0,
                             spatial_rows=8,
                             spatial_cols=8,
                             look_up=vec3(0.0, 1.0, 0.0)):
    """Create a list of randomnly positioned lf cameras

    Keyword arguments:
    num_to_create -- the number of lf cameras to create
    look_from_radii -- min, max distance from the origin to camera look from
    max_look_to_origin -- max distance from the origin to camera look to    
    interspatial_distance -- distance between cameras in array (default 1.0)
    spatial_rows, spatial_cols -- dimensions of camera array (default 8 x 8)
    """
    lf_cameras = []
    for _ in range(num_to_create):
        look_from, look_to, look_up = create_random_camera(
            look_from_radii, max_look_to_origin, look_up, False)

        # Centre the light field on the centre image
        view_direction = look_to - look_from
        right_vec = normalize(cross_product(view_direction, look_up))
        correction_x = -ceil(spatial_cols / 2) * interspatial_distance
        correction_y = ceil(spatial_rows / 2) * interspatial_distance
        correction = (normalize(look_up) * correction_y +
                      right_vec * correction_x)
        look_from = look_from + correction
        look_to = look_to + correction
        lf_cam = LightFieldCamera(look_from, look_to, look_up,
                                  interspatial_distance, spatial_rows,
                                  spatial_cols)
        lf_cameras.append(lf_cam)
    return lf_cameras
def create_random_camera(look_from_radii,
                        max_look_to_origin=1.0,
                        look_up=vec3(0, 1, 0),
                        fix_look_up=False,
                        random_look_up=False):
    """Create a randomly positioned camera"""
    d = max_look_to_origin
    look_from = rand_vec_between_spheres(*look_from_radii)
    look_to = vec3(random_float(), random_float(), random_float()) * d
    reverse_direction = normalize(look_from - look_to)
    if random_look_up:
        look_up = normalize(
            vec3(random_float(), random_float(), random_float()))
    if fix_look_up:
        right = normalize(cross_product(look_up, reverse_direction))
        look_up = cross_product(reverse_direction, right)
    return (look_from, look_to, look_up)
def rand_vec_between_spheres(big_radius, small_radius):
    """
    Generates a vec3 in between the shell of two spheres
    Input is the radius of the big and small sphere
    """
    radius_diff = big_radius - small_radius
    point_on_unit_sphere = normalize(rand_vec_in_unit_sphere())
    scale_factor = (random() * radius_diff + small_radius)
    point_in_between = point_on_unit_sphere * scale_factor    
    return point_in_between
示例#4
0
    def callback(self, pickevent, type):
        if pickevent.state == ivw.PickingState.Updated:
            i = pickevent.pickedId
            points = json.loads(self.pts.value)
            pos = points["from"][i] if type == 1 else points["to"][i]
            pickevent.setToolTip(f"{type} {i} {pos}")
        else:
            pickevent.setToolTip("")

        # and ivw.PickingPressItem.Primary in pickevent.pressItems
        if (pickevent.pressState == ivw.PickingPressState.Move
                and ivw.PickingPressItem.Primary in pickevent.pressItems):
            points = json.loads(self.pts.value)

            delta = pickevent.getWorldSpaceDeltaAtPressDepth(
                self.camera.camera)
            print(f"drag {delta}")

            upPos = glm.dvec3(points["up"][pickevent.pickedId])

            if type == 1:
                points["from"][pickevent.pickedId][0] += delta.x
                points["from"][pickevent.pickedId][1] += delta.y
                points["from"][pickevent.pickedId][2] += delta.z
            elif type == 2:
                points["to"][pickevent.pickedId][0] += delta.x
                points["to"][pickevent.pickedId][1] += delta.y
                points["to"][pickevent.pickedId][2] += delta.z
            else:
                upPos += delta / self.scale.value

            normal = glm.dvec3(points["to"][pickevent.pickedId]) - glm.dvec3(
                points["from"][pickevent.pickedId])
            upPos = upPos - normal * (glm.dot(upPos, normal) /
                                      glm.length2(normal))
            upPos = glm.normalize(upPos)
            points["up"][pickevent.pickedId][0] = upPos.x
            points["up"][pickevent.pickedId][1] = upPos.y
            points["up"][pickevent.pickedId][2] = upPos.z

            pickevent.markAsUsed()
            self.pts.value = json.dumps(
                points,
                indent=4,
            )
            self.invalidate(ivw.properties.InvalidationLevel.InvalidOutput)
示例#5
0
    def updateFrame(self):
        currentFrame = self.frame.value
        if currentFrame < len(self.fromTrack):
            self.outCamera.properties.lookFrom.minValue = glm.vec3(-10000.0)
            self.outCamera.properties.lookFrom.maxValue = glm.vec3(+10000.0)
            self.outCamera.properties.lookTo.minValue = glm.vec3(-10000.0)
            self.outCamera.properties.lookTo.maxValue = glm.vec3(+10000.0)

            fromVec = glm.vec3(self.fromTrack[currentFrame])
            toVec = glm.vec3(self.toTrack[currentFrame])
            upVec = glm.vec3(self.upTrack[currentFrame])

            normal = toVec - fromVec
            right = glm.cross(normal, upVec)
            upVec = glm.normalize(glm.cross(right, normal))

            self.outCamera.lookFrom = fromVec
            self.outCamera.lookTo = toVec
            self.outCamera.lookUp = upVec
示例#6
0
    def calculate_camera_array(self):
        """Returns list of (look_from, look_to) tuples for the camera array"""
        look_list = []

        row_step_vec = normalize(self.look_up) * self.interspatial_distance
        col_step_vec = self.get_look_right() * self.interspatial_distance

        #Start at the top left camera position
        for i in range(self.spatial_rows):
            row_movement = row_step_vec * (-i)
            row_look_from = self.look_from + row_movement
            row_look_to = self.look_to + row_movement

            for j in range(self.spatial_cols):
                col_movement = col_step_vec * j
                cam_look_from = row_look_from + col_movement
                cam_look_to = row_look_to + col_movement

                look_list.append((cam_look_from, cam_look_to))

        return look_list
示例#7
0
 def get_look_right(self):
     """Get the right look vector for the top left camera"""
     view_direction = self.look_to - self.look_from
     right_vec = normalize(cross_product(view_direction, self.look_up))
     return right_vec