Skip to content

Commit b6f0344

Browse files
authored
Merge pull request #132 from nschloe/rename-variable
Rename variable
2 parents 384d50c + a714e06 commit b6f0344

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ to create high-quality 2D, 3D volume meshes, periodic volume meshes, and surface
2828
#### 2D meshes
2929
<img src="https://nschloe.github.io/pygalmesh/rect.svg" width="30%">
3030

31-
CGAL generates 2D meshes from linear contraints.
31+
CGAL generates 2D meshes from linear constraints.
3232
```python
3333
import numpy
3434
import pygalmesh
@@ -375,15 +375,15 @@ import meshio
375375
Nx = 722
376376
Ny = 411
377377
Nz = 284
378-
h = [0.2] * 3
378+
voxel_size = [0.2, 0.2, 0.2]
379379

380380
with open("MergedPhantom.DAT", "rb") as fid:
381381
vol = np.fromfile(fid, dtype=np.uint8)
382382

383383
vol = vol.reshape((Nx, Ny, Nz))
384384

385385
mesh = pygalmesh.generate_from_array(
386-
vol, h, max_facet_distance=0.2, max_cell_circumradius=1.0
386+
vol, voxel_size, max_facet_distance=0.2, max_cell_circumradius=1.0
387387
)
388388
mesh.write("breast.vtk")
389389
```

pygalmesh/main.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22
import os
33
import tempfile
4+
from typing import Tuple
45

56
import meshio
67
import numpy
@@ -382,13 +383,13 @@ def remesh_surface(
382383
return mesh
383384

384385

385-
def save_inr(vol, h, fname: str):
386+
def save_inr(vol, voxel_size: Tuple[float, float, float], fname: str):
386387
"""
387388
Save a volume (described as a numpy array) to INR format.
388389
Code inspired by iso2mesh (http://iso2mesh.sf.net) by Q. Fang
389390
INPUTS:
390-
- vol: volume as numpy array
391-
- h: voxel sizes as list or numpy array
391+
- vol: volume as a 3D numpy array
392+
- h: voxel sizes
392393
- fname: filename for saving the inr file
393394
"""
394395
fid = open(fname, "wb")
@@ -400,10 +401,23 @@ def save_inr(vol, h, fname: str):
400401
"float64": ("float", 64),
401402
}[vol.dtype.name]
402403

403-
header = (
404-
"#INRIMAGE-4#{8:s}\nXDIM={0:d}\nYDIM={1:d}\nZDIM={2:d}\nVDIM=1\nTYPE={3:s}\n"
405-
+ "PIXSIZE={4:d} bits\nCPU=decm\nVX={5:f}\nVY={6:f}\nVZ={7:f}\n"
406-
).format(*vol.shape, btype, bitlen, h[0], h[1], h[2], "{")
404+
xdim, ydim, zdim = vol.shape
405+
header = "\n".join(
406+
[
407+
"#INRIMAGE-4#{",
408+
f"XDIM={xdim}",
409+
f"YDIM={ydim}",
410+
f"ZDIM={zdim}",
411+
"VDIM=1",
412+
f"TYPE={btype}",
413+
f"PIXSIZE={bitlen} bits",
414+
"CPU=decm",
415+
f"VX={voxel_size[0]:f}",
416+
f"VY={voxel_size[1]:f}",
417+
f"VZ={voxel_size[2]:f}",
418+
]
419+
)
420+
header += "\n"
407421

408422
header = header + "\n" * (256 - 4 - len(header)) + "##}\n"
409423

@@ -413,7 +427,7 @@ def save_inr(vol, h, fname: str):
413427

414428
def generate_from_array(
415429
vol,
416-
h,
430+
voxel_size: Tuple[float, float, float],
417431
lloyd: bool = False,
418432
odt: bool = False,
419433
perturb: bool = True,
@@ -430,7 +444,7 @@ def generate_from_array(
430444
assert vol.dtype in ["uint8", "uint16"]
431445
fh, inr_filename = tempfile.mkstemp(suffix=".inr")
432446
os.close(fh)
433-
save_inr(vol, h, inr_filename)
447+
save_inr(vol, voxel_size, inr_filename)
434448
mesh = generate_from_inr(
435449
inr_filename,
436450
lloyd,

setup.cfg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[metadata]
22
name = pygalmesh
3-
version = 0.9.3
4-
url = https://github.com/nschloe/pygalmesh
3+
version = 0.9.4
54
author = Nico Schlömer
65
author_email = nico.schloemer@gmail.com
76
description = Python frontend to CGAL's mesh generation capabilities
7+
url = https://github.com/nschloe/pygalmesh
8+
project_urls =
9+
Code=https://github.com/nschloe/pygalmesh
10+
Issues=https://github.com/nschloe/pygalmesh/issues
11+
Funding=https://github.com/sponsors/nschloe
812
long_description = file: README.md
913
long_description_content_type = text/markdown
1014
license = GPL-3.0-or-later

0 commit comments

Comments
 (0)