generated from cubao/pybind11-rdp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* integrate scipy convex hull * test * add concave_hull as suggested by @ChrisBarker-NOAA * lint code * fix doc
- Loading branch information
1 parent
dd77193
commit c3b1e19
Showing
9 changed files
with
148 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import List, Tuple, Union | ||
|
||
import numpy as np | ||
from pybind11_concave_hull import __version__ # noqa | ||
from pybind11_concave_hull import ( # noqa | ||
concave_hull_indexes as concave_hull_indexes_impl, | ||
) | ||
from scipy.spatial import ConvexHull | ||
|
||
|
||
def concave_hull_indexes( | ||
points: Union[np.ndarray, List, Tuple], | ||
*, | ||
concavity: float = 2.0, | ||
length_threshold: float = 0.0, | ||
convex_hull_indexes: np.ndarray = None, | ||
): | ||
""" | ||
Get concave hull indexes of points. | ||
- `points` is an array of [x, y, [z]] points (can be numpy.ndarray, list, or tuple). | ||
- `concavity` is a relative measure of concavity. 1 results in a relatively | ||
detailed shape, Infinity results in a convex hull. You can use values lower | ||
than 1, but they can produce pretty crazy shapes. | ||
- `length_threshold`: when a segment length is under this threshold, it stops | ||
being considered for further detalization. Higher values result in simpler | ||
shapes. | ||
See original document here: https://github.com/mapbox/concaveman | ||
""" | ||
points = np.asarray(points, dtype=np.float64) | ||
points = points[:, :2] | ||
if convex_hull_indexes is None: | ||
convex_hull = ConvexHull(points) | ||
convex_hull_indexes = convex_hull.vertices.astype(np.int32) | ||
return concave_hull_indexes_impl( | ||
points, | ||
convex_hull_indexes=convex_hull_indexes, | ||
concavity=concavity, | ||
length_threshold=length_threshold, | ||
) | ||
|
||
|
||
def concave_hull(points: Union[np.ndarray, List, Tuple], *args, **kwargs): | ||
indexes = concave_hull_indexes(points, *args, **kwargs) | ||
return ( | ||
points[indexes] | ||
if isinstance(points, np.ndarray) | ||
else [points[i] for i in indexes] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import subprocess | ||
import sys | ||
|
||
from setuptools import Extension, setup | ||
from setuptools import Extension, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
|
||
# Convert distutils Windows platform specifiers to CMake -A arguments | ||
|
@@ -122,16 +122,17 @@ def build_extension(self, ext): | |
# logic and declaration, and simpler if you include description/version in a file. | ||
setup( | ||
name="concave_hull", | ||
version="0.0.2", | ||
version="0.0.3", | ||
author="tzx", | ||
author_email="[email protected]", | ||
url="https://github.com/cubao/concave_hull", | ||
description="A very fast 2D concave hull algorithm", | ||
long_description=open("README.md", encoding="utf-8").read(), | ||
long_description_content_type="text/markdown", | ||
packages=find_packages(), | ||
ext_modules=[CMakeExtension("concave_hull")], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
zip_safe=False, | ||
install_requires=["numpy"], | ||
install_requires=["numpy", "scipy"], | ||
extras_require={"test": ["pytest>=6.0"]}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters