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:
+25
-10
@@ -2,6 +2,7 @@
|
||||
|
||||
import sys
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
import numpy as np
|
||||
import scipy.spatial
|
||||
@@ -45,19 +46,28 @@ class grid(object):
|
||||
vert_re = re.compile(r'''
|
||||
(p\d+)
|
||||
''', re.S|re.X)
|
||||
|
||||
|
||||
def __init__(self, points, q):
|
||||
"""
|
||||
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
|
||||
"""
|
||||
|
||||
self.points = np.array(points)
|
||||
self.q = np.array(q)
|
||||
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 = []
|
||||
for matcher in grid.facet_re.finditer(qdelaunay_string):
|
||||
d = matcher.groupdict()
|
||||
@@ -70,7 +80,9 @@ class grid(object):
|
||||
self.faces[facet_name] = cur_face
|
||||
|
||||
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()]
|
||||
facet_to_facets.extend(nghbrs)
|
||||
@@ -79,13 +91,13 @@ class grid(object):
|
||||
if rel[1] in self.faces:
|
||||
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
|
||||
|
||||
for matcher in grid.point_re.finditer(qdelaunay_string):
|
||||
d = matcher.groupdict()
|
||||
# for matcher in grid.point_re.finditer(qdelaunay_string):
|
||||
# d = matcher.groupdict()
|
||||
|
||||
point = d['point']
|
||||
neighboring_facets = d['neigh']
|
||||
# point = d['point']
|
||||
# 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):
|
||||
"""
|
||||
@@ -113,7 +125,9 @@ class grid(object):
|
||||
assert( len(self.points) == len(self.q) )
|
||||
for c, i in enumerate(zip(self.points, self.q)):
|
||||
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:
|
||||
for v in self.faces.itervalues():
|
||||
r += "%s\n" % v
|
||||
@@ -141,6 +155,7 @@ class simple_rect_grid(grid):
|
||||
points.append([cur_x, cur_y])
|
||||
q.append(exact_func(cur_x, cur_y))
|
||||
grid.__init__(self, points, q)
|
||||
self.construct_connectivity()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user