Loading...
Searching...
No Matches
UsdUtilsSparseValueWriter Class Reference

Utility class that manages sparse authoring of a set of UsdAttributes. More...

#include <sparseValueWriter.h>

Public Member Functions

USDUTILS_API bool SetAttribute (const UsdAttribute &attr, const VtValue &value, const UsdTimeCode time=UsdTimeCode::Default())
 Sets the value of attr to value at time time.
 
USDUTILS_API bool SetAttribute (const UsdAttribute &attr, VtValue *value, const UsdTimeCode time=UsdTimeCode::Default())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. For efficiency, this function swaps out the given value, leaving it empty.
 
template<typename T >
bool SetAttribute (const UsdAttribute &attr, T &value, const UsdTimeCode time=UsdTimeCode::Default())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
USDUTILS_API void Clear ()
 Clears the internal map, thereby releasing all the memory used by the sparse value-writers.
 
USDUTILS_API std::vector< UsdUtilsSparseAttrValueWriterGetSparseAttrValueWriters () const
 Returns a new vector of UsdUtilsSparseAttrValueWriter populated from the attrValueWriter map.
 

Detailed Description

Utility class that manages sparse authoring of a set of UsdAttributes.

It does this by maintaining a map of UsdAttributes to their corresponding UsdUtilsSparseAttrValueWriter objects.

To use this class, simply instantiate an instance of it and invoke the SetAttribute() method with various attributes and their associated time-samples.

Note
If the attribute has a default value, SetAttribute() must be called with time=Default first (multiple times, if necessary), followed by calls to author time-samples in sequentially increasing time order.
This class is not threadsafe. In general, authoring to a single USD layer from multiple threads isn't threadsafe. Hence, there is little value in making this class threadsafe.

Example c++ usage:

UsdGeomCylinder cylinder = UsdGeomCylinder::Define(stage, SdfPath("/Cylinder"));
UsdAttribute radius = cylinder.CreateRadiusAttr();
UsdAttribute height = cylinder.CreateHeightAttr();
valueWriter.SetAttribute(radius, 2.0, UsdTimeCode::Default());
valueWriter.SetAttribute(height, 2.0, UsdTimeCode::Default());
valueWriter.SetAttribute(radius, 10.0, UsdTimeCode(1.0));
valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(2.0));
valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(3.0));
valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(4.0));
valueWriter.SetAttribute(height, 2.0, UsdTimeCode(1.0));
valueWriter.SetAttribute(height, 2.0, UsdTimeCode(2.0));
valueWriter.SetAttribute(height, 3.0, UsdTimeCode(3.0));
valueWriter.SetAttribute(height, 3.0, UsdTimeCode(4.0));
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
Defines a primitive cylinder with closed ends, centered at the origin, whose spine is along the speci...
Definition: cylinder.h:67
USDGEOM_API UsdAttribute CreateRadiusAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetRadiusAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
static USDGEOM_API UsdGeomCylinder Define(const UsdStagePtr &stage, const SdfPath &path)
Attempt to ensure a UsdPrim adhering to this schema at path is defined (according to UsdPrim::IsDefin...
USDGEOM_API UsdAttribute CreateHeightAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetHeightAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:112
Utility class that manages sparse authoring of a set of UsdAttributes.
USDUTILS_API bool SetAttribute(const UsdAttribute &attr, const VtValue &value, const UsdTimeCode time=UsdTimeCode::Default())
Sets the value of attr to value at time time.

Equivalent python code:

cylinder = UsdGeom.Cylinder.Define(stage, Sdf.Path("/Cylinder"))
radius = cylinder.CreateRadiusAttr()
height = cylinder.CreateHeightAttr()
valueWriter = UsdUtils.SparseValueWriter()
valueWriter.SetAttribute(radius, 2.0, Usd.TimeCode.Default())
valueWriter.SetAttribute(height, 2.0, Usd.TimeCode.Default())
valueWriter.SetAttribute(radius, 10.0, 1.0)
valueWriter.SetAttribute(radius, 20.0, 2.0)
valueWriter.SetAttribute(radius, 20.0, 3.0)
valueWriter.SetAttribute(radius, 20.0, 4.0)
valueWriter.SetAttribute(height, 2.0, 1.0)
valueWriter.SetAttribute(height, 2.0, 2.0)
valueWriter.SetAttribute(height, 3.0, 3.0)
valueWriter.SetAttribute(height, 3.0, 4.0)

In the above example,

  • The default value of the "height" attribute is not authored into scene description since it matches the fallback value.
  • Time-samples at time=3.0 and time=4.0 will be skipped for the radius attribute.
  • For the "height" attribute, the first timesample at time=1.0 will be skipped since it matches the default value.
  • The last time-sample at time=4.0 will also be skipped for "height" since it matches the previously written value at time=3.0.

Definition at line 229 of file sparseValueWriter.h.

Member Function Documentation

◆ Clear()

USDUTILS_API void Clear ( )
inline

Clears the internal map, thereby releasing all the memory used by the sparse value-writers.

Definition at line 264 of file sparseValueWriter.h.

◆ GetSparseAttrValueWriters()

USDUTILS_API std::vector< UsdUtilsSparseAttrValueWriter > GetSparseAttrValueWriters ( ) const

Returns a new vector of UsdUtilsSparseAttrValueWriter populated from the attrValueWriter map.

◆ SetAttribute() [1/3]

USDUTILS_API bool SetAttribute ( const UsdAttribute attr,
const VtValue value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)

Sets the value of attr to value at time time.

The value is written sparsely, i.e., the default value is authored only if it is different from the fallback value or the existing default value, and any redundant time-samples are skipped when the attribute value does not change significantly between consecutive time-samples.

◆ SetAttribute() [2/3]

bool SetAttribute ( const UsdAttribute attr,
T &  value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 253 of file sparseValueWriter.h.

◆ SetAttribute() [3/3]

USDUTILS_API bool SetAttribute ( const UsdAttribute attr,
VtValue value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. For efficiency, this function swaps out the given value, leaving it empty.

The value will be held in memory at least until the next time-sample is written or until the SparseAttrValueWriter instance is destroyed.


The documentation for this class was generated from the following file: