7#ifndef PXR_USD_USD_GEOM_PRIMVAR_H
8#define PXR_USD_USD_GEOM_PRIMVAR_H
11#include "pxr/usd/usdGeom/api.h"
12#include "pxr/usd/usd/attribute.h"
19PXR_NAMESPACE_OPEN_SCOPE
370 TfToken *interpolation,
int *elementSize)
const;
401 explicit operator bool()
const {
402 return IsDefined() ? &UsdGeomPrimvar::_attr : 0;
442 template <
typename T>
444 return _attr.
Get(value, time);
448 template <
typename T>
450 return _attr.
Set(value, time);
471 std::vector<double>* times)
const;
581 template <
typename ScalarType>
609 const VtIntArray &indices,
610 std::string *errString);
625 const VtIntArray &indices,
627 std::string *errString);
688 return !(lhs == rhs);
699 template <
typename HashState>
700 friend void TfHashAppend(HashState& h,
const UsdGeomPrimvar& obj) {
716 static bool _IsNamespaced(
const TfToken& name);
725 static TfToken _MakeNamespaced(
const TfToken& name,
bool quiet=
false);
727 static TfToken const &_GetNamespacePrefix();
757 template<
typename ScalarType>
759 const VtIntArray &indices,
762 std::string *errString);
766 template <
typename ArrayType>
767 static bool _ComputeFlattenedArray(
const VtValue &attrVal,
768 const VtIntArray &indices,
771 std::string *errString);
781 bool _ComputeIdTargetPossibility()
const;
783 enum _IdTargetStatus {
784 IdTargetUninitialized,
785 IdTargetInitializing,
789 mutable TfToken _idTargetRelName;
790 mutable std::atomic<_IdTargetStatus> _idTargetStatus;
804template <
typename ScalarType>
809 if (!
Get(&authored, time))
819 TF_WARN(
"No indices authored for indexed primvar <%s>.",
825 if (authored.
empty())
828 std::string errString;
829 bool res = _ComputeFlattenedHelper(authored, indices,
GetElementSize(), value, &errString);
830 if (!errString.empty()) {
837template<
typename ScalarType>
840 const VtIntArray &indices,
843 std::string *errString)
846 value->
resize(indices.size() * elementSize);
849 std::vector<size_t> invalidIndexPositions;
850 for (
size_t i=0; i < indices.size(); i++) {
851 if (indices[i] < 0 ||
static_cast<size_t>((indices[i] + 1) * elementSize) > authored.
size()) {
852 invalidIndexPositions.push_back(i);
857 const size_t indicesIdx = indices[i] * elementSize;
858 const size_t valuesIdx = i * elementSize;
859 for (
size_t j=0; j < static_cast<size_t>(elementSize); j++) {
860 size_t index = indicesIdx + j;
861 (*value)[valuesIdx + j] = authored[index];
865 if (!invalidIndexPositions.empty() && errString) {
867 "Found %ld invalid indices into authored array of size %ld with"
868 " element size of %i:",
869 invalidIndexPositions.size(),
870 authored.
size(), elementSize);
873 size_t numElementsToPrint = std::min(invalidIndexPositions.size(),
875 for (
size_t i = 0; i < numElementsToPrint ; ++i) {
876 int invalidIndex = indices[invalidIndexPositions[i]];
877 int authoredStartIndex = invalidIndex * elementSize;
880 "\n\t Invalid index %i at position %ld refers to %s of the"
881 " authored array, which is out of bounds",
883 invalidIndexPositions[i],
884 elementSize == 1 ?
TfStringPrintf(
"index %i", authoredStartIndex).c_str()
885 :
TfStringPrintf(
"indices [%i,...,%i]", authoredStartIndex, authoredStartIndex + elementSize - 1).c_str());
892PXR_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.