Skip to content

Commit d7b16bb

Browse files
authored
Merge pull request #107 from nschloe/better-interface
Better interface
2 parents d1d92ce + 93464e7 commit d7b16bb

11 files changed

Lines changed: 153 additions & 258 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
comment: no

.github/workflows/ci.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/setup-python@v1
9+
- uses: actions/setup-python@v2
1010
with:
1111
python-version: "3.x"
1212
- uses: actions/checkout@v2
@@ -20,29 +20,26 @@ jobs:
2020
black --check .
2121
2222
build:
23-
runs-on: ubuntu-latest
23+
runs-on: ubuntu-20.04
2424
steps:
25-
- uses: actions/setup-python@v1
25+
- uses: actions/setup-python@v2
2626
with:
2727
python-version: "3.x"
2828
- uses: actions/checkout@v2
2929
with:
3030
lfs: true
31-
- name: Install dependencies
32-
run: |
33-
sudo apt-get install -y libcgal-dev libeigen3-dev python3-pip clang
34-
- name: install cgal-5 from ppa
31+
- name: Install CGAL 5 from PPA
3532
run: |
3633
sudo apt-get install -y software-properties-common
3734
sudo apt-add-repository -y ppa:nschloe/cgal-backports
3835
sudo apt update
3936
sudo apt install -y libcgal-dev
40-
- name: Install package
37+
- name: Install other dependencies
4138
run: |
42-
CC="clang" pip install .[all]
43-
pip install pytest pytest-cov
44-
- name: Test with pytest
39+
sudo apt-get install -y libeigen3-dev python3-pip clang
40+
- name: Test with tox
4541
run: |
46-
cd test && pytest --cov pygalmesh
47-
# - name: Submit to codecov
48-
# run: bash <(curl -s https://codecov.io/bash)
42+
pip install tox
43+
CC="clang" tox
44+
- name: Submit to codecov
45+
run: bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
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
```
6465
You can write the mesh with
66+
<!--exdown-skip-->
6567
```python
6668
mesh.write("out.vtk")
6769
```
6870
You can use any format supported by [meshio](https://github.com/nschloe/meshio).
6971

7072
The 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
7376
mesh = 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
```
107110
To 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
109122
a = numpy.sqrt(radius ** 2 - displacement ** 2)
110123
edge_size = 0.15
111124
n = 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
217231
class 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
254268
domain, one needs to specify a bounding box, and optionally the number of copies in the
255269
output (1, 2, 4, or 8). Example:
256270
```python
271+
import numpy
257272
import 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

297312
In Python, do
313+
<!--exdown-skip-->
298314
```python
299315
import pygalmesh
300316

@@ -318,6 +334,7 @@ either on the command line
318334
pygalmesh-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
322339
import 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

334351
pygalmesh 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
340361
import pygalmesh
341362
import meshio
@@ -350,17 +371,18 @@ with open("MergedPhantom.DAT", "rb") as fid:
350371

351372
vol = vol.reshape((Nx, Ny, Nz))
352373

353-
354374
mesh = pygalmesh.generate_from_array(vol, h, facet_distance=0.2, cell_size=1.0)
355375
mesh.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
)
365387
mesh.write("breast_adapted.vtk")
366388
```
@@ -377,6 +399,7 @@ the command line, use
377399
pygalmesh-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
381404
import pygalmesh
382405

@@ -406,9 +429,6 @@ pip install -U pygalmesh
406429
```
407430
you 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

414434
For manual installation (if you're a developer or just really keen on getting

pygalmesh/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@
2525
from .__about__ import __version__
2626
from .main import (
2727
generate_from_array,
28-
generate_from_array_with_subdomain_sizing,
2928
generate_from_inr,
30-
generate_from_inr_with_subdomain_sizing,
3129
generate_mesh,
3230
generate_periodic_mesh,
3331
generate_surface_mesh,
3432
generate_volume_mesh_from_surface_mesh,
35-
generate_with_sizing_field,
3633
remesh_surface,
37-
saveinr,
34+
save_inr,
3835
)
3936

4037
__all__ = [
@@ -62,14 +59,11 @@
6259
"RingExtrude",
6360
#
6461
"generate_mesh",
65-
"generate_with_sizing_field",
6662
"generate_periodic_mesh",
6763
"generate_surface_mesh",
6864
"generate_volume_mesh_from_surface_mesh",
6965
"generate_from_array",
70-
"generate_from_array_with_subdomain_sizing",
7166
"generate_from_inr",
72-
"generate_from_inr_with_subdomain_sizing",
7367
"remesh_surface",
74-
"saveinr",
68+
"save_inr",
7569
]

0 commit comments

Comments
 (0)