pygel3d.spatial

This module provides a kD-tree implementation but specialized to 3D

 1""" This module provides a kD-tree implementation but specialized to 3D """
 2
 3from pygel3d import lib_py_gel, Vec3dVector, IntVector
 4import ctypes as ct
 5
 6class I3DTree:
 7    """ kD tree specialized for 3D keys and integer values.
 8    This tree data structure is useful for storing 3D points and
 9    associated integer values - typically indices. There is also
10    a more general kd tree in scipy.spatial if this one does not
11    suit your needs. """
12    def __init__(self):
13        self.obj = lib_py_gel.I3DTree_new()
14    def __del__(self):
15        lib_py_gel.I3DTree_delete(self.obj)
16    def insert(self,p,v):
17        """ Insert v at 3D point given by p. Insert should be called before
18        calling build. """
19        lib_py_gel.I3DTree_insert(self.obj, p[0],p[1],p[2],v)
20    def build(self):
21        """ Build the tree. This function call makes the tree searchable. It is
22        assumed that all calls to insert come before calling this function."""
23        lib_py_gel.I3DTree_build(self.obj)
24    def closest_point(self,p,r):
25        """ Search for point closest to p within a max radius r.
26        This function should only be called after build. """
27        key = (ct.c_double * 3)()
28        val = ct.c_size_t()
29        n = lib_py_gel.I3DTree_closest_point(self.obj, p[0],p[1],p[2],r,ct.byref(key),ct.byref(val))
30        if n==1:
31            return ([key[0],key[1],key[2]],val.value)
32        return None
33    def in_sphere(self, p, r):
34        """ Retrieve all points within a radius r of p.
35        This function should only be called after build. """
36        keys = Vec3dVector()
37        vals = IntVector()
38        n = lib_py_gel.I3DTree_in_sphere(self.obj, p[0],p[1],p[2],r,keys.obj,vals.obj)
39        return (keys,vals)
class I3DTree:
 7class I3DTree:
 8    """ kD tree specialized for 3D keys and integer values.
 9    This tree data structure is useful for storing 3D points and
10    associated integer values - typically indices. There is also
11    a more general kd tree in scipy.spatial if this one does not
12    suit your needs. """
13    def __init__(self):
14        self.obj = lib_py_gel.I3DTree_new()
15    def __del__(self):
16        lib_py_gel.I3DTree_delete(self.obj)
17    def insert(self,p,v):
18        """ Insert v at 3D point given by p. Insert should be called before
19        calling build. """
20        lib_py_gel.I3DTree_insert(self.obj, p[0],p[1],p[2],v)
21    def build(self):
22        """ Build the tree. This function call makes the tree searchable. It is
23        assumed that all calls to insert come before calling this function."""
24        lib_py_gel.I3DTree_build(self.obj)
25    def closest_point(self,p,r):
26        """ Search for point closest to p within a max radius r.
27        This function should only be called after build. """
28        key = (ct.c_double * 3)()
29        val = ct.c_size_t()
30        n = lib_py_gel.I3DTree_closest_point(self.obj, p[0],p[1],p[2],r,ct.byref(key),ct.byref(val))
31        if n==1:
32            return ([key[0],key[1],key[2]],val.value)
33        return None
34    def in_sphere(self, p, r):
35        """ Retrieve all points within a radius r of p.
36        This function should only be called after build. """
37        keys = Vec3dVector()
38        vals = IntVector()
39        n = lib_py_gel.I3DTree_in_sphere(self.obj, p[0],p[1],p[2],r,keys.obj,vals.obj)
40        return (keys,vals)

kD tree specialized for 3D keys and integer values. This tree data structure is useful for storing 3D points and associated integer values - typically indices. There is also a more general kd tree in scipy.spatial if this one does not suit your needs.

def insert(self, p, v):
17    def insert(self,p,v):
18        """ Insert v at 3D point given by p. Insert should be called before
19        calling build. """
20        lib_py_gel.I3DTree_insert(self.obj, p[0],p[1],p[2],v)

Insert v at 3D point given by p. Insert should be called before calling build.

def build(self):
21    def build(self):
22        """ Build the tree. This function call makes the tree searchable. It is
23        assumed that all calls to insert come before calling this function."""
24        lib_py_gel.I3DTree_build(self.obj)

Build the tree. This function call makes the tree searchable. It is assumed that all calls to insert come before calling this function.

def closest_point(self, p, r):
25    def closest_point(self,p,r):
26        """ Search for point closest to p within a max radius r.
27        This function should only be called after build. """
28        key = (ct.c_double * 3)()
29        val = ct.c_size_t()
30        n = lib_py_gel.I3DTree_closest_point(self.obj, p[0],p[1],p[2],r,ct.byref(key),ct.byref(val))
31        if n==1:
32            return ([key[0],key[1],key[2]],val.value)
33        return None

Search for point closest to p within a max radius r. This function should only be called after build.

def in_sphere(self, p, r):
34    def in_sphere(self, p, r):
35        """ Retrieve all points within a radius r of p.
36        This function should only be called after build. """
37        keys = Vec3dVector()
38        vals = IntVector()
39        n = lib_py_gel.I3DTree_in_sphere(self.obj, p[0],p[1],p[2],r,keys.obj,vals.obj)
40        return (keys,vals)

Retrieve all points within a radius r of p. This function should only be called after build.