bellockk / alphashape Goto Github PK
View Code? Open in Web Editor NEWToolbox for constructing alpha shapes.
License: MIT License
Toolbox for constructing alpha shapes.
License: MIT License
After upgrading to shapely 2.0, when I am trying to get the optimized alpha from a set of points, I encounter the following error:
Traceback (most recent call last):
File "/home/hanatok/HDD/Documents/playground/python/test_alphashape/./test.py", line 5, in <module>
alpha = 0.95 * alphashape.optimizealpha(points)
File "/home/hanatok/mambaforge/lib/python3.10/site-packages/alphashape/optimizealpha.py", line 100, in optimizealpha
if _testalpha(points, test_alpha):
File "/home/hanatok/mambaforge/lib/python3.10/site-packages/alphashape/optimizealpha.py", line 41, in _testalpha
return all([polygon.intersects(point) for point in points])
TypeError: 'MultiPoint' object is not iterable
After debugging I have found that the issue is related to the changes in shapely 2.0. If I apply the following patch:
diff --git a/alphashape/optimizealpha.py b/alphashape/optimizealpha.py
index 6c0b72f..a3391c2 100644
--- a/alphashape/optimizealpha.py
+++ b/alphashape/optimizealpha.py
@@ -37,7 +37,7 @@ def _testalpha(points: Union[List[Tuple[float]], np.ndarray], alpha: float):
polygon = alphashape(points, alpha)
if isinstance(polygon, shapely.geometry.polygon.Polygon):
if not isinstance(points, MultiPoint):
- points = MultiPoint(list(points))
+ points = MultiPoint(list(points)).geoms
return all([polygon.intersects(point) for point in points])
elif isinstance(polygon, trimesh.base.Trimesh):
return len(polygon.faces) > 0 and all(
then it works as expected.
The traceback is attached above.
import alphashape
import numpy as np
points = np.array([[1, 1], [1, -1], [-1, 1], [-1, -1]])
alpha = 0.95 * alphashape.optimizealpha(points)
hull = alphashape.alphashape(points, alpha)
hull_pts = hull.exterior.coords.xy
The above code runs without throwing the traceback.
No runtime exceptions.
I tryied the simple example proposed in the documentation (read also 1.1.2 from the Alphashape documentation)
The code I tried:
`
import alphashape
import matplotlib.pyplot as plt
from descartes import PolygonPatch
points = [(0., 0.), (0., 1.), (1., 1.), (1., 0.), (0.5, 0.5)]
alpha = 0.2
alpha_shape = alphashape.alphashape(points, alpha)
fig, ax = plt.subplots()
ax.scatter(*zip(*points))
ax.add_patch(PolygonPatch(alpha_shape, alpha=.2))
plt.show()
`
I obtained the following:
IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed
I was trying to recreate verbatim the 3D alphashape example found on https://pypi.org/project/alphashape/ (about 1/3 down the page). I copied the code into a Jupyter notebook, and it ran correctly, but a recent update (from a sub-package?) causes a ValueError described with photos below.
import alphashape
import pandas as pd
import matplotlib.pyplot as plt
points_3d = [
(0., 0., 0.), (0., 0., 1.), (0., 1., 0.),
(1., 0., 0.), (1., 1., 0.), (1., 0., 1.),
(0., 1., 1.), (1., 1., 1.), (.25, .5, .5),
(.5, .25, .5), (.5, .5, .25), (.75, .5, .5),
(.5, .75, .5), (.5, .5, .75)
]
df_3d = pd.DataFrame(points_3d, columns=['x', 'y', 'z'])
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.scatter(df_3d['x'], df_3d['y'], df_3d['z'])
plt.show()
alpha_shape = alphashape.alphashape(points_3d, 1.1)
alpha_shape.show()
The same output as indicated on https://pypi.org/project/alphashape/ about 1/3 down.
The points plot properly in 3D space, however the call to alphashape.alphashape() returns the following error:
ValueError Traceback (most recent call last)
in
13 plt.show()
14
---> 15 alpha_shape = alphashape.alphashape(points_3d, 1.1)
16 alpha_shape.show()
~\Anaconda3\lib\site-packages\alphashape\alphashape.py in alphashape(points, alpha)
72
73 # Loop over triangles
---> 74 for ia, ib, ic in tri.vertices:
75 pa = coords[ia]
76 pb = coords[ib]
Receive the same output as listed on https://pypi.org/project/alphashape/
Note1: I have tried this on a Macintosh system, and the correct output results were obtained for the same code, running from the same Jupyter Notebook.
Note2: Prior to running the notebook, I performed a global update via anaconda command prompt: conda update --all
Documentation should include an example gallery for creating scripts and plots utilizing this toolbox.
Viewed the documentation.
To see usage examples of the toolbox.
Documentation will include an example gallery with at least one example.
Running alphashape 1.3.1 with Shapely 2.x returns TypeError: 'MultiPoint' object is not iterable
error. This could be fixed by using the .geoms
attribute in optimizealpha.py
, however it returns a ZeroDivisionError: float division by zero
in alphashape.py
Does anyone have a fix for running it with Shapely 2?
Hi,
Was wandering if you have a reference anywhere for the correctness of the alpha-shape algorithm implemented here.
using conda install -c conda-forge
doesn't install alphashape as intended. conda hangs for more than 10 minutes on the solve.
conda install -c conda-forge/label/cf202003 alphashape
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: | failed
CondaError: KeyboardInterrupt
^C
conda list
# packages in environment at /Users/matthiasf/miniconda/miniconda3:
#
# Name Version Build Channel
apptools 5.1.0 pyhd3eb1b0_0
arviz 0.11.2 pyhd3eb1b0_0
asteval 0.9.23 pyhd8ed1ab_0 conda-forge
blas 1.0 mkl
bottleneck 1.3.2 py39he3068b8_1
brotli 1.0.9 hb1e8313_2
brotlipy 0.7.0 py39h9ed2024_1003
bzip2 1.0.8 h1de35cc_0
c-ares 1.17.1 h9ed2024_0
ca-certificates 2021.10.26 hecd8cb5_2
certifi 2021.10.8 py39hecd8cb5_0
cffi 1.14.6 py39h2125817_0
cftime 1.5.1.1 py39h67323c0_0
charset-normalizer 2.0.4 pyhd3eb1b0_0
conda 4.11.0 py39hecd8cb5_0
conda-package-handling 1.7.3 py39h9ed2024_1
configobj 5.0.6 py39hecd8cb5_1
corner 2.2.1 pyhd8ed1ab_0 conda-forge
cryptography 35.0.0 py39h2fd3fbb_0
curl 7.78.0 h7bc2e8c_0
cycler 0.11.0 pyhd3eb1b0_0
cython 0.29.24 py39he9d5cce_0
dbus 1.13.18 h18a8e69_0
double-conversion 3.1.5 haf313ee_1
eigen 3.3.7 h04f5b5a_0
emcee 3.1.1 pyh8a188c0_0 conda-forge
envisage 6.0.1 pyhd3eb1b0_0
expat 2.4.1 h23ab428_2
ffmpeg 4.3.2 h4dad6da_0 conda-forge
fonttools 4.25.0 pyhd3eb1b0_0
freetype 2.11.0 hd8bbffd_0
future 0.18.2 py39hecd8cb5_1
gettext 0.21.0 h7535e17_0
giflib 5.2.1 haf1e3a3_0
gl2ps 1.4.2 h4cff582_0 conda-forge
glew 2.1.0 h046ec9c_2 conda-forge
glib 2.69.1 hdf23fa2_0
gmp 6.2.1 h23ab428_2
gnutls 3.6.15 hed9c0bf_0
h5py 3.6.0 py39h4a1dd59_0
hdf4 4.2.15 hefd3b78_3 conda-forge
hdf5 1.10.6 nompi_hc5d9132_1114 conda-forge
icu 68.1 h23ab428_0
idna 3.3 pyhd3eb1b0_0
intel-openmp 2021.4.0 hecd8cb5_3538
jbig 2.1 h4d881f8_0
jpeg 9d h9ed2024_0
jsoncpp 1.9.4 hf7b0b51_2
kiwisolver 1.3.1 py39h23ab428_0
krb5 1.19.2 hcd88c3b_0
lame 3.100 h1de35cc_0
lcms2 2.12 hf1fd2bf_0
lerc 2.2.1 h046ec9c_0 conda-forge
libblas 3.9.0 11_osx64_mkl conda-forge
libcblas 3.9.0 11_osx64_mkl conda-forge
libclang 11.1.0 default_he082bbe_1 conda-forge
libcurl 7.78.0 hb8e4fae_0
libcxx 12.0.0 h2f01273_0
libdeflate 1.7 h35c211d_5 conda-forge
libedit 3.1.20210910 hca72f7f_0
libev 4.33 h9ed2024_1
libffi 3.3 hb1e8313_2
libgfortran 5.0.0 9_3_0_h6c81a4c_23 conda-forge
libgfortran5 9.3.0 h6c81a4c_23 conda-forge
libiconv 1.16 h1de35cc_0
libidn2 2.3.2 h9ed2024_0
liblapack 3.9.0 11_osx64_mkl conda-forge
libllvm11 11.1.0 h9b2ccf5_0
libnetcdf 4.8.0 nompi_hb4d10b0_103 conda-forge
libnghttp2 1.46.0 ha29bfda_0
libogg 1.3.5 h9ed2024_1
libpng 1.6.37 ha441bb4_0
libpq 13.3 hea3049e_0 conda-forge
libssh2 1.9.0 ha12b0ac_1
libtasn1 4.16.0 h9ed2024_0
libtheora 1.1.1 hb4e5f40_1
libtiff 4.3.0 h1167814_1 conda-forge
libunistring 0.9.10 h9ed2024_0
libvorbis 1.3.7 haf1e3a3_0
libwebp 1.2.0 hacca55c_0
libwebp-base 1.2.0 h9ed2024_0
libxml2 2.9.12 h93ec3fd_0 conda-forge
libzip 1.8.0 h8b0c345_1 conda-forge
llvm-openmp 12.0.0 h0dcd299_1
lmfit 1.0.3 pyhd8ed1ab_0 conda-forge
loguru 0.5.3 py39h6e9494a_2 conda-forge
lz4-c 1.9.3 h23ab428_1
matplotlib 3.5.0 py39hecd8cb5_0
matplotlib-base 3.5.0 py39h4f681db_0
mayavi 4.7.2 py39h4634037_5 conda-forge
mkl 2021.4.0 hecd8cb5_637
mkl-service 2.4.0 py39h9ed2024_0
mkl_fft 1.3.1 py39h4ab4a9b_0
mkl_random 1.2.2 py39hb2f4e1b_0
mpi 1.0 mpich
mpi4py 3.1.2 py39ha81d895_0 conda-forge
mpich 3.4.2 hd33e60e_100 conda-forge
munkres 1.1.4 py_0
mysql-common 8.0.25 h694c41f_2 conda-forge
mysql-libs 8.0.25 h115446f_2 conda-forge
ncurses 6.3 hca72f7f_2
netcdf4 1.5.7 nompi_py39hfa5ec60_100 conda-forge
nettle 3.7.3 h230ac6f_1
nspr 4.30 hcd9eead_0 conda-forge
nss 3.69 h31e2bf1_1 conda-forge
numexpr 2.7.3 py39h5873af2_1
numpy 1.21.2 py39h4b4dc7a_0
numpy-base 1.21.2 py39he0bd621_0
olefile 0.46 pyhd3eb1b0_0
openh264 2.1.1 hfd3ada9_0 conda-forge
openssl 1.1.1l h9ed2024_0
packaging 21.3 pyhd3eb1b0_0
pandas 1.3.4 py39h743cdd8_0
pcre 8.45 h23ab428_0
pillow 8.4.0 py39h98e4679_0
pip 21.2.4 py39hecd8cb5_0
proj 7.2.0 h78d1473_2 conda-forge
pugixml 1.11.4 he49afe7_0 conda-forge
pycosat 0.6.3 py39h9ed2024_0
pycparser 2.21 pyhd3eb1b0_0
pyface 7.3.0 py39hecd8cb5_1
pygments 2.10.0 pyhd3eb1b0_0
pyopenssl 21.0.0 pyhd3eb1b0_1
pyparsing 3.0.4 pyhd3eb1b0_0
pyqt 5.12.3 py39h6e9494a_7 conda-forge
pyqt-impl 5.12.3 py39hef7122c_7 conda-forge
pyqt5-sip 4.19.18 py39hd8f94c5_7 conda-forge
pyqtchart 5.12 py39hef7122c_7 conda-forge
pyqtwebengine 5.12.1 py39hef7122c_7 conda-forge
pysocks 1.7.1 py39hecd8cb5_0
python 3.9.7 h88f2d9e_1
python-dateutil 2.8.2 pyhd3eb1b0_0
python.app 3 py39hca72f7f_0
python_abi 3.9 2_cp39 conda-forge
pytz 2021.3 pyhd3eb1b0_0
qt 5.12.9 h126340a_4 conda-forge
readline 8.1 h9ed2024_0
requests 2.26.0 pyhd3eb1b0_0
ruamel_yaml 0.15.100 py39h9ed2024_0
schwimmbad 0.3.2 py39h6e9494a_1 conda-forge
scipy 1.7.1 py39h056f1c0_0 conda-forge
setuptools 58.0.4 py39hecd8cb5_0
setuptools-scm 6.3.2 pyhd3eb1b0_0
six 1.16.0 pyhd3eb1b0_0
sqlite 3.36.0 hce871da_0
tbb 2020.2 h940c156_4 conda-forge
tbb-devel 2020.2 h940c156_4 conda-forge
tk 8.6.11 h7bc2e8c_0
tomli 1.2.2 pyhd3eb1b0_0
tornado 6.1 py39h9ed2024_0
tqdm 4.62.3 pyhd3eb1b0_1
traits 6.2.0 py39h9ed2024_0
traitsui 7.2.1 pyhd3eb1b0_0
typing-extensions 3.10.0.2 hd3eb1b0_0
typing_extensions 3.10.0.2 pyh06a4308_0
tzdata 2021e hda174b7_0
uncertainties 3.1.6 pyhd8ed1ab_0 conda-forge
urllib3 1.26.7 pyhd3eb1b0_0
utfcpp 3.2.1 hecd8cb5_0
vtk 9.0.3 no_osmesa_py39h9af63fb_100 conda-forge
wheel 0.37.0 pyhd3eb1b0_1
x264 1!161.3030 h0d85af4_1 conda-forge
xarray 0.19.0 pyhd3eb1b0_1
xz 5.2.5 h1de35cc_0
yaml 0.2.5 haf1e3a3_0
zlib 1.2.11 h1de35cc_3
zstd 1.5.0 hcb37349_1
the installation of the alphashape package
installation must be possible in less than a minute
Hi. Great job with alphashape!
I am doing alpha_shape = alphashape.alphashape(points, 5)
, where points is a Nx3
numpy array.
I found that if I do alpha_shape.exterior.coords.xy
I can retrieve the coordinates of the points in the alpha shape contour. I was wondering whether there is a way to retrieve instead the original indexes relative to points
.
Many thanks,
I followed the documentation example. https://github.com/bellockk/alphashape#readme
It seems there is a compatibility issue with PolygonPatch
.
Here's what I ran. I expected a plot but got an error.
import os
import sys
import pandas as pd
import numpy as np
from descartes import PolygonPatch
import matplotlib.pyplot as plt
sys.path.insert(0, os.path.dirname(os.getcwd()))
import alphashape
points_2d = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
alpha_shape = alphashape.alphashape(points_2d, 0.)
alpha_shape
fig, ax = plt.subplots()
ax.scatter(*zip(*points_2d))
ax.add_patch(PolygonPatch(alpha_shape, alpha=0.2))
plt.show()
I tried ~30 STLs, but I either get empty alphashapes or seemingly random, disconnected triangles.
Even the simplest example I could think of - on the command line
python -c "import alphashape as al; points_3d = [ (0., 0., 0.), (0., 0., 1.), (0., 1., 0.), (1., 0., 0.), (1., 1., 0.), (0.,1.,1.)]; a = al.alphashape(points_3d,10); print(a.faces);"
returns
[]
At least a manifold
Getting the alpha shape
Provenance: conda forge
conda version: 4.14.0
Set-up:
conda install alphashape
conda list
# packages in environment at C:\ProgramData\Miniconda3\envs\test_alphashape_forge:
#
# Name Version Build Channel
alphashape 1.3.1 pyh44b312d_0 conda-forge
attrs 22.1.0 pyh71513ae_1 conda-forge
blosc 1.21.1 h74325e0_3 conda-forge
boost-cpp 1.78.0 h9f4b32c_1 conda-forge
branca 0.5.0 pyhd8ed1ab_0 conda-forge
brotli 1.0.9 h8ffe710_7 conda-forge
brotli-bin 1.0.9 h8ffe710_7 conda-forge
brotlipy 0.7.0 py310he2412df_1004 conda-forge
bzip2 1.0.8 h8ffe710_4 conda-forge
ca-certificates 2022.9.24 h5b45459_0 conda-forge
cairo 1.16.0 hd694305_1014 conda-forge
certifi 2022.9.24 pyhd8ed1ab_0 conda-forge
cffi 1.15.1 py310hcbf9ad4_0 conda-forge
cfitsio 4.1.0 h5a969a9_0 conda-forge
charset-normalizer 2.1.1 pyhd8ed1ab_0 conda-forge
click 8.1.3 py310h5588dad_0 conda-forge
click-log 0.4.0 pyhd8ed1ab_0 conda-forge
click-plugins 1.1.1 py_0 conda-forge
cligj 0.7.2 pyhd8ed1ab_1 conda-forge
colorama 0.4.5 pyhd8ed1ab_0 conda-forge
contourpy 1.0.5 py310h232114e_0 conda-forge
cryptography 37.0.1 py310h21b164f_0
curl 7.85.0 heaf79c2_0 conda-forge
cycler 0.11.0 pyhd8ed1ab_0 conda-forge
expat 2.4.9 h1537add_0 conda-forge
fiona 1.8.21 py310hfed10a5_2 conda-forge
folium 0.12.1.post1 pyhd8ed1ab_1 conda-forge
font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge
font-ttf-inconsolata 3.000 h77eed37_0 conda-forge
font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge
font-ttf-ubuntu 0.83 hab24e00_0 conda-forge
fontconfig 2.14.0 h720f74d_1 conda-forge
fonts-conda-ecosystem 1 0 conda-forge
fonts-conda-forge 1 0 conda-forge
fonttools 4.37.4 py310h8d17308_0 conda-forge
freetype 2.12.1 h546665d_0 conda-forge
freexl 1.0.6 h67ca5e6_1 conda-forge
gdal 3.5.2 py310h644bc08_3 conda-forge
geopandas 0.11.1 pyhd8ed1ab_0 conda-forge
geopandas-base 0.11.1 pyha770c72_0 conda-forge
geos 3.11.0 h39d44d4_0 conda-forge
geotiff 1.7.1 h714bc5f_3 conda-forge
gettext 0.19.8.1 h5728263_1009 conda-forge
hdf4 4.2.15 h0e5069d_4 conda-forge
hdf5 1.12.2 nompi_h57737ce_100 conda-forge
icu 70.1 h0e60522_0 conda-forge
idna 3.4 pyhd8ed1ab_0 conda-forge
intel-openmp 2022.1.0 h57928b3_3787 conda-forge
jinja2 3.1.2 pyhd8ed1ab_1 conda-forge
joblib 1.2.0 pyhd8ed1ab_0 conda-forge
jpeg 9e h8ffe710_2 conda-forge
kealib 1.4.15 hdf81f3a_1 conda-forge
kiwisolver 1.4.4 py310h476a331_0 conda-forge
krb5 1.19.3 hc8ab02b_0 conda-forge
lcms2 2.12 h2a16943_0 conda-forge
lerc 4.0.0 h63175ca_0 conda-forge
libblas 3.9.0 16_win64_mkl conda-forge
libbrotlicommon 1.0.9 h8ffe710_7 conda-forge
libbrotlidec 1.0.9 h8ffe710_7 conda-forge
libbrotlienc 1.0.9 h8ffe710_7 conda-forge
libcblas 3.9.0 16_win64_mkl conda-forge
libcurl 7.85.0 heaf79c2_0 conda-forge
libdeflate 1.14 hcfcfb64_0 conda-forge
libffi 3.4.2 h8ffe710_5 conda-forge
libgdal 3.5.2 hec59f66_3 conda-forge
libglib 2.74.0 h79619a9_0 conda-forge
libiconv 1.17 h8ffe710_0 conda-forge
libkml 1.3.0 hf2ab4e4_1015 conda-forge
liblapack 3.9.0 16_win64_mkl conda-forge
libnetcdf 4.8.1 nompi_h85765be_104 conda-forge
libpng 1.6.38 h19919ed_0 conda-forge
libpq 14.5 h1ea2d34_0 conda-forge
librttopo 1.1.0 h2842628_11 conda-forge
libspatialindex 1.9.3 h39d44d4_4 conda-forge
libspatialite 5.0.1 ha17912d_18 conda-forge
libsqlite 3.39.4 hcfcfb64_0 conda-forge
libssh2 1.10.0 h9a1e1f7_3 conda-forge
libtiff 4.4.0 h8e97e67_4 conda-forge
libwebp-base 1.2.4 h8ffe710_0 conda-forge
libxcb 1.13 hcd874cb_1004 conda-forge
libxml2 2.9.14 hf5bbc77_4 conda-forge
libzip 1.9.2 h519de47_1 conda-forge
libzlib 1.2.12 hcfcfb64_4 conda-forge
lz4-c 1.9.3 h8ffe710_1 conda-forge
m2w64-gcc-libgfortran 5.3.0 6 conda-forge
m2w64-gcc-libs 5.3.0 7 conda-forge
m2w64-gcc-libs-core 5.3.0 7 conda-forge
m2w64-gmp 6.1.0 2 conda-forge
m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge
mapclassify 2.4.3 pyhd8ed1ab_0 conda-forge
markupsafe 2.1.1 py310he2412df_1 conda-forge
matplotlib-base 3.6.0 py310h51140c5_0 conda-forge
mkl 2022.1.0 h6a75c08_874 conda-forge
msys2-conda-epoch 20160418 1 conda-forge
munch 2.5.0 py_0 conda-forge
munkres 1.1.4 pyh9f0ad1d_0 conda-forge
networkx 2.8.7 pyhd8ed1ab_0 conda-forge
numpy 1.23.3 py310h4a8f9c9_0 conda-forge
openjpeg 2.5.0 hc9384bd_1 conda-forge
openssl 3.0.5 hcfcfb64_2 conda-forge
packaging 21.3 pyhd8ed1ab_0 conda-forge
pandas 1.5.0 py310h1c4a608_0 conda-forge
pcre 8.45 h0e60522_0 conda-forge
pcre2 10.37 hdfff0fc_1 conda-forge
pillow 9.2.0 py310h52929f7_2 conda-forge
pip 22.2.2 pyhd8ed1ab_0 conda-forge
pixman 0.40.0 h8ffe710_0 conda-forge
poppler 22.04.0 hb57f792_3 conda-forge
poppler-data 0.4.11 hd8ed1ab_0 conda-forge
postgresql 14.5 he353ca9_0 conda-forge
proj 9.0.1 h1cfcee9_1 conda-forge
pthread-stubs 0.4 hcd874cb_1001 conda-forge
pycparser 2.21 pyhd8ed1ab_0 conda-forge
pyopenssl 22.0.0 pyhd8ed1ab_1 conda-forge
pyparsing 3.0.9 pyhd8ed1ab_0 conda-forge
pyproj 3.4.0 py310h6377384_0 conda-forge
pysocks 1.7.1 pyh0701188_6 conda-forge
python 3.10.6 hcf16a7b_0_cpython conda-forge
python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge
python_abi 3.10 2_cp310 conda-forge
pytz 2022.4 pyhd8ed1ab_0 conda-forge
requests 2.28.1 pyhd8ed1ab_1 conda-forge
rtree 1.0.0 py310h1cbd46b_1 conda-forge
scikit-learn 1.1.2 py310h3a564e9_0 conda-forge
scipy 1.9.1 py310h578b7cb_0 conda-forge
setuptools 65.4.1 pyhd8ed1ab_0 conda-forge
shapely 1.8.4 py310h523c7d9_0 conda-forge
six 1.16.0 pyh6c4a22f_0 conda-forge
snappy 1.1.9 h82413e6_1 conda-forge
sqlite 3.39.4 hcfcfb64_0 conda-forge
tbb 2021.6.0 h91493d7_0 conda-forge
threadpoolctl 3.1.0 pyh8a188c0_0 conda-forge
tiledb 2.11.3 h3132609_0 conda-forge
tk 8.6.12 h8ffe710_0 conda-forge
trimesh 3.15.3 pyh1a96a4e_0 conda-forge
tzdata 2022d h191b570_0 conda-forge
ucrt 10.0.20348.0 h57928b3_0 conda-forge
unicodedata2 14.0.0 py310he2412df_1 conda-forge
urllib3 1.26.11 pyhd8ed1ab_0 conda-forge
vc 14.2 hac3ee0b_8 conda-forge
vs2015_runtime 14.29.30139 h890b9b1_8 conda-forge
wheel 0.37.1 pyhd8ed1ab_0 conda-forge
win_inet_pton 1.1.0 py310h5588dad_4 conda-forge
xerces-c 3.2.3 h0e60522_5 conda-forge
xorg-libxau 1.0.9 hcd874cb_0 conda-forge
xorg-libxdmcp 1.1.3 hcd874cb_0 conda-forge
xyzservices 2022.9.0 pyhd8ed1ab_0 conda-forge
xz 5.2.6 h8d14728_0 conda-forge
zlib 1.2.12 hcfcfb64_4 conda-forge
zstd 1.5.2 h7755175_4 conda-forge
For tens of thousands of data, it's really too slow
I was using alphashape and Shapely together and it lead to a Segmentation Fault when creating a Polygon in Shapely.
After uninstall alphashape, Click and click-log this fault still occurs.
I had to completely remove pip3 to clear this error.
Not sure if this issue belongs more to alphashape or Shapely.
I am using Ubuntu 18.04 with the newest python3 and pip3 version.
I have those dots that need to convert to a 3D volume using this code
But I found that there was something wrong with the compiled period after I entered it.
points_3d = [
(57, 11, 18), (51.22318624, 7.595082359,
18.96144895), (63.90307229, 0.612714382, 18.92441008),
(54.04337196, 13.09810222, -36.37036356), (74.99878683, -66.99592395, 22.63615156)
]
alphashape.alphashape(points_3d, lambda ind, r: 1.0 + any(
np.array(points_3d)[ind][:, 0] == 0.0)).show()
the crash is this
line 22, in <module>
np.array(points_3d)[ind][:, 0] == 0.0)).show()
File "C:\Python310\lib\site-packages\trimesh\base.py", line 2644, in show
return scene.show(**kwargs)
File "C:\Python310\lib\site-packages\trimesh\scene\scene.py", line 1091, in show
return SceneViewer(self, **kwargs)
File "C:\Python310\lib\site-packages\trimesh\viewer\windowed.py", line 103, in __init__
self._initial_camera_transform = scene.camera_transform.copy()
File "C:\Python310\lib\site-packages\trimesh\scene\scene.py", line 598, in camera_transform
return self.graph[self.camera.name][0]
File "C:\Python310\lib\site-packages\trimesh\scene\scene.py", line 655, in camera
return self.set_camera()
File "C:\Python310\lib\site-packages\trimesh\scene\scene.py", line 569, in set_camera
transform = cameras.look_at(
File "C:\Python310\lib\site-packages\trimesh\scene\cameras.py", line 329, in look_at
points_c = rinv.dot(points.T).T
ValueError: shapes (3,3) and (0,) not aligned: 3 (dim 1) != 0 (dim 0)
I want to connect those dots to a 3D volume like those images.
There is a .travis.yml
here, but no badge in the README (image for https://api.travis-ci.com/bellockk/alphashape.svg?branch=master
) and a 404 on the Travis site for this project.
So perhaps you'd still need to sign up your Github account for Travis CI?
(Also, it would probably be great to run the coverage test on the CI itself and upload its report to codecov.io. This should be as simple as adding a second line to scripts
running the first two lines of your coverage
recipe, and then adding a directive codecov
under after_success
.)
A binder link exists in the top level README.md file, but there are no jupyter notebooks in the examples folder to view.
Clicked on the binder link, and explored the project looking for notebooks.
To find a notebook in the examples folder.
A jupyter notebook demonstrating toolbox usage and capabilities will be available when using the binder link.
Continuous integration testing is only occurring on a linux target. Add a Windows build node and configure it to test builds.
Submitted a patch.
Tests to be executed on Windows build node.
Automated continuous integration testing will be executed on a Windows build node.
As far as I can tell, the alphshape optimization feature is only available in 2D. I have implemented that feature in 3D, too. If you like, I could try to contribute it.
A placeholder for a command line application using the alphashape
toolbox is in the source code. This needs to be updated to include capability to read in a ESRI shapefile, an alpha parameter, and a target ESRI shapefile location and write out the geometries created by the alphashape
tool to the target file.
Installing the alphashape
toolbox will add a command line utility with the capability described in the Description of this issue.
GeoPandas is a useful tool for dealing with GIS data that will have geographic data stored within an associated coordinate reference frame.
Include GeoPandas capability into the alphashape toolbox by allowing the user to supply a geodataframe
as an input to the alphashape function. Include examples and a jupyter notebook demonstrating the capability.
Called the alphashape
function with a geodataframe
as the input data.
To get back a geodataframe
object containing the geometry of the alphashape.
Calling the alphashape
function with a geodataframe
object as input will return a geodataframe
object containing the alpha shape geometry.
A very common use case of the alphashape toolbox is to find the concave hull that best fits a set of points in one polygon. A user will manually repeating the generation of alpha shapes with different parameters until a tight fitting shape is found in one polygon. Automate this process with an optimizealpha
function. Also update the alphashape
function to determine an alpha parameter if one is not given by the user.
A new function optimizealpha
will be available that will solve for the alpha parameter that results in the tightest fitting alpha shape that returns one polygon. The alphashape
function will also be able to be called without an alpha parameter, and this new function will be used to determine one. Tests must be included for this new capability.
I intend to cite your work in a paper I am writing, in which this code is being used. Could you possibly provide a Zenodo link or some other kind of citation information somewhere in your readme (and here)?
The documentation is not clear if the package is only two dimensional or N-dimensional. All examples are also in two-dimensions, not helping again to understand if more than two dimensions are supported. It should be stated at the beginning of the documentation if the package is N-dimensional or only two-dimensional.
optimizealpha fails when the optimal alpha is a bit big. In my particular case, upper and lower values are:
lower = 4.5
upper = np.nextafter(lower, 9)
print((upper - lower) > numpy.finfo(float).eps * 2 )
True
The middle point is identical to lower
, so the model never converges below the threshold.
I see two ways of solving the problem:
eps
for the current value range: 2 * np.finfo(float).eps * lower
, or more accurately, np.finfo(float).eps * 2 ** math.floor(1 + math.log2(lower))
,The first case is better suited to the current code, but getting alpha to within machine precision may not always be necessary.
Identified some libraries that can be updated to allow the tutorial to function properly
Attempted to run the tutorial but found the same issues as motioned in #44
Attempted to match my env to that described in requirements.txt (note that this is different than that described in setup.py) and found that many library versions used are no longer stable and fail on install.
pip install shapely==1.7.0
[21 lines of output] Traceback (most recent call last): File "C:\Users\wisch\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\wisch\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\Users\wisch\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) File "C:\Users\wisch\AppData\Local\Temp\pip-build-env-2jghjqcx\overlay\Lib\site-packages\setuptools\build_meta.py", line 355, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "C:\Users\wisch\AppData\Local\Temp\pip-build-env-2jghjqcx\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in _get_build_requires self.run_setup() File "C:\Users\wisch\AppData\Local\Temp\pip-build-env-2jghjqcx\overlay\Lib\site-packages\setuptools\build_meta.py", line 507, in run_setup super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script) File "C:\Users\wisch\AppData\Local\Temp\pip-build-env-2jghjqcx\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup exec(code, locals()) File "<string>", line 85, in <module> File "C:\Users\wisch\AppData\Local\Temp\pip-install-tt23r6e_\shapely_7768876d24d64883a68e39f25fabf682\shapely\_buildcfg.py", line 205, in <module> lgeos = CDLL("geos_c.dll") File "C:\Users\wisch\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 374, in __init__ self._handle = _dlopen(self._name, mode) FileNotFoundError: Could not find module 'geos_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
pip install scipy==1.5.2
` C:\Users\wisch\AppData\Local\Temp\pip-install-n4htu1uc\numpy_7f356b0642a84939984027a4849e48bc\numpy\distutils\system_info.py:1712: UserWarning:
Lapack (http://www.netlib.org/lapack/) sources not found.
Directories to search for the sources can be specified in the
numpy/distutils/site.cfg file (section [lapack_src]) or by setting
the LAPACK_SRC environment variable.
if getattr(self, 'calc_info{}'.format(lapack))():
NOT AVAILABLE
C:\Users\wisch\AppData\Local\Temp\pip-build-env-2r1mfm2k\overlay\Lib\site-packages\setuptools\_distutils\dist.py:265: UserWarning: Unknown distribution option: 'define_macros'
warnings.warn(msg)
running dist_info
running build_src
build_src
building py_modules sources
creating build
creating build\src.win-amd64-3.1
creating build\src.win-amd64-3.1\numpy
creating build\src.win-amd64-3.1\numpy\distutils
building library "npymath" sources
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed`
Successfully installed shapely-1.8.0
Successfully installed scipy-1.5.2
successful run of the following
python -m venv c:\path\to\myenv c:\path\to\myenv\Scripts\activate.ps1 pip install -r requirements.txt
returns:
Successfully installed <libraries listed in requirements.txt>
Also Numpy version: numpy==1.16.3
Alphashape.alphashape is taking a few seconds to compute for an alpha hull of 0.1 and thousands of points.
However, it seems around a hundred times faster on Windows.
I am working on a reproduction with clearer measurements, but in the meantime, do you have any tip what I could do to investigate the issue or what info I could provide to help?
Is there a specific computation that could provoke some slowness, eg some intensive computation that rely specifically on Numpy or any other 3rd party lib to be performant, or anything like that?
Same perfs on Windows and Linux
From a set of points I am trying to find the best alpha shape so am not providing the alphashape function with an alpha value so that it can find the best one for my points ie. alphashape.alphashape(points)
. However, this generated an error from optimizealpha()
when there should not have been one as this was a working example provided in the docs. I think there may be a bug in the code of the actual package so it needs to be updated given not even the provided example works.
points_2d = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
alpha_shape = alphashape.alphashape(points_2d)
fig, ax = plt.subplots()
ax.scatter(*zip(*points))
ax.add_patch(PolygonPatch(alpha_shape, alpha=.2))
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[86], line 3
1 points_2d = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
2 (0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
----> 3 alpha_shape = alphashape.alphashape(points_2d)
4 fig, ax = plt.subplots()
5 ax.scatter(*zip(*points))
File ~/Documents/ALA/galah-env/lib/python3.10/site-packages/alphashape/alphashape.py:131, in alphashape(points, alpha)
129 except ImportError:
130 from .optimizealpha import optimizealpha
--> 131 alpha = optimizealpha(points)
133 # Convert the points to a numpy array
134 if USE_GP and isinstance(points, geopandas.geoseries.GeoSeries):
File ~/Documents/ALA/galah-env/lib/python3.10/site-packages/alphashape/optimizealpha.py:100, in optimizealpha(points, max_iterations, lower, upper, silent)
97 test_alpha = (upper + lower) * .5
99 # Update the bounds to include the solution space
--> 100 if _testalpha(points, test_alpha):
101 lower = test_alpha
102 else:
File ~/Documents/ALA/galah-env/lib/python3.10/site-packages/alphashape/optimizealpha.py:41, in _testalpha(points, alpha)
39 if not isinstance(points, MultiPoint):
40 points = MultiPoint(list(points))
---> 41 return all([polygon.intersects(point) for point in points])
42 elif isinstance(polygon, trimesh.base.Trimesh):
43 return len(polygon.faces) > 0 and all(
44 trimesh.proximity.signed_distance(polygon, list(points)) >= 0)
TypeError: 'MultiPoint' object is not iterable
Dear community,
I would like to know how to save the created / computed concave hull with alpha shape as mesh file (e.g. OBJ format)?
I would appreciate any help.
Best,
Continuous integration testing is only occurring on a linux target. Add an OSX build node and configure it to test builds.
Submitted a patch.
Tests to be executed on OSX build node.
Automated continuous integration testing will be executed on a OSX build node.
If I run the code given in the documentation:
points_2d = [(0., 0.), (0., 1.), (1., 1.), (1., 0.),
(0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
fig, ax = plt.subplots()
ax.scatter(*zip(*points_2d))
plt.show()
alpha_shape = alphashape.alphashape(points_2d, 0.)
alpha_shape
fig, ax = plt.subplots()
ax.scatter(*zip(*points_2d))
ax.add_patch(PolygonPatch(alpha_shape, alpha=0.5))
plt.show()
I get the following error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_19312/2363699982.py in <module>
12 fig, ax = plt.subplots()
13 ax.scatter(*zip(*points_2d))
---> 14 ax.add_patch(PolygonPatch(alpha_shape, alpha=0.5))
15 plt.show()
~\AppData\Roaming\Python\Python39\site-packages\descartes\patch.py in PolygonPatch(polygon, **kwargs)
85
86 """
---> 87 return PathPatch(PolygonPath(polygon), **kwargs)
~\AppData\Roaming\Python\Python39\site-packages\descartes\patch.py in PolygonPath(polygon)
60 "A polygon or multi-polygon representation is required")
61
---> 62 vertices = concatenate([
63 concatenate([asarray(t.exterior)[:, :2]] +
64 [asarray(r)[:, :2] for r in t.interiors])
~\AppData\Roaming\Python\Python39\site-packages\descartes\patch.py in <listcomp>(.0)
61
62 vertices = concatenate([
---> 63 concatenate([asarray(t.exterior)[:, :2]] +
64 [asarray(r)[:, :2] for r in t.interiors])
65 for t in polygon])
IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed
Do you know why I am getting this error?
Please check line 134 in alphashape.py -> add a check for the geopandas import to avoid a non-defined variable name error (in case goepandas is not imported)
if (USE_GP and isinstance(points, geopandas.geoseries.GeoSeries)):
...
I believe there is a strong use case for the warnings output by logger
to be instead created by warnings
. In this case, one can fetch cases where the algorithm would not converge and, for example, try again with known lower / upper parameters. This is helpful, for example, when one is working with a lot of different geometries for which one would like to get the concave hull.
The same goes for the warning "'Singular matrix. Likely caused by all points lying in an N-1 space." If this warning can be fetched, one can possibly stop the execution of the optimizealpha
algorithm right away and set, e.g., alpha=0 directly.
I benefitted from changing these details in the code, so I am posting this as a suggestion. Can also do it myself.
The features list in the README is empty, there should be an informative introduction to the project and its capabilities.
Viewed the project on https://github.com/bellockk/alphashape
To see an infomative introduction to the product and its capabilities.
Viewing the top level README.md file will show plots and a description of the capabilities of this toolbox.
Hi, thanks for your contribution. I would like to ask for some methods to extract point cloud surface boundaries by using this toolbox. Do you have some suggestions or demonstrations on it?
Thanks
### What I Expected
### Acceptance Criteria
After installing alphashape I get this error when I try to import alphashape:
Traceback (most recent call last):
File "computer_vision/segmentation/concave_hull_segmentation.py", line 7, in
from alphashape import alphashape
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\site-packages\alphashape_init_.py", line 6, in
from .alphashape import alphashape
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\site-packages\alphashape\alphashape.py", line 8, in
from shapely.ops import cascaded_union, polygonize
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\site-packages\shapely\ops.py", line 13, in
from shapely.prepared import prep
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\site-packages\shapely\prepared.py", line 5, in
from shapely.geos import lgeos
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\site-packages\shapely\geos.py", line 154, in
lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
File "C:\Users\nlb\Anaconda3\envs\ai_platform\lib\ctypes_init.py", line 364, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
from alphashape import alphashape, optimizealpha
points = [(0., 0.), (0., 1.), (1., 1.), (1., 0.), (0.5, 0.25), (0.5, 0.75), (0.25, 0.5), (0.75, 0.5)]
alpha = 0.95 * alphashape.optimizealpha(points)
hull = alphashape.alphashape(points, alpha)
I tried to understand how to set a varying Alpha parameter from this link but with no vail.
I have some problems regarding this line of code:
lambda ind, r: 1.0 + any(np.array(points_2d)[ind][:,0] == 0.0)
ind
the iterator that loops through the points array?r
is circumradius of the simplex. Is that correct?[:,0]
mean?Also, more examples on setting varying alpha parameter would be highly appreciated, e.g. based on point density, or by passing in an alpha parameter list?
When creating an alphashpe with a set of points running alphashape.alphashape.contains() on all of the points the edge and corner points come up as false. the points are floating point numbers and this could be a rounding issue of some sort.
Create random floating point coordinates and generate an alphashape using optimizealpha. Then run the alphashap.alphashape.contains() method on all of the points. All of the border points come back false.
Use the script from https://stackoverflow.com/questions/61757304/how-to-determine-if-a-point-lies-inside-a-concave-hull-alpha-shape but also run the original points through the if statement and see what color they end up being.
Border points used to create an alphashape should be true if passed into the contain method for that alphashape object.
Border points used to create an alphashape will be true if passed into the contain method for that alphashape object.
Hi, I'm trying to detect the edges of a bunch of cloud points. I wonder what is the computational complexity of the AlphaShape algorithm you implemented. Is it O(n^2)? What about using Delaunay Triangulation?
Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.