Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
496a8bd5
Commit
496a8bd5
authored
2 months ago
by
Alessia Saccardo
Browse files
Options
Downloads
Patches
Plain Diff
add pytest for mesh conversion function
parent
72a66162
No related branches found
No related tags found
1 merge request
!156
Mesh pygel3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
qim3d/mesh/_common_mesh_methods.py
+4
-1
4 additions, 1 deletion
qim3d/mesh/_common_mesh_methods.py
qim3d/tests/mesh/test_mesh.py
+42
-0
42 additions, 0 deletions
qim3d/tests/mesh/test_mesh.py
with
46 additions
and
1 deletion
qim3d/mesh/_common_mesh_methods.py
+
4
−
1
View file @
496a8bd5
...
...
@@ -16,7 +16,7 @@ def from_volume(
**kwargs: Additional arguments to pass to the Pygel3D volumetric_isocontour function.
Raises:
ValueError: If the input volume is not a 3D numpy array.
ValueError: If the input volume is not a 3D numpy array
or if the input volume is empty
.
Returns:
hmesh.Manifold: A Pygel3D mesh object representing the input volume.
...
...
@@ -37,5 +37,8 @@ def from_volume(
if
volume
.
ndim
!=
3
:
raise
ValueError
(
"
The input volume must be a 3D numpy array.
"
)
if
volume
.
size
==
0
:
raise
ValueError
(
"
The input volume must not be empty.
"
)
mesh
=
hmesh
.
volumetric_isocontour
(
volume
,
**
kwargs
)
return
mesh
\ No newline at end of file
This diff is collapsed.
Click to expand it.
qim3d/tests/mesh/test_mesh.py
0 → 100644
+
42
−
0
View file @
496a8bd5
import
pytest
import
numpy
as
np
from
pygel3d
import
hmesh
import
qim3d
def
test_from_volume_valid_input
():
"""
Test that from_volume returns a hmesh.Manifold object for a valid 3D input.
"""
volume
=
np
.
random
.
rand
(
50
,
50
,
50
).
astype
(
np
.
float32
)
# Generate a random 3D volume
mesh
=
qim3d
.
mesh
.
from_volume
(
volume
)
assert
isinstance
(
mesh
,
hmesh
.
Manifold
)
# Check if output is a Manifold object
def
test_from_volume_invalid_input
():
"""
Test that from_volume raises ValueError for non-3D input.
"""
volume
=
np
.
random
.
rand
(
50
,
50
)
# A 2D array
with
pytest
.
raises
(
ValueError
,
match
=
"
The input volume must be a 3D numpy array.
"
):
qim3d
.
mesh
.
from_volume
(
volume
)
def
test_from_volume_empty_array
():
"""
Test how from_volume handles an empty 3D array.
"""
volume
=
np
.
empty
((
0
,
0
,
0
))
# Empty 3D array
with
pytest
.
raises
(
ValueError
):
# It should fail because it doesn't make sense to generate a mesh from empty data
qim3d
.
mesh
.
from_volume
(
volume
)
def
test_from_volume_with_kwargs
():
"""
Test that from_volume correctly passes kwargs.
"""
volume
=
np
.
random
.
rand
(
50
,
50
,
50
).
astype
(
np
.
float32
)
# Mock volumetric_isocontour to check if kwargs are passed
def
mock_volumetric_isocontour
(
vol
,
**
kwargs
):
assert
"
isovalue
"
in
kwargs
assert
kwargs
[
"
isovalue
"
]
==
0.5
return
hmesh
.
Manifold
()
# Replace the function temporarily
original_function
=
hmesh
.
volumetric_isocontour
hmesh
.
volumetric_isocontour
=
mock_volumetric_isocontour
try
:
qim3d
.
mesh
.
from_volume
(
volume
,
isovalue
=
0.5
)
finally
:
hmesh
.
volumetric_isocontour
=
original_function
# Restore original function
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment