Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
Tucano::Path Class Reference

Path class, defines control points and a cubic Bezier approximation for defining a smooth path from key frames. More...

#include <path.hpp>

Inheritance diagram for Tucano::Path:
Tucano::Camera

Public Member Functions

 Path ()
 Default constructor. More...
 
void reset (void)
 Resets the path. More...
 
void initOpenGLMatrices (void)
 Initializes the view and projection matrices. They are all initialized as Identity matrices, but view is then translated by the defaultTranslation vector. More...
 
void initialize (string shader_dir="../effects/shaders/")
 Initializes shaders. More...
 
void fillVertexData (void)
 Fill the vertices array. More...
 
void addKeyPosition (const Tucano::Camera &camera, float interval=0.0)
 Add key position The camera will pause at this position for given number of steps, default is zero. More...
 
void addKeyDirection (const Eigen::Quaternion< float > q)
 Add an optial key direction Key directions are interpolated via SLERP and not SQUAD This is specially useful for interpolating a light direction together with the camera path Key directions should be always allocated together with a key position to work properly. More...
 
void render (const Tucano::Camera &camera, const Tucano::Camera &light)
 Renders smooth path End points for each Beziér is passed as line_strip and control points as vertex attributes Inside geometry shader each Beziér segment is approximate by linear segments. More...
 
int curveSegment (float t)
 returns the segment given a time t in [0,1] for the whole path More...
 
float toLocalParameter (float t)
 converts global parameter t to a local t inside a segment More...
 
Eigen::Vector4f pointOnSegment (float t, int segment)
 Returns a point at time t on a given Beziér segment. More...
 
Eigen::Vector4f pointOnPath (float global_t)
 compute point on path given t in [0,1] More...
 
Eigen::Quaternionf logQuaternion (const Eigen::Quaternionf &qi)
 Returns the log of a quaternion log(q) q in the form [cos(a), sin(a) v], log(q) = [0, a v]. More...
 
Eigen::Quaternionf expQuaternion (const Eigen::Quaternionf &q)
 Returns the exp of a quaternion exp(q) q in the form [0, a v], exp(q) = [cos(a), sin(a) v] with |v|=1. More...
 
Eigen::Quaternionf squad (int seg, float t)
 SQUAD - Spherical and Quadrangle quaternion interpolation. More...
 
Eigen::Affine3f cameraAtTime (float global_t)
 return a view matrix at a given path parameter More...
 
Eigen::Quaternion< float > directionAtTime (float global_t)
 return a direction at a given path parameter More...
 
Eigen::Affine3f cameraAtCurrentTime (void)
 Return the view matrix at current animation time. More...
 
Eigen::Quaternion< float > directionAtCurrentTime (void)
 Return the direction at current animation time. More...
 
float arcLengthToTime (float s)
 Converts from given arc length to time parameter. More...
 
void toggleAnimation (void)
 Toggle animation. More...
 
void setLoopAnimation (bool f)
 Set loop animation flag. More...
 
void toggleDrawControlPoints (void)
 Toggle render control points. More...
 
void toggleDrawQuaternions (void)
 Toggle render control quaternions. More...
 
bool isAnimating (void)
 Returns if Animation is running or not. More...
 
void stepForward (void)
 Move animation forward one step. More...
 
void stepBackward (void)
 Move animation backward one step. More...
 
void startAnimation (void)
 Start animation following camera path. More...
 
void stopAnimation (void)
 Stop animation. More...
 
void resetAnimation (void)
 Resets animation to first key position. More...
 
float animTime (void)
 Return current animation time. More...
 
float animSpeed (void)
 Return animation speed where 1 covers the whole curve in one step. More...
 
void setAnimSpeed (float as)
 Sets the animation speed. More...
 
void computeControlQuaternions (void)
 Compute control points for SQUAD. More...
 
void computeInnerControlPoints (void)
 Compute inner control points from key positions. More...
 
