Blender  V3.3
mathutils_interpolate.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <Python.h>
8 
9 #include "mathutils.h"
10 #include "mathutils_interpolate.h"
11 
12 #include "BLI_math.h"
13 #include "BLI_utildefines.h"
14 
15 #ifndef MATH_STANDALONE /* define when building outside blender */
16 # include "MEM_guardedalloc.h"
17 #endif
18 
19 /*-------------------------DOC STRINGS ---------------------------*/
20 PyDoc_STRVAR(M_Interpolate_doc, "The Blender interpolate module");
21 
22 /* ---------------------------------WEIGHT CALCULATION ----------------------- */
23 
24 #ifndef MATH_STANDALONE
25 
26 PyDoc_STRVAR(M_Interpolate_poly_3d_calc_doc,
27  ".. function:: poly_3d_calc(veclist, pt)\n"
28  "\n"
29  " Calculate barycentric weights for a point on a polygon.\n"
30  "\n"
31  " :arg veclist: list of vectors\n"
32  " :arg pt: point"
33  " :rtype: list of per-vector weights\n");
34 static PyObject *M_Interpolate_poly_3d_calc(PyObject *UNUSED(self), PyObject *args)
35 {
36  float fp[3];
37  float(*vecs)[3];
38  Py_ssize_t len;
39 
40  PyObject *point, *veclist, *ret;
41  int i;
42 
43  if (!PyArg_ParseTuple(args, "OO:poly_3d_calc", &veclist, &point)) {
44  return NULL;
45  }
46 
48  fp, 2, 3 | MU_ARRAY_ZERO, point, "pt must be a 2-3 dimensional vector") == -1) {
49  return NULL;
50  }
51 
52  len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__);
53  if (len == -1) {
54  return NULL;
55  }
56 
57  if (len) {
58  float *weights = MEM_mallocN(sizeof(float) * len, __func__);
59 
60  interp_weights_poly_v3(weights, vecs, len, fp);
61 
62  ret = PyList_New(len);
63  for (i = 0; i < len; i++) {
64  PyList_SET_ITEM(ret, i, PyFloat_FromDouble(weights[i]));
65  }
66 
67  MEM_freeN(weights);
68 
69  PyMem_Free(vecs);
70  }
71  else {
72  ret = PyList_New(0);
73  }
74 
75  return ret;
76 }
77 
78 #endif /* MATH_STANDALONE */
79 
80 static PyMethodDef M_Interpolate_methods[] = {
81 #ifndef MATH_STANDALONE
82  {"poly_3d_calc",
83  (PyCFunction)M_Interpolate_poly_3d_calc,
84  METH_VARARGS,
85  M_Interpolate_poly_3d_calc_doc},
86 #endif
87  {NULL, NULL, 0, NULL},
88 };
89 
90 static struct PyModuleDef M_Interpolate_module_def = {
91  PyModuleDef_HEAD_INIT,
92  "mathutils.interpolate", /* m_name */
93  M_Interpolate_doc, /* m_doc */
94  0, /* m_size */
95  M_Interpolate_methods, /* m_methods */
96  NULL, /* m_reload */
97  NULL, /* m_traverse */
98  NULL, /* m_clear */
99  NULL, /* m_free */
100 };
101 
102 /*----------------------------MODULE INIT-------------------------*/
103 PyMODINIT_FUNC PyInit_mathutils_interpolate(void)
104 {
105  PyObject *submodule = PyModule_Create(&M_Interpolate_module_def);
106  return submodule;
107 }
typedef float(TangentPoint)[2]
void interp_weights_poly_v3(float w[], float v[][3], int n, const float co[3])
#define UNUSED(x)
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
int len
Definition: draw_manager.c:108
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition: mathutils.c:98
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
Definition: mathutils.c:259
#define MU_ARRAY_ZERO
Definition: mathutils.h:203
PyDoc_STRVAR(M_Interpolate_doc, "The Blender interpolate module")
static PyMethodDef M_Interpolate_methods[]
static struct PyModuleDef M_Interpolate_module_def
PyMODINIT_FUNC PyInit_mathutils_interpolate(void)
static PyObject * M_Interpolate_poly_3d_calc(PyObject *UNUSED(self), PyObject *args)
return ret