Skip to content

Commit

Permalink
further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 19, 2023
1 parent 11ec088 commit 4a2f8b1
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 354 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
docs:
runs-on: macos-latest
runs-on: windows-latest
steps:
- uses: compas-dev/compas-actions.docs@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/compas_cgal.measure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Functions
:toctree: generated/
:nosignatures:

measure.volume
measure.mesh_volume
4 changes: 2 additions & 2 deletions docs/examples/booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from compas_view2.app import App

from compas_cgal.booleans import boolean_union_mesh_mesh
from compas_cgal.meshing import remesh
from compas_cgal.meshing import mesh_remesh

# ==============================================================================
# Make a box and a sphere
Expand All @@ -21,7 +21,7 @@
# Remesh the sphere
# ==============================================================================

B = remesh(B, 0.3, 50)
B = mesh_remesh(B, 0.3, 50)

# ==============================================================================
# Compute the boolean mesh
Expand Down
16 changes: 8 additions & 8 deletions docs/examples/remeshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
from compas.geometry import Rotation
from compas.geometry import Translation
from compas.geometry import Scale

from compas.datastructures import Mesh
from compas_cgal.meshing import mesh_remesh
from compas_view2.app import App

from compas_cgal.trimesh import TriMesh

HERE = Path(__file__).parent.absolute()
FILE = HERE.parent.parent / "data" / "Bunny.ply"

# ==============================================================================
# Get the bunny and construct a mesh
# ==============================================================================

bunny = TriMesh.from_ply(FILE)
bunny = Mesh.from_ply(FILE)

bunny.cull_vertices()
bunny.remove_unused_vertices()

# ==============================================================================
# Move the bunny to the origin and rotate it upright.
# ==============================================================================

vector = scale_vector(bunny.centroid, -1)
vector = scale_vector(bunny.centroid(), -1)

T = Translation.from_vector(vector)
S = Scale.from_factors([100, 100, 100])
Expand All @@ -38,8 +37,9 @@
# Remesh
# ==============================================================================

bunny.remesh(bunny.average_edge_length)
mesh = bunny.to_mesh()
V, F = mesh_remesh(bunny.to_vertices_and_faces(), 0.3, 10)

mesh = Mesh.from_vertices_and_faces(V, F)

# ==============================================================================
# Visualize
Expand Down
4 changes: 2 additions & 2 deletions src/compas_cgal/booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def split_mesh_mesh(
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
>>> C = split_mesh_mesh(A, B)
>>> shape = Polyhedron(*C)
>>> V, F = split_mesh_mesh(A, B)
>>> shape = Polyhedron(V.tolist(), F.tolist())
"""
return _boolean(A, B, "split")
Expand Down
23 changes: 20 additions & 3 deletions src/compas_cgal/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@plugin(category="trimesh", pluggable_name="trimesh_volume")
def volume(mesh: VerticesFaces) -> float:
def mesh_volume(mesh: VerticesFaces) -> float:
"""Compute the volume of a closed triangle mesh.
Parameters
Expand All @@ -22,16 +22,33 @@ def volume(mesh: VerticesFaces) -> float:
Examples
--------
>>> from compas.geometry import Box
>>> from compas_cgal.measure import volume
>>> from compas_cgal.measure import mesh_volume
>>> box = Box(1)
>>> mesh = box.to_vertices_and_faces(triangulated=True)
>>> volume(mesh)
>>> mesh_volume(mesh)
1.0
"""
V, F = mesh
V = np.asarray(V, dtype=np.float64)
F = np.asarray(F, dtype=np.int32)
return measure.volume(V, F)


def mesh_area(mesh: VerticesFaces) -> float:
"""Compute the area of a triangle mesh.
Parameters
----------
mesh : :attr:`compas_cgal.types.VerticesFaces`
The mesh.
Returns
-------
float
The area of the mesh.
"""
raise NotImplementedError
6 changes: 3 additions & 3 deletions src/compas_cgal/meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@plugin(category="trimesh", pluggable_name="trimesh_remesh")
def remesh(
def mesh_remesh(
mesh: VerticesFaces,
target_edge_length: float,
number_of_iterations: int = 10,
Expand Down Expand Up @@ -38,12 +38,12 @@ def remesh(
Examples
--------
>>> from compas.geometry import Sphere, Polyhedron
>>> from compas_cgal.meshing import remesh
>>> from compas_cgal.meshing import mesh_remesh
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> mesh = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
>>> V, F = remesh(mesh, 1.0)
>>> V, F = mesh_remesh(mesh, 1.0)
>>> shape = Polyhedron(V.tolist(), F.tolist())
"""
Expand Down
24 changes: 21 additions & 3 deletions src/compas_cgal/subdivision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from compas_cgal._cgal import subdivision


def catmull_clark(mesh: VerticesFaces, k=1) -> VerticesFacesNumpy:
def mesh_subdivide_catmull_clark(mesh: VerticesFaces, k=1) -> VerticesFacesNumpy:
"""Subdivide a mesh withe the Catmull Clark scheme.
Parameters
Expand All @@ -22,16 +22,34 @@ def catmull_clark(mesh: VerticesFaces, k=1) -> VerticesFacesNumpy:
Examples
--------
>>> from compas.geometry import Box, Polyhedron
>>> from compas_cgal.subdivision import catmull_clark
>>> from compas_cgal.subdivision import mesh_subdivide_catmull_clark
>>> box = Box(1)
>>> mesh = box.to_vertices_and_faces()
>>> result = catmull_clark(mesh, k=3)
>>> result = mesh_subdivide_catmull_clark(mesh, k=3)
>>> shape = Polyhedron(*result)
"""
V, F = mesh
V = np.asarray(V, dtype=np.float64)
F = np.asarray(F, dtype=np.int32)
return subdivision.subd_catmullclark(V, F, k)


def mesh_subdivide_loop(mesh: VerticesFaces, k=1) -> VerticesFacesNumpy:
"""Subdivide a mesh withe the Loop scheme.
Parameters
----------
mesh : :attr:`compas_cgal.types.VerticesFaces`
The mesh to remesh.
k : int, optional
The number of subdivision steps.
Returns
-------
:attr:`compas_cgal.types.VerticesFacesNumpy`
"""
raise NotImplementedError
Loading

0 comments on commit 4a2f8b1

Please sign in to comment.