refactored the term 'face' to 'cell' to match what I've found in literature

This commit is contained in:
Stephen Mardson McQuay
2010-11-08 15:07:48 -07:00
parent 075dd586a3
commit 93fec67cc7
3 changed files with 85 additions and 85 deletions
+50 -50
View File
@@ -8,7 +8,7 @@ import scipy.spatial
from interp.baker import run_baker
from interp.tools import log
from simplex import face, contains
from simplex import cell, contains
from smcqdelaunay import *
@@ -32,12 +32,12 @@ class grid(object):
if q:
self.q = np.array(q)
self.faces = {}
self.faces_for_vert = defaultdict(list)
self.cells = {}
self.cells_for_vert = defaultdict(list)
def get_containing_simplex(self, X):
if not self.faces:
raise Exception("face connectivity is not set up")
if not self.cells:
raise Exception("cell connectivity is not set up")
# get closest point
(dist, indicies) = self.tree.query(X, 2)
@@ -49,26 +49,26 @@ class grid(object):
log.debug('distance = %0.4f' % dist[0])
simplex = None
checked_faces = []
faces_to_check = list(self.faces_for_vert[closest_point])
checked_cells = []
cells_to_check = list(self.cells_for_vert[closest_point])
attempts = 0
while not simplex and faces_to_check:
while not simplex and cells_to_check:
attempts += 1
# if attempts > 20:
# raise Exception("probably recursing to many times")
cur_face = faces_to_check.pop(0)
checked_faces.append(cur_face)
cur_cell = cells_to_check.pop(0)
checked_cells.append(cur_cell)
if cur_face.contains(X, self):
simplex = cur_face
if cur_cell.contains(X, self):
simplex = cur_cell
continue
for neighbor in cur_face.neighbors:
if (neighbor not in checked_faces) and (neighbor not in faces_to_check):
faces_to_check.append(neighbor)
for neighbor in cur_cell.neighbors:
if (neighbor not in checked_cells) and (neighbor not in cells_to_check):
cells_to_check.append(neighbor)
if not simplex:
raise Exception('no containing simplex found')
@@ -137,21 +137,21 @@ class grid(object):
assert( len(self.verts) == len(self.q) )
for c, i in enumerate(zip(self.verts, self.q)):
r += "%d vert(%s): q(%0.4f)" % (c,i[0], i[1])
face_str = ", ".join([str(f.name) for f in self.faces_for_vert[c]])
r += " faces: [%s]" % face_str
cell_str = ", ".join([str(f.name) for f in self.cells_for_vert[c]])
r += " cells: [%s]" % cell_str
r += "\n"
if self.faces:
for v in self.faces.itervalues():
if self.cells:
for v in self.cells.itervalues():
r += "%s\n" % v
return r
class delaunay_grid(grid):
face_re = re.compile(r'''
-\s+(?P<face>f\d+).*?
cell_re = re.compile(r'''
-\s+(?P<cell>f\d+).*?
vertices:\s(?P<verts>.*?)\n.*?
neighboring\s faces:\s+(?P<neigh>[\sf\d]*)
neighboring\s cells:\s+(?P<neigh>[\sf\d]*)
''', re.S|re.X)
point_re = re.compile(r'''
@@ -168,7 +168,7 @@ class delaunay_grid(grid):
def get_containing_simplex(self, X):
if not self.faces:
if not self.cells:
self.construct_connectivity()
# get closest point
@@ -181,24 +181,24 @@ class delaunay_grid(grid):
log.debug('distance = %0.4f' % dist[0])
simplex = None
checked_faces = []
faces_to_check = self.faces_for_vert[closest_point]
checked_cells = []
cells_to_check = self.cells_for_vert[closest_point]
attempts = 0
while not simplex and faces_to_check:
while not simplex and cells_to_check:
attempts += 1
# if attempts > 20:
# raise Exception("probably recursing to many times")
cur_face = faces_to_check.pop(0)
checked_faces.append(cur_face)
cur_cell = cells_to_check.pop(0)
checked_cells.append(cur_cell)
if cur_face.contains(X, self):
simplex = cur_face
if cur_cell.contains(X, self):
simplex = cur_cell
continue
for neighbor in cur_face.neighbors:
if (neighbor not in checked_faces) and (neighbor not in faces_to_check):
faces_to_check.append(neighbor)
for neighbor in cur_cell.neighbors:
if (neighbor not in checked_cells) and (neighbor not in cells_to_check):
cells_to_check.append(neighbor)
if not simplex:
raise Exception('no containing simplex found')
@@ -262,16 +262,16 @@ class delaunay_grid(grid):
R is a grid object that is the (a) containing simplex around point X
S is a connectivity-based nearest-neighbor lookup, limited to 3 extra verts
"""
if not self.faces:
if not self.cells:
self.construct_connectivity()
# get closest point
(dist, indicies) = self.tree.query(X, 2)
simplex = None
for face in self.faces_for_vert[indicies[0]]:
if face.contains(X, self):
simplex = face
for cell in self.cells_for_vert[indicies[0]]:
if cell.contains(X, self):
simplex = cell
break
if not simplex:
@@ -312,27 +312,27 @@ class delaunay_grid(grid):
"""
log.debug('start')
qdelaunay_string = get_qdelaunay_dump_str(self)
face_to_faces = []
for matcher in grid.face_re.finditer(qdelaunay_string):
cell_to_cells = []
for matcher in grid.cell_re.finditer(qdelaunay_string):
d = matcher.groupdict()
face_name = d['face']
cell_name = d['cell']
verticies = d['verts']
neighboring_faces = d['neigh']
neighboring_cells = d['neigh']
cur_face = face(face_name)
self.faces[face_name] = cur_face
cur_cell = cell(cell_name)
self.cells[cell_name] = cur_cell
for v in grid.vert_re.findall(verticies):
vertex_index = int(v[1:])
cur_face.add_vert(vertex_index)
self.faces_for_vert[vertex_index].append(cur_face)
cur_cell.add_vert(vertex_index)
self.cells_for_vert[vertex_index].append(cur_cell)
nghbrs = [(face_name, i) for i in neighboring_faces.split()]
face_to_faces.extend(nghbrs)
nghbrs = [(cell_name, i) for i in neighboring_cells.split()]
cell_to_cells.extend(nghbrs)
for rel in face_to_faces:
if rel[1] in self.faces:
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
for rel in cell_to_cells:
if rel[1] in self.cells:
self.cells[rel[0]].add_neighbor(self.cells[rel[1]])
log.debug('end')