diff --git a/src/python/pyflann/flann_ctypes.py b/src/python/pyflann/flann_ctypes.py index b851587d4d5e9230e8c4c80996f7022999ca32fb..5fbf2649818e153b0c12fc36cfe62081aac68dc1 100644 --- a/src/python/pyflann/flann_ctypes.py +++ b/src/python/pyflann/flann_ctypes.py @@ -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 diff --git a/src/python/pyflann/index.py b/src/python/pyflann/index.py index 6c984f4c167e56c17b94b47ad9efb21b74746e61..3b7358d15695efec30e3987a15b1b242c005a7ba 100644 --- a/src/python/pyflann/index.py +++ b/src/python/pyflann/index.py @@ -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): """