OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sampler.h
Go to the documentation of this file.
1 /* -*-c++-*-
2  * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3  *
4  * This library is open source and may be redistributed and/or modified under
5  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6  * (at your option) any later version. The full license is in LICENSE file
7  * included with this distribution, and on the openscenegraph.org website.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * OpenSceneGraph Public License for more details.
13  *
14  * Authors:
15  * Cedric Pinson <cedric.pinson@plopbyte.net>
16  * Michael Platings <mplatings@pixelpower.com>
17  */
18 
19 #ifndef OSGANIMATION_SAMPLER
20 #define OSGANIMATION_SAMPLER 1
21 
22 #include <vector>
23 #include <iostream>
24 #include <osg/Referenced>
25 #include <osg/ref_ptr>
26 #include <osgAnimation/Keyframe>
27 #include <osgAnimation/Interpolator>
28 
29 namespace osgAnimation
30 {
31 
32  class Sampler : public osg::Referenced
33  {
34  public:
36  virtual const KeyframeContainer* getKeyframeContainer() const = 0;
37  protected:
38  };
39 
40  // Sampler generic
41  template <class F>
42  class TemplateSampler : public Sampler
43  {
44  public:
45  typedef typename F::KeyframeType KeyframeType;
47  typedef typename F::UsingType UsingType;
48  typedef F FunctorType;
49 
52 
53  void getValueAt(double time, UsingType& result) const { _functor.getValue(*_keyframes, time, result);}
54  void setKeyframeContainer(KeyframeContainerType* kf) { _keyframes = kf;}
55 
56  virtual KeyframeContainer* getKeyframeContainer() { return _keyframes.get(); }
57  virtual const KeyframeContainer* getKeyframeContainer() const { return _keyframes.get();}
58 
59  KeyframeContainerType* getKeyframeContainerTyped() { return _keyframes.get();}
60  const KeyframeContainerType* getKeyframeContainerTyped() const { return _keyframes.get();}
61  KeyframeContainerType* getOrCreateKeyframeContainer()
62  {
63  if (_keyframes != 0)
64  return _keyframes.get();
66  return _keyframes.get();
67  }
68 
69  double getStartTime() const
70  {
71  if (!_keyframes || _keyframes->empty())
72  return 0.0;
73  return _keyframes->front().getTime();
74  }
75 
76  double getEndTime() const
77  {
78  if (!_keyframes || _keyframes->empty())
79  return 0.0;
80  return _keyframes->back().getTime();
81  }
82 
83  protected:
84 
85  FunctorType _functor;
87  };
88 
89 
90  template<typename VALUESAMPLERTYPE, typename TIMESAMPLERTYPE>
92  {
93  VALUESAMPLERTYPE& _value;
94  TIMESAMPLERTYPE& _time;
95 
96  public:
97  typedef typename VALUESAMPLERTYPE::FunctorType::UsingType UsingType;
98  typedef typename VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType;
99 
100  TemplateCompositeSampler(VALUESAMPLERTYPE& value, TIMESAMPLERTYPE& time) : _value(value), _time(time)
101  {
102  }
103 
104  void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType& result)
105  {
106  double newtime;
107  _time.getValueAt(time, newtime);
108  _value.getValueAt(newtime, result);
109  }
110  float getStartTime() const {return _time.getStartTime(); }
111  float getEndTime() const {return _time.getEndTime();}
112  };
113 
114 
121 
129 
135 
136 }
137 
138 #endif
TemplateSampler< Vec3CubicBezierInterpolator > Vec3CubicBezierSampler
Definition: Sampler.h:133
double getEndTime() const
Definition: Sampler.h:76
TemplateSampler< Vec3StepInterpolator > Vec3StepSampler
Definition: Sampler.h:118
osg::ref_ptr< KeyframeContainerType > _keyframes
Definition: Sampler.h:86
TemplateSampler< DoubleLinearInterpolator > DoubleLinearSampler
Definition: Sampler.h:122
TemplateSampler< QuatSphericalLinearInterpolator > QuatSphericalLinearSampler
Definition: Sampler.h:127
TemplateSampler< Vec4StepInterpolator > Vec4StepSampler
Definition: Sampler.h:119
KeyframeContainerType * getOrCreateKeyframeContainer()
Definition: Sampler.h:61
double getStartTime() const
Definition: Sampler.h:69
TemplateSampler< MatrixLinearInterpolator > MatrixLinearSampler
Definition: Sampler.h:128
TemplateSampler< Vec4CubicBezierInterpolator > Vec4CubicBezierSampler
Definition: Sampler.h:134
TemplateSampler< Vec2StepInterpolator > Vec2StepSampler
Definition: Sampler.h:117
virtual const KeyframeContainer * getKeyframeContainer() const
Definition: Sampler.h:57
TemplateCompositeSampler(VALUESAMPLERTYPE &value, TIMESAMPLERTYPE &time)
Definition: Sampler.h:100
VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType
Definition: Sampler.h:98
TemplateSampler< FloatStepInterpolator > FloatStepSampler
Definition: Sampler.h:116
TemplateSampler< Vec2LinearInterpolator > Vec2LinearSampler
Definition: Sampler.h:124
KeyframeContainerType * getKeyframeContainerTyped()
Definition: Sampler.h:59
void setKeyframeContainer(KeyframeContainerType *kf)
Definition: Sampler.h:54
VALUESAMPLERTYPE::FunctorType::UsingType UsingType
Definition: Sampler.h:97
TemplateKeyframeContainer< KeyframeType > KeyframeContainerType
Definition: Sampler.h:46
TemplateSampler< Vec3LinearInterpolator > Vec3LinearSampler
Definition: Sampler.h:125
TemplateSampler< DoubleCubicBezierInterpolator > DoubleCubicBezierSampler
Definition: Sampler.h:131
TemplateSampler< Vec2CubicBezierInterpolator > Vec2CubicBezierSampler
Definition: Sampler.h:132
TemplateSampler< FloatCubicBezierInterpolator > FloatCubicBezierSampler
Definition: Sampler.h:130
TemplateSampler< DoubleStepInterpolator > DoubleStepSampler
Definition: Sampler.h:115
const KeyframeContainerType * getKeyframeContainerTyped() const
Definition: Sampler.h:60
TemplateSampler< FloatLinearInterpolator > FloatLinearSampler
Definition: Sampler.h:123
virtual KeyframeContainer * getKeyframeContainer()
Definition: Sampler.h:56
F::KeyframeType KeyframeType
Definition: Sampler.h:45
void getValueAt(double time, UsingType &result) const
Definition: Sampler.h:53
virtual KeyframeContainer * getKeyframeContainer()=0
TemplateSampler< QuatStepInterpolator > QuatStepSampler
Definition: Sampler.h:120
TemplateSampler< Vec4LinearInterpolator > Vec4LinearSampler
Definition: Sampler.h:126
void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType &result)
Definition: Sampler.h:104