Пример #1
0
def test_add_polydata_numeric_field():
    my_polydata = PolyData()
    poly_field_data = my_polydata.GetFieldData()
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    bool_data = True
    add_polydata_numeric_field(my_polydata, 'Test Bool', bool_data)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_equal(
        poly_field_data.GetArray('Test Bool').GetValue(0), bool_data)
    poly_field_data.RemoveArray('Test Bool')
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    int_data = 1
    add_polydata_numeric_field(my_polydata, 'Test Int', int_data)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_equal(
        poly_field_data.GetArray('Test Int').GetValue(0), int_data)
    poly_field_data.RemoveArray('Test Int')
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    float_data = .1
    add_polydata_numeric_field(my_polydata,
                               'Test Float',
                               float_data,
                               array_type=VTK_FLOAT)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_almost_equal(
        poly_field_data.GetArray('Test Float').GetValue(0), float_data)
    poly_field_data.RemoveArray('Test Float')
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    double_data = .1
    add_polydata_numeric_field(my_polydata,
                               'Test Double',
                               double_data,
                               array_type=VTK_DOUBLE)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_equal(
        poly_field_data.GetArray('Test Double').GetValue(0), double_data)
    poly_field_data.RemoveArray('Test Double')
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    array_data = [-1, 0, 1]
    add_polydata_numeric_field(my_polydata, 'Test Array', array_data)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_equal(
        numpy_support.vtk_to_numpy(poly_field_data.GetArray('Test Array')),
        array_data)
    poly_field_data.RemoveArray('Test Array')
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 0)
    ndarray_data = np.array([[-.1, -.1], [0, 0], [.1, .1]])
    add_polydata_numeric_field(my_polydata,
                               'Test NDArray',
                               ndarray_data,
                               array_type=VTK_FLOAT)
    npt.assert_equal(poly_field_data.GetNumberOfArrays(), 1)
    npt.assert_almost_equal(
        numpy_support.vtk_to_numpy(poly_field_data.GetArray('Test NDArray')),
        ndarray_data)
Пример #2
0
def test_get_polydata_field():
    my_polydata = PolyData()
    field_data = get_polydata_field(my_polydata, 'Test')
    npt.assert_equal(field_data, None)
    data = 1
    field_name = 'Test'
    vtk_data = numpy_support.numpy_to_vtk(data)
    vtk_data.SetName(field_name)
    my_polydata.GetFieldData().AddArray(vtk_data)
    field_data = get_polydata_field(my_polydata, field_name)
    npt.assert_equal(field_data, data)