void computeArcLength (void)
 Compute an approximation of the arclength. More...
 
void printDebugInfo (void)
 
void writeToFile (const string filename)
 
void loadFromFile (const string filename)
 
- Public Member Functions inherited from Tucano::Camera
void resetViewMatrix (void)
 Reset view matrix. More...
 
void resetProjectionMatrix (void)
 Reset projection matrix. More...
 
void reset (void)
 Resets trackball to initial position and orientation. More...
 
Eigen::Vector3f getCenter (void) const
 Returns the center of the camera in world space. More...
 
void getViewMatrix (GLdouble *matrix)
 Return the modelview matrix as a GLdouble array. More...
 
void getProjectionMatrix (GLdouble *matrix)
 Return the projection matrix as a GLdouble array. More...
 
Eigen::Vector3f projectPoint (const Eigen::Vector4f &pt, Eigen::Vector4f &viewport)
 Returns screen space coordinates of a 3D point. More...
 
Eigen::Affine3f getViewMatrix (void) const
 Returns the view matrix as an Affine 3x3 matrix. More...
 
Eigen::Affine3f * viewMatrix (void)
 Returns a pointer to the view matrix as an Affine 3x3 matrix. More...
 
Eigen::Matrix4f getProjectionMatrix (void) const
 Returns the view matrix as an 4x4 matrix. More...
 
Eigen::Matrix4f * projectionMatrix (void)
 Returns a pointer to the projection matrix as an 4x4 matrix. More...
 
Eigen::Matrix3f getRotationMatrix (void) const
 Returns a 3x3 matrix containing only the rotation of the view matrix. More...
 
Eigen::Vector3f getTranslationMatrix (void) const
 Returns the translation part of the view matrix as a vector. More...
 
float getPerspectiveScale (void) const
 Returns the perspective scale. More...
 
Eigen::Vector4f getViewport (void) const
 Returns the viewport coordinates. More...
 
Eigen::Vector2i getViewportSize (void) const
 Returns the dimensions of the viewport. More...
 
float getViewportAspectRatio (void) const
 Returns the viewport aspect ratio. More...
 
void setViewport (const Eigen::Vector4f &vp)
 Sets the viewport coordinates. More...
 
void setViewport (const Eigen::Vector2i &vp)
 
void setViewport (const Eigen::Vector2f &vp)
 Sets the viewport coordinates considering that the minimum coordinates are zero. More...
 
void setProjectionMatrix (const Eigen::Matrix4f &mat)
 Sets the projection matrix from a given 4x4 matrix. More...
 
void setViewMatrix (const Eigen::Affine3f &mat)
 Sets the view matrix from a given an affine 3x3 matrix. More...
 
float getNearPlane (void) const
 Returns near plane value. More...
 
float getFarPlane (void) const
 Returns far plane value. More...
 
 ~Camera ()
 Default destructor. More...
 
float getFovy (void) const
 Returns current field of view angle in y axis. More...
 
 Camera (void)
 Default constructor. More...
 
Eigen::Matrix4f setPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane)
 Sets the projection matrix as a perspective matrix. More...
 
void changeFovy (float new_fovy)
 Changes the fovy and computes new perspective projection matrix. More...
 
Eigen::Matrix4f setOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane)
 Sets the projection matrix as a orthographic matrix. More...
 
void incrementFov (float inc)
 Increases the fov of the perspective matrix by a given increment. More...
 
void translate (const Eigen::Vector3f &translation)
 Translates the view matrix by a given vector. More...
 
void rotate (const Eigen::Quaternion< float > &rotation)
 Rotate the view matrix by a given quaternion. More...
 
void scale (const Eigen::Vector3f &scale_factors)
 Scales the view matrix by given factors. More...
 
void scale (float scale_factor)
 Scales the view matrix by given factor in all axis. More...
 

Private Attributes

float anim_speed = 0.025
 Movement speed, arc length increment for each animation step. More...
 
