VtArray#

Fully qualified name: usdrt::VtArray

template<typename ElementType>
class VtArray#

Represents an arbitrary dimensional rectangular container class.

VtArray can

  • own its own CPU memory via a std::vector<ElementType> which follows Copy On Write and Copy On Non-Const Access, semantics the same way Pixar’s VtArray does

  • refer to a Fabric CPU/GPU attribute via a stage ID, a path and an attribute

  • refer to an external CPU python array (numpy) or GPU python array (pytorch/warp)

Special RT functionality When a VtArray is initialized from Fabric data, generally with UsdAttribute.Get(), its underlying span will point at data directly in Fabric. In this default attached state, the VtArray can be used to modify Fabric arrays directly. The developer may choose to make an instance-local copy of the array data using DetachFromSource, at which point modifications happen on the instance-local array. IsFabricData() will let you know if a VtArray instance is reading/writing Fabric data directly. See

Template Parameters:

ElementType – The type of element contained in this VtArray

Public Types

using element_type = ElementType#
using value_type = std::remove_cv_t<ElementType>#
using size_type = std::size_t#
using pointer = element_type*#
using const_pointer = const element_type*#
using reference = element_type&#
using const_reference = const element_type&#
using difference_type = std::ptrdiff_t#
typedef gsl::details::span_iterator<ElementType> iterator#

Iterator.

typedef gsl::details::span_iterator<const ElementType> const_iterator#

Const iterator.

typedef std::reverse_iterator<iterator> reverse_iterator#

Reverse iterator.

typedef std::reverse_iterator<const_iterator> const_reverse_iterator#

Const reverse iterator.

Public Functions

inline VtArray()#

Create an empty array.

inline VtArray(const VtArray<ElementType> &other)#

Copy other. The new array shares underlying data with other.

inline VtArray(VtArray<ElementType> &&other)#

Move from !p other. The new array takes ownership of !p other’s underlying data.

inline VtArray(size_t n)#

Create an array with n value-initialized elements.

inline VtArray(gsl::span<ElementType> span)#

Create a new array from span.

Make a copy of data from span that is unique to this instance.

inline VtArray(const std::vector<ElementType> &vec)#

Create a new array from vec.

Make a copy of data from vec that is unique to this instance.

inline VtArray(size_t n, ElementType *data, void *gpuData)#

Create a new array from given data.

Parameters:
  • n – size of array

  • data – Pointer to n elements.

  • gpuData – Pointer to GPU data.

inline VtArray(std::initializer_list<ElementType> initList)#

Create a new array from initList.

Make a copy of data from initList that is unique to this instance.

Parameters:

initList

inline VtArray(
omni::fabric::StageReaderWriterId stageId,
omni::fabric::PathC path,
omni::fabric::TokenC attr,
)#

Create a new array that points to fabric data.

Parameters:
  • stageId – stage on which this data exists.

  • path – path to the attribute whose value is this array data.

  • attr – attribute name whose value is this array data.

inline virtual ~VtArray()#

Destructor.

inline virtual VtArray &operator=(
const VtArray<ElementType> &other,
)#

Copy assign from other. This array shares underlying data with other.

inline VtArray &operator=(gsl::span<ElementType> other)#

Replace current array contents with a copy of those in other.

inline VtArray &operator=(
std::initializer_list<ElementType> initList,
)#

Replace current array contents with a copy of those in initList.

inline ElementType &operator[](size_t index)#

Allows usage of [i]. TODO more detail of gpu & fabric stuff.

inline ElementType const &operator[](size_t index) const#

Allows usage of [i].

inline size_t size() const#

Return the total number of elements in this array.

inline size_t capacity() const#

Return the capacity of this array.

inline bool empty() const#

Check if this array is empty.

Returns:

Return true if empty, false otherwise.

inline virtual void reset()#

Reset this array to empty.

Reset the capactiy to 0, delete the contents, an nullify any external data pointers.

inline void resize(size_t newSize)#

Resize this array.

Localize the data, and resize. Increase the capacity if needed.

Parameters:

newSize – New length of this array.

inline void reserve(size_t num)#

Reserve memory to increase the length of this array.

Localize the data. If num is less than the max capacity of this array, reserve new localized memory for an array of size num. If this instance already contains local data, copy that to the new span.

Used by push_back.

Parameters:

num – new size of this array.

inline void push_back(const ElementType &element)#

Append element to the back of the array.

Parameters:

element – New element to add.

inline pointer data()#

Localize the data, and return a pointer to the beginning of the data sequence.

inline const_pointer data() const#

Return a const pointer to the beginning of the data sequence.

inline const_pointer cdata() const#

Return a const pointer to the beginning of the data sequence.

inline gsl::span<ElementType> span()#

Get the span for this data array.

This can be:

  • the localized CPU memory

  • the Fabric data

  • the external CPU python array (numpy)

  • or the GPU python array (pytorch/warp)

Returns:

Return the span for this data array.

inline gsl::span<const ElementType> cspan() const#

Get the const span for this data array.

This can be:

  • the localized CPU memory

  • the Fabric data

  • the external CPU python array (numpy)

  • or the GPU python array (pytorch/warp)

Returns:

Return the const span for this data array.

inline void DetachFromSource()#

Make an instance-local copy of the fabric array data, at which point modifications happen on the instance-local array.

inline bool IsFabricData() const#

Check if this instance is reading/writing Fabric data directly.

Returns:

true if this instance is reading/writing fabric data directly, and false if the data has been localized. See DetatchFromSource.

inline virtual bool IsPythonData() const#

Check if this instance was created from an external python object (buffer or cuda array interface)

Returns:

Returns true if this instance was created from an external python object.

inline bool IsOwnData() const#

Check if this instance contains its own localized data (not external or fabric data)

Returns:

Return true if this data is localized.

inline bool HasFabricCpuData() const#

Check if this instance has fabric cpu data. Debug use only.

Warning

For debug use only.

Returns:

Return true if this instance has fabric CPU data, and false otherwise.

inline bool HasFabricGpuData() const#

Check if this instance has fabric Gpu data. Debug use only.

Warning

For debug use only.

Returns:

Return true if this instance has fabric GPU data, and false otherwise.

inline void *GetGpuData() const#

Get GPU data. Debugging use only.

Warning

For debug use only.

Returns:

Return void* pointer to GPU data.

inline iterator begin()#

Localizes the data, and returns an iterator to the first element in this array.

inline iterator end()#

Returns an iterator to the element following the last element in this array.

inline const_iterator cbegin()#

Returns a const iterator to the first element in this array.

inline const_iterator cend()#

Returns a const iterator to the element following the last element in this array.

inline reverse_iterator rbegin()#

Localize the data, and return an iterator to the element following the last element in this array.

inline reverse_iterator rend()#

Returns an iterator to the first element in this array.

inline const_reverse_iterator rbegin() const#

Localize the data, and return a const iterator to the element following the last element in this array.

inline const_reverse_iterator rend() const#

Returns a const iterator to the first element in this array.

inline const_reverse_iterator crbegin() const#

Localize the data, and return a const iterator to the element following the last element in this array.

inline const_reverse_iterator crend() const#

Returns a const iterator to the first element in this array.