Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wms fix transpose #38

Merged
merged 12 commits into from
Jun 23, 2023
Merged
Prev Previous commit
Next Next commit
test: add get to some tests
  • Loading branch information
william-silversmith committed Jun 21, 2023
commit 8535be1a3434592e52b6e1cf0d6252fca512c6d0
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ mesher.mesh(labels, close=False)
meshes = []
for obj_id in mesher.ids():
meshes.append(
mesher.get_mesh(
mesher.get(
obj_id,
normals=False, # whether to calculate normals or not

# tries to reduce triangles by this factor
# 0 disables simplification
simplification_factor=100,
reduction_factor=100,

# Max tolerable error in physical distance
max_simplification_error=8,
# note: if max_error is not set, the max error
# will be set equivalent to one voxel along the
# smallest dimension.
max_error=8,
# whether meshes should be centered in the voxel
# on (0,0,0) [False] or (0.5,0.5,0.5) [True]
voxel_centered=False,
Expand All @@ -39,7 +42,7 @@ mesh = mesher.simplify(
mesh,
# same as simplification_factor in get_mesh
reduction_factor=100,
# same as max_simplification_error in get_mesh
# same as max_error in get
max_error=40,
compute_normals=False, # whether to also compute face normals
) # apply simplifier to a pre-existing mesh
Expand All @@ -65,6 +68,8 @@ with open('10001001:0', 'wb') as f:
f.write(mesh.to_precomputed())
```

Note: As of the latest version, `mesher.get_mesh` has been deprecated in favor of `mesher.get` which fixes a long standing bug where you needed to transpose your data in order to get a mesh in the correct orientation.

## Installation

If binaries are not available for your system, ensure you have a C++ compiler installed.
Expand Down
54 changes: 47 additions & 7 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fanc_label():
@pytest.mark.parametrize("dtype", DTYPE)
@pytest.mark.parametrize("close", [ False, True ])
@pytest.mark.parametrize("order", [ 'C', 'F' ])
def test_executes(dtype, close, order):
def test_executes_legacy(dtype, close, order):
labels = np.zeros( (11,17,19), dtype=dtype, order=order)
labels[1:-1, 1:-1, 1:-1] = 1

Expand All @@ -37,6 +37,27 @@ def test_executes(dtype, close, order):
assert len(mesh.faces) > 0
assert len(mesh.normals) > 0


@pytest.mark.parametrize("dtype", DTYPE)
@pytest.mark.parametrize("close", [ False, True ])
@pytest.mark.parametrize("order", [ 'C', 'F' ])
def test_executes(dtype, close, order):
labels = np.zeros( (11,17,19), dtype=dtype, order=order)
labels[1:-1, 1:-1, 1:-1] = 1

mesher = zmesh.Mesher( (4,4,40) )
mesher.mesh(labels, close=close)

mesh = mesher.get(1, normals=False)
assert len(mesh.vertices) > 0
assert len(mesh.faces) > 0
assert mesh.normals is None

mesh = mesher.get(1, normals=True)
assert len(mesh.vertices) > 0
assert len(mesh.faces) > 0
assert len(mesh.normals) > 0

@pytest.mark.parametrize("dtype", DTYPE)
@pytest.mark.parametrize("order", [ 'C', 'F' ])
def test_simplify(dtype, order):
Expand Down Expand Up @@ -83,7 +104,7 @@ def test_simplify(dtype, order):
pass

@pytest.mark.parametrize("dtype", DTYPE)
def test_precomputed(dtype):
def test_precomputed_legacy(dtype):
labels = np.zeros( (11,17,19), dtype=dtype)
labels[1:-1, 1:-1, 1:-1] = 1

Expand All @@ -101,13 +122,32 @@ def test_precomputed(dtype):
reconstituted = zmesh.Mesh.from_precomputed(precomputed_mesh)
assert reconstituted != mesh # Precomputed doesn't preserve normals

@pytest.mark.parametrize("dtype", DTYPE)
def test_precomputed(dtype):
labels = np.zeros( (11,17,19), dtype=dtype)
labels[1:-1, 1:-1, 1:-1] = 1

mesher = zmesh.Mesher( (4,4,40) )
mesher.mesh(labels)
mesh = mesher.get(1, normals=False)

precomputed_mesh = mesh.to_precomputed()
reconstituted = zmesh.Mesh.from_precomputed(precomputed_mesh)
assert reconstituted == mesh

mesh = mesher.get(1, normals=True)

precomputed_mesh = mesh.to_precomputed()
reconstituted = zmesh.Mesh.from_precomputed(precomputed_mesh)
assert reconstituted != mesh # Precomputed doesn't preserve normals

def test_obj_import():
labels = np.zeros( (11,17,19), dtype=np.uint32)
labels[1:-1, 1:-1, 1:-1] = 1

mesher = zmesh.Mesher( (4,4,40) )
mesher.mesh(labels)
mesh = mesher.get_mesh(1, normals=False)
mesh = mesher.get(1, normals=False)

obj_str = mesh.to_obj()
mesh2 = zmesh.Mesh.from_obj(obj_str)
Expand All @@ -120,14 +160,14 @@ def test_ply_import():

mesher = zmesh.Mesher( (4,4,40) )
mesher.mesh(labels)
mesh = mesher.get_mesh(1, normals=False)
mesh = mesher.get(1, normals=False)

plydata = mesh.to_ply()
mesh2 = zmesh.Mesh.from_ply(plydata)

assert mesh == mesh2

def test_C_F_meshes_same(connectomics_labels):
def test_C_F_meshes_same_legacy(connectomics_labels):
connectomics_labels = connectomics_labels[102:,31:,17:]

fdata = np.asfortranarray(connectomics_labels)
Expand Down Expand Up @@ -166,8 +206,8 @@ def test_fanc_bug(fanc_label, transpose):
assert c_mesher.ids() == f_mesher.ids()

for label in c_mesher.ids():
c_mesh = c_mesher.get_mesh(label, normals=False, simplification_factor=0)
f_mesh = f_mesher.get_mesh(label, normals=False, simplification_factor=0)
c_mesh = c_mesher.get(label, normals=False, reduction_factor=0)
f_mesh = f_mesher.get(label, normals=False, reduction_factor=0)
assert np.isclose(c_mesh.vertices.mean(), f_mesh.vertices.mean())

@pytest.mark.parametrize("order", [ 'C', 'F' ])
Expand Down