osgAnimation/Sampler
Go to the documentation of this file.
/* -*-c++-*-
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*
* Authors:
* Cedric Pinson <cedric.pinson@plopbyte.net>
* Michael Platings <mplatings@pixelpower.com>
*/
#ifndef OSGANIMATION_SAMPLER
#define OSGANIMATION_SAMPLER 1
#include <vector>
#include <iostream>
#include <osg/Referenced>
#include <osg/ref_ptr>
#include <osgAnimation/Keyframe>
#include <osgAnimation/Interpolator>
namespace osgAnimation
{
class Sampler : public osg::Referenced
{
public:
virtual KeyframeContainer* getKeyframeContainer() = 0;
virtual const KeyframeContainer* getKeyframeContainer() const = 0;
protected:
};
// Sampler generic
template <class F>
class TemplateSampler : public Sampler
{
public:
typedef typename F::KeyframeType KeyframeType;
typedef TemplateKeyframeContainer<KeyframeType> KeyframeContainerType;
typedef typename F::UsingType UsingType;
typedef F FunctorType;
TemplateSampler() {}
~TemplateSampler() {}
void getValueAt(double time, UsingType& result) const { _functor.getValue(*_keyframes, time, result);}
void setKeyframeContainer(KeyframeContainerType* kf) { _keyframes = kf;}
virtual KeyframeContainer* getKeyframeContainer() { return _keyframes.get(); }
virtual const KeyframeContainer* getKeyframeContainer() const { return _keyframes.get();}
KeyframeContainerType* getKeyframeContainerTyped() { return _keyframes.get();}
const KeyframeContainerType* getKeyframeContainerTyped() const { return _keyframes.get();}
KeyframeContainerType* getOrCreateKeyframeContainer()
{
if (_keyframes != 0)
return _keyframes.get();
_keyframes = new KeyframeContainerType;
return _keyframes.get();
}
double getStartTime() const
{
if (!_keyframes || _keyframes->empty())
return 0.0;
return _keyframes->front().getTime();
}
double getEndTime() const
{
if (!_keyframes || _keyframes->empty())
return 0.0;
return _keyframes->back().getTime();
}
protected:
FunctorType _functor;
osg::ref_ptr<KeyframeContainerType> _keyframes;
};
template<typename VALUESAMPLERTYPE, typename TIMESAMPLERTYPE>
class TemplateCompositeSampler : public osg::Referenced
{
VALUESAMPLERTYPE& _value;
TIMESAMPLERTYPE& _time;
public:
typedef typename VALUESAMPLERTYPE::FunctorType::UsingType UsingType;
typedef typename VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType;
TemplateCompositeSampler(VALUESAMPLERTYPE& value, TIMESAMPLERTYPE& time) : _value(value), _time(time)
{
}
void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType& result)
{
double newtime;
_time.getValueAt(time, newtime);
_value.getValueAt(newtime, result);
}
float getStartTime() const {return _time.getStartTime(); }
float getEndTime() const {return _time.getEndTime();}
};
typedef TemplateSampler<DoubleStepInterpolator> DoubleStepSampler;
typedef TemplateSampler<FloatStepInterpolator> FloatStepSampler;
typedef TemplateSampler<Vec2StepInterpolator> Vec2StepSampler;
typedef TemplateSampler<Vec3StepInterpolator> Vec3StepSampler;
typedef TemplateSampler<Vec4StepInterpolator> Vec4StepSampler;
typedef TemplateSampler<QuatStepInterpolator> QuatStepSampler;
typedef TemplateSampler<DoubleLinearInterpolator> DoubleLinearSampler;
typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
typedef TemplateSampler<MatrixLinearInterpolator> MatrixLinearSampler;
typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;
typedef TemplateSampler<DoubleCubicBezierInterpolator> DoubleCubicBezierSampler;
typedef TemplateSampler<Vec2CubicBezierInterpolator> Vec2CubicBezierSampler;
typedef TemplateSampler<Vec3CubicBezierInterpolator> Vec3CubicBezierSampler;
typedef TemplateSampler<Vec4CubicBezierInterpolator> Vec4CubicBezierSampler;
}
#endif
Keyframe
Referenced
osgAnimation::KeyframeContainer
Definition Keyframe:67
osgAnimation::Sampler
Definition osgAnimation/Sampler:33
osgAnimation::Sampler::getKeyframeContainer
virtual const KeyframeContainer * getKeyframeContainer() const =0
osgAnimation::Sampler::getKeyframeContainer
virtual KeyframeContainer * getKeyframeContainer()=0
osgAnimation::TemplateCompositeSampler::TemplateCompositeSampler
TemplateCompositeSampler(VALUESAMPLERTYPE &value, TIMESAMPLERTYPE &time)
Definition osgAnimation/Sampler:100
osgAnimation::TemplateCompositeSampler::getStartTime
float getStartTime() const
Definition osgAnimation/Sampler:110
osgAnimation::TemplateCompositeSampler::KeyframeType
VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType
Definition osgAnimation/Sampler:98
osgAnimation::TemplateCompositeSampler::getEndTime
float getEndTime() const
Definition osgAnimation/Sampler:111
osgAnimation::TemplateCompositeSampler::getValueAt
void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType &result)
Definition osgAnimation/Sampler:104
osgAnimation::TemplateCompositeSampler::UsingType
VALUESAMPLERTYPE::FunctorType::UsingType UsingType
Definition osgAnimation/Sampler:97
osgAnimation::TemplateKeyframeContainer
Definition Keyframe:80
osgAnimation::TemplateSampler
Definition osgAnimation/Sampler:43
osgAnimation::TemplateSampler::TemplateSampler
TemplateSampler()
Definition osgAnimation/Sampler:50
osgAnimation::TemplateSampler::setKeyframeContainer
void setKeyframeContainer(KeyframeContainerType *kf)
Definition osgAnimation/Sampler:54
osgAnimation::TemplateSampler::getKeyframeContainer
virtual const KeyframeContainer * getKeyframeContainer() const
Definition osgAnimation/Sampler:57
osgAnimation::TemplateSampler::getEndTime
double getEndTime() const
Definition osgAnimation/Sampler:76
osgAnimation::TemplateSampler::UsingType
F::UsingType UsingType
Definition osgAnimation/Sampler:47
osgAnimation::TemplateSampler< DoubleStepInterpolator >::_keyframes
osg::ref_ptr< KeyframeContainerType > _keyframes
Definition osgAnimation/Sampler:86
osgAnimation::TemplateSampler::getKeyframeContainerTyped
const KeyframeContainerType * getKeyframeContainerTyped() const
Definition osgAnimation/Sampler:60
osgAnimation::TemplateSampler::getKeyframeContainerTyped
KeyframeContainerType * getKeyframeContainerTyped()
Definition osgAnimation/Sampler:59
osgAnimation::TemplateSampler::getValueAt
void getValueAt(double time, UsingType &result) const
Definition osgAnimation/Sampler:53
osgAnimation::TemplateSampler::~TemplateSampler
~TemplateSampler()
Definition osgAnimation/Sampler:51
osgAnimation::TemplateSampler< DoubleStepInterpolator >::_functor
FunctorType _functor
Definition osgAnimation/Sampler:85
osgAnimation::TemplateSampler::KeyframeType
F::KeyframeType KeyframeType
Definition osgAnimation/Sampler:45
osgAnimation::TemplateSampler::getStartTime
double getStartTime() const
Definition osgAnimation/Sampler:69
osgAnimation::TemplateSampler::getKeyframeContainer
virtual KeyframeContainer * getKeyframeContainer()
Definition osgAnimation/Sampler:56
osgAnimation::TemplateSampler::KeyframeContainerType
TemplateKeyframeContainer< KeyframeType > KeyframeContainerType
Definition osgAnimation/Sampler:46
osgAnimation::TemplateSampler::getOrCreateKeyframeContainer
KeyframeContainerType * getOrCreateKeyframeContainer()
Definition osgAnimation/Sampler:61
osgAnimation::TemplateSampler::FunctorType
F FunctorType
Definition osgAnimation/Sampler:48
osg::Referenced
Definition Referenced:44
osg::ref_ptr
Definition ref_ptr:32
osgAnimation
Definition Action:34
osgAnimation::Vec3StepSampler
TemplateSampler< Vec3StepInterpolator > Vec3StepSampler
Definition osgAnimation/Sampler:118
osgAnimation::Vec4LinearSampler
TemplateSampler< Vec4LinearInterpolator > Vec4LinearSampler
Definition osgAnimation/Sampler:126
osgAnimation::FloatLinearSampler
TemplateSampler< FloatLinearInterpolator > FloatLinearSampler
Definition osgAnimation/Sampler:123
osgAnimation::Vec3CubicBezierSampler
TemplateSampler< Vec3CubicBezierInterpolator > Vec3CubicBezierSampler
Definition osgAnimation/Sampler:133
osgAnimation::DoubleStepSampler
TemplateSampler< DoubleStepInterpolator > DoubleStepSampler
Definition osgAnimation/Sampler:115
osgAnimation::FloatStepSampler
TemplateSampler< FloatStepInterpolator > FloatStepSampler
Definition osgAnimation/Sampler:116
osgAnimation::Vec4StepSampler
TemplateSampler< Vec4StepInterpolator > Vec4StepSampler
Definition osgAnimation/Sampler:119
osgAnimation::MatrixLinearSampler
TemplateSampler< MatrixLinearInterpolator > MatrixLinearSampler
Definition osgAnimation/Sampler:128
osgAnimation::Vec3LinearSampler
TemplateSampler< Vec3LinearInterpolator > Vec3LinearSampler
Definition osgAnimation/Sampler:125
osgAnimation::Vec2StepSampler
TemplateSampler< Vec2StepInterpolator > Vec2StepSampler
Definition osgAnimation/Sampler:117
osgAnimation::DoubleLinearSampler
TemplateSampler< DoubleLinearInterpolator > DoubleLinearSampler
Definition osgAnimation/Sampler:122
osgAnimation::FloatCubicBezierSampler
TemplateSampler< FloatCubicBezierInterpolator > FloatCubicBezierSampler
Definition osgAnimation/Sampler:130
osgAnimation::QuatSphericalLinearSampler
TemplateSampler< QuatSphericalLinearInterpolator > QuatSphericalLinearSampler
Definition osgAnimation/Sampler:127
osgAnimation::Vec2LinearSampler
TemplateSampler< Vec2LinearInterpolator > Vec2LinearSampler
Definition osgAnimation/Sampler:124
osgAnimation::QuatStepSampler
TemplateSampler< QuatStepInterpolator > QuatStepSampler
Definition osgAnimation/Sampler:120
osgAnimation::Vec4CubicBezierSampler
TemplateSampler< Vec4CubicBezierInterpolator > Vec4CubicBezierSampler
Definition osgAnimation/Sampler:134
osgAnimation::DoubleCubicBezierSampler
TemplateSampler< DoubleCubicBezierInterpolator > DoubleCubicBezierSampler
Definition osgAnimation/Sampler:131
osgAnimation::Vec2CubicBezierSampler
TemplateSampler< Vec2CubicBezierInterpolator > Vec2CubicBezierSampler
Definition osgAnimation/Sampler:132
Interpolator
ref_ptr