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