Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests on distanceMapFromContours on cuda and non-cuda modes #4042

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test_regression/test_algorithms/test_dm_from_contour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.skipif(
"not config.getoption('--run-cuda')=='positive'",
reason="Only run when --run-cuda is 'positive'",
)
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())

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)
32 changes: 32 additions & 0 deletions test_regression/test_cuda/test_cuda_dm_from_contour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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


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())

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)
Loading