Ejemplo n.º 1
0
    def generate_ray_differential(self, sample):
        """Generate a RayDifferential from the camera."""
        # generate the ray
        weight, ray = self.generate_ray(sample)
        ray_diff = RayDifferential.from_ray(ray)
        
        # find ray after shifting one pixel in the x direction
        sshift = CameraSample.from_sample(sample)
        sshift.image_x += 1
        weight_x, ray_x = self.generate_ray(sshift)
        ray_diff.rx_origin = ray_x.o
        ray_diff.rx_direction = ray_x.d
        
        # find ray after shifting one pixel in the y direction
        sshift.image_x -= 1
        sshift.image_y += 1
        weight_y, ray_y = self.generate_ray(sshift)
        ray_diff.ry_origin = ray_y.o
        ray_diff.ry_direction = ray_y.d

        if (weight_x == 0.0) or (weight_y == 0.0):
            return 0.0, ray_diff

        ray_diff.has_differentials = True
        return weight, ray_diff
Ejemplo n.º 2
0
    def generate_ray_differential(self, sample):
        """Generate a RayDifferential from the camera."""
        # generate the ray
        weight, ray = self.generate_ray(sample)
        ray_diff = RayDifferential.from_ray(ray)

        # find ray after shifting one pixel in the x direction
        sshift = CameraSample.from_sample(sample)
        sshift.image_x += 1
        weight_x, ray_x = self.generate_ray(sshift)
        ray_diff.rx_origin = ray_x.o
        ray_diff.rx_direction = ray_x.d

        # find ray after shifting one pixel in the y direction
        sshift.image_x -= 1
        sshift.image_y += 1
        weight_y, ray_y = self.generate_ray(sshift)
        ray_diff.ry_origin = ray_y.o
        ray_diff.ry_direction = ray_y.d

        if (weight_x == 0.0) or (weight_y == 0.0):
            return 0.0, ray_diff

        ray_diff.has_differentials = True
        return weight, ray_diff
Ejemplo n.º 3
0
    def test_ray_differential(self):
        r = Ray(Point(0, 0, 0), Vector(1, 2, 3))
        rd = RayDifferential(Point(0, 0, 0), Vector(1, 2, 3))
        
        # test copy constructor from Ray
        rd.has_differentials = True
        rd1 = RayDifferential.from_ray_differential(rd)
        self.assertTrue(isinstance(rd1, RayDifferential))        
        self.assertEqual(rd1.o, rd.o)
        self.assertEqual(rd1.d, rd.d)
        self.assertEqual(rd1.rx_origin, rd.rx_origin)
        self.assertEqual(rd1.ry_origin, rd.ry_origin)
        self.assertEqual(rd1.rx_direction, rd.rx_direction)
        self.assertEqual(rd1.ry_direction, rd.ry_direction)
        self.assertEqual(rd1.has_differentials, rd.has_differentials)

        # test copy constructor from Ray
        rd2 = RayDifferential.from_ray(r)
        self.assertTrue(isinstance(rd2, RayDifferential))
        self.assertEqual(rd2.d, r.d)
        self.assertEqual(rd2.has_differentials, False)

        # test constructor from parent ray
        rd3 = RayDifferential.from_ray_parent(r.o, r.d, r, r.mint)
        self.assertTrue(isinstance(rd3, RayDifferential))
        self.assertEqual(rd3.depth, r.depth+1)

        # test operator()
        p = rd(1.7)        
        self.assertEqual(p, Point(1.7, 3.4, 5.1))
Ejemplo n.º 4
0
    def test_ray_differential(self):
        r = Ray(Point(0, 0, 0), Vector(1, 2, 3))
        rd = RayDifferential(Point(0, 0, 0), Vector(1, 2, 3))

        # test copy constructor from Ray
        rd.has_differentials = True
        rd1 = RayDifferential.from_ray_differential(rd)
        self.assertTrue(isinstance(rd1, RayDifferential))
        self.assertEqual(rd1.o, rd.o)
        self.assertEqual(rd1.d, rd.d)
        self.assertEqual(rd1.rx_origin, rd.rx_origin)
        self.assertEqual(rd1.ry_origin, rd.ry_origin)
        self.assertEqual(rd1.rx_direction, rd.rx_direction)
        self.assertEqual(rd1.ry_direction, rd.ry_direction)
        self.assertEqual(rd1.has_differentials, rd.has_differentials)

        # test copy constructor from Ray
        rd2 = RayDifferential.from_ray(r)
        self.assertTrue(isinstance(rd2, RayDifferential))
        self.assertEqual(rd2.d, r.d)
        self.assertEqual(rd2.has_differentials, False)

        # test constructor from parent ray
        rd3 = RayDifferential.from_ray_parent(r.o, r.d, r, r.mint)
        self.assertTrue(isinstance(rd3, RayDifferential))
        self.assertEqual(rd3.depth, r.depth + 1)

        # test operator()
        p = rd(1.7)
        self.assertEqual(p, Point(1.7, 3.4, 5.1))