Example #1
0
def test_factory(dim):
    lower_bound = dgtal.Point(dim=dim).zero
    upper_bound = dgtal.Point(dim=dim).diagonal(3)
    domain = dgtal.Domain(lower_bound=lower_bound, upper_bound=upper_bound)
    ds = dgtal.DigitalSet(domain=domain)
    ds.insert(dgtal.Point(dim=dim).diagonal(2))
    assert len(ds) == 1
Example #2
0
def test_factoryWithNumpyArray(dtype):
    numpy = pytest.importorskip("numpy")
    np = numpy
    dim = 2
    np_array = np.array([2,3], dtype=dtype)
    with_data_as_np_array = dgtal.Point(dim=dim, dtype=dtype, data=np_array)
    assert with_data_as_np_array[1] == 3
    dim = 3
    np_array = np.array([2,3,4], dtype=dtype)
    with_data_as_np_array = dgtal.Point(dim=dim, dtype=dtype, data=np_array)
    assert with_data_as_np_array[2] == 4
Example #3
0
def test_factoryPreCell(dim):
    # With just dim
    dgtal.PreCell(dim=dim)
    dgtal.SPreCell(dim=dim)
    # With just point
    dgtal.PreCell(point=dgtal.Point(dim=dim).diagonal(2))
    dgtal.SPreCell(point=dgtal.Point(dim=dim).diagonal(2))
    dgtal.SPreCell(point=dgtal.Point(dim=dim).diagonal(2), positive=False)
    with pytest.raises(ValueError):
        dgtal.PreCell(dim=4)
    with pytest.raises(ValueError):
        dgtal.PreCell(dim=3, point=dgtal.Point(dim=2).diagonal(2))
Example #4
0
def test_factory():
    topo8_4 = dgtal.DigitalTopology(foreground="8", background="4")
    domain = dgtal.Domain(lower_bound=dgtal.Point(dim=2),
                          upper_bound=dgtal.Point(dim=2).diagonal(2))
    obj_with_domain = dgtal.Object(topology=topo8_4, domain=domain)
    a_point = dgtal.Point(data=[1, 2])
    other_point = dgtal.Point(data=[0, 1])
    obj_with_domain.pointSet().insert(a_point)
    assert len(obj_with_domain) == 1
    point_set = dgtal.DigitalSet(domain=domain)
    point_set.insert(a_point)
    obj_with_point_set = dgtal.Object(topology=topo8_4, point_set=point_set)
    assert len(obj_with_point_set) == 1
    # point set is copied inside object.
    point_set.insert(other_point)
    assert len(obj_with_point_set) == 1
Example #5
0
def test_factory_with_data(dim):
    numpy = pytest.importorskip("numpy")
    np = numpy

    # single value data
    dtype = 'int32'
    if dim == 2:
        data=[[2,3], [3,4], [4,5], [3,4]]
        expected_shape = (4,2)
        expected_upper_bound = (1,3)
    if dim == 3:
        data=[[[2,2],[3,3],[4,4]], [[3,3],[4,4],[5,5]]]
        expected_shape = (2,3,2)
        expected_upper_bound = (1,2,1)
    array_single_value_dtype = np.array(data, dtype=dtype)
    assert array_single_value_dtype.shape == expected_shape
    img_single_value_dtype = dgtal.ImageContainer(dtype=dtype, data=array_single_value_dtype)
    print(img_single_value_dtype)
    assert img_single_value_dtype.domain.dimension == dim
    assert img_single_value_dtype.domain.lower_bound == dgtal.Point(dim=dim).zero
    assert img_single_value_dtype.domain.upper_bound == dgtal.Point(dim=dim, data=expected_upper_bound)

    # multi-dimensional value data (3D real point)
    dtype = 'real_point3D'
    if dim == 2:
        data = [[[2,2,2],[3,3,3]], [[3,3,3],[4,4,4]], [[4,4,4],[5,5,5]], [[3,3,3],[4,4,4]]]
        expected_shape = (4,2, 3)
        expected_upper_bound = (1,3)
    if dim == 3:
        data=[[[[2,2,2],[2,2,2]],
               [[3,3,3],[3,3,3]],
               [[4,4,4],[4,4,4]]],
              [[[3,3,3],[3,3,3]],
               [[4,4,4],[4,4,4]],
               [[5,5,5],[5,5,5]]]]
        expected_shape = (2,3,2, 3)
        expected_upper_bound = (1,2,1)

    array_real_point3D = np.array(data, dtype='float')
    assert array_real_point3D.shape == expected_shape
    img_real_point3D = dgtal.ImageContainer(dtype=dtype, data=array_real_point3D)
    assert img_real_point3D.domain.dimension == dim
    assert img_real_point3D.domain.lower_bound == dgtal.Point(dim=dim).zero
    assert img_real_point3D.domain.upper_bound == dgtal.Point(dim=dim, data=expected_upper_bound)
Example #6
0
def test_factory(dtype):
    dim = 2
    default_constructed = dgtal.Point(dim=dim, dtype=dtype)
    with_data_as_tuple = dgtal.Point(dim=dim, dtype=dtype, data=[2,3])
    with_data_as_list = dgtal.Point(dim=dim, dtype=dtype, data=(2,3))
    assert default_constructed[0] == 0
    assert with_data_as_tuple[1] == 3
    assert with_data_as_list[1] == 3
    dim = 3
    default_constructed = dgtal.Point(dim=dim, dtype=dtype)
    with_data_as_tuple = dgtal.Point(dim=dim, dtype=dtype, data=[2,3,4])
    with_data_as_list = dgtal.Point(dim=dim, dtype=dtype, data=(2,3,4))
    assert default_constructed[0] == 0
    assert with_data_as_tuple[2] == 4
    assert with_data_as_list[2] == 4
Example #7
0
def test_factory_with_domain(dim):
    lower_bound = dgtal.Point(dim=dim)
    upper_bound = dgtal.Point(dim=dim).diagonal(2)
    domain = dgtal.Domain(lower_bound=lower_bound, upper_bound=upper_bound)
    with_domain = dgtal.ImageContainer(domain=domain, dtype='int32')
def test_factory(dim):
    lower_bound = dgtal.Point(dim=dim).zero
    upper_bound = dgtal.Point(dim=dim).diagonal(5)
    dom = dgtal.Domain(lower_bound=lower_bound, upper_bound=upper_bound)
    assert dom.lower_bound == lower_bound
    assert dom.upper_bound == upper_bound