예제 #1
0
 def test_bounding_box_5(self):
     bbox1 = BBox(Point(0, -2, 0),
                  Point(1, -1, 1))
     p1 = Point(-3,3,0.5)
     bbox2 = union(bbox1, p1)
     self.assertEqual(bbox2.p_min, Point(-3, -2, 0))
     self.assertEqual(bbox2.p_max, Point(1, 3, 1))
예제 #2
0
 def test_bounding_box_6(self):
     bbox1 = BBox(Point(0, -2, 0),
                  Point(1, -1, 1))
     bbox2 = BBox(Point(-2, 0, -2),
                  Point(-1, 1, -1))
     bbox3 = union(bbox1, bbox2)
     self.assertEqual(bbox3.p_min, Point(-2, -2, -2))
     self.assertEqual(bbox3.p_max, Point(1, 1, 1))
예제 #3
0
    def __init__(self, accel, lights=None, volume_region=None):
        """Default constructor for Scene."""

        # Primitive
        self.aggregate = accel

        # array of Light
        if lights:
            self.lights = lights
        else:
            self.lights = []

        # VolumeRegion
        self.volume_region = volume_region

        # initialize bounding box
        self.bound = self.aggregate.world_bound()
        if self.volume_region:
            self.bound = union(self.bound, self.volume_region.world_bound())
예제 #4
0
파일: scene.py 프로젝트: BaldrLector/pyPbrt
    def __init__(self, accel, lights=None, volume_region=None):
        """Default constructor for Scene."""

        # Primitive
        self.aggregate = accel

        # array of Light
        if lights:
            self.lights = lights
        else:
            self.lights = []

        # VolumeRegion
        self.volume_region = volume_region

        # initialize bounding box
        self.bound = self.aggregate.world_bound()
        if self.volume_region:
            self.bound = union(self.bound, self.volume_region.world_bound())
예제 #5
0
    def __call__(self, elt):
        """Overload the operator().

        Supported operations:
        * Transform(Point)
        * Transform(Vector)
        * Transform(Normal)
        * Transform(Ray)
        * Transform(RayDifferential)
        * Transform(BBox)
        
        """
        if isinstance(elt, Point):
            x = elt.x
            y = elt.y
            z = elt.z
            xp = self.m.m[0][0] * x + self.m.m[0][1] * y + self.m.m[0][
                2] * z + self.m.m[0][3]
            yp = self.m.m[1][0] * x + self.m.m[1][1] * y + self.m.m[1][
                2] * z + self.m.m[1][3]
            zp = self.m.m[2][0] * x + self.m.m[2][1] * y + self.m.m[2][
                2] * z + self.m.m[2][3]
            wp = self.m.m[3][0] * x + self.m.m[3][1] * y + self.m.m[3][
                2] * z + self.m.m[3][3]
            if wp == 1.0:
                return Point(xp, yp, zp)
            else:
                return Point(xp, yp, zp) / wp
        elif isinstance(elt, Vector):
            x = elt.x
            y = elt.y
            z = elt.z
            xp = self.m.m[0][0] * x + self.m.m[0][1] * y + self.m.m[0][2] * z
            yp = self.m.m[1][0] * x + self.m.m[1][1] * y + self.m.m[1][2] * z
            zp = self.m.m[2][0] * x + self.m.m[2][1] * y + self.m.m[2][2] * z
            return Vector(xp, yp, zp)
        elif isinstance(elt, Normal):
            x = elt.x
            y = elt.y
            z = elt.z
            return Normal(
                self.m_inv.m[0][0] * x + self.m_inv.m[1][0] * y +
                self.m_inv.m[2][0] * z, self.m_inv.m[0][1] * x +
                self.m_inv.m[1][1] * y + self.m_inv.m[2][1] * z,
                self.m_inv.m[0][2] * x + self.m_inv.m[1][2] * y +
                self.m_inv.m[2][2] * z)
        elif isinstance(elt, RayDifferential):
            ray = RayDifferential.from_ray_differential(elt)
            ray.o = self(ray.o)
            ray.d = self(ray.d)
            ray.rx_origin = self(ray.rx_origin)
            ray.ry_origin = self(ray.ry_origin)
            ray.rx_direction = self(ray.rx_direction)
            ray.ry_direction = self(ray.ry_direction)
            return ray
        elif isinstance(elt, Ray):
            ray = Ray.from_ray(elt)
            ray.o = self(ray.o)
            ray.d = self(ray.d)
            return ray
        elif isinstance(elt, BBox):
            ret = BBox(self(Point(elt.p_min.x, elt.p_min.y, elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_min.y,
                                        elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_max.y,
                                        elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_min.y,
                                        elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_max.y,
                                        elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_max.y,
                                        elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_min.y,
                                        elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_max.y,
                                        elt.p_max.z)))
            return ret
예제 #6
0
파일: grid.py 프로젝트: BaldrLector/pyPbrt
    def __init__(self, primitives, refine_immediately):
        """Default constructor for GridAccel."""
        # initialize self.primitives with primitives for grid
        if refine_immediately:
            self.primitives = []
            for primitive in primitives:
                primitive.fully_refine(self.primitives)
        else:
            self.primitives = list(primitives)

        # compute bounds and choose grid resolution
        self.bounds = BBox()
        for primitive in self.primitives:
            self.bounds = union(self.bounds, primitive.world_bound())
        delta = self.bounds.p_max - self.bounds.p_min

        # find voxels_per_unit_dist for grid
        max_axis = self.bounds.maximum_extent()
        inv_max_width = 1.0 / delta[max_axis]
        cube_root = 3.0 * pow(len(self.primitives), 1.0 / 3.0)
        voxels_per_unit_dist = cube_root * inv_max_width
        self.n_voxels = []
        for axis in range(3):
            self.n_voxels.append(
                clamp(round_to_int(delta[axis] * voxels_per_unit_dist), 1, 64))

        # compute voxel widths and allocate voxels
        self.width = Vector()
        self.inv_width = Vector()
        for axis in range(3):
            self.width[axis] = delta[axis] / self.n_voxels[axis]
            if self.width[axis] == 0.0:
                self.inv_width[axis] = 0.0
            else:
                self.inv_width[axis] = 1.0 / self.width[axis]
        nv = self.n_voxels[0] * self.n_voxels[1] * self.n_voxels[2]

        # array of voxels, initialized at None
        self.voxels = [None] * nv

        # add primitives to grid voxels
        for primitive in self.primitives:
            # find voxel extent of primitive
            primitive_bound = primitive.world_bound()
            v_min = []
            v_max = []
            for axis in range(3):
                v_min.append(self._pos_to_voxel(primitive_bound.p_min, axis))
                v_max.append(self._pos_to_voxel(primitive_bound.p_max, axis))

            # add primitive to overlapping voxels
            for z in range(v_min[2], v_max[2] + 1):
                for y in range(v_min[1], v_max[1] + 1):
                    for x in range(v_min[0], v_max[0] + 1):
                        index = self._offset(x, y, z)
                        if self.voxels[index] is None:
                            self.voxels[index] = Voxel(primitive)
                        else:
                            self.voxels[index].add_primitive(primitive)

        # create reader-writer mutex for grid
        self.rw_lock = DummyRWLock()
예제 #7
0
    def __call__(self, elt):
        """Overload the operator().

        Supported operations:
        * Transform(Point)
        * Transform(Vector)
        * Transform(Normal)
        * Transform(Ray)
        * Transform(RayDifferential)
        * Transform(BBox)
        
        """
        if isinstance(elt, Point):
            x = elt.x
            y = elt.y
            z = elt.z
            xp = self.m.m[0][0]*x + self.m.m[0][1]*y + self.m.m[0][2]*z + self.m.m[0][3]
            yp = self.m.m[1][0]*x + self.m.m[1][1]*y + self.m.m[1][2]*z + self.m.m[1][3]
            zp = self.m.m[2][0]*x + self.m.m[2][1]*y + self.m.m[2][2]*z + self.m.m[2][3]
            wp = self.m.m[3][0]*x + self.m.m[3][1]*y + self.m.m[3][2]*z + self.m.m[3][3]
            if wp == 1.0:
                return Point(xp, yp, zp)
            else:
                return Point(xp, yp, zp)/wp
        elif isinstance(elt, Vector):
            x = elt.x
            y = elt.y
            z = elt.z
            xp = self.m.m[0][0]*x + self.m.m[0][1]*y + self.m.m[0][2]*z
            yp = self.m.m[1][0]*x + self.m.m[1][1]*y + self.m.m[1][2]*z
            zp = self.m.m[2][0]*x + self.m.m[2][1]*y + self.m.m[2][2]*z
            return Vector(xp, yp, zp)
        elif isinstance(elt, Normal):
            x = elt.x
            y = elt.y
            z = elt.z
            return Normal(self.m_inv.m[0][0]*x + self.m_inv.m[1][0]*y + self.m_inv.m[2][0]*z,
                          self.m_inv.m[0][1]*x + self.m_inv.m[1][1]*y + self.m_inv.m[2][1]*z,
                          self.m_inv.m[0][2]*x + self.m_inv.m[1][2]*y + self.m_inv.m[2][2]*z)
        elif isinstance(elt, RayDifferential):
            ray = RayDifferential.from_ray_differential(elt)
            ray.o = self(ray.o)
            ray.d = self(ray.d)
            ray.rx_origin = self(ray.rx_origin)
            ray.ry_origin = self(ray.ry_origin)
            ray.rx_direction = self(ray.rx_direction)
            ray.ry_direction = self(ray.ry_direction)
            return ray
        elif isinstance(elt, Ray):
            ray = Ray.from_ray(elt)
            ray.o = self(ray.o)
            ray.d = self(ray.d)
            return ray
        elif isinstance(elt, BBox):
            ret = BBox(self(Point(elt.p_min.x, elt.p_min.y, elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_min.y, elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_max.y, elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_min.y, elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_min.x, elt.p_max.y, elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_max.y, elt.p_min.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_min.y, elt.p_max.z)))
            ret = union(ret, self(Point(elt.p_max.x, elt.p_max.y, elt.p_max.z)))
            return ret
