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.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))
Exemple #2
0
 def __init__(self):
     ReverseImageDataAxii.__init__(self)
Exemple #3
0
 def set_flip_z(self, flag):
     ReverseImageDataAxii.set_flip_z(self, flag)
Exemple #4
0
 def SetFlipZ(self, flag):
     ReverseImageDataAxii.SetFlipZ(self, flag)