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"
35 PXR_NAMESPACE_OPEN_SCOPE
378 TfToken *interpolation,
int *elementSize)
const;
409 explicit operator bool()
const {
410 return IsDefined() ? &UsdGeomPrimvar::_attr : 0;
450 template <
typename T>
452 return _attr.
Get(value, time);
456 template <
typename T>
458 return _attr.
Set(value, time);
479 std::vector<double>* times)
const;
589 template <
typename ScalarType>
616 const VtIntArray &indices,
617 std::string *errString);
671 friend bool operator==(
const UsdGeomPrimvar &lhs,
const UsdGeomPrimvar &rhs) {
677 friend bool operator!=(
const UsdGeomPrimvar &lhs,
const UsdGeomPrimvar &rhs) {
678 return !(lhs == rhs);
684 friend bool operator<(
const UsdGeomPrimvar &lhs,
const UsdGeomPrimvar &rhs) {
690 friend size_t hash_value(
const UsdGeomPrimvar &obj) {
691 return hash_value(obj.
GetAttr());
701 static bool _IsNamespaced(
const TfToken& name);
710 static TfToken _MakeNamespaced(
const TfToken& name,
bool quiet=
false);
712 static TfToken const &_GetNamespacePrefix();
741 void _SetIdTargetRelName();
747 template<
typename ScalarType>
749 const VtIntArray &indices,
751 std::string *errString);
755 template <
typename ArrayType>
756 static bool _ComputeFlattenedArray(
const VtValue &attrVal,
757 const VtIntArray &indices,
759 std::string *errString);
777 template <
typename ScalarType>
782 if (!
Get(&authored, time))
792 TF_WARN(
"No indices authored for indexed primvar <%s>.",
798 if (authored.
empty())
801 std::string errString;
802 bool res = _ComputeFlattenedHelper(authored, indices, value, &errString);
803 if (!errString.empty()) {
810 template<
typename ScalarType>
813 const VtIntArray &indices,
815 std::string *errString)
817 value->
resize(indices.size());
820 std::vector<size_t> invalidIndexPositions;
821 for (
size_t i=0; i < indices.size(); i++) {
822 int index = indices[i];
823 if (index >= 0 && (
size_t)index < authored.
size()) {
824 (*value)[i] = authored[index];
826 invalidIndexPositions.push_back(i);
831 if (!invalidIndexPositions.empty()) {
832 std::vector<std::string> invalidPositionsStrVec;
834 size_t numElementsToPrint = std::min(invalidIndexPositions.size(),
836 invalidPositionsStrVec.reserve(numElementsToPrint);
837 for (
size_t i = 0; i < numElementsToPrint ; ++i) {
838 invalidPositionsStrVec.push_back(
844 "Found %ld invalid indices at positions [%s%s] that are out of "
845 "range [0,%ld).", invalidIndexPositions.size(),
847 invalidIndexPositions.size() > 5 ?
", ..." :
"",
856 PXR_NAMESPACE_CLOSE_SCOPE
858 #endif // USD_PRIMVAR_H
USDGEOM_API bool SetElementSize(int eltSize)
Set the elementSize for this Primvar.
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...
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.
friend bool operator!=(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Inequality comparison.
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...
#define TF_WARN(...)
Issue a warning, but continue execution.
USDGEOM_API int GetUnauthoredValuesIndex() const
Returns the index that represents unauthored values in the indices array.
SdfPath GetPath() const
Return the complete scene path to this object on its UsdStage, which may (UsdPrim) or may not (all ot...
static USDGEOM_API bool IsPrimvar(const UsdAttribute &attr)
Test whether a given UsdAttribute represents valid Primvar, which implies that creating a UsdGeomPrim...
USD_API TfToken GetNamespace() const
Return this property's complete namespace prefix.
Represents a value type name, i.e.
USDGEOM_API bool HasAuthoredElementSize() const
Has elementSize been explicitly authored on this Primvar?
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
bool HasValue() const
Return true if the underlying attribute has a value, either from authored scene description or a fall...
void resize(size_t newSize)
Resize this array.
USDGEOM_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
USD_API std::string UsdDescribe(const UsdObject &)
Return a human-readable description.
USDGEOM_API UsdAttribute GetIndicesAttr() const
Returns a valid indices attribute if the primvar is indexed.
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate ac...
UsdAttribute const & GetAttr() const
Explicit UsdAttribute extractor.
USDGEOM_API bool SetInterpolation(const TfToken &interpolation)
Set the Primvar's interpolation.
Token for efficient comparison, assignment, and hashing of known strings.
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the attribute value of the Primvar at time.
USD_API std::vector< std::string > SplitName() const
Return this property's name elements including namespaces and its base name as the final element...
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
bool HasAuthoredValue() const
Return true if the underlying attribute has an unblocked, authored value.
SdfValueTypeName GetTypeName() const
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
TfToken GetNamespace() const
USDGEOM_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this primvar's value changes over time...
USD_API bool HasValue() const
Return true if this attribute has an authored default value, authored time samples or a fallback valu...
A basic mathematical interval class.
std::vector< std::string > SplitName() const
size_t size() const
Return the total number of elements in this array.
Represents an arbitrary dimensional rectangular container class.
A path value used to locate objects in layers or scenegraphs.
std::string TfStringJoin(ForwardIterator begin, ForwardIterator end, const char *separator=" ")
Concatenates the strings (begin, end), with default separator.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Get the attribute value of the Primvar at time .
USDGEOM_API TfToken GetInterpolation() const
Return the Primvar's interpolation, which is UsdGeomTokens->constant if unauthored.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time...
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
USDGEOM_API bool HasAuthoredInterpolation() const
Has interpolation 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.
USDGEOM_API UsdAttribute CreateIndicesAttr() const
Returns the existing indices attribute if the primvar is indexed or creates a new one...
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 IsIdTarget() const
Returns true if the primvar is an Id primvar.
bool ComputeFlattened(VtArray< ScalarType > *value, UsdTimeCode time=UsdTimeCode::Default()) const
Computes the flattened value of the primvar at time.
USDGEOM_API bool SetIndices(const VtIntArray &indices, UsdTimeCode time=UsdTimeCode::Default()) const
Sets the indices value of the indexed 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...
static USDGEOM_API TfToken StripPrimvarsName(const TfToken &name)
Returns the name, devoid of the "primvars:" token if present, otherwise returns the name unchanged...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
USDGEOM_API bool NameContainsNamespaces() const
Does this primvar contain any namespaces other than the "primvars:" namespace?
TfToken GetBaseName() const
const TfToken & GetName() const
Return the full name of this object, i.e.
USDGEOM_API bool SetUnauthoredValuesIndex(int unauthoredValuesIndex) const
Set the index that represents unauthored values in the indices array.
USDGEOM_API void BlockIndices() const
Block the indices that were previously set.
bool IsDefined() const
Return true if the underlying UsdAttribute::IsDefined(), and in addition the attribute is identified ...
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars...
USDGEOM_API bool IsIndexed() const
Returns true if the primvar is indexed, i.e., if it has an associated "indices" attribute.
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.
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Convert an arbitrary type into a string.
USDGEOM_API TfToken GetPrimvarName() const
Returns the primvar's name, devoid of the "primvars:" namespace.
bool empty() const
Return true if this array contains no elements, false otherwise.
friend bool operator==(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Equality comparison.
Base class for all prims that may require rendering or visualization of some sort.
USD_API SdfValueTypeName GetTypeName() const
Return the "scene description" value type name for this attribute.
USDGEOM_API int GetElementSize() const
Return the "element size" for this Primvar, which is 1 if unauthored.
friend bool operator<(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Less-than operator.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
static USDGEOM_API bool IsValidInterpolation(const TfToken &interpolation)
Validate that the provided interpolation is a valid setting for interpolation as defined by Interpola...
USD_API TfToken GetBaseName() const
Return this property's name with all namespace prefixes removed, i.e.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
TfToken const & GetName() const