55
66[ ![ PyPi Version] ( https://img.shields.io/pypi/v/pygalmesh.svg?style=flat-square )] ( https://pypi.org/project/pygalmesh )
77[ ![ Anaconda Cloud] ( https://anaconda.org/conda-forge/pygalmesh/badges/version.svg?=style=flat-square )] ( https://anaconda.org/conda-forge/pygalmesh/ )
8- [ ![ Debian CI ] ( https://badges.debian.net/badges/debian/testing/python3-pygalmesh/version .svg?style=flat-square )] ( https://tracker.debian. org/pkg/python3- pygalmesh )
8+ [ ![ Packaging status ] ( https://repology.org/badge/tiny-repos/pygalmesh .svg )] ( https://repology. org/project/ pygalmesh/versions )
99[ ![ PyPI pyversions] ( https://img.shields.io/pypi/pyversions/pygalmesh.svg?style=flat-square )] ( https://pypi.org/pypi/pygalmesh/ )
1010[ ![ GitHub stars] ( https://img.shields.io/github/stars/nschloe/pygalmesh.svg?style=flat-square&label=Stars&logo=github )] ( https://github.com/nschloe/pygalmesh )
1111[ ![ PyPi downloads] ( https://img.shields.io/pypi/dm/pygalmesh.svg?style=flat-square )] ( https://pypistats.org/packages/pygalmesh )
1212
1313[ ![ Slack] ( https://img.shields.io/static/v1?logo=slack&label=chat&message=on%20slack&color=4a154b&style=flat-square )] (https://join.slack.com/t/nschloe/shared_invite/zt-cofhrwm8-BgdrXAtVkOjnDmADROKD7A
1414)
1515
16- [ ![ CircleCI] ( https://img.shields.io/circleci/project/github/nschloe/pygalmesh/master.svg?style=flat-square )] ( https://circleci.com/gh/nschloe/pygalmesh/tree/master )
16+ [ ![ gh-actions] ( https://img.shields.io/github/workflow/status/nschloe/pygalmesh/ci?style=flat-square )] ( https://github.com/nschloe/pygalmesh/actions?query=workflow%3Aci )
17+ [ ![ codecov] ( https://img.shields.io/codecov/c/github/nschloe/pygalmesh.svg?style=flat-square )] ( https://codecov.io/gh/nschloe/pygalmesh )
1718[ ![ LGTM] ( https://img.shields.io/lgtm/grade/python/github/nschloe/pygalmesh.svg?style=flat-square )] ( https://lgtm.com/projects/g/nschloe/pygalmesh )
1819[ ![ Code style: black] ( https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square )] ( https://github.com/psf/black )
1920
@@ -62,13 +63,15 @@ mesh = pygalmesh.generate_mesh(s, cell_size=0.2)
6263# mesh.points, mesh.cells, ...
6364```
6465You can write the mesh with
66+ <!-- exdown-skip-->
6567``` python
6668mesh.write(" out.vtk" )
6769```
6870You can use any format supported by [ meshio] ( https://github.com/nschloe/meshio ) .
6971
7072The mesh generation comes with many more options, described
7173[ here] ( https://doc.cgal.org/latest/Mesh_3/ ) . Try, for example,
74+ <!-- exdown-skip-->
7275``` python
7376mesh = pygalmesh.generate_mesh(
7477 s, cell_size = 0.2 , edge_size = 0.1 , odt = True , lloyd = True , verbose = False
@@ -106,6 +109,16 @@ u = pygalmesh.Difference(s0, s1)
106109```
107110To sharpen the intersection circle, add it as a feature edge polygon line, e.g.,
108111``` python
112+ import numpy
113+ import pygalmesh
114+
115+ radius = 1.0
116+ displacement = 0.5
117+ s0 = pygalmesh.Ball([displacement, 0 , 0 ], radius)
118+ s1 = pygalmesh.Ball([- displacement, 0 , 0 ], radius)
119+ u = pygalmesh.Difference(s0, s1)
120+
121+ # add circle
109122a = numpy.sqrt(radius ** 2 - displacement ** 2 )
110123edge_size = 0.15
111124n = int (2 * numpy.pi * a / edge_size)
@@ -209,17 +222,18 @@ to CGAL's mesh generator.
209222#### Local refinement
210223<img src =" https://nschloe.github.io/pygalmesh/ball-local-refinement.png " width =" 30% " >
211224
212- If you want to have local refinement, you can use
213- ` generate_with_sizing_field ` . It works just like ` generate_mesh ` except that it takes a
214- ` SizingFieldBase ` object as ` cell_size ` .
225+ Use ` generate_mesh ` with a ` SizingFieldBase ` object as ` cell_size ` .
215226``` python
227+ import numpy
228+ import pygalmesh
229+
216230# define a cell_size function
217231class Field (pygalmesh .SizingFieldBase ):
218232 def eval (self , x ):
219233 return abs (numpy.sqrt(numpy.dot(x, x)) - 0.5 ) / 5 + 0.025
220234
221235
222- mesh = pygalmesh.generate_with_sizing_field (
236+ mesh = pygalmesh.generate_mesh (
223237 pygalmesh.Ball([0.0 , 0.0 , 0.0 ], 1.0 ),
224238 facet_angle = 30 ,
225239 facet_size = 0.1 ,
@@ -254,6 +268,7 @@ mesh generation](https://doc.cgal.org/latest/Periodic_3_mesh_3/index.html). Besi
254268domain, one needs to specify a bounding box, and optionally the number of copies in the
255269output (1, 2, 4, or 8). Example:
256270``` python
271+ import numpy
257272import pygalmesh
258273
259274
@@ -295,6 +310,7 @@ pygalmesh-volume-from-surface elephant.vtu out.vtk --cell-size 1.0 --odt
295310(See ` pygalmesh-volume-from-surface -h ` for all options.)
296311
297312In Python, do
313+ <!-- exdown-skip-->
298314``` python
299315import pygalmesh
300316
@@ -318,6 +334,7 @@ either on the command line
318334pygalmesh-from-inr skull_2.9.inr out.vtu --cell-size 5.0 --odt
319335```
320336(see ` pygalmesh-from-inr -h ` for all options) or from Python
337+ <!-- exdown-skip-->
321338``` python
322339import pygalmesh
323340
@@ -328,14 +345,18 @@ mesh = pygalmesh.generate_from_inr(
328345)
329346```
330347
331- ## Meshes from numpy array representing 3D images
348+ #### Meshes from numpy arrays representing 3D images
332349<img src =" https://nschloe.github.io/pygalmesh/phantom.png " width =" 30% " >
333350
334351pygalmesh can help generating unstructed meshes from 3D numpy arrays.
335352
336- The code below creates a mesh from the 3D breast phantom from [ Lou et al] ( http://biomedicaloptics.spiedigitallibrary.org/article.aspx?articleid=2600985 ) available [ here] ( https://wustl.app.box.com/s/rqivtin0xcofjwlkz43acou8jknsbfx8/file/127108205145 ) .
337- The phantom comprises four tissue types (background, fat, fibrograndular, skin, vascular tissues). The generated mesh conforms to tissues interfaces.
338-
353+ The code below creates a mesh from the 3D breast phantom from [ Lou et
354+ al] ( http://biomedicaloptics.spiedigitallibrary.org/article.aspx?articleid=2600985 )
355+ available
356+ [ here] ( https://wustl.app.box.com/s/rqivtin0xcofjwlkz43acou8jknsbfx8/file/127108205145 ) .
357+ The phantom comprises four tissue types (background, fat, fibrograndular, skin, vascular
358+ tissues). The generated mesh conforms to tissues interfaces.
359+ <!-- exdown-skip-->
339360``` python
340361import pygalmesh
341362import meshio
@@ -350,17 +371,18 @@ with open("MergedPhantom.DAT", "rb") as fid:
350371
351372vol = vol.reshape((Nx, Ny, Nz))
352373
353-
354374mesh = pygalmesh.generate_from_array(vol, h, facet_distance = 0.2 , cell_size = 1.0 )
355375mesh.write(" breast.vtk" )
356376```
357377
358- In addition, we can specify different mesh sizes for each tissue type. The code below sets the mesh size to * 1 mm* for the skin tissue (label ` 4 ` ), * 0.5 mm* for the vascular tissue (label ` 5 ` ), and * 2 mm* for all other tissues (` default ` ).
378+ In addition, we can specify different mesh sizes for each tissue type. The code below
379+ sets the mesh size to * 1 mm* for the skin tissue (label ` 4 ` ), * 0.5 mm* for the vascular
380+ tissue (label ` 5 ` ), and * 2 mm* for all other tissues (` default ` ).
359381
382+ <!-- exdown-skip-->
360383``` python
361- cell_sizes_map = {" default" : 2.0 , 4 : 1.0 , 5 : 0.5 }
362- mesh = pygalmesh.generate_from_array_with_subdomain_sizing(
363- vol, h, facet_distance = 0.2 , cell_sizes_map = cell_sizes_map
384+ mesh = pygalmesh.generate_from_array(
385+ vol, h, facet_distance = 0.2 , cell_size = {" default" : 2.0 , 4 : 1.0 , 5 : 0.5 }
364386)
365387mesh.write(" breast_adapted.vtk" )
366388```
@@ -377,6 +399,7 @@ the command line, use
377399pygalmesh-remesh-surface lion-head.off out.vtu -e 0.025 -a 25 -s 0.1 -d 0.001
378400```
379401(see ` pygalmesh-remesh-surface -h ` for all options) or from Python
402+ <!-- exdown-skip-->
380403``` python
381404import pygalmesh
382405
@@ -406,9 +429,6 @@ pip install -U pygalmesh
406429```
407430you can install/upgrade.
408431
409- [ meshio] ( https://github.com/nschloe/meshio ) (` pip install meshio ` )
410- can be helpful in processing the meshes.
411-
412432#### Manual installation
413433
414434For manual installation (if you're a developer or just really keen on getting
0 commit comments