float anim_time = 0.0
 Animation time. More...
 
bool animating = false
 Start/stop animation. More...
 
bool loop_animation = false
 Flag to loop animation. More...
 
bool draw_control_points = false
 Flag to render control points. More...
 
bool draw_quaternions = false
 Flag to render quaternions at key positions. More...
 
vector< Eigen::Vector4f > key_positions
 Camera position at each Key frames. More...
 
vector< float > key_intervals
 Steps to stay paused at a given key position, usually zero. More...
 
vector< Eigen::Vector4f > control_points_1
 First control point between two key positions. More...
 
vector< Eigen::Vector4f > control_points_2
 Second control point between two key positions. More...
 
vector< vector< float > > arc_lengths
 Arc-length approximation splitting each Beziér segment into linear segments. More...
 
float path_length
 Total path length. More...
 
vector< Eigen::Quaternion< float > > key_quaternions
 Rotation state at each key frame. More...
 
vector< Eigen::Quaternion< float > > control_quaternions
 Control quaternions for SQUAD. More...
 
vector< Eigen::Quaternion< float > > key_directions
 Rotation only interpolation (via Slerp) useful for accompaning light direction for example. More...
 
Mesh curve
 
Mesh control_segments
 
Shapes::Sphere sphere
 A sphere to visually represent the path's key positions. More...
 
Shapes::CoordinateAxes axes
 Coordinate axes for visualizing quaternions at key positions. More...
 
Shader camerapath_shader
 Path shader, used for rendering the curve. More...
 
Shader phong_shader
 To render simple lines. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Tucano::Camera
static Eigen::Matrix4f createPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane)
 Returns a perspective projection matrix with the given parameters. More...
 
static Eigen::Matrix4f createOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane)
 Returns an orthographic projection matrix with the given parameters. More...
 
- Protected Attributes inherited from Tucano::Camera
Eigen::Matrix4f projection_matrix
 Projection, or intrinsic, matrix. More...
 
Eigen::Affine3f view_matrix
 View, or extrinsic, matrix. More...
 
Eigen::Vector4f viewport
 Viewport dimensions [minX, minY, width, height]. More...
 
Eigen::Affine3f default_view
 
float near_plane
 Near plane used for projection matrix. More...
 
float far_plane
 Far plane used for projection matrix. More...
 
float frustum_left
 Frustum left dimension. More...
 
float frustum_right
 Frustum right dimension. More...
 
float frustum_top
 Frustum top dimension. More...
 
float frustum_bottom
 Frustum bottom dimension. More...
 
float aspect_ratio
 Aspect ratio for projection matrix. More...
 
float focal_length
 Camera's Focal Length. More...
 
float fovy
 Field of view angle in y axis. More...
 
bool use_perspective
 Flag to indicate if using a perspective or othograpic projection. More...
 

Detailed Description

Path class, defines control points and a cubic Bezier approximation for defining a smooth path from key frames.

Very useful for creating camera paths for example, but it is generic enough to be used for other purposes. Each key frame stores a position and an orientation.

Reference: https://www.particleincell.com/2012/bezier-splines/

Notation: We refer to time as the curve parameter (analogy to particle moving along path) We refer to curve as the whole path, and a segment as one Cubic Bezíér that composes path

Constructor & Destructor Documentation

Tucano::Path::Path ( )
inline

Default constructor.

Member Function Documentation

void Tucano::Path::addKeyDirection ( const Eigen::Quaternion< float >  q)
inline

Add an optial key direction Key directions are interpolated via SLERP and not SQUAD This is specially useful for interpolating a light direction together with the camera path Key directions should be always allocated together with a key position to work properly.

Parameters
cameraCamera with directional information
void Tucano::Path::addKeyPosition ( const Tucano::Camera camera,
float  interval = 0.0 
)
inline

Add key position The camera will pause at this position for given number of steps, default is zero.

