提交 f4ee0100 编写于 作者: J Jannik Boll Nielsen

Added python wrapper for add_points and remove_point methods.

上级 27f9d933
......@@ -256,6 +256,29 @@ flannlib.flann_load_index_%(C)s.argtypes = [
flann.load_index[%(numpy)s] = flannlib.flann_load_index_%(C)s
""")
flann.add_points = {}
define_functions(r"""
flannlib.flann_add_points_%(C)s.restype = None
flannlib.flann_add_points_%(C)s.argtypes = [
FLANN_INDEX, # index_id
ndpointer(%(numpy)s, ndim = 2, flags='aligned, c_contiguous'), # dataset
c_int, # rows
c_int, # cols
c_float, # rebuild_threshhold
]
flann.add_points[%(numpy)s] = flannlib.flann_add_points_%(C)s
""")
flann.remove_point = {}
define_functions(r"""
flannlib.flann_remove_point_%(C)s.restype = None
flannlib.flann_remove_point_%(C)s.argtypes = [
FLANN_INDEX, # index_id
c_uint, # point_id
]
flann.remove_point[%(numpy)s] = flannlib.flann_remove_point_%(C)s
""")
flann.find_nearest_neighbors = {}
define_functions(r"""
flannlib.flann_find_nearest_neighbors_%(C)s.restype = c_int
......
......@@ -211,6 +211,29 @@ class FLANN(object):
c_char_p(to_bytes(filename)), pts, npts, dim)
self.__curindex_data = pts
self.__curindex_type = pts.dtype.type
def add_points(self, pts, rebuild_threshold=2.0):
"""
Adds points to pre-built index.
Params:
pts: 2D numpy array of points.\n
rebuild_threshold: reallocs index when it grows by factor of \
`rebuild_threshold`. A smaller value results is more space \
efficient but less computationally efficient. Must be greater \
than 1.
"""
if not pts.dtype.type in allowed_types:
raise FLANNException("Cannot handle type: %s"%pts.dtype)
pts = ensure_2d_array(pts,default_flags)
npts, dim = pts.shape
flann.add_points[self.__curindex_type](self.__curindex, pts, npts, dim, rebuild_threshold)
def remove_point(self, idx):
"""
Removes a point from a pre-built index.
"""
flann.remove_point[self.__curindex_type](self.__curindex, idx)
def nn_index(self, qpts, num_neighbors=1, **kwargs):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册