Giter VIP home page Giter VIP logo

pyacvd's Introduction

pyacvd

image

This module takes a surface mesh and returns a uniformly meshed surface using voronoi clustering. This approach is loosely based on research by S. Valette, and J. M. Chassery in ACVD.

Installation

Installation is straightforward using pip:

$ pip install pyacvd

Example

This example remeshes a non-uniform quad mesh into a uniform triangular mesh.

from pyvista import examples
import pyacvd

# download cow mesh
cow = examples.download_cow()

# plot original mesh
cow.plot(show_edges=True, color='w')

original cow mesh

zoomed cow mesh

clus = pyacvd.Clustering(cow)
# mesh is not dense enough for uniform remeshing
clus.subdivide(3)
clus.cluster(20000)

# plot clustered cow mesh
clus.plot()

zoomed cow mesh

# remesh
remesh = clus.create_mesh()

# plot uniformly remeshed cow
remesh.plot(color='w', show_edges=True)

zoomed cow mesh

pyacvd's People

Contributors

akaszynski avatar banesullivan avatar fedemiorelli avatar pre-commit-ci[bot] avatar ralic avatar sitic avatar truenicoco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyacvd's Issues

Erroneous sub-triangle

Under some conditions, pyacvd produces incorrect triangles, as seen in the image below:
triangles

The small triangle is indeed inside the large one, resulting in incorrect half-edge structure. Changing the number of subdivsions or the cluster parameter solves this. However, it is inconvenient to rerun the whole application once this pops up.

Could you help me with this? I can provide input files to reproduce the issue.

How to use this with vtkPolyData?

Thank you for providing this package! How can I use this package if I have the input as vtkPolyData and would need the processed mesh as vtkPolyData? All the examples use some pyvista mesh objects and I don't know how to convert those to/from vtkPolyData.

Randomly inside-outsided mesh generated by create_mesh()

Hi

Following the README, I created and saved new mesh file by remesh.save("test.ply").
Although it looks fine in built-in viewer remesh.plot(color='w', show_edges=True), I found that the output includes randomly inside-outside reversed faces.

For example, when visualized by meshlab, the mesh looks like

snapshot01

Latest pyacvd 0.2.9 compilation from source fails when code is taken from PyPI

Latest pyacvd 0.2.9 compilation from source fails when code is taken from PyPI, https://files.pythonhosted.org/packages/d7/9d/1d10109cbd9409e0885d5a824ff2610d3adf2a2066a90abb66490ae9706a/pyacvd-0.2.9.tar.gz

Looks like this is fixed in main branch long time ago but PyPI source needs update.

