def test_compute_bounds(): size = (15, 15) test_bounds = [0.0, 15, 0.0, 15, 0.0, 0.0] points = vtk.vtkPoints() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(size[0], 0, 0) points.InsertNextPoint(size[0], size[1], 0) points.InsertNextPoint(0, size[1], 0) # Create the polygon polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(4) # make a quad polygon.GetPointIds().SetId(0, 0) polygon.GetPointIds().SetId(1, 1) polygon.GetPointIds().SetId(2, 2) polygon.GetPointIds().SetId(3, 3) # Add the polygon to a list of polygons polygons = vtk.vtkCellArray() polygons.InsertNextCell(polygon) # Create a PolyData polygonPolyData = vtk.vtkPolyData() polygonPolyData.SetPoints(points) polygonPolyData.SetPolys(polygons) # Create a mapper and actor mapper = vtk.vtkPolyDataMapper2D() mapper = set_input(mapper, polygonPolyData) actor = vtk.vtkActor2D() actor.SetMapper(mapper) npt.assert_equal(compute_bounds(actor), None) npt.assert_equal(actor.GetMapper().GetInput().GetBounds(), test_bounds)
def test_update_actor(): size = (15, 15) test_bounds = [0.0, 15, 0.0, 15, 0.0, 0.0] points = Points() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(size[0], 0, 0) points.InsertNextPoint(size[0], size[1], 0) points.InsertNextPoint(0, size[1], 0) # Create the polygon polygon = Polygon() polygon.GetPointIds().SetNumberOfIds(4) # make a quad polygon.GetPointIds().SetId(0, 0) polygon.GetPointIds().SetId(1, 1) polygon.GetPointIds().SetId(2, 2) polygon.GetPointIds().SetId(3, 3) # Add the polygon to a list of polygons polygons = CellArray() polygons.InsertNextCell(polygon) # Create a PolyData polygonPolyData = PolyData() polygonPolyData.SetPoints(points) polygonPolyData.SetPolys(polygons) # Create a mapper and actor mapper = PolyDataMapper2D() mapper = set_input(mapper, polygonPolyData) actor = Actor2D() actor.SetMapper(mapper) compute_bounds(actor) npt.assert_equal(actor.GetMapper().GetInput().GetBounds(), test_bounds) updated_size = (35, 35) points.SetPoint(0, 0, 0, 0.0) points.SetPoint(1, updated_size[0], 0, 0.0) points.SetPoint(2, updated_size[0], updated_size[1], 0.0) points.SetPoint(3, 0, updated_size[1], 0.0) polygonPolyData.SetPoints(points) test_bounds = [0.0, 35.0, 0.0, 35.0, 0.0, 0.0] compute_bounds(actor) npt.assert_equal(None, update_actor(actor)) npt.assert_equal(test_bounds, actor.GetMapper().GetInput().GetBounds())