HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
layerOffset.h
Go to the documentation of this file.
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 PXR_USD_SDF_LAYER_OFFSET_H
25 #define PXR_USD_SDF_LAYER_OFFSET_H
26 
27 /// \file sdf/layerOffset.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 
32 #include <hboost/operators.hpp>
33 #include <iosfwd>
34 #include <vector>
35 
37 
38 class SdfTimeCode;
39 
40 /// \class SdfLayerOffset
41 ///
42 /// Represents a time offset and scale between layers.
43 ///
44 /// The SdfLayerOffset class is an affine transform, providing both a scale and
45 /// a translate. It supports vector algebra semantics for composing
46 /// SdfLayerOffsets together via multiplication. The SdfLayerOffset class is
47 /// unitless: it does not refer to seconds or frames.
48 ///
49 /// For example, suppose layer A uses layer B, with an offset of X:
50 /// when bringing animation from B into A, you first apply the scale of X, and
51 /// then the offset. Suppose you have a scale of 2 and an offset of 24:
52 /// first multiply B's frame numbers by 2, and then add 24. The animation from
53 /// B as seen in A will take twice as long and start 24 frames later.
54 ///
55 /// Offsets are typically used in either sublayers or prim references. For more
56 /// information, see the SetSubLayerOffset() method of the SdfLayer class (the
57 /// subLayerOffsets property in Python), as well as the SetReference() and
58 /// GetReferenceLayerOffset() methods (the latter is the referenceLayerOffset
59 /// property in Python) of the SdfPrimSpec class.
60 ///
61 class SdfLayerOffset : public hboost::totally_ordered<SdfLayerOffset>
62 {
63 public:
64  /// \name Constructors
65  /// @{
66 
67  /// Constructs a new SdfLayerOffset instance.
68  SDF_API
69  explicit SdfLayerOffset(double offset = 0.0, double scale = 1.0);
70 
71  /// @}
72 
73  /// \name Accessors
74  /// @{
75 
76  /// Returns the time offset.
77  double GetOffset() const { return _offset; }
78 
79  /// Returns the time scale factor.
80  double GetScale() const { return _scale; }
81 
82  /// Sets the time offset.
83  void SetOffset(double newOffset) { _offset = newOffset; }
84 
85  /// Sets the time scale factor.
86  void SetScale(double newScale) { _scale = newScale; }
87 
88  /// Returns \c true if this is an identity transformation, with
89  /// an offset of 0.0 and a scale of 1.0.
90  SDF_API
91  bool IsIdentity() const;
92 
93  /// Returns \c true if this offset is valid, i.e. both the offset and
94  /// scale are finite (not infinite or NaN). Note that a valid layer
95  /// offset's inverse may be invalid.
96  SDF_API
97  bool IsValid() const;
98 
99  /// Gets the inverse offset, which performs the opposite transformation.
100  SDF_API
101  SdfLayerOffset GetInverse() const;
102 
103  /// \name Hashing
104  /// @{
105 
106  /// Returns hash for this offset.
107  SDF_API
108  size_t GetHash() const;
109 
110  /// Hash functor for hash maps and sets.
111  struct Hash {
112  size_t operator()(const SdfLayerOffset &offset) const {
113  return offset.GetHash();
114  }
115  };
116 
117  friend inline size_t hash_value(const SdfLayerOffset &offset) {
118  return offset.GetHash();
119  }
120 
121  /// @}
122 
123  /// \name Operators
124  /// @{
125 
126  /// Returns whether the offsets are equal.
127  SDF_API
128  bool operator==(const SdfLayerOffset &rhs) const;
129 
130  /// Returns whether this offset is less than another. The meaning
131  /// of less than is somewhat arbitrary.
132  SDF_API
133  bool operator<(const SdfLayerOffset &rhs) const;
134 
135  /// Composes this with the offset \e rhs, such that the resulting
136  /// offset is equivalent to first applying \e rhs and then \e *this.
137  SDF_API
138  SdfLayerOffset operator*(const SdfLayerOffset &rhs) const;
139 
140  /// Applies the offset to the given value.
141  SDF_API
142  double operator*(double rhs) const;
143 
144  /// Applies the offset to the given value.
145  SDF_API
146  SdfTimeCode operator*(const SdfTimeCode &rhs) const;
147 
148  /// @}
149 
150 private:
151  double _offset;
152  double _scale;
153 };
154 
155 typedef std::vector<SdfLayerOffset> SdfLayerOffsetVector;
156 
157 ///
158 /// Writes the string representation of \a SdfLayerOffset to \a out.
159 SDF_API
160 std::ostream & operator<<( std::ostream &out,
161  const SdfLayerOffset &layerOffset );
162 
164 
165 #endif // PXR_USD_SDF_LAYER_OFFSET_H
SDF_API SdfLayerOffset GetInverse() const
Gets the inverse offset, which performs the opposite transformation.
SDF_API bool IsIdentity() const
SDF_API bool operator<(const SdfLayerOffset &rhs) const
SDF_API size_t GetHash() const
Returns hash for this offset.
std::vector< SdfLayerOffset > SdfLayerOffsetVector
Definition: layerOffset.h:155
GA_API const UT_StringHolder scale
void SetScale(double newScale)
Sets the time scale factor.
Definition: layerOffset.h:86
GLintptr offset
Definition: glcorearb.h:665
SDF_API SdfLayerOffset operator*(const SdfLayerOffset &rhs) const
double GetScale() const
Returns the time scale factor.
Definition: layerOffset.h:80
size_t operator()(const SdfLayerOffset &offset) const
Definition: layerOffset.h:112
Hash functor for hash maps and sets.
Definition: layerOffset.h:111
SDF_API bool operator==(const SdfLayerOffset &rhs) const
Returns whether the offsets are equal.
SDF_API std::ostream & operator<<(std::ostream &out, const SdfLayerOffset &layerOffset)
Writes the string representation of SdfLayerOffset to out.
friend size_t hash_value(const SdfLayerOffset &offset)
Returns hash for this offset.
Definition: layerOffset.h:117
SDF_API bool IsValid() const
#define SDF_API
Definition: api.h:40
double GetOffset() const
Returns the time offset.
Definition: layerOffset.h:77
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SDF_API SdfLayerOffset(double offset=0.0, double scale=1.0)
Constructs a new SdfLayerOffset instance.
void SetOffset(double newOffset)
Sets the time offset.
Definition: layerOffset.h:83