All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clip.h
1 //
2 // Copyright 2016 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 #ifndef USD_CLIP_H
25 #define USD_CLIP_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/layerStack.h"
29 
30 #include "pxr/usd/sdf/assetPath.h"
31 #include "pxr/usd/sdf/layer.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/usd/sdf/propertySpec.h"
34 
35 #include <boost/optional.hpp>
36 
37 #include <iosfwd>
38 #include <map>
39 #include <memory>
40 #include <mutex>
41 #include <utility>
42 #include <vector>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 class PcpPrimIndex;
47 class Usd_InterpolatorBase;
48 
51 bool
52 UsdIsClipRelatedField(const TfToken& fieldName);
53 
55 std::vector<TfToken>
56 UsdGetClipRelatedFields();
57 
62 struct Usd_ResolvedClipInfo
63 {
64  Usd_ResolvedClipInfo() : indexOfLayerWhereAssetPathsFound(0) { }
65 
66  bool operator==(const Usd_ResolvedClipInfo& rhs) const
67  {
68  return (clipAssetPaths == rhs.clipAssetPaths
69  && clipManifestAssetPath == rhs.clipManifestAssetPath
70  && clipPrimPath == rhs.clipPrimPath
71  && clipActive == rhs.clipActive
72  && clipTimes == rhs.clipTimes
73  && sourceLayerStack == rhs.sourceLayerStack
74  && sourcePrimPath == rhs.sourcePrimPath
75  && indexOfLayerWhereAssetPathsFound
76  == rhs.indexOfLayerWhereAssetPathsFound);
77  }
78 
79  bool operator!=(const Usd_ResolvedClipInfo& rhs) const
80  {
81  return !(*this == rhs);
82  }
83 
84  size_t GetHash() const
85  {
86  size_t hash = indexOfLayerWhereAssetPathsFound;
87  boost::hash_combine(hash, sourceLayerStack);
88  boost::hash_combine(hash, sourcePrimPath);
89 
90  if (clipAssetPaths) {
91  for (const auto& assetPath : *clipAssetPaths) {
92  boost::hash_combine(hash, assetPath.GetHash());
93  }
94  }
95  if (clipManifestAssetPath) {
96  boost::hash_combine(hash, clipManifestAssetPath->GetHash());
97  }
98  if (clipPrimPath) {
99  boost::hash_combine(hash, *clipPrimPath);
100  }
101  if (clipActive) {
102  for (const auto& active : *clipActive) {
103  boost::hash_combine(hash, active[0]);
104  boost::hash_combine(hash, active[1]);
105  }
106  }
107  if (clipTimes) {
108  for (const auto& time : *clipTimes) {
109  boost::hash_combine(hash, time[0]);
110  boost::hash_combine(hash, time[1]);
111  }
112  }
113 
114  return hash;
115  }
116 
117  boost::optional<VtArray<SdfAssetPath> > clipAssetPaths;
118  boost::optional<SdfAssetPath> clipManifestAssetPath;
119  boost::optional<std::string> clipPrimPath;
120  boost::optional<VtVec2dArray> clipActive;
121  boost::optional<VtVec2dArray> clipTimes;
122 
123  PcpLayerStackPtr sourceLayerStack;
124  SdfPath sourcePrimPath;
125  size_t indexOfLayerWhereAssetPathsFound;
126 };
127 
131 bool
132 Usd_ResolveClipInfo(
133  const PcpPrimIndex& primIndex,
134  std::vector<Usd_ResolvedClipInfo>* clipInfo);
135 
137 constexpr double Usd_ClipTimesEarliest = -std::numeric_limits<double>::max();
138 constexpr double Usd_ClipTimesLatest = std::numeric_limits<double>::max();
139 
145 struct Usd_Clip
146 {
147  Usd_Clip(Usd_Clip const &) = delete;
148  Usd_Clip &operator=(Usd_Clip const &) = delete;
149 public:
172  typedef double ExternalTime;
173  typedef double InternalTime;
174  struct TimeMapping {
175  ExternalTime externalTime;
176  InternalTime internalTime;
177 
178  TimeMapping() {}
179  TimeMapping(const ExternalTime e, const InternalTime i)
180  : externalTime(e),
181  internalTime(i)
182  {}
183  };
184 
185  typedef std::vector<TimeMapping> TimeMappings;
186 
187  Usd_Clip();
188  Usd_Clip(
189  const PcpLayerStackPtr& clipSourceLayerStack,
190  const SdfPath& clipSourcePrimPath,
191  size_t clipSourceLayerIndex,
192  const SdfAssetPath& clipAssetPath,
193  const SdfPath& clipPrimPath,
194  ExternalTime clipStartTime,
195  ExternalTime clipEndTime,
196  const TimeMappings& timeMapping);
197 
198  bool HasField(const SdfPath& path, const TfToken& field) const;
199 
200  SdfPropertySpecHandle GetPropertyAtPath(const SdfPath& path) const;
201 
202  template <class T>
203  bool HasField(
204  const SdfPath& path, const TfToken& field,
205  T* value) const
206  {
207  return _GetLayerForClip()->HasField(
208  _TranslatePathToClip(path), field, value);
209  }
210 
211  size_t GetNumTimeSamplesForPath(const SdfPath& path) const;
212 
213  // Internal function used during value resolution. When determining
214  // resolve info sources, value resolution needs to determine when clipTimes
215  // are mapping into an empty clip with no samples, so it can continue
216  // searching for value sources.
217  size_t _GetNumTimeSamplesForPathInLayerForClip(
218  const SdfPath& path) const
219  {
220  return _GetLayerForClip()->GetNumTimeSamplesForPath(
221  _TranslatePathToClip(path));
222  }
223 
224  std::set<ExternalTime>
225  ListTimeSamplesForPath(const SdfPath& path) const;
226 
227  bool GetBracketingTimeSamplesForPath(
228  const SdfPath& path, ExternalTime time,
229  ExternalTime* tLower, ExternalTime* tUpper) const;
230 
231  template <class T>
232  bool QueryTimeSample(
233  const SdfPath& path, ExternalTime time,
234  Usd_InterpolatorBase* interpolator, T* value) const;
235 
242  SdfLayerHandle GetLayerIfOpen() const;
243 
246  PcpLayerStackPtr sourceLayerStack;
247  SdfPath sourcePrimPath;
248  size_t sourceLayerIndex;
249 
252  SdfAssetPath assetPath;
253  SdfPath primPath;
254 
256  ExternalTime startTime;
257  ExternalTime endTime;
258 
260  TimeMappings times;
261 
262 private:
263  friend class UsdStage;
264 
265  std::set<InternalTime>
266  _GetMergedTimeSamplesForPath(const SdfPath& path) const;
267 
268  bool
269  _GetBracketingTimeSamplesForPathInternal(const SdfPath& path,
270  ExternalTime time,
271  ExternalTime* tLower,
272  ExternalTime* tUpper) const;
273 
274  SdfPath _TranslatePathToClip(const SdfPath &path) const;
275 
276  // Helpers to translate between internal and external time domains.
277  InternalTime _TranslateTimeToInternal(
278  ExternalTime extTime) const;
279  ExternalTime _TranslateTimeToExternal(
280  InternalTime clipTime, TimeMapping m1, TimeMapping m2) const;
281 
282  SdfLayerRefPtr _GetLayerForClip() const;
283 
284 private:
285  mutable bool _hasLayer;
286  mutable std::mutex _layerMutex;
287  mutable SdfLayerRefPtr _layer;
288 };
289 
290 typedef std::shared_ptr<Usd_Clip> Usd_ClipRefPtr;
291 typedef std::vector<Usd_ClipRefPtr> Usd_ClipRefPtrVector;
292 
293 std::ostream&
294 operator<<(std::ostream& out, const Usd_ClipRefPtr& clip);
295 
296 PXR_NAMESPACE_CLOSE_SCOPE
297 
298 #endif // USD_CLIP_H
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:77
The outermost container for scene description, which owns and presents composed prims as a scenegraph...
Definition: stage.h:142
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Contains an asset path and an optional resolved path.
Definition: assetPath.h:43
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.