Parameters
cameraCamera containing position and orientation in view matrix
intervalNumber of steps to stay at this position
float Tucano::Path::animSpeed ( void  )
inline

Return animation speed where 1 covers the whole curve in one step.

Returns
Animation speed
float Tucano::Path::animTime ( void  )
inline

Return current animation time.

Returns
anim time
float Tucano::Path::arcLengthToTime ( float  s)
inline

Converts from given arc length to time parameter.

Parameters
sArc length parameter in [0,1]
Returns
Time at given arc length
Eigen::Affine3f Tucano::Path::cameraAtCurrentTime ( void  )
inline

Return the view matrix at current animation time.

Returns
View matrix at current animation time
Eigen::Affine3f Tucano::Path::cameraAtTime ( float  global_t)
inline

return a view matrix at a given path parameter

Returns
view matrix at time t of the path
void Tucano::Path::computeArcLength ( void  )
inline

Compute an approximation of the arclength.

approximates the curve by linear segments divide the curve between two key positions and compute the total length of the linear segments

void Tucano::Path::computeControlQuaternions ( void  )
inline

Compute control points for SQUAD.

Quaternions, Interpolation and Animation, Erik B. Dam, Martin Koch, Martin Lillholm

void Tucano::Path::computeInnerControlPoints ( void  )
inline

Compute inner control points from key positions.

For each pair of subsequent key positions, compute two control points to define a Beziér Spline. Since we are restricting the splines to join with same position, and first two derivatives, the result is a smooth curve passing through all control points See reference at class info for more details.

To solve the tridiagonal system we use Thomas Algorithm (see Wikipedia)

int Tucano::Path::curveSegment ( float  t)
inline

returns the segment given a time t in [0,1] for the whole path

Returns
curve segment number
Eigen::Quaternion<float> Tucano::Path::directionAtCurrentTime ( void  )
inline

Return the direction at current animation time.

Returns
Interpolated direction as Quaternion at current animation time
Eigen::Quaternion<float> Tucano::Path::directionAtTime ( float  global_t)
inline

return a direction at a given path parameter

Returns
quaternion with interpolated direction
Eigen::Quaternionf Tucano::Path::expQuaternion ( const Eigen::Quaternionf &  q)
inline

Returns the exp of a quaternion exp(q) q in the form [0, a v], exp(q) = [cos(a), sin(a) v] with |v|=1.

Parameters
qGiven quaternion
Returns
exp(q)
void Tucano::Path::fillVertexData ( void  )
inline

Fill the vertices array.

void Tucano::Path::initialize ( string  shader_dir = "../effects/shaders/")
inline

Initializes shaders.

Parameters
shader_dirLocation of shader files
void Tucano::Path::initOpenGLMatrices ( void  )
inline

Initializes the view and projection matrices. They are all initialized as Identity matrices, but view is then translated by the defaultTranslation vector.

bool Tucano::Path::isAnimating ( void  )
inline

Returns if Animation is running or not.

Returns
True if animation is running, false otherwise
void Tucano::Path::loadFromFile ( const string  filename)
inline
Eigen::Quaternionf Tucano::Path::logQuaternion ( const Eigen::Quaternionf &  qi)
inline

Returns the log of a quaternion log(q) q in the form [cos(a), sin(a) v], log(q) = [0, a v].

Parameters
qiGiven quaternion
Returns
log(q)
Eigen::Vector4f Tucano::Path::pointOnPath ( float  global_t)
inline

compute point on path given t in [0,1]

Note that t refers to the whole path, so t=0 is the first key position and t=1 is the last key position

Parameters
global_tGlobal parameter on path in [0,1]
Eigen::Vector4f Tucano::Path::pointOnSegment ( float  t,
int  segment 
)
inline

Returns a point at time t on a given Beziér segment.

Parameters
tBeziér segment parameter
segmentBeziér segment on path
Returns
Point on curve
void Tucano::Path::printDebugInfo ( void  )
inline
void Tucano::Path::render ( const Tucano::Camera camera,
const Tucano::Camera light 
)
inline

