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,
49  };
50  struct CV {
51  CV(double pos, const T& val, InterpType type) : _pos(pos), _val(val), _interp(type) {}
52 
53  double _pos;
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 }
std::vector< CV > _cvData
Definition: Curve.h:59
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
Definition: Curve.cpp:56
static bool interpTypeValid(InterpType interp)
Returns whether the given interpolation type is supported.
Definition: Curve.cpp:211
static bool cvLessThan(const CV &cv1, const CV &cv2)
CV Parameter ordering (cv1._pos &lt; cv2._pos)
Definition: Curve.cpp:38
Interpolation curve class for double-&gt;double and double-&gt;Vec3D.
Definition: Curve.h:38
InterpType _interp
Definition: Curve.h:55
T getValue(const double param) const
Evaluates curve and returns full value.
Definition: Curve.cpp:104
CV getLowerBoundCV(const double param) const
Definition: Curve.cpp:199
bool prepared
Definition: Curve.h:60
double _pos
Definition: Curve.h:53
CV(double pos, const T &val, InterpType type)
Definition: Curve.h:51
int cacheCV
Definition: Curve.h:39
static double comp(const T &val, const int i)
Returns a component of the given value.
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
Definition: Curve.cpp:50
InterpType
Supported interpolation types.
Definition: Curve.h:43
double getChannelValue(const double param, int channel) const
Definition: Curve.cpp:150
void clampCurveSegment(const T &delta, T &d1, T &d2)
Performs hermite derivative clamping in canonical space.