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" 36 PXR_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>
625 const VtIntArray &indices,
626 std::string *errString);
687 return !(lhs == rhs);
700 return hash_value(obj.
GetAttr());
710 static bool _IsNamespaced(
const TfToken& name);
719 static TfToken _MakeNamespaced(
const TfToken& name,
bool quiet=
false);
721 static TfToken const &_GetNamespacePrefix();
751 template<
typename ScalarType>
753 const VtIntArray &indices,
755 std::string *errString);
759 template <
typename ArrayType>
760 static bool _ComputeFlattenedArray(
const VtValue &attrVal,
761 const VtIntArray &indices,
763 std::string *errString);
773 bool _ComputeIdTargetPossibility()
const;
775 enum _IdTargetStatus {
776 IdTargetUninitialized,
777 IdTargetInitializing,
781 mutable TfToken _idTargetRelName;
782 mutable std::atomic<_IdTargetStatus> _idTargetStatus;
796 template <
typename ScalarType>
801 if (!
Get(&authored, time))
811 TF_WARN(
"No indices authored for indexed primvar <%s>.",
817 if (authored.
empty())
820 std::string errString;
821 bool res = _ComputeFlattenedHelper(authored, indices, value, &errString);
822 if (!errString.empty()) {
829 template<
typename ScalarType>
832 const VtIntArray &indices,
834 std::string *errString)
836 value->
resize(indices.size());
839 std::vector<size_t> invalidIndexPositions;
840 for (
size_t i=0; i < indices.size(); i++) {
841 int index = indices[i];
842 if (index >= 0 && (
size_t)index < authored.
size()) {
843 (*value)[i] = authored[index];
845 invalidIndexPositions.push_back(i);
850 if (!invalidIndexPositions.empty()) {
851 std::vector<std::string> invalidPositionsStrVec;
853 size_t numElementsToPrint = std::min(invalidIndexPositions.size(),
855 invalidPositionsStrVec.reserve(numElementsToPrint);
856 for (
size_t i = 0; i < numElementsToPrint ; ++i) {
857 invalidPositionsStrVec.push_back(
863 "Found %ld invalid indices at positions [%s%s] that are out of " 864 "range [0,%ld).", invalidIndexPositions.size(),
866 invalidIndexPositions.size() > 5 ?
", ..." :
"",
875 PXR_NAMESPACE_CLOSE_SCOPE
877 #endif // USD_PRIMVAR_H USDGEOM_API bool SetElementSize(int eltSize)
Set the elementSize for this Primvar.
TF_API std::string TfStringPrintf(const char *fmt,...)
Returns a string formed by a printf()-like specification.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time,...
USDGEOM_API bool IsIdTarget() const
Returns true if the primvar is an Id primvar.
USDGEOM_API bool SetIndices(const VtIntArray &indices, UsdTimeCode time=UsdTimeCode::Default()) const
Sets the indices value of the indexed primvar at time.
friend bool operator!=(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Inequality comparison.
TfToken GetBaseName() const
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the attribute value of the Primvar at time.
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.
USDGEOM_API bool HasAuthoredInterpolation() const
Has interpolation been explicitly authored on this Primvar?
size_t size() const
Return the total number of elements in this array.
#define TF_WARN(...)
Issue a warning, but continue execution.
USD_API bool HasValue() const
Return true if this attribute has an authored default value, authored time samples or a fallback valu...
USDGEOM_API bool NameContainsNamespaces() const
Does this primvar contain any namespaces other than the "primvars:" namespace?
static USDGEOM_API bool IsPrimvar(const UsdAttribute &attr)
Test whether a given UsdAttribute represents valid Primvar, which implies that creating a UsdGeomPrim...
std::vector< std::string > SplitName() const
Represents a value type name, i.e.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
USDGEOM_API UsdAttribute GetIndicesAttr() const
Returns a valid indices attribute if the primvar is indexed.
void resize(size_t newSize)
Resize this array.
USDGEOM_API TfToken GetInterpolation() const
Return the Primvar's interpolation, which is UsdGeomTokens->constant if unauthored.
USDGEOM_API void BlockIndices() const
Block the indices that were previously set.
USD_API std::string UsdDescribe(const UsdObject &)
Return a human-readable description.
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate acro...
USDGEOM_API bool SetInterpolation(const TfToken &interpolation)
Set the Primvar's interpolation.
Token for efficient comparison, assignment, and hashing of known strings.
bool ComputeFlattened(VtArray< ScalarType > *value, UsdTimeCode time=UsdTimeCode::Default()) const
Computes the flattened value of the primvar at time.
USDGEOM_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times for this primvar.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
SdfValueTypeName GetTypeName() const
USDGEOM_API bool SetUnauthoredValuesIndex(int unauthoredValuesIndex) const
Set the index that represents unauthored values in the indices array.
USD_API std::vector< std::string > SplitName() const
Return this property's name elements including namespaces and its base name as the final element.
USDGEOM_API int GetUnauthoredValuesIndex() const
Returns the index that represents unauthored values in the indices array.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
A basic mathematical interval class.
Represents an arbitrary dimensional rectangular container class.
A path value used to locate objects in layers or scenegraphs.
USDGEOM_API bool IsIndexed() const
Returns true if the primvar is indexed, i.e., if it has an associated "indices" attribute.
USDGEOM_API bool SetIdTarget(const SdfPath &path) const
This primvar must be of String or StringArray type for this method to succeed.
USDGEOM_API UsdAttribute CreateIndicesAttr() const
Returns the existing indices attribute if the primvar is indexed or creates a new one.
std::string TfStringJoin(ForwardIterator begin, ForwardIterator end, const char *separator=" ")
Concatenates the strings (begin, end), with default separator.
UsdAttribute const & GetAttr() const
Explicit UsdAttribute extractor.
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,...
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
bool HasAuthoredValue() const
Return true if the underlying attribute has an unblocked, authored value.
USDGEOM_API bool HasAuthoredElementSize() const
Has elementSize been explicitly authored on this Primvar?
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 int GetElementSize() const
Return the "element size" for this Primvar, which is 1 if unauthored.
TfToken GetNamespace() const
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'.
const TfToken & GetName() const
Return the full name of this object, i.e.
bool empty() const
Return true if this array contains no elements, false otherwise.
bool HasValue() const
Return true if the underlying attribute has a value, either from authored scene description or a fall...
USDGEOM_API UsdGeomPrimvar & operator=(const UsdGeomPrimvar &other)
Copy assign.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Get the attribute value of the Primvar at time .
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.
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Convert an arbitrary type into a string.
USDGEOM_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
USD_API SdfValueTypeName GetTypeName() const
Return the "scene description" value type name for this attribute.
TfToken const & GetName() const
USD_API TfToken GetBaseName() const
Return this property's name with all namespace prefixes removed, i.e.
friend bool operator==(const UsdGeomPrimvar &lhs, const UsdGeomPrimvar &rhs)
Equality comparison.
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.
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 GetNamespace() const
Return this property's complete namespace prefix.
SdfPath GetPath() const
Return the complete scene path to this object on its UsdStage, which may (UsdPrim) or may not (all ot...
USDGEOM_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this primvar's value changes over time,...
USDGEOM_API TfToken GetPrimvarName() const
Returns the primvar's name, devoid of the "primvars:" namespace.