Exemple #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.convertArray(arr.flatten(), name='Data', deep=True)
     cellData = interface.convertArray(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.SetFlipX(True)
     f.SetFlipY(False)
     f.SetFlipZ(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.SetFlipX(True)
     f.SetFlipY(True)
     f.SetFlipZ(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))
Exemple #2
0
 def setUp(self):
     TestBase.setUp(self)
     # Create some input tables
     self.t0 = vtk.vtkTable()
     # Populate the tables
     self.arrs = [None, None]
     self.n = 400
     self.titles = ('Array 0', 'Array 1')
     self.arrs[0] = np.random.random(self.n)  # Table 0
     self.arrs[1] = np.random.random(self.n)  # Table 0
     self.t0.AddColumn(interface.convertArray(self.arrs[0], self.titles[0]))
     self.t0.AddColumn(interface.convertArray(self.arrs[1], self.titles[1]))
     return
Exemple #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.convertArray(self.arr, self.title))
     return
Exemple #4
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.convertArray(self.arrs[0], self.titles[0]))
     self.t0.AddColumn(interface.convertArray(self.arrs[1], self.titles[1]))
     self.t1.AddColumn(interface.convertArray(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)
Exemple #5
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.convertArray(self.arr, self.title))
     return
Exemple #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.pointsToPolyData(points)
        vtkpoints.GetPointData().AddArray(
            interface.convertArray(rand, 'Random'))
        # Use filter
        v = VoxelizePoints()
        v.SetInputDataObject(vtkpoints)
        v.SetEstimateGrid(False)  # Cell size is explicitly set
        v.SetDeltaX(10)
        v.SetDeltaY(10)
        v.SetDeltaZ(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.SetDeltas(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