3#include <Core/Containers/VectorArray.hpp>
4#include <Core/Geometry/Spline.hpp>
5#include <Core/RaCore.hpp>
14 enum CurveType { LINE, CUBICBEZIER, SPLINE, SIZE };
16 using Vector = Eigen::Matrix<Scalar, 2, 1>;
18 virtual void addPoint(
const Vector p ) = 0;
19 virtual ~Curve2D() =
default;
21 virtual Vector f( Scalar u )
const = 0;
22 virtual Vector df( Scalar u )
const = 0;
23 virtual Vector fdf( Scalar t, Vector& grad )
const = 0;
29class QuadraSpline :
public Curve2D
32 QuadraSpline() { this->size = 0; }
33 QuadraSpline(
const Curve2D::Vector& p0,
34 const Curve2D::Vector& p1,
35 const Curve2D::Vector& p2 ) :
36 m_points { p0, p1, p2 } {
39 ~QuadraSpline()
override =
default;
41 inline void addPoint(
const Vector p )
override;
43 inline Vector f( Scalar u )
const override;
44 inline Vector df( Scalar u )
const override;
45 inline Vector fdf( Scalar u, Vector& grad )
const override;
48 Core::VectorArray<Vector> m_points;
51class CubicBezier :
public Curve2D
54 CubicBezier() { this->size = 0; }
55 CubicBezier(
const Curve2D::Vector& p0,
56 const Curve2D::Vector& p1,
57 const Curve2D::Vector& p2,
58 const Curve2D::Vector& p3 ) :
59 m_points { p0, p1, p2, p3 } {
62 ~CubicBezier()
override =
default;
64 inline void addPoint(
const Vector p )
override;
66 inline Vector f( Scalar u )
const override;
67 inline Vector df( Scalar u )
const override;
68 inline Vector fdf( Scalar t, Vector& grad )
const override;
74class Line :
public Curve2D
77 Line() { this->size = 0; }
78 Line(
const Vector& p0,
const Vector& p1 ) : m_points { p0, p1 } { this->size = 2; }
79 ~Line()
override =
default;
81 inline void addPoint(
const Vector p )
override;
83 inline Vector f( Scalar u )
const override;
84 inline Vector df( Scalar u )
const override;
85 inline Vector fdf( Scalar t, Vector& grad )
const override;
91class SplineCurve :
public Curve2D
94 SplineCurve() { this->size = 0; }
95 explicit SplineCurve( Core::VectorArray<Vector> points ) : m_points( points ) {
96 this->size = points.size();
98 ~SplineCurve()
override =
default;
100 inline void addPoint(
const Vector p )
override;
102 inline Vector f( Scalar u )
const override;
103 inline Vector df( Scalar u )
const override;
104 inline Vector fdf( Scalar t, Vector& grad )
const override;
107 Core::VectorArray<Vector> m_points;
112void CubicBezier::addPoint(
const Curve2D::Vector p ) {
113 if ( size < 4 ) { m_points[size++] = p; }
116Curve2D::Vector CubicBezier::f( Scalar u )
const {
118 return fdf( u, grad );
121Curve2D::Vector CubicBezier::df( Scalar u )
const {
127Curve2D::Vector CubicBezier::fdf( Scalar t, Vector& grad )
const {
130 float oneMinusT = 1.0 - t;
131 float oneMinusT2 = oneMinusT * oneMinusT;
132 float oneMinusT3 = oneMinusT2 * oneMinusT;
134 grad = 3.0 * oneMinusT2 * ( m_points[1] - m_points[0] ) +
135 6.0 * oneMinusT * t * ( m_points[2] - m_points[1] ) +
136 3.0 * t2 * ( m_points[3] - m_points[2] );
137 return oneMinusT3 * m_points[0] + 3.0 * oneMinusT2 * t * m_points[1] +
138 3.0 * oneMinusT * t2 * m_points[2] + t3 * m_points[3];
143void Line::addPoint(
const Curve2D::Vector p ) {
144 if ( size < 2 ) { m_points[size++] = p; }
147Curve2D::Vector Line::f( Scalar u )
const {
148 return ( 1.0 - u ) * m_points[0] + u * m_points[1];
151Curve2D::Vector Line::df( Scalar )
const {
152 return m_points[1] - m_points[0];
155Curve2D::Vector Line::fdf( Scalar t, Vector& grad )
const {
156 grad = m_points[1] - m_points[0];
157 return ( 1.0 - t ) * m_points[0] + t * m_points[1];
162void SplineCurve::addPoint(
const Curve2D::Vector p ) {
163 m_points.push_back( p );
167Curve2D::Vector SplineCurve::f( Scalar u )
const {
169 spline.setCtrlPoints( m_points );
171 return spline.f( u );
174Curve2D::Vector SplineCurve::df( Scalar u )
const {
176 spline.setCtrlPoints( m_points );
178 return spline.df( u );
181Curve2D::Vector SplineCurve::fdf( Scalar u, Curve2D::Vector& grad )
const {
183 spline.setCtrlPoints( m_points );
185 grad = spline.df( u );
186 return spline.f( u );
191void QuadraSpline::addPoint(
const Curve2D::Vector p ) {
192 m_points.push_back( p );
196Curve2D::Vector QuadraSpline::f( Scalar u )
const {
198 spline.setCtrlPoints( m_points );
200 return spline.f( u );
203Curve2D::Vector QuadraSpline::df( Scalar u )
const {
205 spline.setCtrlPoints( m_points );
207 return spline.df( u );
210Curve2D::Vector QuadraSpline::fdf( Scalar u, Vector& grad )
const {
212 spline.setCtrlPoints( m_points );
214 grad = spline.df( u );
215 return spline.f( u );
LineMeshPtr Line(const Core::Vector3 &a, const Core::Vector3 &b, const Core::Utils::Color &color)
Displays given line.
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet