SeExpr

Curve.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #pragma once
18
19 #include "Vec.h"
20 #include <vector>
21
22 #include <cfloat>
23 #include <cassert>
24
25 namespace SeExpr2 {
26
28
37 template <class T>
38 class Curve {
39 mutable int cacheCV;
40
41 public:
43 enum InterpType {
44 kNone = 0,
45 kLinear,
46 kSmooth,
47 kSpline,
48 kMonotoneSpline
49 };
50 struct CV {
51 CV(double pos, const T& val, InterpType type) : _pos(pos), _val(val), _interp(type) {}
52
53 double _pos;
54 T _val, _deriv;
55 InterpType _interp;
56 };
57
58 private:
59 std::vector<CV> _cvData;
60 bool prepared;
61
62 public:
63 Curve();
64
66 void addPoint(double position, const T& val, InterpType type);
67
69 void preparePoints();
70
72 T getValue(const double param) const;
73
76 double getChannelValue(const double param, int channel) const;
77
80 CV getLowerBoundCV(const double param) const;
81
83 static bool interpTypeValid(InterpType interp);
84
86 static bool cvLessThan(const CV& cv1, const CV& cv2);
87
88 private:
90 void clampCurveSegment(const T& delta, T& d1, T& d2);
91
93 static double comp(const T& val, const int i);
94 };
95 }
SeExpr2::Curve::clampCurveSegment
void clampCurveSegment(const T &delta, T &d1, T &d2)
Performs hermite derivative clamping in canonical space.
SeExpr2::Curve::kSmooth
Definition: Curve.h:46
SeExpr2::Curve::_cvData
std::vector< CV > _cvData
Definition: Curve.h:59
SeExpr2::Curve::CV::_val
T _val
Definition: Curve.h:54
SeExpr2::Curve::kMonotoneSpline
Definition: Curve.h:48
SeExpr2::Curve::cacheCV
int cacheCV
Definition: Curve.h:39
SeExpr2::Curve::prepared
bool prepared
Definition: Curve.h:60
SeExpr2::Curve::getValue
T getValue(const double param) const
Evaluates curve and returns full value.
Definition: Curve.cpp:104
SeExpr2::Curve::CV::_pos
double _pos
Definition: Curve.h:53
SeExpr2::Curve::CV::_interp
InterpType _interp
Definition: Curve.h:55
SeExpr2::Curve::kSpline
Definition: Curve.h:47
SeExpr2
Definition: Context.h:22
Vec.h
SeExpr2::Curve
Interpolation curve class for double->double and double->Vec3D.
Definition: Curve.h:38
SeExpr2::Curve::Curve
Curve()
Definition: Curve.cpp:43
SeExpr2::Curve::getLowerBoundCV
CV getLowerBoundCV(const double param) const
Definition: Curve.cpp:199
SeExpr2::Curve::CV::_deriv
T _deriv
Definition: Curve.h:54
SeExpr2::Curve::kLinear
Definition: Curve.h:45
SeExpr2::Curve::comp
static double comp(const T &val, const int i)
Returns a component of the given value.
SeExpr2::Curve::CV::CV
CV(double pos, const T &val, InterpType type)
Definition: Curve.h:51
SeExpr2::Curve::interpTypeValid
static bool interpTypeValid(InterpType interp)
Returns whether the given interpolation type is supported.
Definition: Curve.cpp:211
SeExpr2::Curve::kNone
Definition: Curve.h:44
SeExpr2::Curve::InterpType
InterpType
Supported interpolation types.
Definition: Curve.h:43
SeExpr2::Curve::preparePoints
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
Definition: Curve.cpp:56
SeExpr2::Curve::getChannelValue
double getChannelValue(const double param, int channel) const
Definition: Curve.cpp:150
SeExpr2::Curve::CV
Definition: Curve.h:50
SeExpr2::Curve::addPoint
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
Definition: Curve.cpp:50
SeExpr2::Curve::cvLessThan
static bool cvLessThan(const CV &cv1, const CV &cv2)
CV Parameter ordering (cv1._pos < cv2._pos)
Definition: Curve.cpp:38