コード例 #1
0
ファイル: test_utils.py プロジェクト: MarcCote/fury
def test_get_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)
    compute_bounds(actor)
    npt.assert_equal(get_bounds(actor), test_bounds)
コード例 #2
0
    def _timer(_obj, _event):
        nonlocal counter, pos
        counter += 1
        if mode == 0:
            iterate(1)
        else:
            pos[:] += (np.random.random(pos.shape) - 0.5) * 1.5
        spheres_positions = vertices_from_actor(sphere_actor)
        spheres_positions[:] = sphere_geometry + \
            np.repeat(pos, geometry_length, axis=0)

        edges_positions = vertices_from_actor(lines_actor)
        edges_positions[::2] = pos[edges_list[:, 0]]
        edges_positions[1::2] = pos[edges_list[:, 1]]

        update_actor(lines_actor)
        compute_bounds(lines_actor)

        update_actor(sphere_actor)
        compute_bounds(lines_actor)
        showm.scene.reset_clipping_range()
        showm.render()

        if counter >= max_iterations:
            showm.exit()
コード例 #3
0
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())