Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 19, 2023
1 parent cc035c0 commit 4eadfa3
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 206 deletions.
77 changes: 0 additions & 77 deletions src/compas_cgal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
"""
********************************************************************************
compas_cgal
********************************************************************************
.. currentmodule:: compas_cgal
Booleans
========
.. autosummary::
:toctree: generated/
:nosignatures:
booleans.boolean_union
booleans.boolean_difference
booleans.boolean_intersection
booleans.split
Intersections
=============
.. autosummary::
:toctree: generated/
:nosignatures:
intersections.intersection_mesh_mesh
Measure
=======
.. autosummary::
:toctree: generated/
:nosignatures:
measure.volume
Meshing
=======
.. autosummary::
:toctree: generated/
:nosignatures:
meshing.remesh
Slicer
======
.. autosummary::
:toctree: generated/
:nosignatures:
slicer.slice_mesh
Subdivision
===========
.. autosummary::
:toctree: generated/
:nosignatures:
subdivision.catmull_clark
Triangulation
=============
.. autosummary::
:toctree: generated/
:nosignatures:
triangulation.delaunay_triangulation
triangulation.constrained_delaunay_triangulation
triangulation.conforming_delaunay_triangulation
triangulation.refined_delaunay_mesh
"""
from __future__ import print_function

import os
Expand Down
109 changes: 55 additions & 54 deletions src/compas_cgal/booleans.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from __future__ import annotations
from typing import Literal
from .types import VerticesFaces
from .types import VerticesFacesNumpy

import numpy as np
from compas.plugins import plugin
from compas_cgal._cgal import booleans


def _boolean(A, B, operation):
def _boolean(
A: VerticesFaces,
B: VerticesFaces,
operation: Literal["union", "difference", "intersection"],
) -> VerticesFacesNumpy:
"""Wrapper for all boolean operations.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : VerticesFaces
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : VerticesFaces
Mesh B.
operation : Literal['union', 'difference', 'intersection']
The type of boolean operation.
Returns
-------
NDArray[(Any, 3), np.float64]
The vertices of the boolean mesh.
NDArray[(Any, 3), np.int32]
The faces of the boolean mesh.
VerticesFacesNumpy
Raises
------
Expand Down Expand Up @@ -50,32 +56,30 @@ def _boolean(A, B, operation):


@plugin(category="booleans", pluggable_name="boolean_union_mesh_mesh")
def boolean_union(A, B):
def boolean_union_mesh_mesh(
A: VerticesFaces,
B: VerticesFaces,
) -> VerticesFacesNumpy:
"""Boolean union of two meshes.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : :attr:`compas_cgal.types.VerticesFaces`
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : :attr:`compas_cgal.types.VerticesFaces`
Mesh B.
operation : Literal['union', 'difference', 'intersection']
The type of boolean operation.
Returns
-------
NDArray[(Any, 3), np.float64]
The vertices of the boolean mesh.
NDArray[(Any, 3), np.int32]
The faces of the boolean mesh.
:attr:`compas_cgal.types.VerticesFacesNumpy`
Examples
--------
>>> from compas.geometry import Box, Sphere, Polyhedron
>>> from compas_cgal.booleans import boolean_union
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> sphere = Sphere([1, 1, 1], 0.5)
>>> box = Box(1)
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
Expand All @@ -88,32 +92,30 @@ def boolean_union(A, B):


