Go to the documentation of this file.
37 #ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
53 namespace point_attribute_internal {
55 template <
typename ValueType>
58 static inline ValueType
value() {
return zeroVal<ValueType>(); }
75 template <
typename Po
intDataTreeT>
79 const Index strideOrTotalSize = 1,
80 const bool constantStride =
true,
82 const bool hidden =
false,
83 const bool transient =
false);
95 template <
typename ValueType,
96 typename CodecType = NullCodec,
99 const std::string& name,
100 const ValueType& uniformValue =
101 point_attribute_internal::Default<ValueType>::value(),
102 const Index strideOrTotalSize = 1,
103 const bool constantStride =
true,
105 const bool hidden =
false,
106 const bool transient =
false);
113 template <
typename ValueType,
typename Po
intDataTreeT>
116 const ValueType& uniformValue =
117 point_attribute_internal::Default<ValueType>::value());
123 template <
typename Po
intDataTreeT>
125 const std::vector<size_t>& indices);
131 template <
typename Po
intDataTreeT>
133 const std::vector<Name>& names);
139 template <
typename Po
intDataTreeT>
141 const size_t& index);
147 template <
typename Po
intDataTreeT>
160 template <
typename Po
intDataTreeT>
162 const std::vector<Name>& oldNames,
163 const std::vector<Name>& newNames);
172 template <
typename Po
intDataTreeT>
175 const Name& newName);
180 template <
typename Po
intDataTreeT>
187 namespace point_attribute_internal {
190 template <
typename ValueType>
192 const AttributeSet::Descriptor&,
const ValueType& uniformValue)
200 const AttributeSet::Descriptor& descriptor,
const Name& uniformValue)
210 template <
typename ValueType,
typename CodecType>
219 template <
typename CodecType>
222 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
229 template <
typename Po
intDataTreeT,
typename ValueType>
232 static void add(PointDataTreeT&,
const ValueType&) {}
234 template<
typename AttributeListType>
235 static void add(PointDataTreeT&,
const AttributeListType&) {}
239 template <
typename Po
intDataTreeT>
242 static void add(PointDataTreeT& tree,
const Name& uniformValue) {
245 inserter.
insert(uniformValue);
248 template<
typename AttributeListType>
249 static void add(PointDataTreeT& tree,
const AttributeListType& data) {
254 for (
size_t i = 0; i < data.size(); i++) {
268 template <
typename Po
intDataTreeT>
272 const Index strideOrTotalSize,
273 const bool constantStride,
276 const bool transient)
278 auto iter = tree.cbeginLeaf();
284 const auto& descriptor = iter->attributeSet().descriptor();
285 const size_t index = descriptor.find(name);
287 if (index != AttributeSet::INVALID_POS) {
289 "Cannot append an attribute with a non-unique name - " << name <<
".");
294 auto newDescriptor = descriptor.duplicateAppend(name, type);
298 if (metaDefaultValue) {
299 newDescriptor->setDefaultValue(name, *metaDefaultValue);
304 const size_t pos = newDescriptor->find(name);
315 auto expected = leaf.attributeSet().descriptorPtr();
317 auto attribute = leaf.appendAttribute(*expected, newDescriptor,
318 pos, strideOrTotalSize, constantStride, &lock);
320 if (hidden) attribute->setHidden(
true);
321 if (
transient) attribute->setTransient(
true);
330 template <
typename ValueType,
typename CodecType,
typename Po
intDataTreeT>
332 const std::string& name,
333 const ValueType& uniformValue,
334 const Index strideOrTotalSize,
335 const bool constantStride,
338 const bool transient)
340 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
341 "ValueType must not be derived from AttributeArray");
347 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
348 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
351 MetadataStorage<PointDataTreeT, ValueType>::add(tree, uniformValue);
352 collapseAttribute<ValueType>(tree, name, uniformValue);
360 template <
typename ValueType,
typename Po
intDataTreeT>
363 const ValueType& uniformValue)
365 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
366 "ValueType must not be derived from AttributeArray");
368 auto iter = tree.cbeginLeaf();
372 const auto& descriptor = iter->attributeSet().descriptor();
376 const size_t index = descriptor.find(name);
377 if (index == AttributeSet::INVALID_POS) {
384 assert(leaf.hasAttribute(index));
387 array, descriptor, uniformValue);
396 template <
typename Po
intDataTreeT>
398 const std::vector<size_t>& indices)
400 auto iter = tree.cbeginLeaf();
404 const auto& descriptor = iter->attributeSet().descriptor();
408 const size_t positionIndex = descriptor.find(
"P");
409 if (positionIndex!= AttributeSet::INVALID_POS &&
410 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
416 auto newDescriptor = descriptor.duplicateDrop(indices);
421 auto expected = leaf.attributeSet().descriptorPtr();
422 leaf.dropAttributes(indices, *expected, newDescriptor);
431 template <
typename Po
intDataTreeT>
433 const std::vector<Name>& names)
435 auto iter = tree.cbeginLeaf();
439 const AttributeSet& attributeSet = iter->attributeSet();
440 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
442 std::vector<size_t> indices;
444 for (
const Name& name : names) {
445 const size_t index = descriptor.find(name);
448 if (index == AttributeSet::INVALID_POS) {
450 "Cannot drop an attribute that does not exist - " << name <<
".");
453 indices.push_back(index);
463 template <
typename Po
intDataTreeT>
467 std::vector<size_t> indices{index};
472 template <
typename Po
intDataTreeT>
476 std::vector<Name> names{name};
484 template <
typename Po
intDataTreeT>
486 const std::vector<Name>& oldNames,
487 const std::vector<Name>& newNames)
489 if (oldNames.size() != newNames.size()) {
493 using Descriptor = AttributeSet::Descriptor;
495 auto iter = tree.beginLeaf();
499 const AttributeSet& attributeSet = iter->attributeSet();
500 const Descriptor::Ptr descriptor = attributeSet.
descriptorPtr();
501 auto newDescriptor = std::make_shared<Descriptor>(*descriptor);
503 for (
size_t i = 0; i < oldNames.size(); i++) {
504 const Name& oldName = oldNames[i];
505 if (descriptor->find(oldName) == AttributeSet::INVALID_POS) {
509 const Name& newName = newNames[i];
510 if (descriptor->find(newName) != AttributeSet::INVALID_POS) {
512 "Cannot rename attribute as new name already exists - " << newName <<
".");
522 newDescriptor->rename(oldName, newName);
525 for (; iter; ++iter) {
526 iter->renameAttributes(*descriptor, newDescriptor);
531 template <
typename Po
intDataTreeT>
543 template <
typename Po
intDataTreeT>
546 auto iter = tree.beginLeaf();
552 leaf.compactAttributes();
561 template <
typename Po
intDataTreeT>
576 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
Set of Attribute Arrays which tracks metadata about each array.
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2292
std::string Name
Definition: Name.h:44
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:415
void dropAttribute(PointDataTreeT &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:473
Write-able version of AttributeHandle.
Definition: AttributeArray.h:944
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1618
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
void appendAttribute(PointDataTreeT &tree, const std::string &name, const ValueType &uniformValue=point_attribute_internal::Default< ValueType >::value(), const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree.
Definition: PointAttribute.h:331
const AttributeArray * getConst(const std::string &name) const
Return a pointer to the attribute array whose name is name or a null pointer if no match is found.
Index32 Index
Definition: Types.h:61
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:125
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > >> PointDataTree
Point index tree configured to match the default VDB configurations.
Definition: PointDataGrid.h:216
Definition: AttributeArray.h:145
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:212
Definition: Exceptions.h:92
Attribute Group access and filtering for iteration.
void dropAttributes(PointDataTreeT &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:432
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: PointAttribute.h:211
static const NamePair & type()
Definition: PointAttribute.h:213
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:485
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
void collapseAttribute(AttributeArray &array, const AttributeSet::Descriptor &descriptor, const Name &uniformValue)
Definition: PointAttribute.h:199
Attribute array storage for string data using Descriptor Metadata.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
static const NamePair & type()
Definition: PointAttribute.h:222
Base class for storing attribute data.
Definition: AttributeArray.h:118
Definition: AttributeArrayString.h:168
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:532
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:544
Definition: PointAttribute.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:134
Typed class for storing attribute data.
Definition: AttributeArray.h:608
Definition: Exceptions.h:86
OPENVDB_DEPRECATED void bloscCompressAttribute(PointDataTreeT &, const Name &)
Definition: PointAttribute.h:562
Definition: Exceptions.h:40
void collapse()
Set membership for the whole array and attempt to collapse.
void foreach(const LeafOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager.
Definition: LeafManager.h:523
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:131
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
static ValueType value()
Definition: PointAttribute.h:58