D:\build_pyacvd\pyacvd-0.2.9>python -m pip install .
Processing d:\build_pyacvd\pyacvd-0.2.9
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      Traceback (most recent call last):
        File "C:\DE-Python\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in <module>
          main()
        File "C:\DE-Python\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "C:\DE-Python\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "C:\Users\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\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\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in _get_build_requires
          self.run_setup()
        File "C:\Users\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 28, in <module>
        File "C:\Users\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 1010, in cythonize
          module_list, module_metadata = create_extension_list(
        File "C:\Users\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 845, in create_extension_list
          for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
        File "C:\Users\ashish.shirodkar\AppData\Local\Temp\pip-build-env-ae4d0jag\overlay\Lib\site-packages\Cython\Build\Dependencies.py", line 117, in nonempty
          raise ValueError(error_msg)
      ValueError: 'pyacvd/cython/_clustering.pyx' doesn't match any files
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Clustering fails due to vtkSubdivisionFilter

I have a mesh, that I'm trying to resample with the ACVD algorithm. While the mesh is manifold, the subdivision filter employed by the ACVD algorithm appears to return a non-manifold mesh, that makes the algorithm crash mid-way.

In particular:

import pyvista as pv
from PyACVD import Clustering

mesh = pv.PolyData('shoot_manifold_acvd_crash.ply')
non_manifold_edges = mesh.extract_edges(feature_edges=False, boundary_edges=False, 
                                        manifold_edges=False, non_manifold_edges=True)
print(non_manifold_edges.n_cells, non_manifold_edges.n_points)
0 0

The step that fails is the generation of the clusters:

cobj = Clustering.Cluster(mesh)
cobj.GenClusters(mesh.n_points)
Subdividing mesh with 3 subdivision(s)
ERROR:root:Dataset is non-manifold and cannot be subdivided. Edge shared by 4 cells
ERROR:root:Subdivision failed.
ERROR:root:vtkInformation (0x55df794fb890)
Traceback (most recent call last):

  File "<ipython-input-2-be1bf5dcec33>", line 2, in <module>
    cobj.GenClusters(mesh.n_points)

  File "/home/henrik/.local/anaconda2/envs/surface/lib/python3.7/site-packages/PyACVD/Clustering.py", line 184, in GenClusters
    self.PrepareMesh(nclus, subratio, verbose)

  File "/home/henrik/.local/anaconda2/envs/surface/lib/python3.7/site-packages/PyACVD/Clustering.py", line 139, in PrepareMesh
    v = VN.vtk_to_numpy(self.mesh.GetPoints().GetData()).astype(np.float)

AttributeError: 'NoneType' object has no attribute 'GetData'

Digging deeper shows that this is due to the subdivision that is happening inside the mesh preparation step:

mesh.subdivide(3, 'loop')
ERROR:root:Dataset is non-manifold and cannot be subdivided. Edge shared by 4 cells
ERROR:root:Subdivision failed.
ERROR:root:vtkInformation (0x55df796458b0)
PolyData (0x7ff0b08cab28)
  N Cells:	0
  N Points:	0
  X Bounds:	1.000e+00, -1.000e+00
  Y Bounds:	1.000e+00, -1.000e+00
  Z Bounds:	1.000e+00, -1.000e+00
  N Scalars:	0
mesh.subdivide(2, 'loop')
mesh.subdivide(2, 'loop')
ERROR:root:Dataset is non-manifold and cannot be subdivided. Edge shared by 4 cells
ERROR:root:Subdivision failed.
ERROR:root:vtkInformation (0x55df79436670)
PolyData (0x7ff0b08caa68)
  N Cells:	0
  N Points:	0
  X Bounds:	1.000e+00, -1.000e+00
  Y Bounds:	1.000e+00, -1.000e+00
  Z Bounds:	1.000e+00, -1.000e+00
  N Scalars:	0

Notably, the issue doesn't arise for when only a single subdivision is needed, but the output of that is non-manifold.

mesh = mesh.subdivide(1, 'loop')
non_manifold_edges = mesh.extract_edges(feature_edges=False, boundary_edges=False, 
                                        manifold_edges=False, non_manifold_edges=True)
print(non_manifold_edges.n_cells, non_manifold_edges.n_points)
18 18

How to load and export mesh

Hi,

I would like to know how to use this library for loading an input mesh from my hard disk and then exporting the remeshed output, for example in OBJ format.

Thank you in advance!

Best,
HollowHeartNet

[Feature Request] Anaconda package

When time permits, ...so, never it'd be great to publish a conda package for PyACVD. Assuming conda-forge, hot behind-the-scenes automation will automatically bump the conda package for you on each PyPI bump – saving precious dev time for fun things like full-blown ACVD bindings. 😉

Thanks for all the Pythonic volunteerism, Alex. PyACVD is jaw-droppingly awesome! The resulting meshes are a big improvement over standard implicit modelling techniques available in VTK and PyVista like marching cubes and flying edges.

ImportError: cannot import name '_clustering' from 'pyacvd'

Hi, there are some problem when I run this code.

Traceback (most recent call last):
File "/home/cyj/project/others/pyacvd/example.py", line 2, in
import pyacvd
File "/home/cyj/project/others/pyacvd/pyacvd/init.py", line 1, in
from pyacvd.clustering import Clustering
File "/home/cyj/project/others/pyacvd/pyacvd/clustering.py", line 6, in
from pyacvd import _clustering
ImportError: cannot import name '_clustering' from 'pyacvd' (/home/cyj/project/others/pyacvd/pyacvd/init.py)

pyvista 0.2.6 does not work with numpy 1.18.5

I'm trying to use pyvista in broader context (with tensorflow 2.3, which needs numpy 1.18.5). While I am aware 'its not your problem what is my current package setup'. I just want to know if you plan to support older versions of numpy?

For pyacvd 0.2.6:
creating fresh python 3.7 environment, and installing from pip: pyacvd==0.2.6 and then numpy 1.18.5: results in exception during import of pyacvd in python terminal/script:

import pyacvd
Traceback (most recent call last):
File "", line 1, in
File "/home/user123/progs/anaconda3/envs/envone37pv1/lib/python3.7/site-packages/pyacvd/init.py", line 1, in
from pyacvd.clustering import Clustering
File "/home/user123/progs/anaconda3/envs/envone37pv1/lib/python3.7/site-packages/pyacvd/clustering.py", line 7, in
from pyacvd import _clustering
File "pyacvd/cython/_clustering.pyx", line 1, in init pyacvd._clustering
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

For pyacvd 0.2.5:
creating fresh python 3.7 environment, and installing from pip: pyacvd==0.2.5 and then numpy 1.18.5: results in proper import of pyacvd in python terminal/script (all works ok)

Import error when installing module via pip

Hi

Just tried to run your module, but I was not able to load it.

Here is what I tried:

  • pip install PyACVD => installed successfully
  • python -c "import PyACVD"

Here is what I get:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyACVD/__init__.py", line 1, in <module>
    from PyACVD import Clustering_Cython
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyACVD/Clustering_Cython.so, 2): Symbol not found: __ZTINSt8ios_base7failureE
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyACVD/Clustering_Cython.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyACVD/Clustering_Cython.so

