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>
72 template <
typename Po
intDataTree>
76 const Index strideOrTotalSize = 1,
77 const bool constantStride =
true,
79 const bool hidden =
false,
80 const bool transient =
false);
92 template <
typename ValueType,
typename CodecType,
typename Po
intDataTree>
94 const std::string& name,
95 const ValueType& uniformValue =
96 point_attribute_internal::defaultValue<ValueType>(),
97 const Index strideOrTotalSize = 1,
98 const bool constantStride =
true,
100 const bool hidden =
false,
101 const bool transient =
false);
113 template <
typename ValueType,
typename Po
intDataTree>
115 const std::string& name,
116 const ValueType& uniformValue =
117 point_attribute_internal::defaultValue<ValueType>(),
118 const Index strideOrTotalSize = 1,
119 const bool constantStride =
true,
121 const bool hidden =
false,
122 const bool transient =
false);
129 template <
typename ValueType,
typename Po
intDataTree>
132 const ValueType& uniformValue =
133 point_attribute_internal::defaultValue<ValueType>());
139 template <
typename Po
intDataTree>
141 const std::vector<size_t>& indices);
147 template <
typename Po
intDataTree>
149 const std::vector<Name>& names);
155 template <
typename Po
intDataTree>
157 const size_t& index);
163 template <
typename Po
intDataTree>
176 template <
typename Po
intDataTree>
178 const std::vector<Name>& oldNames,
179 const std::vector<Name>& newNames);
188 template <
typename Po
intDataTree>
191 const Name& newName);
196 template <
typename Po
intDataTree>
203 template <
typename Po
intDataTree>
210 namespace point_attribute_internal {
212 template<
typename Po
intDataTreeType>
220 const Index strideOrTotalSize = 1,
221 const bool constantStride =
true,
222 const bool hidden =
false,
223 const bool transient =
false)
224 : mDescriptor(descriptor)
226 , mStrideOrTotalSize(strideOrTotalSize)
227 , mConstantStride(constantStride)
229 , mTransient(transient) { }
233 for (
auto leaf = range.begin(); leaf; ++leaf) {
234 const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
237 expected, mDescriptor, mPos, mStrideOrTotalSize, mConstantStride);
239 if (mHidden) attribute->setHidden(
true);
240 if (mTransient) attribute->setTransient(
true);
258 template <
typename ValueType,
typename Po
intDataTreeType>
265 const ValueType& uniformValue)
267 , mUniformValue(uniformValue) { }
271 for (
auto leaf = range.begin(); leaf; ++leaf) {
272 assert(leaf->hasAttribute(mPos));
289 template <
typename Po
intDataTreeType>
296 const Name& uniformValue)
298 , mUniformValue(uniformValue) { }
302 for (
auto leaf = range.begin(); leaf; ++leaf) {
303 assert(leaf->hasAttribute(mPos));
306 const AttributeSet::Descriptor& descriptor = leaf->attributeSet().descriptor();
324 template<
typename Po
intDataTreeType>
334 , mDescriptor(descriptor) { }
338 for (
auto leaf = range.begin(); leaf; ++leaf) {
340 const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
342 leaf->dropAttributes(mIndices, expected, mDescriptor);
356 template<
typename Po
intDataTreeType>
363 for (
auto leaf = range.begin(); leaf; ++leaf) {
364 leaf->compactAttributes();
373 template<
typename Po
intDataTreeType>
381 : mIndices(indices) { }
385 for (
auto leaf = range.begin(); leaf; ++leaf) {
387 for (
const size_t index : mIndices) {
404 template <
typename ValueType,
typename CodecType>
413 template <
typename CodecType>
416 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
423 template <
typename Po
intDataTree,
typename ValueType>
428 template<
typename AttributeListType>
433 template <
typename Po
intDataTree>
439 inserter.
insert(uniformValue);
442 template<
typename AttributeListType>
448 for (
size_t i = 0; i < data.size(); i++) {
462 template <
typename Po
intDataTree>
466 const Index strideOrTotalSize,
467 const bool constantStride,
470 const bool transient)
472 using Descriptor = AttributeSet::Descriptor;
482 const Descriptor& descriptor = iter->attributeSet().descriptor();
483 const size_t index = descriptor.find(name);
485 if (index != AttributeSet::INVALID_POS) {
487 "Cannot append an attribute with a non-unique name - " << name <<
".");
492 Descriptor::Ptr newDescriptor = descriptor.duplicateAppend(name, type);
496 if (metaDefaultValue) {
497 newDescriptor->setDefaultValue(name, *metaDefaultValue);
502 const size_t pos = newDescriptor->find(name);
507 AppendAttributeOp<PointDataTree> append(newDescriptor, pos, strideOrTotalSize,
508 constantStride, hidden,
transient);
509 tbb::parallel_for(leafManager.
leafRange(), append);
516 template <
typename ValueType,
typename CodecType,
typename Po
intDataTree>
518 const std::string& name,
519 const ValueType& uniformValue,
520 const Index strideOrTotalSize,
521 const bool constantStride,
524 const bool transient)
526 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
527 "ValueType must not be derived from AttributeArray");
533 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
534 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
537 MetadataStorage<PointDataTree, ValueType>::add(tree, uniformValue);
538 collapseAttribute<ValueType>(tree, name, uniformValue);
546 template <
typename ValueType,
typename Po
intDataTree>
548 const std::string& name,
549 const ValueType& uniformValue,
550 const Index strideOrTotalSize,
551 const bool constantStride,
554 const bool transient)
556 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
557 "ValueType must not be derived from AttributeArray");
559 appendAttribute<ValueType, NullCodec>(tree, name, uniformValue, strideOrTotalSize,
560 constantStride, metaDefaultValue, hidden,
transient);
567 template <
typename ValueType,
typename Po
intDataTree>
570 const ValueType& uniformValue)
572 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
573 "ValueType must not be derived from AttributeArray");
576 using Descriptor = AttributeSet::Descriptor;
585 const Descriptor& descriptor = iter->attributeSet().descriptor();
589 const size_t index = descriptor.find(name);
590 if (index == AttributeSet::INVALID_POS) {
594 LeafManagerT leafManager(tree);
595 tbb::parallel_for(leafManager.leafRange(),
596 CollapseAttributeOp<ValueType, PointDataTree>(index, uniformValue));
603 template <
typename Po
intDataTree>
605 const std::vector<size_t>& indices)
608 using Descriptor = AttributeSet::Descriptor;
616 const Descriptor& descriptor = iter->attributeSet().descriptor();
620 const size_t positionIndex = descriptor.find(
"P");
621 if (positionIndex!= AttributeSet::INVALID_POS &&
622 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
628 Descriptor::Ptr newDescriptor = descriptor.duplicateDrop(indices);
629 tbb::parallel_for(LeafManagerT(tree).leafRange(),
630 DropAttributesOp<PointDataTree>(indices, newDescriptor));
637 template <
typename Po
intDataTree>
639 const std::vector<Name>& names)
645 const AttributeSet& attributeSet = iter->attributeSet();
646 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
648 std::vector<size_t> indices;
650 for (
const Name& name : names) {
651 const size_t index = descriptor.find(name);
654 if (index == AttributeSet::INVALID_POS) {
656 "Cannot drop an attribute that does not exist - " << name <<
".");
659 indices.push_back(index);
669 template <
typename Po
intDataTree>
673 std::vector<size_t> indices{index};
678 template <
typename Po
intDataTree>
682 std::vector<Name> names{name};
690 template <
typename Po
intDataTree>
692 const std::vector<Name>& oldNames,
693 const std::vector<Name>& newNames)
695 if (oldNames.size() != newNames.size()) {
699 using Descriptor = AttributeSet::Descriptor;
705 const AttributeSet& attributeSet = iter->attributeSet();
706 const Descriptor& descriptor = attributeSet.
descriptor();
707 auto newDescriptor = std::make_shared<Descriptor>(descriptor);
709 for (
size_t i = 0; i < oldNames.size(); i++) {
710 const Name& oldName = oldNames[i];
711 if (descriptor.find(oldName) == AttributeSet::INVALID_POS) {
715 const Name& newName = newNames[i];
716 if (descriptor.find(newName) != AttributeSet::INVALID_POS) {
718 "Cannot rename attribute as new name already exists - " << newName <<
".");
728 newDescriptor->rename(oldName, newName);
731 for (; iter; ++iter) {
732 iter->renameAttributes(descriptor, newDescriptor);
737 template <
typename Po
intDataTree>
749 template <
typename Po
intDataTree>
759 tbb::parallel_for(LeafManagerT(tree).leafRange(), CompactAttributesOp<PointDataTree>());
766 template <
typename Po
intDataTree>
773 using Descriptor = AttributeSet::Descriptor;
779 const Descriptor& descriptor = iter->attributeSet().descriptor();
783 const size_t index = descriptor.find(name);
784 if (index == AttributeSet::INVALID_POS) {
790 std::vector<size_t> indices{index};
792 tbb::parallel_for(LeafManagerT(tree).leafRange(),
793 BloscCompressAttributesOp<PointDataTree>(indices));
803 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED const bool mTransient
Definition: PointAttribute.h:251
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:300
Attribute Group access and filtering for iteration.
const Indices & mIndices
Definition: PointAttribute.h:348
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1182
AppendAttributeOp(AttributeSet::DescriptorPtr &descriptor, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true, const bool hidden=false, const bool transient=false)
Definition: PointAttribute.h:218
const ValueType mUniformValue
Definition: PointAttribute.h:282
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
void bloscCompressAttribute(PointDataTree &tree, const Name &name)
Apply Blosc compression to one attribute in the VDB tree.
Definition: PointAttribute.h:767
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...
BloscCompressAttributesOp(const Indices &indices)
Definition: PointAttribute.h:380
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
void dropAttributes(PointDataTree &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:638
const Name mUniformValue
Definition: PointAttribute.h:317
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
Definition: AttributeArrayString.h:160
Definition: PointAttribute.h:405
void dropAttribute(PointDataTree &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:679
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:349
const Indices & mIndices
Definition: PointAttribute.h:397
Write-able version of AttributeHandle.
Definition: AttributeArray.h:709
CollapseAttributeOp(const size_t pos, const ValueType &uniformValue)
Definition: PointAttribute.h:264
Base class for storing attribute data.
Definition: AttributeArray.h:118
Definition: PointAttribute.h:325
std::vector< size_t > Indices
Definition: PointAttribute.h:378
Definition: PointAttribute.h:374
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:269
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:376
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:231
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:328
const Index mStrideOrTotalSize
Definition: PointAttribute.h:248
ValueType defaultValue()
Definition: PointAttribute.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:43
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:262
CollapseAttributeOp(const size_t pos, const Name &uniformValue)
Definition: PointAttribute.h:295
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:246
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1567
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:391
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:750
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:377
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:336
Definition: Exceptions.h:39
Typed class for storing attribute data.
Definition: AttributeArray.h:437
void collapse()
Set membership for the whole array and attempt to collapse.
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:327
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:216
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:691
const bool mConstantStride
Definition: PointAttribute.h:249
void appendAttribute(PointDataTree &tree, const std::string &name, const ValueType &uniformValue=point_attribute_internal::defaultValue< ValueType >(), 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:547
Definition: PointAttribute.h:213
static const NamePair & type()
Definition: PointAttribute.h:416
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:383
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2000
Definition: Exceptions.h:92
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
void collapseAttribute(PointDataTree &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::defaultValue< ValueType >())
Collapse the attribute into a uniform value.
Definition: PointAttribute.h:568
virtual bool compress()=0
Compress the attribute array.
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:215
const size_t mPos
Definition: PointAttribute.h:281
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:359
std::string Name
Definition: Name.h:44
const bool mHidden
Definition: PointAttribute.h:250
static const NamePair & type()
Definition: PointAttribute.h:407
void renameAttribute(PointDataTree &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:738
DropAttributesOp(const Indices &indices, AttributeSet::DescriptorPtr &descriptor)
Definition: PointAttribute.h:331
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:293
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1180
const size_t mPos
Definition: PointAttribute.h:316
Attribute array storage for string data using Descriptor Metadata.
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:360
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: Exceptions.h:86
std::vector< size_t > Indices
Definition: PointAttribute.h:329
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:261
Index32 Index
Definition: Types.h:57
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:292
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:362
const size_t mPos
Definition: PointAttribute.h:247
Set of Attribute Arrays which tracks metadata about each array.
Definition: PointAttribute.h:259
Definition: PointAttribute.h:357