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

How to use switches? #7

Closed
banesullivan opened this issue May 21, 2019 · 4 comments
Closed

How to use switches? #7

banesullivan opened this issue May 21, 2019 · 4 comments

Comments

@banesullivan
Copy link
Member

banesullivan commented May 21, 2019

I can't complete the following example which is a hacked attempt to reproduce the example at the bottom of this page: http://wias-berlin.de/software/tetgen/features.html

from pyvista import examples
import tetgen

cow_mesh = examples.download_cow().tri_filter()

cpos = [(13., 7.6, -13.85),
 (0.44, -0.4, -0.37),
 (-0.28, 0.9, 0.3)]

cow_mesh.plot(cpos=cpos)

tet = tetgen.TetGen(cow_mesh)
tet.tetrahedralize(switches='-d')

Last line above throws error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-ff4a5030d854> in <module>
----> 1 tet.tetrahedralize(switches='-d')

~/Documents/OpenGeoVis/Software/tetgen/tetgen/pytetgen.py in tetrahedralize(self, switches, plc, psc, refine, quality, nobisect, coarsen, metric, weighted, brio_hilbert, incrflip, flipinsert, varvolume, fixedvolume, noexact, nostaticfilter, insertaddpoints, regionattrib, cdtrefine, diagnose, convex, zeroindex, facesout, edgesout, neighout, voroout, meditview, vtkview, nobound, nonodewritten, noelewritten, nofacewritten, noiterationnum, nomergefacet, nomergevertex, nojettison, docheck, quiet, verbose, vertexperblock, tetrahedraperblock, shellfaceperblock, nobisect_nomerge, supsteiner_level, addsteiner_algo, coarsen_param, weighted_param, fliplinklevel, flipstarsize, fliplinklevelinc, reflevel, optscheme, optlevel, delmaxfliplevel, order, reversetetori, steinerleft, no_sort, hilbert_order, hilbert_limit, brio_threshold, brio_ratio, facet_separate_ang_tol, facet_overlap_ang_tol, facet_small_ang_tol, maxvolume, minratio, mindihedral, optmaxdihedral, optminsmtdihed, optminslidihed, epsilon, coarsen_percent)
    498                                                           optminslidihed,
    499                                                           epsilon,
--> 500                                                           coarsen_percent)
    501         except RuntimeError:
    502             raise Exception('Failed to tetrahedralize.\n' +

~/Documents/OpenGeoVis/Software/tetgen/tetgen/cython/tetgen/_tetgen.pyx in tetgen._tetgen.Tetrahedralize()

TypeError: a bytes-like object is required, not 'str'
@akaszynski
Copy link
Member

It's the code's fault. It's not a frequently used module for us, so code coverage isn't a huge issue, but I'll clean it up a bit.

The good news is this is a great demo for pyvista. The bad news is I need to make a wheel for pymeshfix and push a patch for tetgen as there was a bug due to a refactoring.

I'll comment back when the modules are updated.

import numpy as np
import pyvista as pv
from pyvista import examples
import tetgen
import pymeshfix

cow_mesh = examples.download_cow().tri_filter()

cpos = [(13., 7.6, -13.85),
 (0.44, -0.4, -0.37),
 (-0.28, 0.9, 0.3)]

# cow_mesh.plot(cpos=cpos)

tet = tetgen.TetGen(cow_mesh)
tet.make_manifold()
tet.tetrahedralize()

cow_grid = tet.grid

# plot half the cow
mask = np.logical_or(cow_grid.points[:, 0] < 0, cow_grid.points[:, 0] > 4)
half_cow = cow_grid.extract_selection_points(mask)

plotter = pv.Plotter()
plotter.add_mesh(half_cow, color='w', show_edges=True)
plotter.add_mesh(cow_grid, color='r', style='wireframe', opacity=0.2)
plotter.camera_position = cpos
plotter.show()

# construct silly spinning cow
plotter = pv.Plotter(off_screen=True, window_size=[400, 400])
plotter.open_gif('/tmp/tmp.gif')
plotter.add_mesh(half_cow, color='w', show_edges=True)
plotter.add_mesh(cow_grid, color='r', style='wireframe', opacity=0.2)
plotter.camera_position = cpos
plotter.write_frame()
nframe = 36
deg = 360./(nframe + 1)
for i in range(nframe):
    half_cow.rotate_y(deg)
    cow_grid.rotate_y(deg)
    plotter.update()
    plotter.write_frame()
plotter.close()

new

@banesullivan
Copy link
Member Author

Woah awesome! Thanks, @akaszynski!

The good news is this is a great demo for pyvista

Oh yeah! This is an excellent demo for PyVista - which is why I started playing around with this toolset

@banesullivan
Copy link
Member Author

I'll include this in #6

I'll comment back when the modules are updated.

Let me know when you patch things up and then I'll make sure PR #6 is good to go!

@akaszynski
Copy link
Member

Use the latest modules and you'll be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants