Choreonoid  1.1
Seq.h
[詳解]
1 
6 #ifndef CNOID_UTIL_SEQ_H_INCLUDED
7 #define CNOID_UTIL_SEQ_H_INCLUDED
8 
9 #include "SeqBase.h"
10 #include <vector>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15  template <typename ElementType> class Seq : public SeqBase
16  {
17  public:
18  typedef boost::shared_ptr< Seq<ElementType> > Ptr;
19 
20  Seq(const char* seqType, int nFrames = 0.0, double frameRate = 100.0)
21  : SeqBase(seqType),
22  container(nFrames) {
24  }
25 
26  Seq(const Seq<ElementType>& org)
27  : SeqBase(org),
28  container(org.container) {
29  frameRate_ = org.frameRate_;
30  }
31 
32  virtual ~Seq() { }
33 
34  virtual double getFrameRate() const {
35  return frameRate_;
36  }
37 
38  inline double frameRate() const {
39  return frameRate_;
40  }
41 
42  virtual void setFrameRate(double frameRate) {
44  }
45 
46  virtual int getNumFrames() const {
47  return container.size();
48  }
49 
50  inline int numFrames() const {
51  return container.size();
52  }
53 
54  virtual void setNumFrames(int n, bool clearNewElements = false) {
55  if(clearNewElements){
56  container.resize(n, defaultValue());
57  } else {
58  container.resize(n);
59  }
60  }
61 
62  inline bool empty() const {
63  return container.empty();
64  }
65 
66  inline int frameOfTime(double time) const {
67  return (int)(time * frameRate_);
68  }
69 
70  inline double timeOfFrame(int frame) const {
71  return (frame / frameRate_);
72  }
73 
74  inline ElementType& operator[](int frameIndex) {
75  return container[frameIndex];
76  }
77 
78  inline const ElementType& operator[](int frameIndex) const {
79  return container[frameIndex];
80  }
81 
82  inline ElementType& at(int frameIndex) {
83  return container[frameIndex];
84  }
85 
86  inline const ElementType& at(int frameIndex) const {
87  return container[frameIndex];
88  }
89 
90  virtual bool read(const YamlMapping& archive) { return SeqBase::read(archive); }
91  virtual bool write(YamlWriter& writer) { return SeqBase::write(writer); }
92 
93  protected:
94 
95  std::vector<ElementType> container;
96  double frameRate_;
97 
98  virtual ElementType defaultValue() const { return ElementType(); }
99  };
100 }
101 
102 #endif
Definition: YamlWriter.h:18
virtual void setFrameRate(double frameRate)
Definition: Seq.h:42
const ElementType & at(int frameIndex) const
Definition: Seq.h:86
virtual bool write(YamlWriter &writer)
Definition: SeqBase.cpp:43
int frameOfTime(double time) const
Definition: Seq.h:66
boost::shared_ptr< Seq< ElementType > > Ptr
Definition: Seq.h:18
bool empty() const
Definition: Seq.h:62
ElementType & at(int frameIndex)
Definition: Seq.h:82
virtual ElementType defaultValue() const
Definition: Seq.h:98
const std::string & seqType() const
Definition: SeqBase.h:28
virtual ~Seq()
Definition: Seq.h:32
Definition: Seq.h:15
Definition: SeqBase.h:20
std::vector< ElementType > container
Definition: Seq.h:95
Definition: EasyScanner.h:16
virtual bool write(YamlWriter &writer)
Definition: Seq.h:91
virtual double getFrameRate() const
Definition: Seq.h:34
Seq(const char *seqType, int nFrames=0.0, double frameRate=100.0)
Definition: Seq.h:20
ElementType & operator[](int frameIndex)
Definition: Seq.h:74
Definition: YamlNodes.h:212
Seq(const Seq< ElementType > &org)
Definition: Seq.h:26
virtual bool read(const YamlMapping &archive)
Definition: SeqBase.cpp:35
double frameRate() const
Definition: Seq.h:38
const ElementType & operator[](int frameIndex) const
Definition: Seq.h:78
int numFrames() const
Definition: Seq.h:50
double frameRate_
Definition: Seq.h:96
double timeOfFrame(int frame) const
Definition: Seq.h:70
virtual bool read(const YamlMapping &archive)
Definition: Seq.h:90
virtual int getNumFrames() const
Definition: Seq.h:46
virtual void setNumFrames(int n, bool clearNewElements=false)
Definition: Seq.h:54