예제 #8
0
    def __init__(self, primitives, refine_immediately):
        """Default constructor for GridAccel."""
        # initialize self.primitives with primitives for grid
        if refine_immediately:
            self.primitives = []
            for primitive in primitives:
                primitive.fully_refine(self.primitives)
        else:
            self.primitives = list(primitives)

        # compute bounds and choose grid resolution
        self.bounds = BBox()
        for primitive in self.primitives:
            self.bounds = union(self.bounds, primitive.world_bound())
        delta = self.bounds.p_max - self.bounds.p_min
        
        # find voxels_per_unit_dist for grid
        max_axis = self.bounds.maximum_extent()
        inv_max_width = 1.0 / delta[max_axis]
        cube_root = 3.0 * pow(len(self.primitives), 1.0/3.0)
        voxels_per_unit_dist = cube_root * inv_max_width
        self.n_voxels = []
        for axis in range(3):
            self.n_voxels.append(clamp(
                round_to_int(delta[axis] * voxels_per_unit_dist), 1, 64))

        # compute voxel widths and allocate voxels
        self.width = Vector()
        self.inv_width = Vector()
        for axis in range(3):
            self.width[axis] = delta[axis] / self.n_voxels[axis]
            if self.width[axis] == 0.0:
                self.inv_width[axis] = 0.0
            else:
                self.inv_width[axis] = 1.0 / self.width[axis]
        nv = self.n_voxels[0] * self.n_voxels[1] * self.n_voxels[2]

        # array of voxels, initialized at None
        self.voxels = [None] * nv
        
        # add primitives to grid voxels
        for primitive in self.primitives:
            # find voxel extent of primitive
            primitive_bound = primitive.world_bound()
            v_min = []
            v_max = []
            for axis in range(3):
                v_min.append(self._pos_to_voxel(primitive_bound.p_min, axis))
                v_max.append(self._pos_to_voxel(primitive_bound.p_max, axis))

            # add primitive to overlapping voxels
            for z in range(v_min[2], v_max[2]+1):
                for y in range(v_min[1], v_max[1]+1):
                    for x in range(v_min[0], v_max[0]+1):
                        index = self._offset(x, y, z)
                        if self.voxels[index] is None:
                            self.voxels[index] = Voxel(primitive)
                        else:
                            self.voxels[index].add_primitive(primitive)

        # create reader-writer mutex for grid
        self.rw_lock = DummyRWLock()
예제 #9
0
 def test_bounding_box_6(self):
     bbox1 = BBox(Point(0, -2, 0), Point(1, -1, 1))
     bbox2 = BBox(Point(-2, 0, -2), Point(-1, 1, -1))
     bbox3 = union(bbox1, bbox2)
     self.assertEqual(bbox3.p_min, Point(-2, -2, -2))
     self.assertEqual(bbox3.p_max, Point(1, 1, 1))
예제 #10
0
 def test_bounding_box_5(self):
     bbox1 = BBox(Point(0, -2, 0), Point(1, -1, 1))
     p1 = Point(-3, 3, 0.5)
     bbox2 = union(bbox1, p1)
     self.assertEqual(bbox2.p_min, Point(-3, -2, 0))
     self.assertEqual(bbox2.p_max, Point(1, 3, 1))