diff --git a/test_regression/test_algorithms/test_dm_from_contour.py b/test_regression/test_algorithms/test_dm_from_contour.py new file mode 100644 index 000000000000..7b34d31b06de --- /dev/null +++ b/test_regression/test_algorithms/test_dm_from_contour.py @@ -0,0 +1,26 @@ +from module_helper import * +from pathlib import Path +from constants import test_files_path +from helpers.meshlib_helpers import compare_distance_maps +import pytest + +@pytest.mark.bindingsV3 +def test_dm_from_contour(tmp_path): + # Load input point + input_folder = Path(test_files_path) / "algorithms" / "lines_to_dm" + pl3 = mrmeshpy.loadLines(input_folder / "input.mrlines") + pl2 = mrmeshpy.Polyline2(pl3.contours2()) + + # process + params = mrmeshpy.ContourToDistanceMapParams() + params.pixelSize = mrmeshpy.Vector2f(0.1, 0.1) + params.resolution = mrmeshpy.Vector2i(100, 100) + params.orgPoint = mrmeshpy.Vector2f(0, -5) + dm = mrmeshpy.distanceMapFromContours(pl2, params) + mrmeshpy.saveDistanceMapToImage(dm, tmp_path / "dm_out.png") + + # verification + + dm_ref = mrmeshpy.loadDistanceMapFromImage(input_folder / "dm_out.png") + dm_out = mrmeshpy.loadDistanceMapFromImage(tmp_path / "dm_out.png") + compare_distance_maps(dm_ref, dm_out) diff --git a/test_regression/test_cuda/test_cuda_dm_from_contour.py b/test_regression/test_cuda/test_cuda_dm_from_contour.py new file mode 100644 index 000000000000..eca326b48654 --- /dev/null +++ b/test_regression/test_cuda/test_cuda_dm_from_contour.py @@ -0,0 +1,35 @@ +import pytest +from pytest_check import check + +from module_helper import * +from pathlib import Path +from constants import test_files_path +from helpers.meshlib_helpers import compare_distance_maps + + +@pytest.mark.skipif( + "not config.getoption('--run-cuda')=='positive'", + reason="Only run when --run-cuda is 'positive'", +) +def test_dm_from_contour(cuda_module, tmp_path): + # Load input point + input_folder = Path(test_files_path) / "cuda" / "lines_to_dm" + pl3 = mrmeshpy.loadLines(input_folder / "input.mrlines") + pl2 = mrmeshpy.Polyline2(pl3.contours2()) + + # process + params = mrmeshpy.ContourToDistanceMapParams() + params.pixelSize = mrmeshpy.Vector2f(0.1, 0.1) + params.resolution = mrmeshpy.Vector2i(100, 100) + params.orgPoint = mrmeshpy.Vector2f(0, -5) + dm = cuda_module.distanceMapFromContours(pl2, params) + mrmeshpy.saveDistanceMapToImage(dm, tmp_path / "dm_out.png") + + # verification + + dm_ref = mrmeshpy.loadDistanceMapFromImage(input_folder / "dm_out.png") + dm_out = mrmeshpy.loadDistanceMapFromImage(tmp_path / "dm_out.png") + with check: + assert 40000 < cuda_module.distanceMapFromContoursHeapBytes(pl2, params) < 80000 + with check: + compare_distance_maps(dm_ref, dm_out)