Esempio n. 1
0
    def test_transform_ray(self):
        ray_differential = RayDifferential(origin=Point(1,2,3),
                                           direction=Vector(10,20,30))
        ray_differential.rx_origin = Point(4,5,6)
        ray_differential.ry_origin = Point(5,6,7)
        ray_differential.rx_direction = Vector(2,3,4)
        ray_differential.ry_direction = Vector(3,4,5)
        ray_transformed = translate(Point(10,20,30))(ray_differential)

        self.assertTrue(isinstance(ray_transformed, RayDifferential))
        self.assertEqual(ray_transformed.o, Point(11,22,33))
        self.assertEqual(ray_transformed.d, Vector(10,20,30))
        self.assertEqual(ray_transformed.rx_origin, Point(14,25,36))
        self.assertEqual(ray_transformed.ry_origin, Point(15,26,37))
        self.assertEqual(ray_transformed.rx_direction, Vector(2,3,4))
        self.assertEqual(ray_transformed.ry_direction, Vector(3,4,5))
Esempio n. 2
0
    def generate_ray_differential(self, sample):
        """Generate a RayDifferential from the camera."""
        # Generate raster and camera samples
        p_ras = Point(sample.image_x, sample.image_y, 0)
        p_camera = self.raster_to_camera(p_ras)
        ray = RayDifferential(Point(0, 0, 0),
                              normalize(Vector.from_point(p_camera)),
                              0.0,
                              float('inf'))

        #  Modify ray for depth of field
        if self.lens_radius > 0.0:
            # Sample point on lens
            lens_u, lens_v = concentric_sample_disk(sample.lens_u,
                                                    sample.lens_v)
            lens_u *= self.lens_radius
            lens_v *= self.lens_radius

            # Compute point on plane of focus
            ft = self.focal_distance / ray.d.z
            p_focus = ray(ft)

            # Update ray for effect of lens
            ray.o = Point(lens_u, lens_v, 0.0)
            ray.d = normalize(p_focus - ray.o)

        ray.rx_origin = Point.from_point(ray.o)
        ray.ry_origin = Point.from_point(ray.o)
        ray.rx_direction = normalize(Vector.from_point(p_camera) + \
                                     self.dx_camera)
        ray.ry_direction = normalize(Vector.from_point(p_camera) + \
                                     self.dy_camera)
        ray.time = sample.time
        ray = self.camera_to_world(ray)
        ray.has_differentials = True

        return 1.0, ray
Esempio n. 3
0
    def generate_ray_differential(self, sample):
        """Generate a RayDifferential from the camera."""
        # Generate raster and camera samples
        p_ras = Point(sample.image_x, sample.image_y, 0)
        p_camera = self.raster_to_camera(p_ras)
        ray = RayDifferential(Point(0, 0, 0),
                              normalize(Vector.from_point(p_camera)), 0.0,
                              float('inf'))

        #  Modify ray for depth of field
        if self.lens_radius > 0.0:
            # Sample point on lens
            lens_u, lens_v = concentric_sample_disk(sample.lens_u,
                                                    sample.lens_v)
            lens_u *= self.lens_radius
            lens_v *= self.lens_radius

            # Compute point on plane of focus
            ft = self.focal_distance / ray.d.z
            p_focus = ray(ft)

            # Update ray for effect of lens
            ray.o = Point(lens_u, lens_v, 0.0)
            ray.d = normalize(p_focus - ray.o)

        ray.rx_origin = Point.from_point(ray.o)
        ray.ry_origin = Point.from_point(ray.o)
        ray.rx_direction = normalize(Vector.from_point(p_camera) + \
                                     self.dx_camera)
        ray.ry_direction = normalize(Vector.from_point(p_camera) + \
                                     self.dy_camera)
        ray.time = sample.time
        ray = self.camera_to_world(ray)
        ray.has_differentials = True

        return 1.0, ray