working on the containing simplex problem. the get containing simplex function works, if the point is in the domain. I am trying to force the domain to contain the point (placing points along perimiter of the mesh). I am not doing that right, but have to run

--HG--
rename : bin/qhull-029.txt => data/qhull-029.txt
rename : bin/qhull-029.txt.gv => data/qhull-029.txt.gv
This commit is contained in:
Stephen Mardson McQuay
2010-04-24 18:26:44 -06:00
parent cfcd1e15a2
commit 3dcc10ea0e
10 changed files with 604 additions and 56 deletions
+9
View File
@@ -61,6 +61,15 @@ class random_grid(rect_grid):
q = []
r = np.random
appx_side_res = int(np.sqrt(num_points))
delta = 1.0 / float(appx_side_res)
for x in xrange(appx_side_res):
cur_x = x * delta
for y in xrange(appx_side_res):
cur_y = y * delta
new_point = [cur_x, cur_y]
points.append(new_point)
q.append(exact_func(new_point))
for i in xrange(num_points):
cur_x = r.rand()
+45 -7
View File
@@ -6,7 +6,7 @@ import numpy as np
import scipy.spatial
from baker import run_baker
from baker.tools import exact_func, smberror
from baker.tools import exact_func, smberror, logging
from simplex import face, contains
from smcqdelaunay import *
@@ -42,7 +42,7 @@ class grid(object):
self.tree = scipy.spatial.KDTree(self.points)
self.faces = {}
self.facets_for_point = defaultdict(list)
self.counter = 0
def create_mesh(self, indicies):
p = [self.points[i] for i in indicies]
@@ -50,7 +50,45 @@ class grid(object):
return grid(p, q)
def get_containing_simplex(self, X):
pass
if not self.faces:
logging.debug('get_containing_simplex: setting up connectivity')
self.construct_connectivity()
# get closest point
(dist, indicies) = self.tree.query(X, 2)
closest_point = indicies[0]
logging.debug('counter: %d' % self.counter)
self.counter += 1
logging.debug('X: %s' % X)
logging.debug('point index: %d' % closest_point)
logging.debug('actual point %s' % self.points[closest_point])
logging.debug('distance = %0.4f' % dist[0])
simplex = None
checked_facets = []
facets_to_check = self.facets_for_point[closest_point]
attempts = 0
while not simplex:
logging.debug('attempt: %d' % attempts)
attempts += 1
if attempts > 10:
raise smberror("probably recursing to many times")
cur_facet = facets_to_check.pop()
checked_facets.append(cur_facet)
facets_to_check.extend([i for i in cur_facet.neighbors if i not in checked_facets])
if cur_facet.contains(X, self):
simplex = cur_facet
if not simplex:
raise AssertionError('no containing simplex found')
R = self.create_mesh(simplex.verts)
logging.debug('this must be R: %s' % R)
return R
def get_simplex_and_nearest_points(self, X, extra_points = 3, simplex_size = 3):
@@ -64,9 +102,8 @@ class grid(object):
"""
(dist, indicies) = self.tree.query(X, simplex_size + extra_points)
# get the containing simplex
r_mesh = self.create_mesh(indicies[:simplex_size])
# r_mesh = self.create_mesh(indicies[:simplex_size])
r_mesh = self.get_containing_simplex(X)
# and some extra points
s_mesh = self.create_mesh(indicies[simplex_size:])
@@ -103,7 +140,7 @@ class grid(object):
if not simplex:
raise AssertionError('no containing simplex found')
R = self.create_mesh(simplex.verts)
R = get_containing_simplex(X)# self.create_mesh(simplex.verts)
s = []
@@ -136,6 +173,7 @@ class grid(object):
this is part of the __init__ for a rect_grid, but can be called from any grid object
"""
logging.debug('calling construct_connectivity')
qdelaunay_string = get_qdelaunay_dump_str(self)
facet_to_facets = []
for matcher in grid.facet_re.finditer(qdelaunay_string):