Blender  V3.3
Classes | Macros | Functions | Variables
mathutils_kdtree.c File Reference
#include <Python.h>
#include "MEM_guardedalloc.h"
#include "BLI_kdtree.h"
#include "BLI_utildefines.h"
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
#include "mathutils.h"
#include "mathutils_kdtree.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  PyKDTree
 
struct  PyKDTree_NearestData
 

Macros

#define UINT_IS_NEG(n)   ((n) > INT_MAX)
 

Functions

static void kdtree_nearest_to_py_tuple (const KDTreeNearest_3d *nearest, PyObject *py_retval)
 
static PyObject * kdtree_nearest_to_py (const KDTreeNearest_3d *nearest)
 
static PyObject * kdtree_nearest_to_py_and_check (const KDTreeNearest_3d *nearest)
 
static int PyKDTree__tp_init (PyKDTree *self, PyObject *args, PyObject *kwargs)
 
static void PyKDTree__tp_dealloc (PyKDTree *self)
 
 PyDoc_STRVAR (py_kdtree_insert_doc, ".. method:: insert(co, index)\n" "\n" " Insert a point into the KDTree.\n" "\n" " :arg co: Point 3d position.\n" " :type co: float triplet\n" " :arg index: The index of the point.\n" " :type index: int\n")
 
static PyObject * py_kdtree_insert (PyKDTree *self, PyObject *args, PyObject *kwargs)
 
 PyDoc_STRVAR (py_kdtree_balance_doc, ".. method:: balance()\n" "\n" " Balance the tree.\n" "\n" ".. note::\n" "\n" " This builds the entire tree, avoid calling after each insertion.\n")
 
static PyObject * py_kdtree_balance (PyKDTree *self)
 
static int py_find_nearest_cb (void *user_data, int index, const float co[3], float dist_sq)
 
 PyDoc_STRVAR (py_kdtree_find_doc, ".. method:: find(co, filter=None)\n" "\n" " Find nearest point to ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg filter: function which takes an index and returns True for indices to " "include in the search.\n" " :type filter: callable\n" " :return: Returns (:class:`Vector`, index, distance).\n" " :rtype: :class:`tuple`\n")
 
static PyObject * py_kdtree_find (PyKDTree *self, PyObject *args, PyObject *kwargs)
 
 PyDoc_STRVAR (py_kdtree_find_n_doc, ".. method:: find_n(co, n)\n" "\n" " Find nearest ``n`` points to ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg n: Number of points to find.\n" " :type n: int\n" " :return: Returns a list of tuples (:class:`Vector`, index, distance).\n" " :rtype: :class:`list`\n")
 
static PyObject * py_kdtree_find_n (PyKDTree *self, PyObject *args, PyObject *kwargs)
 
 PyDoc_STRVAR (py_kdtree_find_range_doc, ".. method:: find_range(co, radius)\n" "\n" " Find all points within ``radius`` of ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg radius: Distance to search for points.\n" " :type radius: float\n" " :return: Returns a list of tuples (:class:`Vector`, index, distance).\n" " :rtype: :class:`list`\n")
 
static PyObject * py_kdtree_find_range (PyKDTree *self, PyObject *args, PyObject *kwargs)
 
 PyDoc_STRVAR (py_KDtree_doc, "KdTree(size) -> new kd-tree initialized to hold ``size`` items.\n" "\n" ".. note::\n" "\n" " :class:`KDTree.balance` must have been called before using any of the ``find`` " "methods.\n")
 
 PyDoc_STRVAR (py_kdtree_doc, "Generic 3-dimensional kd-tree to perform spatial searches.")
 
PyMODINIT_FUNC PyInit_mathutils_kdtree (void)
 

Variables

static PyMethodDef PyKDTree_methods []
 
PyTypeObject PyKDTree_Type
 
static struct PyModuleDef kdtree_moduledef
 

Detailed Description

This file defines the 'mathutils.kdtree' module, a general purpose module to access blenders kdtree for 3d spatial lookups.

Definition in file mathutils_kdtree.c.

Macro Definition Documentation

◆ UINT_IS_NEG

#define UINT_IS_NEG (   n)    ((n) > INT_MAX)

Definition at line 78 of file mathutils_kdtree.c.

Function Documentation

◆ kdtree_nearest_to_py()

static PyObject* kdtree_nearest_to_py ( const KDTreeNearest_3d *  nearest)
static

Definition at line 47 of file mathutils_kdtree.c.

References kdtree_nearest_to_py_tuple().

Referenced by py_kdtree_find_n(), and py_kdtree_find_range().

◆ kdtree_nearest_to_py_and_check()

static PyObject* kdtree_nearest_to_py_and_check ( const KDTreeNearest_3d *  nearest)
static

Definition at line 58 of file mathutils_kdtree.c.

References kdtree_nearest_to_py_tuple(), and PyC_Tuple_Fill().

Referenced by py_kdtree_find().

◆ kdtree_nearest_to_py_tuple()

static void kdtree_nearest_to_py_tuple ( const KDTreeNearest_3d *  nearest,
PyObject *  py_retval 
)
static

◆ py_find_nearest_cb()

static int py_find_nearest_cb ( void user_data,
int  index,
const float  co[3],
float  dist_sq 
)
static

Definition at line 168 of file mathutils_kdtree.c.

References data, PyC_ParseBool(), result, UNUSED_VARS, and user_data.

Referenced by py_kdtree_find().

◆ py_kdtree_balance()

static PyObject* py_kdtree_balance ( PyKDTree self)
static

Definition at line 156 of file mathutils_kdtree.c.

References self.

◆ py_kdtree_find()

static PyObject* py_kdtree_find ( PyKDTree self,
PyObject *  args,
PyObject *  kwargs 
)
static

