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):
|
|
pass
|
|
|
|
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.verts[0]) == 2:
|
|
pickle.dump([(p[0], p[1], 0.0) for p in self.verts],
|
|
open(pfile, 'w'))
|
|
else:
|
|
pickle.dump([(p[0], p[1], p[2]) for p in self.verts],
|
|
open(pfile, 'w'))
|
|
|
|
pickle.dump([f.verts for f in self.cells.itervalues()],
|
|
open(cfile, 'w'))
|
|
|
|
def get_simplex_extra_points(X, points, triangulation, kdtree, extra_points=8):
|
|
simplex_id = triangulation.find_simplex(X)
|
|
simplex_verts_ids = set(triangulation.vertices[simplex_id])
|
|
|
|
distances, kdt_ids = kdtree.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 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
|