@plugin(category="booleans", pluggable_name="boolean_difference_mesh_mesh")
def boolean_difference(A, B):
def boolean_difference_mesh_mesh(
A: VerticesFaces,
B: VerticesFaces,
) -> VerticesFacesNumpy:
"""Boolean difference of two meshes.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : :attr:`compas_cgal.types.VerticesFaces`
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : :attr:`compas_cgal.types.VerticesFaces`
Mesh B.
operation : Literal['union', 'difference', 'intersection']
The type of boolean operation.
Returns
-------
NDArray[(Any, 3), np.float64]
The vertices of the boolean mesh.
NDArray[(Any, 3), np.int32]
The faces of the boolean mesh.
:attr:`compas_cgal.types.VerticesFacesNumpy`
Examples
--------
>>> from compas.geometry import Box, Sphere, Polyhedron
>>> from compas_cgal.booleans import boolean_difference
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> sphere = Sphere([1, 1, 1], 0.5)
>>> box = Box(1)
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
Expand All @@ -126,32 +128,30 @@ def boolean_difference(A, B):


@plugin(category="booleans", pluggable_name="boolean_intersection_mesh_mesh")
def boolean_intersection(A, B):
def boolean_intersection_mesh_mesh(
A: VerticesFaces,
B: VerticesFaces,
) -> VerticesFacesNumpy:
"""Boolean intersection of two meshes.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : :attr:`compas_cgal.types.VerticesFaces`
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : :attr:`compas_cgal.types.VerticesFaces`
Mesh B.
operation : Literal['union', 'difference', 'intersection']
The type of boolean operation.
Returns
-------
NDArray[(Any, 3), np.float64]
The vertices of the boolean mesh.
NDArray[(Any, 3), np.int32]
The faces of the boolean mesh.
:attr:`compas_cgal.types.VerticesFacesNumpy`
Examples
--------
>>> from compas.geometry import Box, Sphere, Polyhedron
>>> from compas_cgal.booleans import boolean_intersection
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> sphere = Sphere([1, 1, 1], 0.5)
>>> box = Box(1)
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
Expand All @@ -164,38 +164,39 @@ def boolean_intersection(A, B):


@plugin(category="booleans", pluggable_name="split_mesh_mesh")
def split(A, B):
def split_mesh_mesh(
A: VerticesFaces,
B: VerticesFaces,
) -> VerticesFacesNumpy:
"""Split one mesh with another.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : :attr:`compas_cgal.types.VerticesFaces`
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : :attr:`compas_cgal.types.VerticesFaces`
Mesh B.
operation : Literal['union', 'difference', 'intersection']
The type of boolean operation.
Returns
-------
NDArray[(Any, 3), np.float64]
The vertices of the boolean mesh.
NDArray[(Any, 3), np.int32]
The faces of the boolean mesh.
:attr:`compas_cgal.types.VerticesFacesNumpy`
Examples
--------
>>> from compas.geometry import Box, Sphere, Polyhedron
>>> from compas_cgal.booleans import split
>>> from compas_cgal.booleans import split_mesh_mesh
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> sphere = Sphere([1, 1, 1], 0.5)
>>> box = Box(1)
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
>>> V, F = split(A, B)
>>> mesh = Mesh.from_vertices_and_faces(V, F)
>>> C = split_mesh_mesh(A, B)
>>> shape = Polyhedron(*C)
"""
return _boolean(A, B, "split")


split = split_mesh_mesh
18 changes: 12 additions & 6 deletions src/compas_cgal/intersections.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
from __future__ import annotations
from .types import VerticesFaces
from .types import PolylinesNumpy
import numpy as np
from compas_cgal._cgal import intersections
from compas.plugins import plugin


@plugin(category="intersections")
def intersection_mesh_mesh(A, B):
def intersection_mesh_mesh(
A: VerticesFaces,
B: VerticesFaces,
) -> PolylinesNumpy:
"""Compute the intersection of tow meshes.
Parameters
----------
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
A : :attr:`compas_cgal.types.VerticesFaces`
Mesh A.
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
B : :attr:`compas_cgal.types.VerticesFaces`
Mesh B.
Returns
-------
list[NDArray[(Any, 3), np.float64]]
:attr:`compas_cgal.types.PolylinesNumpy`
A list of intersection polylines, with each polyline an array of points.
Examples
--------
>>> from compas.geometry import Box, Sphere, Polyline
>>> from compas_cgal.intersections import intersection_mesh_mesh
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> sphere = Sphere([1, 1, 1], 0.5)
>>> box = Box(1)
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> A = box.to_vertices_and_faces(triangulated=True)
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
Expand Down
8 changes: 5 additions & 3 deletions src/compas_cgal/measure.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations
from .types import VerticesFaces
import numpy as np
from compas_cgal._cgal import measure
from compas.plugins import plugin


@plugin(category="trimesh", pluggable_name="trimesh_volume")
def volume(mesh):
def volume(mesh: VerticesFaces) -> float:
"""Compute the volume of a closed triangle mesh.
Parameters
----------
mesh : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
mesh : :attr:`compas_cgal.types.VerticesFaces`
The mesh.
Returns
Expand All @@ -22,7 +24,7 @@ def volume(mesh):
>>> from compas.geometry import Box
>>> from compas_cgal.measure import volume
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> box = Box(1)
>>> mesh = box.to_vertices_and_faces(triangulated=True)
>>> volume(mesh)
Expand Down
Loading

0 comments on commit 4eadfa3

Please sign in to comment.