◆ py_kdtree_find_n()

static PyObject* py_kdtree_find_n ( PyKDTree self,
PyObject *  args,
PyObject *  kwargs 
)
static

◆ py_kdtree_find_range()

static PyObject* py_kdtree_find_range ( PyKDTree self,
PyObject *  args,
PyObject *  kwargs 
)
static

Definition at line 311 of file mathutils_kdtree.c.

References kdtree_nearest_to_py(), mathutils_array_parse(), MEM_freeN, NULL, and self.

◆ py_kdtree_insert()

static PyObject* py_kdtree_insert ( PyKDTree self,
PyObject *  args,
PyObject *  kwargs 
)
static

Definition at line 117 of file mathutils_kdtree.c.

References mathutils_array_parse(), NULL, and self.

◆ PyDoc_STRVAR() [1/7]

PyDoc_STRVAR ( py_kdtree_balance_doc  ,
".. method:: balance()\n" "\n" " Balance the tree.\n" "\n" ".. note::\n" "\n" " This builds the entire  tree,
avoid calling after each insertion.\n"   
)

◆ PyDoc_STRVAR() [2/7]

PyDoc_STRVAR ( py_kdtree_doc  ,
"Generic 3-dimensional kd-tree to perform spatial searches."   
)

◆ PyDoc_STRVAR() [3/7]

PyDoc_STRVAR ( py_KDtree_doc  ,
"KdTree(size) -> new kd-tree initialized to hold ``size`` items.\n" "\n" ".. note::\n" "\n" " :class:`KDTree.balance` must have been called before using any of the ``find`` " "methods.\n"   
)

◆ PyDoc_STRVAR() [4/7]

PyDoc_STRVAR ( py_kdtree_find_doc  ,
".. method:: find(co, filter=None)\n" "\n" " Find nearest point to ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg filter: function which takes an index and returns True for indices to " "include in the search.\n" " :type filter: callable\n" " :return: Returns (:class:`Vector`, index, distance).\n" " :rtype: :class:`tuple`\n"   
)

◆ PyDoc_STRVAR() [5/7]

PyDoc_STRVAR ( py_kdtree_find_n_doc  ,
".. method:: find_n(co, n)\n" "\n" " Find nearest ``n`` points to ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg n: Number of points to find.\n" " :type n: int\n" " :return: Returns a list of tuples (:class:`Vector`, index, distance).\n" " :rtype: :class:`list`\n"   
)

◆ PyDoc_STRVAR() [6/7]

PyDoc_STRVAR ( py_kdtree_find_range_doc  ,
".. method:: find_range(co, radius)\n" "\n" " Find all points within ``radius`` of ``co``.\n" "\n" " :arg co: 3d coordinates.\n" " :type co: float triplet\n" " :arg radius: Distance to search for points.\n" " :type radius: float\n" " :return: Returns a list of tuples (:class:`Vector`, index, distance).\n" " :rtype: :class:`list`\n"   
)

◆ PyDoc_STRVAR() [7/7]

PyDoc_STRVAR ( py_kdtree_insert_doc  ,
".. method:: insert(co, index)\n" "\n" " Insert a point into the KDTree.\n" "\n" " :arg co: Point 3d position.\n" " :type co: float triplet\n" " :arg index: The index of the point.\n" " :type index: int\n"   
)

◆ PyInit_mathutils_kdtree()

PyMODINIT_FUNC PyInit_mathutils_kdtree ( void  )

Definition at line 437 of file mathutils_kdtree.c.

References kdtree_moduledef, NULL, and PyKDTree_Type.

Referenced by PyInit_mathutils().

◆ PyKDTree__tp_dealloc()

static void PyKDTree__tp_dealloc ( PyKDTree self)
static

Definition at line 102 of file mathutils_kdtree.c.

References self.

◆ PyKDTree__tp_init()

static int PyKDTree__tp_init ( PyKDTree self,
PyObject *  args,
PyObject *  kwargs 
)
static

Definition at line 80 of file mathutils_kdtree.c.

References NULL, and UINT_IS_NEG.

Variable Documentation

◆ kdtree_moduledef

struct PyModuleDef kdtree_moduledef
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"mathutils.kdtree",
py_kdtree_doc,
0,
NULL,
NULL,
NULL,
NULL,
NULL,
}

Definition at line 424 of file mathutils_kdtree.c.

Referenced by PyInit_mathutils_kdtree().

◆ PyKDTree_methods

PyMethodDef PyKDTree_methods[]
static
Initial value:
= {
{"insert", (PyCFunction)py_kdtree_insert, METH_VARARGS | METH_KEYWORDS, py_kdtree_insert_doc},
{"balance", (PyCFunction)py_kdtree_balance, METH_NOARGS, py_kdtree_balance_doc},
{"find", (PyCFunction)py_kdtree_find, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_doc},
{"find_n", (PyCFunction)py_kdtree_find_n, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_n_doc},
{"find_range",
(PyCFunction)py_kdtree_find_range,
METH_VARARGS | METH_KEYWORDS,
py_kdtree_find_range_doc},
{NULL, NULL, 0, NULL},
}
static PyObject * py_kdtree_balance(PyKDTree *self)
static PyObject * py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject *kwargs)
static PyObject * py_kdtree_find_n(PyKDTree *self, PyObject *args, PyObject *kwargs)
static PyObject * py_kdtree_find(PyKDTree *self, PyObject *args, PyObject *kwargs)
static PyObject * py_kdtree_insert(PyKDTree *self, PyObject *args, PyObject *kwargs)

Definition at line 356 of file mathutils_kdtree.c.

◆ PyKDTree_Type

PyTypeObject PyKDTree_Type

Definition at line 375 of file mathutils_kdtree.c.

Referenced by PyInit_mathutils_kdtree().