MCPcopy Create free account
hub / github.com/SimVascular/SimVascular / Math_linear_interpolate

Function Math_linear_interpolate

Code/Source/PythonAPI/Math_PyModule.cxx:311–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309");
310
311static PyObject *
312Math_linear_interpolate(PyObject *self, PyObject *args)
313{
314 auto api = PyUtilApiFunction("Oi", PyRunTimeErr, __func__);
315 PyObject *pointsArg;
316 int numInterpPoints = 0;
317
318 if (!PyArg_ParseTuple(args, api.format, &pointsArg, &numInterpPoints)) {
319 return api.argsError();
320 }
321
322 // Get an array of points from the pointsArgs list.
323 int dim = 2;
324 auto pts = GetPointsFromList(api, pointsArg, dim, "points");
325 if (pts == nullptr) {
326 return nullptr;
327 }
328 int nlistpts = PyList_Size(pointsArg);
329
330 // Calculate dt so that our time series will go from 0 to T.
331 double t0 = pts[0][0];
332 double dt = (pts[nlistpts-1][0]-t0)/(numInterpPoints-1);
333 double **outPts = NULL;
334
335 // Perform the linear interpolation.
336 auto mathObj = cvMath();
337 if (mathObj.linearInterpolate(pts, nlistpts, t0, dt, numInterpPoints, &outPts) == SV_ERROR) {
338 mathObj.deleteArray(pts,nlistpts,dim);
339 api.error("Error linear interplating points.");
340 return nullptr;
341 }
342
343 // create result string
344 char r[2048];
345 PyObject *pylist = PyList_New(numInterpPoints);
346 for (int i = 0; i < numInterpPoints; i++) {
347 r[0] = '\0';
348 sprintf(r,"%.6le %.6le",outPts[i][0],outPts[i][1]);
349 PyObject *rr = PyBytes_FromString(r);
350 PyList_SET_ITEM(pylist, i, rr);
351 }
352
353 mathObj.deleteArray(pts,nlistpts,dim);
354 mathObj.deleteArray(outPts,numInterpPoints,dim);
355
356 return pylist;
357}
358
359//---------------------
360// Math_curve_length

Callers

nothing calls this directly

Calls 5

GetPointsFromListFunction · 0.85
argsErrorMethod · 0.80
errorMethod · 0.80
linearInterpolateMethod · 0.45
deleteArrayMethod · 0.45

Tested by

no test coverage detected