instanceKey.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 PXR_USD_PCP_INSTANCE_KEY_H
25 #define PXR_USD_PCP_INSTANCE_KEY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
29 #include "pxr/usd/pcp/mapExpression.h"
30 #include "pxr/usd/pcp/node.h"
31 #include "pxr/usd/pcp/site.h"
32 #include "pxr/usd/pcp/types.h"
33 
35 #include "pxr/base/tf/hash.h"
36 
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 class PcpPrimIndex;
44 
54 {
55 public:
56  PCP_API
58 
60  PCP_API
61  explicit PcpInstanceKey(const PcpPrimIndex& primIndex);
62 
64  PCP_API
65  bool operator==(const PcpInstanceKey& rhs) const;
66  PCP_API
67  bool operator!=(const PcpInstanceKey& rhs) const;
68 
70  template <typename HashState>
71  friend void TfHashAppend(HashState& h, const PcpInstanceKey& key)
72  {
73  h.Append(key._hash);
74  }
76  friend size_t hash_value(const PcpInstanceKey& key)
77  {
78  return key._hash;
79  }
80 
85  struct Hash {
86  inline size_t operator()(const PcpInstanceKey& key) const
87  {
88  return key._hash;
89  }
90  };
91 
94  PCP_API
95  std::string GetString() const;
96 
97 private:
98  struct _Collector;
99 
100  struct _Arc
101  {
102  explicit _Arc(const PcpNodeRef& node)
103  : _arcType(node.GetArcType())
104  , _sourceSite(node.GetSite())
105  , _timeOffset(node.GetMapToRoot().GetTimeOffset())
106  {
107  }
108 
109  bool operator==(const _Arc& rhs) const
110  {
111  return _arcType == rhs._arcType &&
112  _sourceSite == rhs._sourceSite &&
113  _timeOffset == rhs._timeOffset;
114  }
115 
116  template <typename HashState>
117  friend void TfHashAppend(HashState &h, const _Arc& arc) {
118  h.Append(arc._arcType);
119  h.Append(arc._sourceSite);
120  h.Append(arc._timeOffset);
121  }
122 
123  PcpArcType _arcType;
124  PcpSite _sourceSite;
125  SdfLayerOffset _timeOffset;
126  };
127  std::vector<_Arc> _arcs;
128 
129  typedef std::pair<std::string, std::string> _VariantSelection;
130  std::vector<_VariantSelection> _variantSelection;
131 
132  size_t _hash;
133 };
134 
135 PXR_NAMESPACE_CLOSE_SCOPE
136 
137 #endif // PXR_USD_PCP_INSTANCE_KEY_H
A PcpInstanceKey identifies instanceable prim indexes that share the same set of opinions.
Definition: instanceKey.h:53
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:76
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:67
friend size_t hash_value(const PcpInstanceKey &key)
Returns hash value for this instance key.
Definition: instanceKey.h:76
A site specifies a path in a layer stack of scene description.
Definition: site.h:46
PCP_API std::string GetString() const
Returns string representation of this instance key for debugging purposes.
Hash functor.
Definition: instanceKey.h:85
friend void TfHashAppend(HashState &h, const PcpInstanceKey &key)
Appends hash value for this instance key.
Definition: instanceKey.h:71
PCP_API bool operator==(const PcpInstanceKey &rhs) const
Comparison operators.
Represents a time offset and scale between layers.
Definition: layerOffset.h:61
PcpArcType
Describes the type of arc connecting two nodes in the prim index.
Definition: types.h:46