Giter Site home page Giter Site logo

pytetgen's Introduction

pytetgen

Build Status

This is a python interface to tetgen, a powerful and fast mesh generator (http://wias-berlin.de/software/tetgen/)

This package includes the tetgen source, v.1.5, and provides (so far) minimal bindings to be able to generate meshes in python. The basic interface follows (and can be used to replace) that of scipy.spatial.Delaunay.

2D points triangulation with consistent API is provided through triangle.

Basic Usage

>>> import pytetgen
>>> import numpy as np
>>> points = np.random.random(4*3).reshape(4,3)
>>> tri = pytetgen.Delaunay(points)
>>> np.sort(tri.simplices)
array([[0, 1, 2, 3]], dtype=int32)

Comparison with scipy.spatial.Delaunay()

https://github.com/Marcello-Sega/pytetgen/raw/gh-pages/pics/scaling.png

tetgen (and this project) are distributed under the terms of the GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0.en.html), that can be found in the file LICENSE.txt. Quoting the preamble of the license:

"A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate.[...] However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version."

References

A technical paper about TetGen is available at Hang Si. 2015. "TetGen, a Delaunay-Based Quality Tetrahedral Mesh Generator". ACM Trans. on Mathematical Software. 41 (2), Article 11 (February 2015), 36 pages. DOI=10.1145/2629697 http://doi.acm.org/10.1145/2629697

I guess the author would be glad if you cite him, if you use this wrapper.

See Also

You might also want to have a look at:

pytetgen's People

Contributors

marcello-sega avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

harrydobbs

pytetgen's Issues

Package Rewrite

Hello,

I've also generated a pytetgen module, but it's quite a bit more complete than this module and includes several extra features including mesh repair using pymeshfix and plotting using vtkInterface. I was wondering how to proceed. It would be quite pull to submit.

Cython compile error "Cannot assign type 'double' to 'int'" using Cython 3.x

After trying to build PyTetgen on GitHub actions I got the following error:

running build_ext
/home/runner/.local/lib/python3.10/site-packages/Cython/Compiler/Main.py:384: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/runner/work/porenetworkpy/porenetworkpy/pytetgen/pytetgen/pytetgen.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
warning: pytetgen/pytetgen.pyx:88:12: Unreachable code

Error compiling Cython file:
------------------------------------------------------------
...

    @pointlist.setter
    def pointlist(self,val):
        flatval = np.ascontiguousarray(val.flatten())
        cdef int npoints = flatval.shape[0]
        self.c_tetgenio.numberofpoints = npoints / <int>3
                                                 ^
------------------------------------------------------------

pytetgen/pytetgen.pyx:357:49: Cannot assign type 'double' to 'int'`

This is due to the newest version of Cython (3.x). This is a known issue (https://stackoverflow.com/questions/64932145/cython-compile-error-cannot-assign-type-double-to-int-using-mingw64-in-win) with simple solutions to make PyTetgen compatible. The move to Cython 3.x is required for GitHub actions to find the built package (https://github.com/orgs/community/discussions/25653).

make cylinder mesh

Dear
I try make cylinder mesh by

import pyvista as pv
import tetgen
import numpy as np
pv.set_plot_theme('document')
cylinder=pv.cylinder()
tet = tetgen.TetGen(cylinder)

But it remind 'AttributeError: module 'pyvista' has no attribute 'cylinder''
Thank you very much!

Unable to build on Windows 10, VS 14

I'm getting a rather large error when trying to build this by pip install pytetgen on python 3.8, windows 10 and Visual Studio 14. Cython is installed.

I'm specifically looking for a drop-in replacement of scipy's Delaunay function for use with the scipy point cloud interpolation functions (LinearNDInterpolator and similar). Just in case you have any ideas :)

The full error log is here, should you be interested.

Can pytetgen be used for 2D triangulation?

The name seems to imply 3D, so I'm feeling a bit sheepish having tried the following, where I realised that pytetgen is interpreting my 10_000 2D points as 6666 3D points.

import numpy as np
import pytetgen
from scipy.spatial import Delaunay

N = 10000 # number of points
known_points = np.random.random((N,2))
known_intensities = np.random.random((N,))

tri1 = Delaunay(known_points) 
tri2 = pytetgen.Delaunay(known_points, neighbors=False)

print(tri1.points.shape)
# (10000, 2)
print(tri2.points.shape)
# (6666, 3)

Having done a bit of looking up (stackoverflow), it seems that tetgen is not what I should be looking at instead be using Triangle.

As a cheeky workaround I tried Delaunay on 3D points but with Z=0 for all points, but python crashes:

import numpy as np
import pytetgen
from scipy.interpolate import LinearNDInterpolator
from scipy.spatial import Delaunay

N = 1000 # number of points
known_points1 = np.random.random((N,3)) # 3D for tetgen, with z=0
known_points1[:,2] = 0
known_points2 = known_points1[:,:2] # 2D for scipy

known_intensities = np.random.random((N,))

tri1 = pytetgen.Delaunay(known_points1)
tri2 = Delaunay(known_points2) 

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.