Beispiel #1
0
 def test(self):
     """`ReverseImageDataAxii`: check that it works on point and cell data"""
     # Create input vtkImageData:
     nx, ny, nz = 10, 11, 12
     arr = np.random.random((nz, ny, nx))
     arrCells = np.random.random((nz - 1, ny - 1, nx - 1))
     image = vtk.vtkImageData()
     image.SetDimensions(nx, ny, nz)
     image.SetSpacing(2, 2, 2)
     image.SetOrigin(0, 0, 0)
     data = interface.convert_array(arr.flatten(), name='Data', deep=True)
     cellData = interface.convert_array(arrCells.flatten(),
                                        name='CellData',
                                        deep=True)
     image.GetPointData().AddArray(data)
     image.GetCellData().AddArray(cellData)
     # Now perfrom the reverse for only X:
     f = ReverseImageDataAxii()
     f.SetInputDataObject(image)
     f.set_flip_x(True)
     f.set_flip_y(False)
     f.set_flip_z(False)
     f.Update()
     ido = f.GetOutput()
     self.assertIsNotNone(ido)
     self.assertEqual(ido.GetNumberOfPoints(), len(arr.flatten()))
     # Check that x-axis was reversed
     wido = dsa.WrapDataObject(ido)
     test = wido.PointData['Data']
     testCells = wido.CellData['CellData']
     self.assertTrue(
         np.allclose(test, np.flip(arr, axis=2).flatten(), rtol=RTOL))
     self.assertTrue(
         np.allclose(testCells,
                     np.flip(arrCells, axis=2).flatten(),
                     rtol=RTOL))
     # Now perfrom the reverse for all axii:
     f.set_flip_x(True)
     f.set_flip_y(True)
     f.set_flip_z(True)
     f.Update()
     ido = f.GetOutput()
     self.assertIsNotNone(ido)
     self.assertEqual(ido.GetNumberOfPoints(), len(arr.flatten()))
     # Check that x-axis was reversed
     wido = dsa.WrapDataObject(ido)
     test = wido.PointData['Data']
     testCells = wido.CellData['CellData']
     tarr = np.flip(arr, axis=0)
     tarr = np.flip(tarr, axis=1)
     tarr = np.flip(tarr, axis=2)
     tarrCells = np.flip(arrCells, axis=0)
     tarrCells = np.flip(tarrCells, axis=1)
     tarrCells = np.flip(tarrCells, axis=2)
     self.assertTrue(np.allclose(test, tarr.flatten(), rtol=RTOL))
     self.assertTrue(np.allclose(testCells, tarrCells.flatten(), rtol=RTOL))
Beispiel #2
0
 def setUp(self):
     TestBase.setUp(self)
     # Create some input tables
     self.table = vtk.vtkTable()
     # Populate the tables
     self.arrs = [None, None, None]
     self.n = 400
     self.titles = ('Array 0', 'Array 1', 'Array 2')
     self.arrs[0] = np.random.random(self.n)
     self.arrs[1] = np.random.random(self.n)
     self.arrs[2] = np.random.random(self.n)
     self.table.AddColumn(interface.convert_array(self.arrs[0], self.titles[0]))
     self.table.AddColumn(interface.convert_array(self.arrs[1], self.titles[1]))
     self.table.AddColumn(interface.convert_array(self.arrs[2], self.titles[2]))
     return
Beispiel #3
0
 def setUp(self):
     TestBase.setUp(self)
     # Create some input tables
     self.t0 = vtk.vtkTable()
     # Populate the tables
     self.n = 400
     self.title = 'Array 0'
     self.arr = np.random.random(self.n)  # Table 0
     self.t0.AddColumn(interface.convert_array(self.arr, self.title))
     return
Beispiel #4
0
 def setUp(self):
     TestBase.setUp(self)
     # Create some input tables
     self.idi = vtk.vtkImageData()
     self.idi.SetDimensions(20, 2, 10)
     self.idi.SetSpacing(1, 1, 1)
     self.idi.SetOrigin(100, 100, 100)
     # Populate the tables
     self.n = 400
     self.title = 'Array 0'
     self.arr = np.random.random(self.n)
     self.idi.GetPointData().AddArray(interface.convert_array(self.arr, self.title))
     return
Beispiel #5
0
 def setUp(self):
     TestBase.setUp(self)
     # Create some input tables
     self.t0 = vtk.vtkTable()
     self.t1 = vtk.vtkTable()
     # Populate the tables
     self.n = 100
     self.titles = ('Array 0', 'Array 1', 'Array 2')
     self.arrs = [None, None, None]
     self.arrs[0] = np.random.random(self.n)  # Table 0
     self.arrs[1] = np.random.random(self.n)  # Table 0
     self.arrs[2] = np.random.random(self.n)  # Table 1
     self.t0.AddColumn(interface.convert_array(self.arrs[0],
                                               self.titles[0]))
     self.t0.AddColumn(interface.convert_array(self.arrs[1],
                                               self.titles[1]))
     self.t1.AddColumn(interface.convert_array(self.arrs[2],
                                               self.titles[2]))
     # Now use the `CombineTables` filter:
     f = CombineTables()
     f.SetInputDataObject(0, self.t0)
     f.SetInputDataObject(1, self.t1)
     f.Update()
     self.TABLE = f.GetOutputDataObject(0)
Beispiel #6
0
    def test_mesh_grid_uniform(self):
        """`VoxelizePoints`: uniform mesh grid with given spacings"""
        # make the mesh grid
        dd = 5
        x = y = z = np.arange(0, 100, dd, dtype=float)
        g = np.meshgrid(x, y, z)
        # Convert to XYZ points
        points = np.vstack(map(np.ravel, g)).T
        rand = np.random.random(len(points))
        vtkpoints = interface.points_to_poly_data(points)
        vtkpoints.GetPointData().AddArray(
            interface.convert_array(rand, 'Random'))
        # Use filter
        v = VoxelizePoints()
        v.SetInputDataObject(vtkpoints)
        v.set_estimate_grid(False)  # Cell size is explicitly set
        v.set_delta_x(10)
        v.set_delta_y(10)
        v.set_delta_z(10)
        v.Update()
        grid = v.GetOutput()
        wgrd = dsa.WrapDataObject(grid)
        celldata = wgrd.CellData['Random']
        # Checkout output:
        self.assertEqual(grid.GetNumberOfCells(),
                         8 * 10**3,
                         msg='Number of CELLS is incorrect')
        numPts = (len(x) + 2)**3
        self.assertEqual(grid.GetNumberOfPoints(),
                         numPts,
                         msg='Number of POINTS is incorrect')
        self.assertTrue(np.allclose(celldata, rand))

        # Now check that we can set the spacing for every cell
        spac = np.full((len(points)), 10.0)
        v.set_deltas(spac, spac, spac)
        v.Update()
        grid = v.GetOutput()
        wgrd = dsa.WrapDataObject(grid)
        celldata = wgrd.CellData['Random']
        self.assertEqual(grid.GetNumberOfCells(),
                         8 * 10**3,
                         msg='Number of CELLS is incorrect')
        self.assertEqual(grid.GetNumberOfPoints(),
                         numPts,
                         msg='Number of POINTS is incorrect')
        self.assertTrue(np.allclose(celldata, rand))
        return