I am running python 2.7.12 on MacOS 10.11.6.

Cannot install PyACVD for python3

Here is what I tried:
pip3 install PyACVD

Here is what I get:

Collecting PyACVD
  Using cached PyACVD-0.1.1.tar.gz
Building wheels for collected packages: PyACVD
  Running setup.py bdist_wheel for PyACVD ... error
  Complete output from command /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-build-3a3roe5x/PyACVD/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/tmplbwuglhfpip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.6-intel-3.5
  creating build/lib.macosx-10.6-intel-3.5/PyACVD
  copying PyACVD/__init__.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
  copying PyACVD/Clustering.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
  copying PyACVD/VTK_Plotting.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
  creating build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
  copying PyACVD/Tests/__init__.py -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
  copying PyACVD/Tests/Remesh.py -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
  copying PyACVD/Tests/StanfordBunny.ply -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
  running build_ext
  building 'PyACVD.Clustering_Cython' extension
  creating build/temp.macosx-10.6-intel-3.5
  creating build/temp.macosx-10.6-intel-3.5/PyACVD
  creating build/temp.macosx-10.6-intel-3.5/PyACVD/cython
  ccache clang -Qunused-arguments -fcolor-diagnostics -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -I/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/include -c PyACVD/cython/Clustering_Cython.cpp -o build/temp.macosx-10.6-intel-3.5/PyACVD/cython/Clustering_Cython.o
  clang: error: no such file or directory: 'PyACVD/cython/Clustering_Cython.cpp'
  clang: error: no input files
  error: command 'ccache' failed with exit status 1

  ----------------------------------------
  Failed building wheel for PyACVD
  Running setup.py clean for PyACVD
Failed to build PyACVD
Installing collected packages: PyACVD
  Running setup.py install for PyACVD ... error
    Complete output from command /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-build-3a3roe5x/PyACVD/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-7jmf0xkh-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.6-intel-3.5
    creating build/lib.macosx-10.6-intel-3.5/PyACVD
    copying PyACVD/__init__.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
    copying PyACVD/Clustering.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
    copying PyACVD/VTK_Plotting.py -> build/lib.macosx-10.6-intel-3.5/PyACVD
    creating build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
    copying PyACVD/Tests/__init__.py -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
    copying PyACVD/Tests/Remesh.py -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
    copying PyACVD/Tests/StanfordBunny.ply -> build/lib.macosx-10.6-intel-3.5/PyACVD/Tests
    running build_ext
    building 'PyACVD.Clustering_Cython' extension
    creating build/temp.macosx-10.6-intel-3.5
    creating build/temp.macosx-10.6-intel-3.5/PyACVD
    creating build/temp.macosx-10.6-intel-3.5/PyACVD/cython
    ccache clang -Qunused-arguments -fcolor-diagnostics -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -I/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/include -c PyACVD/cython/Clustering_Cython.cpp -o build/temp.macosx-10.6-intel-3.5/PyACVD/cython/Clustering_Cython.o
    clang: error: no such file or directory: 'PyACVD/cython/Clustering_Cython.cpp'
    clang: error: no input files
    error: command 'ccache' failed with exit status 1

    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-build-3a3roe5x/PyACVD/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-7jmf0xkh-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/v8/vmb7nyj95slb3f__hc5r9x5h0000gn/T/pip-build-3a3roe5x/PyACVD/

I am running python 3.5.2, and pip 8.1.2, on MacOS 10.11.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.