2011-03-28 14:36:50 -07:00
|
|
|
import pickle
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-09-17 14:39:01 -07:00
|
|
|
from interp.baker import interpolate
|
2011-06-07 20:43:03 -07:00
|
|
|
from interp.baker import get_phis
|
2011-09-17 14:38:49 -07:00
|
|
|
import interp
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-09-17 14:38:49 -07:00
|
|
|
__version__ = interp.__version__
|
2010-10-23 16:01:10 -07:00
|
|
|
|
2011-01-26 22:01:18 -08:00
|
|
|
|
2011-09-17 14:38:49 -07:00
|
|
|
class grid(object):
|
2011-09-17 18:23:21 -07:00
|
|
|
def __init__(self):
|
2011-09-17 14:38:49 -07:00
|
|
|
"""
|
2011-09-17 18:23:21 -07:00
|
|
|
Child classes should populate at a minimum the points and values
|
|
|
|
arrays, and a method for getting a simplex and extra points.
|
2011-09-17 14:38:49 -07:00
|
|
|
"""
|
2011-09-17 18:23:21 -07:00
|
|
|
pass
|
2011-09-17 14:38:49 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
def get_simplex_extra_points(self, X, extra_points=8):
|
2011-09-27 14:23:42 -07:00
|
|
|
# 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
|
2011-09-17 14:38:49 -07:00
|
|
|
|
2011-09-17 14:39:01 -07:00
|
|
|
def interpolate(self, X, order=2, extra_points=3):
|
2011-09-17 18:23:21 -07:00
|
|
|
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)
|
2011-09-17 14:38:49 -07:00
|
|
|
|
|
|
|
def dump_to_blender_files(self,
|
|
|
|
pfile='/tmp/points.p', cfile='/tmp/cells.p'):
|
2011-09-27 14:23:42 -07:00
|
|
|
if len(self.points[0]) == 2:
|
|
|
|
pickle.dump([(p[0], p[1], 0.0) for p in self.points.tolist()],
|
2011-09-17 14:38:49 -07:00
|
|
|
open(pfile, 'w'))
|
|
|
|
else:
|
2011-09-27 14:23:42 -07:00
|
|
|
pickle.dump([(p[0], p[1], p[2]) for p in self.points.tolist()],
|
2011-09-17 14:38:49 -07:00
|
|
|
open(pfile, 'w'))
|
|
|
|
|
2011-09-27 14:23:42 -07:00
|
|
|
pickle.dump([face for face in self.simplices.tolist()],
|
|
|
|
open(cfile, 'w'))
|
2011-09-21 11:14:47 -07:00
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2011-09-17 14:38:49 -07:00
|
|
|
def contains(X, R):
|
2010-03-20 16:10:02 -07:00
|
|
|
"""
|
2011-09-17 14:38:49 -07:00
|
|
|
tests if X (point) is in R
|
2011-03-23 10:23:32 -07:00
|
|
|
|
2011-09-17 18:23:21 -07:00
|
|
|
R is a simplex, represented by a list of N-degree coordinates
|
2010-03-20 16:10:02 -07:00
|
|
|
"""
|
2011-09-17 14:38:49 -07:00
|
|
|
phis = get_phis(X, R)
|
2011-09-17 18:23:21 -07:00
|
|
|
any_negatives = any(map(lambda x: x < 0, phis))
|
|
|
|
return not any_negatives
|