7 #ifndef PXR_EXEC_VDF_WEIGHTED_ITERATOR_H
8 #define PXR_EXEC_VDF_WEIGHTED_ITERATOR_H
23 #include <initializer_list>
68 if (_begin != _local) {
80 if (!TF_VERIFY(!_begin && !_end)) {
84 _begin = numInputs > NUM_LOCAL_STORAGE
87 _end = _begin + numInputs;
143 static const size_t NUM_LOCAL_STORAGE = 1;
154 template<
class IteratorType>
169 template<
typename... Args>
174 _iterator(context, std::forward<Args>(
args)...) {
175 const TfToken *weightNamePtr = &weightName;
176 _Init(context, weightNamePtr, weightNamePtr + 1);
182 template<
typename... Args>
185 std::initializer_list<TfToken> weightNames,
187 _iterator(context, std::forward<Args>(
args)...) {
188 _Init(context, weightNames.begin(), weightNames.end());
193 template<
typename... Args>
196 const std::vector<TfToken> &weightNames,
198 _iterator(context, std::forward<Args>(
args)...) {
199 const TfToken *weightNamesBegin = weightNames.
data();
200 const TfToken *weightNamesEnd = weightNamesBegin + weightNames.
size();
201 _Init(context, weightNamesBegin, weightNamesEnd);
215 return _iterator.operator*();
221 return _iterator.IsAtEnd();
235 _iterator.AdvanceToEnd();
242 double GetWeight(
size_t slot = 0,
double defWeight = 0.0)
const {
243 _GetExplicitWeight(slot, &defWeight);
252 return _GetExplicitWeight(slot, &ret);
260 size_t slot = 0,
double defWeight = 0.0)
const;
265 return _slots.
size();
271 return (slot < _slots.
size()) ?
272 _slots[slot].weights->GetSize() : 0;
294 void _AddWeightsInput(
301 bool _GetExplicitWeight(
size_t slot,
double *ret)
const;
311 void _AdvanceIterator();
316 IteratorType _iterator;
322 template<
class IteratorType>
330 if (_iterator.IsAtEnd()) {
339 _slots.Allocate(numInputs);
344 const VdfNode &node = _GetNode(context);
345 for (
const TfToken *it = begin; it !=
end; ++it, ++slot) {
349 "Can't find input '%s' on node %s",
353 _AddWeightsInput(slot, input, context);
357 if (numInputs == 0) {
368 template<
class IteratorType>
378 const VdfVector &out = _GetRequiredInputValue(
379 context, connection, connection.
GetMask());
392 TF_CODING_ERROR(
"Weight input must have exactly one element (got %zu)",
398 TF_CODING_ERROR(
"Weight connector must have at most one input (got %zu)",
407 template<
class IteratorType>
421 _iterator.operator++();
427 template<
class IteratorType>
431 while (!_iterator.IsAtEnd()) {
434 const int currentIndex = Vdf_GetIteratorIndex(_iterator);
435 const int nextExplicitIndex =
436 _slots.AdvanceToNextExplicitIndex(currentIndex);
441 _iterator.AdvanceToEnd();
444 }
else if (nextExplicitIndex != currentIndex) {
448 while (!_iterator.IsAtEnd() &&
449 Vdf_GetIteratorIndex(_iterator) < nextExplicitIndex) {
453 if (_iterator.IsAtEnd() ||
454 Vdf_GetIteratorIndex(_iterator) == nextExplicitIndex) {
497 if (wIndexVal < nextExplicitIndex) {
498 nextExplicitIndex = wIndexVal;
503 return nextExplicitIndex;
506 template<
class IteratorType>
507 std::pair<bool, double>
509 size_t slot,
double defWeight)
const
511 bool hasExplicitWeight = _GetExplicitWeight(slot, &defWeight);
512 return std::pair<bool, double>(hasExplicitWeight, defWeight);
515 template<
class IteratorType>
518 size_t slot,
double *ret)
const
522 if (slot < _slots.size()) {
527 Vdf_GetIteratorIndex(_iterator)) {
const_iterator begin() const
bool HasExplicitWeight(size_t slot) const
VdfWeightedIterator & operator++()
const_iterator end() const
Vdf_WeightSlot value_type
reference operator[](size_t slot)
Access the slot at index slot.
int GetCurrentIndex() const
IteratorType::reference reference
#define PXR_NAMESPACE_OPEN_SCOPE
VDF_API const std::string GetDebugName() const
const VdfInput * GetInput(const TfToken &inputName) const
const VdfIndexedWeights * weights
The vector of weights we are iterating over.
VdfWeightedIterator(const VdfContext &context, const std::vector< TfToken > &weightNames, Args &&...args)
reference operator*() const
size_t size() const
Return the size of the string that this token represents.
size_t GetFirstDataIndex(size_t currentIndex) const
#define TF_DEV_AXIOM(cond)
char const * data() const
Synonym for GetText().
size_t GetNumExplicitWeights(size_t slot=0) const
double GetWeight(size_t slot=0, double defWeight=0.0) const
std::pair< bool, double > GetExplicitWeight(size_t slot=0, double defWeight=0.0) const
size_t GetNumSlots() const
~VdfWeightedIterator()=default
ReadAccessor< TYPE > GetReadAccessor() const
friend int Vdf_GetIteratorIndex(const VdfWeightedIterator &it)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
int AdvanceToNextExplicitIndex(int index)
const_reference operator[](size_t slot) const
Access the slot at index slot.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
VdfWeightedIterator(const VdfContext &context, std::initializer_list< TfToken > weightNames, Args &&...args)
**If you just want to fire and args
GLubyte GLubyte GLubyte GLubyte w
SIM_API const UT_StringHolder distance
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
VdfByValueOrConstRef< T > GetData(size_t i) const
const VdfMask & GetMask() const
Returns the mask for this connection.
size_t currentIndex
The current iterator index into the VdfIndexedWeights above.
int GetIndex(size_t i) const
IteratorType::value_type value_type
VdfWeightedIterator(const VdfContext &context, const TfToken &weightName, Args &&...args)
void Allocate(uint32_t numInputs)