Bifrost SDK
Bifrost SDK documentation
FCurve.h
Go to the documentation of this file.
1//-
2// =============================================================================
3// Copyright 2025 Autodesk, Inc. All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license
6// agreement provided at the time of installation or download, or which
7// otherwise accompanies this software in either electronic or hard copy form.
8// =============================================================================
9//+
10
14
15#ifndef BIFROST_MATH_FCURVE_H
16#define BIFROST_MATH_FCURVE_H
17
19
20#include <Amino/Core/Array.h>
21#include <Amino/Core/Ptr.h>
22#include <Amino/Core/internal/ConfigMacros.h>
23
24#include <Amino/Cpp/Annotate.h>
26
27namespace Amino {
28class FCurveSerializer;
29}
30
34#define BIFROST_IGNORE_NAMESPACE AMINO_ANNOTATE("Amino::Namespace ignore")
36#undef BIFROST_IGNORE_NAMESPACE
37
38namespace Math {
39
40//==============================================================================
41// CLASS FCurve
42//==============================================================================
43
45class AMINO_ANNOTATE("Amino::Class") BIFROST_MATH_SHARED_DECL FCurve {
47 friend class Amino::FCurveSerializer;
48
49public:
50 /*----- types -----*/
51
54 enum class SpanInterpolationMethod : uint8_t {
55 Constant,
56 Linear,
57 Curve
58 };
59
62 enum class CurveInterpolationMethod : uint8_t {
63 Bezier,
64 Hermite,
65 Sine,
66 Parabolic,
67 TangentLog
68 };
69
72 enum class ExtrapolationMode {
74 Constant,
75
77 Linear,
78
80 Cycle,
81
84 RelativeRepeat,
85
88 Oscillate
89 };
90
108 double xp = 0;
109 double yp = 0;
110 double x = 0;
111 double y = 0;
112 double xn = 0;
113 double yn = 0;
114 };
115
118 public:
120 constexpr SegmentPoint() = default;
121
124 constexpr explicit SegmentPoint(ControlPoints const& coords)
125 : m_coords(coords) {}
126
128 constexpr SegmentPoint(
129 ControlPoints const& coords,
130 SpanInterpolationMethod spanInterpolation,
131 CurveInterpolationMethod curveInterpolation,
132 bool locked)
133 : m_coords(coords),
134 m_spanInterpolation(spanInterpolation),
135 m_curveInterpolation(curveInterpolation),
136 m_locked(locked) {}
137
139 ControlPoints const& getControlPoints() const { return m_coords; }
140
144 return m_spanInterpolation;
145 }
146
149 return m_curveInterpolation;
150 }
151
153 bool isLocked() const { return m_locked; }
154
155 private:
156 friend FCurve;
157
159 ControlPoints m_coords;
160
163 SpanInterpolationMethod m_spanInterpolation =
164 SpanInterpolationMethod::Curve;
165
167 CurveInterpolationMethod m_curveInterpolation =
168 CurveInterpolationMethod::Bezier;
169
171 bool m_locked = true;
172 };
173
175
176 /*----- member functions -----*/
177
183 explicit FCurve(bool createDefaultValue = true);
184
187
191 FCurve(FCurve const& other);
192
199
214 static double evaluateCurveSegment(
215 CurveInterpolationMethod interpolation,
216 double x0,
217 double y0,
218 double x1,
219 double y1,
220 double x2,
221 double y2,
222 double x3,
223 double y3,
224 double x);
225
227 static double evalBezier(
228 double x0,
229 double y0,
230 double x1,
231 double y1,
232 double x2,
233 double y2,
234 double x3,
235 double y3,
236 double x) {
237 return evaluateCurveSegment(
238 CurveInterpolationMethod::Bezier, //
239 x0, y0, x1, y1, x2, y2, x3, y3, x);
240 }
241
243 FCurvePoints const& getPoints() const { return m_points; }
244
246 ExtrapolationMode getPreExtrapolation() const { return m_preExtrapolation; }
247
250 return m_postExtrapolation;
251 }
252
256 int numPoints() const;
257
263 double evalFCurve(double x) const;
264
266 void setPoints(FCurvePoints points) { m_points = std::move(points); }
267
271 ExtrapolationMode preExtrapolation,
272 ExtrapolationMode postExtrapolation) {
273 m_preExtrapolation = preExtrapolation;
274 m_postExtrapolation = postExtrapolation;
275 }
276
277private:
278 AMINO_INTERNAL_WARNING_PUSH
279 AMINO_INTERNAL_WARNING_DISABLE_MSC(4251)
280 FCurvePoints m_points;
281 ExtrapolationMode m_preExtrapolation = ExtrapolationMode::Constant;
282 ExtrapolationMode m_postExtrapolation = ExtrapolationMode::Constant;
283 AMINO_INTERNAL_WARNING_POP
284};
285
286} // namespace Math
287} // namespace BIFROST_IGNORE_NAMESPACE
288
291AMINO_DECLARE_DEFAULT_CLASS(BIFROST_MATH_SHARED_DECL, Bifrost::Math::FCurve);
292
293#endif
A resizable container of contiguous elements.
Smart pointers used to allow custom user classes (opaque classes) to be used within Amino graphs....
Header Parser Annotation Macro & Parser Documentation.
Macros used to declare functions and traits about classes exposed to Amino.
AMINO_DECLARE_DEFAULT_CLASS(BIFROST_MATH_SHARED_DECL, Bifrost::Math::FCurve)
Macro for generating the getDefault entry point declaration related to a given opaque type,...
#define BIFROST_IGNORE_NAMESPACE
Use a define, otherwise clang-format gets confused.
Definition: FCurve.h:34
Definition of macros for symbol visibility.
Definition: HostData.h:33
Definition: FCurve.h:35
Define a Amino array of elements of type T.
Definition: Array.h:105
FCurve User Class.
Definition: FCurve.h:45
~FCurve()
Destructor.
static double evaluateCurveSegment(CurveInterpolationMethod interpolation, double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double x)
Support function to evaluate a cubic curve segment.
bool defaultValue()
Reset to a default FCurve.
static double evalBezier(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double x)
Short-hand for evaluateCurveSegment with Bezier interpolation.
Definition: FCurve.h:227
int numPoints() const
Number of points in the FCurve.
FCurvePoints const & getPoints() const
Get the points of the FCurve.
Definition: FCurve.h:243
void setExtrapolationModes(ExtrapolationMode preExtrapolation, ExtrapolationMode postExtrapolation)
Set the extrapolation modes of the regions before the first and after the last point.
Definition: FCurve.h:270
FCurve(FCurve const &other)
Copy constructor.
FCurve(bool createDefaultValue=true)
Constructor.
double evalFCurve(double x) const
Evaluate the FCurve at the given x value.
ExtrapolationMode getPreExtrapolation() const
Get the pre-extrapolation mode.
Definition: FCurve.h:246
ExtrapolationMode getPostExtrapolation() const
Get the post-extrapolation mode.
Definition: FCurve.h:249
void setPoints(FCurvePoints points)
Set the array of segment points.
Definition: FCurve.h:266
Struct for previous, current, and next point for a curve.
Definition: FCurve.h:107
Struct for one point.
Definition: FCurve.h:117
constexpr SegmentPoint(ControlPoints const &coords)
Constructor with control points and default interpolation methods.
Definition: FCurve.h:124
constexpr SegmentPoint()=default
Default constructor.
SpanInterpolationMethod getSpanInterpolation() const
Get the interpolation method for the span between this point and the next point.
Definition: FCurve.h:143
bool isLocked() const
Check if this point is locked.
Definition: FCurve.h:153
CurveInterpolationMethod getCurveInterpolation() const
Get the interpolation method for the curve segment.
Definition: FCurve.h:148
ControlPoints const & getControlPoints() const
Get the control points for the segment.
Definition: FCurve.h:139
constexpr SegmentPoint(ControlPoints const &coords, SpanInterpolationMethod spanInterpolation, CurveInterpolationMethod curveInterpolation, bool locked)
Constructor with control points and interpolation methods.
Definition: FCurve.h:128