From 72d1ddfc9ce44afcf39226aa035249e2c29c1f5e Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Sun, 18 Jul 2021 15:10:34 -0400 Subject: Make it optional to track input->output mapping in delaunay_2d_calc. Some uses of delaunay_2d_calc don't need to know the original verts, edges, and faces that correspond to output elements. This change adds a "need_ids" value to the CDT input spec, default true, which tracks the input ids only when true. The python api mathutils.geometry.delaunay_2d_cdt gets an optional final bool argument that is the value of need_ids. If the argument is not supplied, it is true by default, so this won't break old uses of the API. On a sample text test, not tracking ids save about 30% of the runtime. For most inputs the difference will not be so dramatic: it only really kicks in if there are a lot of holes. --- source/blender/python/mathutils/mathutils_geometry.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source/blender/python/mathutils/mathutils_geometry.c') diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 88b3bddddf6..9b9c12aa1d1 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -1505,6 +1505,9 @@ static PyObject *list_of_lists_from_arrays(const int *array, PyObject *ret, *sublist; int i, j, sublist_len, sublist_start, val; + if (array == NULL) { + return PyList_New(0); + } ret = PyList_New(toplevel_len); for (i = 0; i < toplevel_len; i++) { sublist_len = len_table[i]; @@ -1561,6 +1564,7 @@ static PyObject *M_Geometry_delaunay_2d_cdt(PyObject *UNUSED(self), PyObject *ar PyObject *vert_coords, *edges, *faces, *item; int output_type; float epsilon; + bool need_ids = true; float(*in_coords)[2] = NULL; int(*in_edges)[2] = NULL; int *in_faces = NULL; @@ -1578,8 +1582,14 @@ static PyObject *M_Geometry_delaunay_2d_cdt(PyObject *UNUSED(self), PyObject *ar PyObject *ret_value = NULL; int i; - if (!PyArg_ParseTuple( - args, "OOOif:delaunay_2d_cdt", &vert_coords, &edges, &faces, &output_type, &epsilon)) { + if (!PyArg_ParseTuple(args, + "OOOif|p:delaunay_2d_cdt", + &vert_coords, + &edges, + &faces, + &output_type, + &epsilon, + &need_ids)) { return NULL; } @@ -1609,6 +1619,7 @@ static PyObject *M_Geometry_delaunay_2d_cdt(PyObject *UNUSED(self), PyObject *ar in.faces_start_table = in_faces_start_table; in.faces_len_table = in_faces_len_table; in.epsilon = epsilon; + in.need_ids = need_ids; res = BLI_delaunay_2d_cdt_calc(&in, output_type); -- cgit v1.2.3