Skip to content

Commit c1b3d9c

Browse files
committed
refactor: reduce test complexity and duplication
1 parent 2576ca2 commit c1b3d9c

1 file changed

Lines changed: 32 additions & 100 deletions

File tree

python/test/geometry/test_poisson_parameters.py

Lines changed: 32 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,63 @@
1010
import pytest
1111

1212

13-
def test_poisson_default_parameters():
14-
"""Test Poisson reconstruction with default parameters."""
15-
# Create a simple point cloud (sphere)
13+
@pytest.fixture
14+
def sample_point_cloud():
15+
"""Create a simple point cloud for testing."""
1616
pcd = o3d.geometry.PointCloud()
1717
pcd.points = o3d.utility.Vector3dVector(
1818
np.random.rand(100, 3) - 0.5
1919
)
20-
# Add normals pointing outward
2120
pcd.normals = o3d.utility.Vector3dVector(
2221
np.random.rand(100, 3) - 0.5
2322
)
2423
pcd.normalize_normals()
25-
26-
# Run with default parameters
27-
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
28-
pcd, depth=6
29-
)
30-
24+
return pcd
25+
26+
27+
def _assert_valid_mesh(mesh, densities):
28+
"""Helper to validate mesh and densities output."""
3129
assert mesh is not None
3230
assert len(mesh.vertices) > 0
3331
assert len(mesh.triangles) > 0
3432
assert len(densities) == len(mesh.vertices)
3533

3634

37-
def test_poisson_custom_parameters():
38-
"""Test Poisson reconstruction with custom parameters."""
39-
# Create a simple point cloud
40-
pcd = o3d.geometry.PointCloud()
41-
pcd.points = o3d.utility.Vector3dVector(
42-
np.random.rand(100, 3) - 0.5
43-
)
44-
pcd.normals = o3d.utility.Vector3dVector(
45-
np.random.rand(100, 3) - 0.5
35+
def test_poisson_default_parameters(sample_point_cloud):
36+
"""Test Poisson reconstruction with default parameters."""
37+
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
38+
sample_point_cloud, depth=6
4639
)
47-
pcd.normalize_normals()
48-
49-
# Run with custom parameters
40+
_assert_valid_mesh(mesh, densities)
41+
42+
43+
@pytest.mark.parametrize("params,expected_valid", [
44+
({"depth": 6, "full_depth": 4, "samples_per_node": 2.0,
45+
"point_weight": 5.0, "confidence": 0.5, "exact_interpolation": True}, True),
46+
({"depth": 6, "full_depth": 3}, True),
47+
({"depth": 6, "full_depth": 5}, True),
48+
({"depth": 5, "samples_per_node": 1.0}, True),
49+
({"depth": 5, "samples_per_node": 3.0}, True),
50+
])
51+
def test_poisson_with_various_parameters(sample_point_cloud, params, expected_valid):
52+
"""Test Poisson reconstruction with various parameter combinations."""
5053
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
51-
pcd,
52-
depth=6,
53-
full_depth=4,
54-
samples_per_node=2.0,
55-
point_weight=5.0,
56-
confidence=0.5,
57-
exact_interpolation=True
54+
sample_point_cloud, **params
5855
)
59-
60-
assert mesh is not None
61-
assert len(mesh.vertices) > 0
62-
assert len(mesh.triangles) > 0
63-
assert len(densities) == len(mesh.vertices)
56+
if expected_valid:
57+
_assert_valid_mesh(mesh, densities)
6458

6559

66-
def test_poisson_parameter_variation():
60+
def test_poisson_parameter_variation(sample_point_cloud):
6761
"""Test that different parameters produce different results."""
68-
# Create a simple point cloud
69-
np.random.seed(42)
70-
pcd = o3d.geometry.PointCloud()
71-
pcd.points = o3d.utility.Vector3dVector(
72-
np.random.rand(100, 3) - 0.5
73-
)
74-
pcd.normals = o3d.utility.Vector3dVector(
75-
np.random.rand(100, 3) - 0.5
76-
)
77-
pcd.normalize_normals()
78-
7962
# Run with default point_weight
8063
mesh1, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
81-
pcd, depth=5, point_weight=4.0
64+
sample_point_cloud, depth=5, point_weight=4.0
8265
)
8366

8467
# Run with higher point_weight (should produce different result)
8568
mesh2, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
86-
pcd, depth=5, point_weight=10.0
69+
sample_point_cloud, depth=5, point_weight=10.0
8770
)
8871

8972
# Meshes should be different (different vertex counts or positions)
@@ -107,55 +90,4 @@ def test_poisson_backward_compatibility():
10790
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
10891
pcd, depth=5, scale=1.1, linear_fit=False
10992
)
110-
111-
assert mesh is not None
112-
assert len(mesh.vertices) > 0
113-
assert len(densities) == len(mesh.vertices)
114-
115-
116-
def test_poisson_full_depth_parameter():
117-
"""Test full_depth parameter specifically."""
118-
pcd = o3d.geometry.PointCloud()
119-
pcd.points = o3d.utility.Vector3dVector(
120-
np.random.rand(100, 3) - 0.5
121-
)
122-
pcd.normals = o3d.utility.Vector3dVector(
123-
np.random.rand(100, 3) - 0.5
124-
)
125-
pcd.normalize_normals()
126-
127-
# Test with different full_depth values
128-
mesh1, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
129-
pcd, depth=6, full_depth=3
130-
)
131-
132-
mesh2, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
133-
pcd, depth=6, full_depth=5
134-
)
135-
136-
assert len(mesh1.vertices) > 0
137-
assert len(mesh2.vertices) > 0
138-
139-
140-
def test_poisson_samples_per_node_parameter():
141-
"""Test samples_per_node parameter specifically."""
142-
pcd = o3d.geometry.PointCloud()
143-
pcd.points = o3d.utility.Vector3dVector(
144-
np.random.rand(100, 3) - 0.5
145-
)
146-
pcd.normals = o3d.utility.Vector3dVector(
147-
np.random.rand(100, 3) - 0.5
148-
)
149-
pcd.normalize_normals()
150-
151-
# Test with different samples_per_node values
152-
mesh1, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
153-
pcd, depth=5, samples_per_node=1.0
154-
)
155-
156-
mesh2, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
157-
pcd, depth=5, samples_per_node=3.0
158-
)
159-
160-
assert len(mesh1.vertices) > 0
161-
assert len(mesh2.vertices) > 0
93+
_assert_valid_mesh(mesh, densities)

0 commit comments

Comments
 (0)