Esempio n. 1
0
    def test_slicing(self):
        tensor = pyskip.Tensor((3, 3), 0)
        tensor[1, 0:2] = 1
        tensor[0:2, 0] = 2
        tensor[2:3, 2:3] = 3

        expected = np.array([[2, 2, 0], [0, 1, 0], [0, 0, 3]], dtype=int)
        self.assertTrue(np.all(tensor.to_numpy() == np.array(expected)))
Esempio n. 2
0
    def test_operations(self):
        tensor = pyskip.Tensor(3, 1)
        tensor *= 3
        tensor[0] = 2 * tensor[1]
        tensor[0] += tensor[2] * 3
        tensor[1] += tensor[0] * tensor[2]
        self.assertEqual(tensor[0], 15)
        self.assertEqual(tensor[1], 48)
        self.assertEqual(tensor[2], 3)

        tensor = pyskip.Tensor(shape=(4, 4), val=0)
        tensor[0::2, 0::2] = 1
        tensor[1::2, 0::2] = 2
        tensor[0::2, 1::2] = 3
        tensor[1::2, 1::2] = 4
        expected = np.array([[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]], dtype=int)
        self.assertTrue(np.all(tensor.to_numpy() == np.array(expected)))

        expected = np.array([2, 2, 2, 2], dtype=int)
        self.assertTrue(np.all(tensor[1:4:2, 0:4:2].to_numpy().flatten() == np.array(expected)))
Esempio n. 3
0
 def make_disc(cls):
     D = 4096
     R = D // 4
     disc = pyskip.Tensor((D, D), 0)
     for y in range(D):
         discriminant = R**2 - (y - D // 2 + 0.5)**2
         if discriminant < 0:
             continue
         x_0 = int(D // 2 - 0.5 - discriminant**0.5)
         x_1 = int(D // 2 - 0.5 + discriminant**0.5)
         disc[x_0:x_1, y] = 1
     return disc
Esempio n. 4
0
    def load_default_model(self):
        # Initialize the voxel geometry.
        t = pyskip.Tensor(shape=(3, 3, 3), val=0)
        t[0, 0, 0] = 1
        t[1, 0, 0] = 2
        t[1, 1, 0] = 1
        t[1, 2, 0] = 2

        # Define the color of each voxel type.
        config = voxels.VoxelConfig()
        config[0] = voxels.EmptyVoxel()
        config[1] = voxels.ColorVoxel(128, 0, 0)
        config[2] = voxels.ColorVoxel(0, 0, 128)

        # Map the tensor onto a mesh.
        mesh = voxels.to_mesh(t, config)

        # Load the mesh into a panda geometry node.
        self.model = GeomNode('mesh_node')
        self.model.addGeom(create_geometry_from_mesh(mesh))
        render.attachNewNode(self.model)
Esempio n. 5
0
    def megatensor(self):
        dim_1, dim_2, dim_3 = self._xyz_to_pyskip_col(self.dense_dimensions(),
                                                      self.column_order)
        megatensor = pyskip.Tensor(shape=(dim_1, dim_2, dim_3), dtype=int)
        for chunk in self.chunk_list:
            start_x = chunk.coord[0] - self.bbox[0][0]
            start_y = chunk.coord[1] - self.bbox[1][0]
            start_z = chunk.coord[2] - self.bbox[2][0]

            xyz_tensor_shape = self._pyskip_col_to_xyz(chunk.tensor.shape,
                                                       self.column_order)
            end_x = start_x + xyz_tensor_shape[0]
            end_y = start_y + xyz_tensor_shape[1]
            end_z = start_z + xyz_tensor_shape[2]
            rng = (slice(start_x, end_x,
                         1), slice(start_y, end_y,
                                   1), slice(start_z, end_z, 1))
            try:
                megatensor[self._xyz_to_pyskip_col(
                    rng, self.column_order)] = chunk.tensor
            except ValueError:
                print(rng)
                raise
        return megatensor
Esempio n. 6
0
 def test_tensor_3d(self):
     tensor = pyskip.Tensor((100, 100, 100), 0)
     self.assertIsNotNone(tensor)