MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ interpolate()

Eigen::VectorXd MayaFlux::Kinesis::interpolate ( const Eigen::MatrixXd &  control_points,
double  t,
InterpolationMode  mode,
double  tension = 0.5 
)

Generic interpolation dispatcher.

Parameters
control_pointsMxN matrix where columns are control points
tParameter in [0,1]
modeInterpolation mode
tensionTension parameter (for applicable modes)
Returns
Interpolated point as Nx1 vector

Definition at line 262 of file MotionCurves.cpp.

267{
268 switch (mode) {
269 case InterpolationMode::LINEAR:
270 if (control_points.cols() < 2) {
271 error<std::invalid_argument>(
272 Journal::Component::Kinesis,
273 Journal::Context::Runtime,
274 std::source_location::current(),
275 "Linear interpolation requires at least 2 points, but got {}",
276 control_points.cols());
277 }
278 return (1.0 - t) * control_points.col(0) + t * control_points.col(1);
279
280 case InterpolationMode::CATMULL_ROM:
281 return catmull_rom_spline(control_points, t, tension);
282
283 case InterpolationMode::CUBIC_HERMITE: {
284 Eigen::MatrixXd endpoints = control_points.leftCols(2);
285 Eigen::MatrixXd tangents = control_points.rightCols(2);
286 return cubic_hermite(endpoints, tangents, t);
287 }
288
289 case InterpolationMode::CUBIC_BEZIER:
290 return cubic_bezier(control_points, t);
291
292 case InterpolationMode::QUADRATIC_BEZIER:
293 return quadratic_bezier(control_points, t);
294
295 case InterpolationMode::BSPLINE:
296 return bspline_cubic(control_points, t);
297
298 case InterpolationMode::COSINE: {
299 if (control_points.cols() < 2) {
300 error<std::invalid_argument>(
301 Journal::Component::Kinesis,
302 Journal::Context::Runtime,
303 std::source_location::current(),
304 "Cosine interpolation requires at least 2 points, but got {}",
305 control_points.cols());
306 }
307 double mu2 = (1.0 - std::cos(t * M_PI)) * 0.5;
308 return (1.0 - mu2) * control_points.col(0) + mu2 * control_points.col(1);
309 }
310
311 default:
312 error<std::invalid_argument>(
313 Journal::Component::Kinesis,
314 Journal::Context::Runtime,
315 std::source_location::current(),
316 "Unsupported interpolation mode: {}",
317 static_cast<int>(mode));
318 }
319}

References BSPLINE, bspline_cubic(), CATMULL_ROM, catmull_rom_spline(), COSINE, cubic_bezier(), CUBIC_BEZIER, cubic_hermite(), CUBIC_HERMITE, MayaFlux::Journal::Kinesis, LINEAR, quadratic_bezier(), QUADRATIC_BEZIER, and MayaFlux::Journal::Runtime.

Referenced by generate_interpolated_points().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: