mostly fixed a bug in my qdelaunay parsing. implemented a blender viewer ... mostly
the qdelaunay app doesn't alway display all faces for a point. lame. I worked around it by creating the point-> face relationships manually. There is a max recursion something happeneing when I try to save so pickle. look into this. I spent some time writing a visualizer for blender. 10 lines of code. simple stuff. next steps would be to move the KDTree into the mesh object. GOOD LUCK (me)!! --HG-- rename : bin/grid_driver.py => bin/grid_random.py rename : bin/grid_driver.py => bin/grid_regular.py
This commit is contained in:
parent
9ff48f4c12
commit
2cf9a0b574
@ -1,16 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from grid import simple_rect_grid
|
|
||||||
from smcqdelaunay import get_qdelaunay_dump_str
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
resolution = int(sys.argv[1])
|
|
||||||
except:
|
|
||||||
resolution = 3
|
|
||||||
g = simple_rect_grid(resolution, resolution)
|
|
||||||
s = get_qdelaunay_dump_str(g)
|
|
||||||
g.construct_connectivity(s)
|
|
||||||
print g
|
|
28
bin/grid_random.py
Executable file
28
bin/grid_random.py
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from grid import simple_rect_grid, simple_random_grid
|
||||||
|
|
||||||
|
pfile = '/tmp/grid_random.p'
|
||||||
|
qfile = '/tmp/grid_random.txt'
|
||||||
|
MAX_POINTS = 200
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.setrecursionlimit(4096)
|
||||||
|
print sys.getrecursionlimit()
|
||||||
|
try:
|
||||||
|
total_points = int(sys.argv[1])
|
||||||
|
except:
|
||||||
|
total_points = 10
|
||||||
|
|
||||||
|
if total_points > MAX_POINTS:
|
||||||
|
print "too many points"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
g = simple_random_grid(total_points)
|
||||||
|
g.construct_connectivity()
|
||||||
|
print g
|
||||||
|
open(qfile, 'w').write(g.for_qhull())
|
||||||
|
pickle.dump(g, open(pfile, 'w'))
|
22
bin/grid_regular.py
Executable file
22
bin/grid_regular.py
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from grid import simple_rect_grid, simple_random_grid
|
||||||
|
|
||||||
|
pfile = '/tmp/grid_regular.p'
|
||||||
|
qfile = '/tmp/grid_regular.txt'
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
resolution = int(sys.argv[1])
|
||||||
|
if resolution > 200:
|
||||||
|
raise Exception
|
||||||
|
except:
|
||||||
|
resolution = 3
|
||||||
|
|
||||||
|
g = simple_rect_grid(resolution, resolution)
|
||||||
|
g.construct_connectivity()
|
||||||
|
open(qfile, 'w').write(g.for_qhull())
|
||||||
|
pickle.dump(g, open(pfile, 'w'))
|
35
lib/grid.py
35
lib/grid.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.spatial
|
import scipy.spatial
|
||||||
@ -45,19 +46,28 @@ class grid(object):
|
|||||||
vert_re = re.compile(r'''
|
vert_re = re.compile(r'''
|
||||||
(p\d+)
|
(p\d+)
|
||||||
''', re.S|re.X)
|
''', re.S|re.X)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, points, q):
|
def __init__(self, points, q):
|
||||||
"""
|
"""
|
||||||
this thing eats two pre-constructed arrays of stuff:
|
this thing eats two pre-constructed arrays of stuff:
|
||||||
points = array of arrays (2 for 2D, 3 for 3D)
|
points = array of arrays (i will convert to numpy.array)
|
||||||
|
[[x0,y0], [x1,y1], ...]
|
||||||
q = array (1D) of important values
|
q = array (1D) of important values
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.points = np.array(points)
|
self.points = np.array(points)
|
||||||
self.q = np.array(q)
|
self.q = np.array(q)
|
||||||
self.faces = {}
|
self.faces = {}
|
||||||
self.facets_for_point = {}
|
self.facets_for_point = defaultdict(list)
|
||||||
|
|
||||||
def construct_connectivity(self, qdelaunay_string):
|
def construct_connectivity(self):
|
||||||
|
"""
|
||||||
|
a call to this method prepares the internal connectivity structure.
|
||||||
|
|
||||||
|
this is part of the __init__ for a simple_rect_grid, but can be called from any grid object
|
||||||
|
"""
|
||||||
|
qdelaunay_string = get_qdelaunay_dump_str(self)
|
||||||
facet_to_facets = []
|
facet_to_facets = []
|
||||||
for matcher in grid.facet_re.finditer(qdelaunay_string):
|
for matcher in grid.facet_re.finditer(qdelaunay_string):
|
||||||
d = matcher.groupdict()
|
d = matcher.groupdict()
|
||||||
@ -70,7 +80,9 @@ class grid(object):
|
|||||||
self.faces[facet_name] = cur_face
|
self.faces[facet_name] = cur_face
|
||||||
|
|
||||||
for v in grid.vert_re.findall(verticies):
|
for v in grid.vert_re.findall(verticies):
|
||||||
cur_face.add_vert(int(v[1:]))
|
vertex_index = int(v[1:])
|
||||||
|
cur_face.add_vert(vertex_index)
|
||||||
|
self.facets_for_point[vertex_index].append(cur_face)
|
||||||
|
|
||||||
nghbrs = [(facet_name, i) for i in neighboring_facets.split()]
|
nghbrs = [(facet_name, i) for i in neighboring_facets.split()]
|
||||||
facet_to_facets.extend(nghbrs)
|
facet_to_facets.extend(nghbrs)
|
||||||
@ -79,13 +91,13 @@ class grid(object):
|
|||||||
if rel[1] in self.faces:
|
if rel[1] in self.faces:
|
||||||
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
|
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
|
||||||
|
|
||||||
for matcher in grid.point_re.finditer(qdelaunay_string):
|
# for matcher in grid.point_re.finditer(qdelaunay_string):
|
||||||
d = matcher.groupdict()
|
# d = matcher.groupdict()
|
||||||
|
|
||||||
point = d['point']
|
# point = d['point']
|
||||||
neighboring_facets = d['neigh']
|
# neighboring_facets = d['neigh']
|
||||||
|
|
||||||
self.facets_for_point[int(point[1:])] = [i for i in neighboring_facets.split() if i in self.faces]
|
# self.facets_for_point[int(point[1:])] = [i for i in neighboring_facets.split() if i in self.faces]
|
||||||
|
|
||||||
def for_qhull_generator(self):
|
def for_qhull_generator(self):
|
||||||
"""
|
"""
|
||||||
@ -113,7 +125,9 @@ class grid(object):
|
|||||||
assert( len(self.points) == len(self.q) )
|
assert( len(self.points) == len(self.q) )
|
||||||
for c, i in enumerate(zip(self.points, self.q)):
|
for c, i in enumerate(zip(self.points, self.q)):
|
||||||
r += "%d %r: %0.4f" % (c,i[0], i[1])
|
r += "%d %r: %0.4f" % (c,i[0], i[1])
|
||||||
r += " faces: %s\n" % (self.facets_for_point[c])
|
facet_str = ", ".join([f.name for f in self.facets_for_point[c]])
|
||||||
|
r += " faces: [%s]" % facet_str
|
||||||
|
r += "\n"
|
||||||
if self.faces:
|
if self.faces:
|
||||||
for v in self.faces.itervalues():
|
for v in self.faces.itervalues():
|
||||||
r += "%s\n" % v
|
r += "%s\n" % v
|
||||||
@ -141,6 +155,7 @@ class simple_rect_grid(grid):
|
|||||||
points.append([cur_x, cur_y])
|
points.append([cur_x, cur_y])
|
||||||
q.append(exact_func(cur_x, cur_y))
|
q.append(exact_func(cur_x, cur_y))
|
||||||
grid.__init__(self, points, q)
|
grid.__init__(self, points, q)
|
||||||
|
self.construct_connectivity()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
11
tools/blender/plot.py
Normal file
11
tools/blender/plot.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import pickle
|
||||||
|
|
||||||
|
from Blender import *
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
p = pickle.load(open('/tmp/grid_driver.p', 'r'))
|
||||||
|
me = bpy.data.meshes.new('points')
|
||||||
|
me.verts.extend([[v[0], v[1], 0] for v in p.points])
|
||||||
|
me.faces.extend([i.verts for i in p.faces.itervalues()])
|
||||||
|
scn = bpy.data.scenes.active
|
||||||
|
ob = scn.objects.new(me, 'points_obj')
|
Loading…
Reference in New Issue
Block a user