コード例 #1
0
    def testPickling(self):
        """ Testing that we can render() even after a pickling """
        raytracer = Rangefinder(min_num_aux=1)
        raytracer.set_map(example_world)
        raytracer.add_photoreceptors(linspace(-deg2rad(170), deg2rad(170), 180),
                                    spatial_sigma=deg2rad(0.5), sigma=0.01)

        raytracer.render(RigidBodyState())

        raytracer2 = make_sure_pickable(raytracer)
        raytracer2.render(RigidBodyState())

        make_sure_pickable(raytracer2)
コード例 #2
0
    def try_with(self, center, radius, position, orientation):
        world = { 
            "class": "map",
            "objects": [
                {
                     "class": "circle", "surface": 1, "radius": radius, "center": center, "texture": "lambda x: 0",
                    "solid_inside": 0
                }
            ]
        }
        
        raytracer = Rangefinder(min_num_aux=1)
        raytracer.set_map(world)
        raytracer.add_photoreceptors(linspace(-deg2rad(170), deg2rad(170), 180),
            spatial_sigma=deg2rad(0.5), sigma=0.01)
        
        rbs = RigidBodyState(position, orientation)
        data = raytracer.render(rbs)

        # given min_num_aux and spatial_sigma < 1, we expect
        # only one aux ray per photoreceptors
        for indices in raytracer.aux_indices:
            self.assertEqual(len(indices), 1)
            
        # The direction should remain the same
        for i in range(len(raytracer.directions)):
            j = raytracer.aux_indices[i][0]
            self.assertEqual(i, j)
            self.assertEqual(rad2deg(raytracer.directions[i]),
                rad2deg(raytracer.aux_directions[j]))
                
        # If we are inside the circle, then everything should be valid
        if linalg.norm(array(position) - array(center)) < radius:
            for valid in data['valid']:
                self.assertEqual(valid, 1)
            
        phi_world = numpy.array(raytracer.directions) + orientation
        rho = numpy.array(data['readings'])
        points = vstack([ cos(phi_world) * rho, sin(phi_world) * rho ])
        
        center_world = array(center) - array(position)

        for i in range(points.shape[1]):
            if not data['valid'][i]:
                continue
            distance_to_center = linalg.norm(points[:, i] - center_world)
            self.assertAlmostEqual(distance_to_center, radius, 5)