Loading...
Searching...
No Matches
keyFrameMap.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TS_KEY_FRAME_MAP_H
9#define PXR_BASE_TS_KEY_FRAME_MAP_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/api.h"
13#include "pxr/base/ts/keyFrame.h"
14#include "pxr/base/tf/stl.h"
15
16PXR_NAMESPACE_OPEN_SCOPE
17
34
35public:
36 typedef std::vector<TsKeyFrame>::iterator iterator;
37 typedef std::vector<TsKeyFrame>::const_iterator const_iterator;
38 typedef std::vector<TsKeyFrame>::reverse_iterator reverse_iterator;
39 typedef std::vector<TsKeyFrame>::const_reverse_iterator const_reverse_iterator;
40
41 TS_API
43 }
44
45 TS_API
46 TsKeyFrameMap(TsKeyFrameMap const& other) :
47 _data(other._data) {
48 }
49
50 TS_API
51 TsKeyFrameMap& operator=(TsKeyFrameMap const& other) {
52 _data = other._data;
53 return *this;
54 }
55
56 TS_API
57 iterator begin() {
58 return _data.begin();
59 }
60
61 TS_API
62 const_iterator begin() const {
63 return _data.begin();
64 }
65
66 TS_API
67 iterator end() {
68 return _data.end();
69 }
70
71 TS_API
72 const_iterator end() const {
73 return _data.end();
74 }
75
76 TS_API
77 reverse_iterator rbegin() {
78 return _data.rbegin();
79 }
80
81 TS_API
82 const_reverse_iterator rbegin() const {
83 return _data.rbegin();
84 }
85
86 TS_API
87 reverse_iterator rend() {
88 return _data.rend();
89 }
90
91 TS_API
92 const_reverse_iterator rend() const {
93 return _data.rend();
94 }
95
96 TS_API
97 size_t size() const {
98 return _data.size();
99 }
100
101 TS_API
102 size_t max_size() const {
103 return _data.max_size();
104 }
105
106 TS_API
107 bool empty() const {
108 return _data.empty();
109 }
110
111 TS_API
112 void reserve(size_t size) {
113 _data.reserve(size);
114 }
115
116 TS_API
117 void clear() {
118 _data.clear();
119 }
120
121 TS_API
122 void swap(TsKeyFrameMap& other) {
123 other._data.swap(_data);
124 }
125
126 TS_API
127 void swap(std::vector<TsKeyFrame>& other) {
128 other.swap(_data);
129 }
130
131 TS_API
132 void erase(iterator first, iterator last) {
133 _data.erase(first,last);
134 }
135
136 TS_API
137 void erase(iterator i) {
138 _data.erase(i);
139 }
140
141 TS_API
142 bool operator==(const TsKeyFrameMap& other) const {
143 return (_data == other._data);
144 }
145
146 TS_API
147 bool operator!=(const TsKeyFrameMap& other) const {
148 return (_data != other._data);
149 }
150
151 TS_API
152 iterator lower_bound(TsTime t);
153
154 TS_API
155 const_iterator lower_bound(TsTime t) const;
156
157 TS_API
158 iterator upper_bound(TsTime t);
159
160 TS_API
161 const_iterator upper_bound(TsTime t) const;
162
163 TS_API
164 iterator find(const TsTime &t) {
165 iterator i = lower_bound(t);
166 if (i != _data.end() && i->GetTime() == t) {
167 return i;
168 }
169 return _data.end();
170 }
171
172 TS_API
173 const_iterator find(const TsTime &t) const {
174 const_iterator i = lower_bound(t);
175 if (i != _data.end() && i->GetTime() == t) {
176 return i;
177 }
178 return _data.end();
179 }
180
181 TS_API
182 iterator insert(TsKeyFrame const& value) {
183 // If the inserted value comes at the end, then avoid doing the
184 // lower_bound and just insert there.
185 iterator i = end();
186 if (!empty() && value.GetTime() <= _data.back().GetTime()) {
187 i = lower_bound(value.GetTime());
188 }
189
190 return _data.insert(i,value);
191 }
192
193 template <class Iter>
194 void insert(Iter const& first, Iter const& last) {
195 for(Iter i = first; i != last; i++) {
196 insert(*i);
197 }
198 }
199
200 TS_API
201 void erase(TsTime const& t) {
202 iterator i = find(t);
203 if (i != _data.end()) {
204 erase(i);
205 }
206 }
207
208 TS_API
209 TsKeyFrame& operator[](const TsTime& t) {
210 iterator i = lower_bound(t);
211 if (i != _data.end() && i->GetTime() == t) {
212 return *i;
213 }
214 TsKeyFrame &k = *(_data.insert(i,TsKeyFrame()));
215 k.SetTime(t);
216 return k;
217 }
218
219private:
220 std::vector<TsKeyFrame> _data;
221};
222
223PXR_NAMESPACE_CLOSE_SCOPE
224
225#endif
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:50
TS_API void SetTime(const TsTime &newTime)
Sets the time of this keyframe.
Definition: keyFrame.h:145
TS_API TsTime GetTime() const
Gets the time of this keyframe.
Definition: keyFrame.h:139
An ordered sequence of keyframes with STL-compliant API for finding, inserting, and erasing keyframes...
Definition: keyFrameMap.h:33