KSeExpr  4.0.4.0
Curve.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2 // SPDX-License-Identifier: LicenseRef-Apache-2.0
3 // SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #pragma once
7 
8 #include <cassert>
9 #include <cfloat>
10 #include <vector>
11 
12 #include "Vec.h"
13 
14 namespace KSeExpr
15 {
17 
26 template<class T> class Curve
27 {
28  mutable int cacheCV;
29 
30 public:
33  struct CV {
34  CV(double pos, const T &val, InterpType type)
35  : _pos(pos)
36  , _val(val)
37  , _interp(type)
38  {
39  }
40 
41  double _pos;
44  };
45 
46 private:
47  std::vector<CV> _cvData;
48  bool prepared;
49 
50 public:
51  Curve();
52 
54  void addPoint(double position, const T &val, InterpType type);
55 
57  void preparePoints();
58 
60  T getValue(double param) const;
61 
64  double getChannelValue(double param, int channel) const;
65 
68  CV getLowerBoundCV(double param) const;
69 
71  static bool interpTypeValid(InterpType interp);
72 
74  static bool cvLessThan(const CV &cv1, const CV &cv2);
75 
76 private:
78  void clampCurveSegment(const T &delta, T &d1, T &d2);
79 
81  static double comp(const T &val, int i);
82 };
83 } // namespace KSeExpr
Interpolation curve class for double->double and double->Vec3D.
Definition: Curve.h:27
InterpType
Supported interpolation types.
Definition: Curve.h:32
@ kMonotoneSpline
Definition: Curve.h:32
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
Definition: Curve.cpp:46
T getValue(double param) const
Evaluates curve and returns full value.
Definition: Curve.cpp:94
static bool cvLessThan(const CV &cv1, const CV &cv2)
CV Parameter ordering (cv1._pos < cv2._pos)
Definition: Curve.cpp:26
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
Definition: Curve.cpp:40
std::vector< CV > _cvData
Definition: Curve.h:47
static double comp(const T &val, int i)
Returns a component of the given value.
bool prepared
Definition: Curve.h:48
int cacheCV
Definition: Curve.h:28
double getChannelValue(double param, int channel) const
Definition: Curve.cpp:139
CV getLowerBoundCV(double param) const
Definition: Curve.cpp:186
static bool interpTypeValid(InterpType interp)
Returns whether the given interpolation type is supported.
Definition: Curve.cpp:198
void clampCurveSegment(const T &delta, T &d1, T &d2)
Performs hermite derivative clamping in canonical space.
double _pos
Definition: Curve.h:41
CV(double pos, const T &val, InterpType type)
Definition: Curve.h:34
InterpType _interp
Definition: Curve.h:43