Blender V4.3
mathutils_interpolate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <Python.h>
10
11#include "mathutils.hh"
13
14#include "BLI_math_geom.h"
15#include "BLI_utildefines.h"
16
17#ifndef MATH_STANDALONE /* define when building outside blender */
18# include "MEM_guardedalloc.h"
19#endif
20
21/*-------------------------DOC STRINGS ---------------------------*/
23 /* Wrap. */
24 M_Interpolate_doc,
25 "The Blender interpolate module");
26
27/* ---------------------------------WEIGHT CALCULATION ----------------------- */
28
29#ifndef MATH_STANDALONE
30
32 /* Wrap. */
33 M_Interpolate_poly_3d_calc_doc,
34 ".. function:: poly_3d_calc(veclist, pt)\n"
35 "\n"
36 " Calculate barycentric weights for a point on a polygon.\n"
37 "\n"
38 " :arg veclist: Sequence of 3D positions.\n"
39 " :type veclist: Sequence[Sequence[float]]\n"
40 " :arg pt: 2D or 3D position."
41 " :type pt: Sequence[float]"
42 " :return: list of per-vector weights.\n"
43 " :rtype: list[float]\n");
44static PyObject *M_Interpolate_poly_3d_calc(PyObject * /*self*/, PyObject *args)
45{
46 float fp[3];
47 float(*vecs)[3];
48 Py_ssize_t len;
49
50 PyObject *point, *veclist, *ret;
51 int i;
52
53 if (!PyArg_ParseTuple(args, "OO:poly_3d_calc", &veclist, &point)) {
54 return nullptr;
55 }
56
58 fp, 2, 3 | MU_ARRAY_ZERO, point, "pt must be a 2-3 dimensional vector") == -1)
59 {
60 return nullptr;
61 }
62
63 len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__);
64 if (len == -1) {
65 return nullptr;
66 }
67
68 if (len) {
69 float *weights = static_cast<float *>(MEM_mallocN(sizeof(float) * len, __func__));
70
71 interp_weights_poly_v3(weights, vecs, len, fp);
72
73 ret = PyList_New(len);
74 for (i = 0; i < len; i++) {
75 PyList_SET_ITEM(ret, i, PyFloat_FromDouble(weights[i]));
76 }
77
78 MEM_freeN(weights);
79
80 PyMem_Free(vecs);
81 }
82 else {
83 ret = PyList_New(0);
84 }
85
86 return ret;
87}
88
89#endif /* !MATH_STANDALONE */
90
91static PyMethodDef M_Interpolate_methods[] = {
92#ifndef MATH_STANDALONE
93 {"poly_3d_calc",
94 (PyCFunction)M_Interpolate_poly_3d_calc,
95 METH_VARARGS,
96 M_Interpolate_poly_3d_calc_doc},
97#endif
98 {nullptr, nullptr, 0, nullptr},
99};
100
101static PyModuleDef M_Interpolate_module_def = {
102 /*m_base*/ PyModuleDef_HEAD_INIT,
103 /*m_name*/ "mathutils.interpolate",
104 /*m_doc*/ M_Interpolate_doc,
105 /*m_size*/ 0,
106 /*m_methods*/ M_Interpolate_methods,
107 /*m_slots*/ nullptr,
108 /*m_traverse*/ nullptr,
109 /*m_clear*/ nullptr,
110 /*m_free*/ nullptr,
111};
112
113/*----------------------------MODULE INIT-------------------------*/
114
116{
117 PyObject *submodule = PyModule_Create(&M_Interpolate_module_def);
118 return submodule;
119}
void interp_weights_poly_v3(float w[], float v[][3], int n, const float co[3])
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 Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture 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
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
Definition mathutils.cc:260
#define MU_ARRAY_ZERO
Definition mathutils.hh:206
PyDoc_STRVAR(M_Interpolate_doc, "The Blender interpolate module")
static PyMethodDef M_Interpolate_methods[]
PyMODINIT_FUNC PyInit_mathutils_interpolate()
static PyObject * M_Interpolate_poly_3d_calc(PyObject *, PyObject *args)
static PyModuleDef M_Interpolate_module_def
return ret