1af176a6e0
also did some pep8/pyflakes cleanup
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import pickle
|
|
|
|
from interp.baker import interpolate
|
|
from interp.baker import get_phis
|
|
import interp
|
|
|
|
__version__ = interp.__version__
|
|
|
|
|
|
class grid(object):
|
|
def __init__(self):
|
|
"""
|
|
Child classes should populate at a minimum the points and values
|
|
arrays, and a method for getting a simplex and extra points.
|
|
"""
|
|
pass
|
|
|
|
def get_simplex_extra_points(self, X, extra_points=8):
|
|
# I need two things: find_simplex, and self.simplices
|
|
simplex_id = self.find_simplex(X)
|
|
simplex_verts_ids = set(self.simplices[simplex_id])
|
|
|
|
distances, kdt_ids \
|
|
= self.tree.query(X, extra_points + len(simplex_verts_ids))
|
|
kdt_ids = set(kdt_ids)
|
|
|
|
simplex_ids = list(simplex_verts_ids)
|
|
extra_points_ids = list(kdt_ids - simplex_verts_ids)
|
|
|
|
return simplex_ids, extra_points_ids
|
|
|
|
def interpolate(self, X, order=2, extra_points=3):
|
|
r, s = self.get_simplex_extra_points(X, extra_points=extra_points)
|
|
return interpolate(X, self.points[r], self.values[r],
|
|
self.points[s], self.values[s], order=order)
|
|
|
|
def dump_to_blender_files(self,
|
|
pfile='/tmp/points.p', cfile='/tmp/cells.p'):
|
|
if len(self.points[0]) == 2:
|
|
pickle.dump([(p[0], p[1], 0.0) for p in self.points.tolist()],
|
|
open(pfile, 'w'))
|
|
else:
|
|
pickle.dump([(p[0], p[1], p[2]) for p in self.points.tolist()],
|
|
open(pfile, 'w'))
|
|
|
|
pickle.dump([face for face in self.simplices.tolist()],
|
|
open(cfile, 'w'))
|
|
|
|
|
|
def contains(X, R):
|
|
"""
|
|
tests if X (point) is in R
|
|
|
|
R is a simplex, represented by a list of N-degree coordinates
|
|
"""
|
|
phis = get_phis(X, R)
|
|
any_negatives = any(map(lambda x: x < 0, phis))
|
|
return not any_negatives
|