24#ifndef PXR_USD_USD_GEOM_PRIMVAR_H
25#define PXR_USD_USD_GEOM_PRIMVAR_H
28#include "pxr/usd/usdGeom/api.h"
29#include "pxr/usd/usd/attribute.h"
36PXR_NAMESPACE_OPEN_SCOPE
387 TfToken *interpolation,
int *elementSize)
const;
418 explicit operator bool()
const {
419 return IsDefined() ? &UsdGeomPrimvar::_attr : 0;
459 template <
typename T>
461 return _attr.
Get(value, time);
465 template <
typename T>
467 return _attr.
Set(value, time);
488 std::vector<double>* times)
const;
598 template <
typename ScalarType>
626 const VtIntArray &indices,
627 std::string *errString);
642 const VtIntArray &indices,
644 std::string *errString);
705 return !(lhs == rhs);
716 template <
typename HashState>
717 friend void TfHashAppend(HashState& h,
const UsdGeomPrimvar& obj) {
733 static bool _IsNamespaced(
const TfToken& name);
742 static TfToken _MakeNamespaced(
const TfToken& name,
bool quiet=
false);
744 static TfToken const &_GetNamespacePrefix();
774 template<
typename ScalarType>
776 const VtIntArray &indices,
779 std::string *errString);
783 template <
typename ArrayType>
784 static bool _ComputeFlattenedArray(
const VtValue &attrVal,
785 const VtIntArray &indices,
788 std::string *errString);
798 bool _ComputeIdTargetPossibility()
const;
800 enum _IdTargetStatus {
801 IdTargetUninitialized,
802 IdTargetInitializing,
806 mutable TfToken _idTargetRelName;
807 mutable std::atomic<_IdTargetStatus> _idTargetStatus;
821template <
typename ScalarType>
826 if (!
Get(&authored, time))
836 TF_WARN(
"No indices authored for indexed primvar <%s>.",
842 if (authored.
empty())
845 std::string errString;
846 bool res = _ComputeFlattenedHelper(authored, indices,
GetElementSize(), value, &errString);
847 if (!errString.empty()) {
854template<
typename ScalarType>
857 const VtIntArray &indices,
860 std::string *errString)
863 value->
resize(indices.size() * elementSize);
866 std::vector<size_t> invalidIndexPositions;
867 for (
size_t i=0; i < indices.size(); i++) {
868 if (indices[i] < 0 ||
static_cast<size_t>((indices[i] + 1) * elementSize) > authored.
size()) {
869 invalidIndexPositions.push_back(i);
874 const size_t indicesIdx = indices[i] * elementSize;
875 const size_t valuesIdx = i * elementSize;
876 for (
size_t j=0; j < static_cast<size_t>(elementSize); j++) {
877 size_t index = indicesIdx + j;
878 (*value)[valuesIdx + j] = authored[index];
882 if (!invalidIndexPositions.empty() && errString) {
884 "Found %ld invalid indices into authored array of size %ld with"
885 " element size of %i:",
886 invalidIndexPositions.size(),
887 authored.
size(), elementSize);
890 size_t numElementsToPrint = std::min(invalidIndexPositions.size(),
892 for (
size_t i = 0; i < numElementsToPrint ; ++i) {
893 int invalidIndex = indices[invalidIndexPositions[i]];
894 int authoredStartIndex = invalidIndex * elementSize;
897 "\n\t Invalid index %i at position %ld refers to %s of the"
898 " authored array, which is out of bounds",
900 invalidIndexPositions[i],
901 elementSize == 1 ?
TfStringPrintf(
"index %i", authoredStartIndex).c_str()
902 :
TfStringPrintf(
"indices [%i,...,%i]", authoredStartIndex, authoredStartIndex + elementSize - 1).c_str());
909PXR_NAMESPACE_CLOSE_SCOPE
A basic mathematical interval class.
A path value used to locate objects in layers or scenegraphs.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
Represents a value type name, i.e.
A user-extensible hashing mechanism for use with runtime hash tables.
Token for efficient comparison, assignment, and hashing of known strings.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
USD_API bool HasValue() const
Return true if this attribute has an authored default value, authored time samples or a fallback valu...
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the value of this attribute in the current UsdEditTarget to value at UsdTimeCode time,...
USD_API SdfValueTypeName GetTypeName() const
Return the "scene description" value type name for this attribute.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time,...
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples.
Base class for all prims that may require rendering or visualization of some sort.
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars.
USDGEOM_API bool HasAuthoredElementSize() const
Has elementSize been explicitly authored on this Primvar?
USDGEOM_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times for this primvar.
TfToken GetBaseName() const
USDGEOM_API UsdGeomPrimvar(const UsdAttribute &attr)
Speculative constructor that will produce a valid UsdGeomPrimvar when attr already represents an attr...
static USDGEOM_API bool IsValidInterpolation(const TfToken &interpolation)
Validate that the provided interpolation is a valid setting for interpolation as defined by Interpola...
USDGEOM_API bool ComputeFlattened(VtValue *value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool ComputeFlattened(VtArray< ScalarType > *value, UsdTimeCode time=UsdTimeCode::Default()) const
Computes the flattened value of the primvar at time.
static USDGEOM_API bool IsPrimvar(const UsdAttribute &attr)
Test whether a given UsdAttribute represents valid Primvar, which implies that creating a UsdGeomPrim...
USDGEOM_API bool SetIndices(const VtIntArray &indices, UsdTimeCode time=UsdTimeCode::Default()) const
Sets the indices value of the indexed primvar at time.
USDGEOM_API bool NameContainsNamespaces() const
Does this primvar contain any namespaces other than the "primvars:" namespace?
static USDGEOM_API bool ComputeFlattened(VtValue *value, const VtValue &attrVal, const VtIntArray &indices, int elementSize, std::string *errString)
Computes the flattened value of attrValue given indices and elementSize.
friend bool operator!=(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Inequality comparison.
USDGEOM_API int GetUnauthoredValuesIndex() const
Returns the index that represents unauthored values in the indices array.
USDGEOM_API bool IsIdTarget() const
Returns true if the primvar is an Id primvar.
USDGEOM_API UsdGeomPrimvar & operator=(const UsdGeomPrimvar &other)
Copy assign.
USDGEOM_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
static USDGEOM_API TfToken StripPrimvarsName(const TfToken &name)
Returns the name, devoid of the "primvars:" token if present, otherwise returns the name unchanged.
TfToken GetNamespace() const
static USDGEOM_API bool ComputeFlattened(VtValue *value, const VtValue &attrVal, const VtIntArray &indices, std::string *errString)
Computes the flattened value of attrValue given indices, assuming an elementSize of 1.
friend bool operator==(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Equality comparison.
USDGEOM_API bool SetElementSize(int eltSize)
Set the elementSize for this Primvar.
USDGEOM_API bool SetInterpolation(const TfToken &interpolation)
Set the Primvar's interpolation.
USDGEOM_API bool SetUnauthoredValuesIndex(int unauthoredValuesIndex) const
Set the index that represents unauthored values in the indices array.
USDGEOM_API int GetElementSize() const
Return the "element size" for this Primvar, which is 1 if unauthored.
USDGEOM_API TfToken GetPrimvarName() const
Returns the primvar's name, devoid of the "primvars:" namespace.
USDGEOM_API void GetDeclarationInfo(TfToken *name, SdfValueTypeName *typeName, TfToken *interpolation, int *elementSize) const
Convenience function for fetching all information required to properly declare this Primvar.
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the attribute value of the Primvar at time.
USDGEOM_API UsdAttribute CreateIndicesAttr() const
Returns the existing indices attribute if the primvar is indexed or creates a new one.
USDGEOM_API UsdGeomPrimvar(const UsdGeomPrimvar &other)
Copy construct.
bool IsDefined() const
Return true if the underlying UsdAttribute::IsDefined(), and in addition the attribute is identified ...
std::vector< std::string > SplitName() const
bool HasAuthoredValue() const
Return true if the underlying attribute has an unblocked, authored value.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Get the attribute value of the Primvar at time .
static USDGEOM_API bool IsValidPrimvarName(const TfToken &name)
Test whether a given name represents a valid name of a primvar, which implies that creating a UsdGeom...
SdfValueTypeName GetTypeName() const
TfToken const & GetName() const
UsdAttribute const & GetAttr() const
Explicit UsdAttribute extractor.
USDGEOM_API TfToken GetInterpolation() const
Return the Primvar's interpolation, which is UsdGeomTokens->constant if unauthored.
USDGEOM_API bool SetIdTarget(const SdfPath &path) const
This primvar must be of String or StringArray type for this method to succeed.
USDGEOM_API bool IsIndexed() const
Returns true if the primvar is indexed, i.e., if it has an associated "indices" attribute.
USDGEOM_API UsdAttribute GetIndicesAttr() const
Returns a valid indices attribute if the primvar is indexed.
bool HasValue() const
Return true if the underlying attribute has a value, either from authored scene description or a fall...
USDGEOM_API bool HasAuthoredInterpolation() const
Has interpolation been explicitly authored on this Primvar?
USDGEOM_API void BlockIndices() const
Block the indices that were previously set.
friend bool operator<(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Less-than operator.
USDGEOM_API bool GetIndices(VtIntArray *indices, UsdTimeCode time=UsdTimeCode::Default()) const
Returns the value of the indices array associated with the indexed primvar at time.
USDGEOM_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this primvar's value changes over time,...
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate acro...
SdfPath GetPath() const
Return the complete scene path to this object on its UsdStage, which may (UsdPrim) or may not (all ot...
const TfToken & GetName() const
Return the full name of this object, i.e.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
USD_API TfToken GetBaseName() const
Return this property's name with all namespace prefixes removed, i.e.
USD_API TfToken GetNamespace() const
Return this property's complete namespace prefix.
USD_API std::vector< std::string > SplitName() const
Return this property's name elements including namespaces and its base name as the final element.
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
USD_API std::string UsdDescribe(const UsdObject &)
Return a human-readable description.
size_t size() const
Return the total number of elements in this array.
bool empty() const
Return true if this array contains no elements, false otherwise.
void resize(size_t newSize)
Resize this array.
#define TF_WARN(...)
Issue a warning, but continue execution.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.