Renders smooth path End points for each Beziér is passed as line_strip and control points as vertex attributes Inside geometry shader each Beziér segment is approximate by linear segments.

Parameters
cameraCurrent camera for viewing scene
lightCamera representing light (position and orientation)
void Tucano::Path::reset ( void  )
inline

Resets the path.

void Tucano::Path::resetAnimation ( void  )
inline

Resets animation to first key position.

void Tucano::Path::setAnimSpeed ( float  as)
inline

Sets the animation speed.

Parameters
asGiven animation speed
void Tucano::Path::setLoopAnimation ( bool  f)
inline

Set loop animation flag.

Parameters
fTrue for loop animation, false otherwise
Eigen::Quaternionf Tucano::Path::squad ( int  seg,
float  t 
)
inline

SQUAD - Spherical and Quadrangle quaternion interpolation.

Parameters
segThe current Bezièr segment
tInterpolatio time
void Tucano::Path::startAnimation ( void  )
inline

Start animation following camera path.

void Tucano::Path::stepBackward ( void  )
inline

Move animation backward one step.

void Tucano::Path::stepForward ( void  )
inline

Move animation forward one step.

void Tucano::Path::stopAnimation ( void  )
inline

Stop animation.

void Tucano::Path::toggleAnimation ( void  )
inline

Toggle animation.

void Tucano::Path::toggleDrawControlPoints ( void  )
inline

Toggle render control points.

void Tucano::Path::toggleDrawQuaternions ( void  )
inline

Toggle render control quaternions.

float Tucano::Path::toLocalParameter ( float  t)
inline

converts global parameter t to a local t inside a segment

Returns
Local parameter t in [0,1] for a single Cubic Beziér segment
void Tucano::Path::writeToFile ( const string  filename)
inline

Member Data Documentation

float Tucano::Path::anim_speed = 0.025
private

Movement speed, arc length increment for each animation step.

float Tucano::Path::anim_time = 0.0
private

Animation time.

bool Tucano::Path::animating = false
private

Start/stop animation.

vector< vector <float> > Tucano::Path::arc_lengths
private

Arc-length approximation splitting each Beziér segment into linear segments.

Shapes::CoordinateAxes Tucano::Path::axes
private

Coordinate axes for visualizing quaternions at key positions.

Shader Tucano::Path::camerapath_shader
private

Path shader, used for rendering the curve.

vector< Eigen::Vector4f > Tucano::Path::control_points_1
private

First control point between two key positions.

vector< Eigen::Vector4f > Tucano::Path::control_points_2
private

Second control point between two key positions.

vector< Eigen::Quaternion<float> > Tucano::Path::control_quaternions
private

Control quaternions for SQUAD.

Mesh Tucano::Path::control_segments
private
Mesh Tucano::Path::curve
private

Mesh with path's key positions and computed control points for drawing smooth curve between key positions

bool Tucano::Path::draw_control_points = false
private

Flag to render control points.

bool Tucano::Path::draw_quaternions = false
private

Flag to render quaternions at key positions.

vector< Eigen::Quaternion<float> > Tucano::Path::key_directions
private

Rotation only interpolation (via Slerp) useful for accompaning light direction for example.

vector< float > Tucano::Path::key_intervals
private

Steps to stay paused at a given key position, usually zero.

vector< Eigen::Vector4f > Tucano::Path::key_positions
private

Camera position at each Key frames.

vector< Eigen::Quaternion<float> > Tucano::Path::key_quaternions
private

Rotation state at each key frame.

bool Tucano::Path::loop_animation = false
private

Flag to loop animation.

float Tucano::Path::path_length
private

Total path length.

Shader Tucano::Path::phong_shader
private

To render simple lines.

Shapes::Sphere Tucano::Path::sphere
private

A sphere to visually represent the path's key positions.


The documentation for this class was generated from the following file: