Loading...
Searching...
No Matches
keyFrameMap.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24
25#ifndef PXR_BASE_TS_KEY_FRAME_MAP_H
26#define PXR_BASE_TS_KEY_FRAME_MAP_H
27
28#include "pxr/pxr.h"
29#include "pxr/base/ts/api.h"
30#include "pxr/base/ts/keyFrame.h"
31#include "pxr/base/tf/stl.h"
32
33PXR_NAMESPACE_OPEN_SCOPE
34
51
52public:
53 typedef std::vector<TsKeyFrame>::iterator iterator;
54 typedef std::vector<TsKeyFrame>::const_iterator const_iterator;
55 typedef std::vector<TsKeyFrame>::reverse_iterator reverse_iterator;
56 typedef std::vector<TsKeyFrame>::const_reverse_iterator const_reverse_iterator;
57
58 TS_API
60 }
61
62 TS_API
63 TsKeyFrameMap(TsKeyFrameMap const& other) :
64 _data(other._data) {
65 }
66
67 TS_API
68 TsKeyFrameMap& operator=(TsKeyFrameMap const& other) {
69 _data = other._data;
70 return *this;
71 }
72
73 TS_API
74 iterator begin() {
75 return _data.begin();
76 }
77
78 TS_API
79 const_iterator begin() const {
80 return _data.begin();
81 }
82
83 TS_API
84 iterator end() {
85 return _data.end();
86 }
87
88 TS_API
89 const_iterator end() const {
90 return _data.end();
91 }
92
93 TS_API
94 reverse_iterator rbegin() {
95 return _data.rbegin();
96 }
97
98 TS_API
99 const_reverse_iterator rbegin() const {
100 return _data.rbegin();
101 }
102
103 TS_API
104 reverse_iterator rend() {
105 return _data.rend();
106 }
107
108 TS_API
109 const_reverse_iterator rend() const {
110 return _data.rend();
111 }
112
113 TS_API
114 size_t size() const {
115 return _data.size();
116 }
117
118 TS_API
119 size_t max_size() const {
120 return _data.max_size();
121 }
122
123 TS_API
124 bool empty() const {
125 return _data.empty();
126 }
127
128 TS_API
129 void reserve(size_t size) {
130 _data.reserve(size);
131 }
132
133 TS_API
134 void clear() {
135 _data.clear();
136 }
137
138 TS_API
139 void swap(TsKeyFrameMap& other) {
140 other._data.swap(_data);
141 }
142
143 TS_API
144 void swap(std::vector<TsKeyFrame>& other) {
145 other.swap(_data);
146 }
147
148 TS_API
149 void erase(iterator first, iterator last) {
150 _data.erase(first,last);
151 }
152
153 TS_API
154 void erase(iterator i) {
155 _data.erase(i);
156 }
157
158 TS_API
159 bool operator==(const TsKeyFrameMap& other) const {
160 return (_data == other._data);
161 }
162
163 TS_API
164 bool operator!=(const TsKeyFrameMap& other) const {
165 return (_data != other._data);
166 }
167
168 TS_API
169 iterator lower_bound(TsTime t);
170
171 TS_API
172 const_iterator lower_bound(TsTime t) const;
173
174 TS_API
175 iterator upper_bound(TsTime t);
176
177 TS_API
178 const_iterator upper_bound(TsTime t) const;
179
180 TS_API
181 iterator find(const TsTime &t) {
182 iterator i = lower_bound(t);
183 if (i != _data.end() && i->GetTime() == t) {
184 return i;
185 }
186 return _data.end();
187 }
188
189 TS_API
190 const_iterator find(const TsTime &t) const {
191 const_iterator i = lower_bound(t);
192 if (i != _data.end() && i->GetTime() == t) {
193 return i;
194 }
195 return _data.end();
196 }
197
198 TS_API
199 iterator insert(TsKeyFrame const& value) {
200 // If the inserted value comes at the end, then avoid doing the
201 // lower_bound and just insert there.
202 iterator i = end();
203 if (!empty() && value.GetTime() <= _data.back().GetTime()) {
204 i = lower_bound(value.GetTime());
205 }
206
207 return _data.insert(i,value);
208 }
209
210 template <class Iter>
211 void insert(Iter const& first, Iter const& last) {
212 for(Iter i = first; i != last; i++) {
213 insert(*i);
214 }
215 }
216
217 TS_API
218 void erase(TsTime const& t) {
219 iterator i = find(t);
220 if (i != _data.end()) {
221 erase(i);
222 }
223 }
224
225 TS_API
226 TsKeyFrame& operator[](const TsTime& t) {
227 iterator i = lower_bound(t);
228 if (i != _data.end() && i->GetTime() == t) {
229 return *i;
230 }
231 TsKeyFrame &k = *(_data.insert(i,TsKeyFrame()));
232 k.SetTime(t);
233 return k;
234 }
235
236private:
237 std::vector<TsKeyFrame> _data;
238};
239
240PXR_NAMESPACE_CLOSE_SCOPE
241
242#endif
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:67
TS_API void SetTime(const TsTime &newTime)
Sets the time of this keyframe.
Definition: keyFrame.h:162
TS_API TsTime GetTime() const
Gets the time of this keyframe.
Definition: keyFrame.h:156
An ordered sequence of keyframes with STL-compliant API for finding, inserting, and erasing keyframes...
Definition: keyFrameMap.h:50