2011-05-21 07:53:37 -07:00
|
|
|
from itertools import product
|
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
import numpy as np
|
|
|
|
|
2011-09-17 14:38:49 -07:00
|
|
|
from interp.grid.delaunay import dgrid as basegrid
|
|
|
|
|
2011-03-23 10:47:42 -07:00
|
|
|
class rect_grid(basegrid):
|
2010-03-18 22:32:24 -07:00
|
|
|
def __init__(self, xres = 5, yres = 5, zres = 5):
|
2011-05-20 11:40:42 -07:00
|
|
|
xmin = 0.0
|
|
|
|
xmax = 1.0
|
2010-03-18 22:32:24 -07:00
|
|
|
xspan = xmax - xmin
|
2011-05-20 11:40:42 -07:00
|
|
|
xdel = xspan / float(xres - 1)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2011-05-20 11:40:42 -07:00
|
|
|
ymin = 0.0
|
|
|
|
ymay = 1.0
|
2010-03-18 22:32:24 -07:00
|
|
|
yspan = ymay - ymin
|
2011-05-20 11:40:42 -07:00
|
|
|
ydel = yspan / float(yres - 1)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2011-05-20 11:40:42 -07:00
|
|
|
zmin = 0.0
|
|
|
|
zmaz = 1.0
|
2010-03-18 22:32:24 -07:00
|
|
|
zspan = zmaz - zmin
|
2011-05-20 11:40:42 -07:00
|
|
|
zdel = zspan / float(zres - 1)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-11-08 15:25:09 -08:00
|
|
|
verts = []
|
2011-05-20 11:40:42 -07:00
|
|
|
q = np.zeros(xres * yres * zres)
|
2010-03-18 22:32:24 -07:00
|
|
|
for x in xrange(xres):
|
|
|
|
cur_x = xmin + (x * xdel)
|
|
|
|
for y in xrange(yres):
|
|
|
|
cur_y = ymin + (y * ydel)
|
|
|
|
for z in xrange(zres):
|
|
|
|
cur_z = zmin + (z * zdel)
|
2010-11-08 15:25:09 -08:00
|
|
|
verts.append([cur_x, cur_y, cur_z])
|
2011-05-20 11:40:42 -07:00
|
|
|
|
2011-03-23 10:47:42 -07:00
|
|
|
basegrid.__init__(self, verts, q)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2011-03-21 14:24:25 -07:00
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
class random_grid(rect_grid):
|
2011-05-21 07:53:37 -07:00
|
|
|
def __init__(self, num_verts = 100):
|
2010-11-08 15:25:09 -08:00
|
|
|
verts = []
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-11-08 15:25:09 -08:00
|
|
|
appx_side_res = int(np.power(num_verts, 1/3.0))
|
2010-09-04 15:52:16 -07:00
|
|
|
delta = 1.0 / float(appx_side_res)
|
2010-05-04 22:03:07 -07:00
|
|
|
|
2011-05-21 07:53:37 -07:00
|
|
|
# populate all corners
|
|
|
|
verts = [i for i in product((0,1), repeat = 3)]
|
2010-05-04 22:03:07 -07:00
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2011-05-21 07:53:37 -07:00
|
|
|
# populate the edges (bottom and top squares)
|
|
|
|
for z in (0,1):
|
|
|
|
for x in xrange(1, appx_side_res):
|
|
|
|
cur_x = x * delta
|
|
|
|
for cur_y in (0, 1):
|
|
|
|
new_point = [cur_x, cur_y, z]
|
|
|
|
verts.append(new_point)
|
|
|
|
|
|
|
|
for y in xrange(1, appx_side_res):
|
|
|
|
cur_y = y * delta
|
|
|
|
for cur_x in (0, 1):
|
|
|
|
new_point = [cur_x, cur_y, z]
|
|
|
|
verts.append(new_point)
|
|
|
|
|
|
|
|
# populate side edges
|
|
|
|
for x in (0,1):
|
|
|
|
for y in (0,1):
|
|
|
|
for z in xrange(1, appx_side_res):
|
|
|
|
cur_z = z * delta
|
|
|
|
verts.append((x,y,cur_z))
|
|
|
|
|
|
|
|
verts.extend(np.random.random((num_verts - 12 * appx_side_res, 3)))
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2011-05-21 07:53:37 -07:00
|
|
|
q = np.zeros(len(verts))
|
|
|
|
basegrid.__init__(self, np.array(verts), q)
|