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 {
189 template<
typename Po
intDataTreeT>
197 const Index strideOrTotalSize = 1,
198 const bool constantStride =
true,
199 const bool hidden =
false,
200 const bool transient =
false)
201 : mDescriptor(descriptor)
203 , mStrideOrTotalSize(strideOrTotalSize)
204 , mConstantStride(constantStride)
206 , mTransient(transient) { }
210 for (
auto leaf = range.begin(); leaf; ++leaf) {
211 const AttributeSet::Descriptor::Ptr expected = leaf->attributeSet().descriptorPtr();
214 *expected, mDescriptor, mPos, mStrideOrTotalSize, mConstantStride);
216 if (mHidden) attribute->setHidden(
true);
217 if (mTransient) attribute->setTransient(
true);
235 template <
typename ValueType,
typename Po
intDataTreeT>
242 const ValueType& uniformValue)
244 , mUniformValue(uniformValue) { }
248 for (
auto leaf = range.begin(); leaf; ++leaf) {
249 assert(leaf->hasAttribute(mPos));
266 template <
typename Po
intDataTreeT>
273 const Name& uniformValue)
275 , mUniformValue(uniformValue) { }
279 for (
auto leaf = range.begin(); leaf; ++leaf) {
280 assert(leaf->hasAttribute(mPos));
283 const AttributeSet::Descriptor& descriptor = leaf->attributeSet().descriptor();
301 template<
typename Po
intDataTreeT>
311 , mDescriptor(descriptor) { }
315 for (
auto leaf = range.begin(); leaf; ++leaf) {
317 const AttributeSet::Descriptor::Ptr expected = leaf->attributeSet().descriptorPtr();
319 leaf->dropAttributes(mIndices, *expected, mDescriptor);
333 template<
typename Po
intDataTreeT>
340 for (
auto leaf = range.begin(); leaf; ++leaf) {
341 leaf->compactAttributes();
350 template <
typename ValueType,
typename CodecType>
359 template <
typename CodecType>
362 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
369 template <
typename Po
intDataTreeT,
typename ValueType>
372 static void add(PointDataTreeT&,
const ValueType&) {}
374 template<
typename AttributeListType>
375 static void add(PointDataTreeT&,
const AttributeListType&) {}
379 template <
typename Po
intDataTreeT>
382 static void add(PointDataTreeT& tree,
const Name& uniformValue) {
385 inserter.
insert(uniformValue);
388 template<
typename AttributeListType>
389 static void add(PointDataTreeT& tree,
const AttributeListType& data) {
394 for (
size_t i = 0; i < data.size(); i++) {
408 template <
typename Po
intDataTreeT>
412 const Index strideOrTotalSize,
413 const bool constantStride,
416 const bool transient)
418 using Descriptor = AttributeSet::Descriptor;
422 auto iter = tree.cbeginLeaf();
428 const Descriptor& descriptor = iter->attributeSet().descriptor();
429 const size_t index = descriptor.find(name);
431 if (index != AttributeSet::INVALID_POS) {
433 "Cannot append an attribute with a non-unique name - " << name <<
".");
438 Descriptor::Ptr newDescriptor = descriptor.duplicateAppend(name, type);
442 if (metaDefaultValue) {
443 newDescriptor->setDefaultValue(name, *metaDefaultValue);
448 const size_t pos = newDescriptor->find(name);
453 AppendAttributeOp<PointDataTreeT> append(newDescriptor, pos, strideOrTotalSize,
454 constantStride, hidden,
transient);
455 tbb::parallel_for(leafManager.
leafRange(), append);
462 template <
typename ValueType,
typename CodecType,
typename Po
intDataTreeT>
464 const std::string& name,
465 const ValueType& uniformValue,
466 const Index strideOrTotalSize,
467 const bool constantStride,
470 const bool transient)
472 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
473 "ValueType must not be derived from AttributeArray");
479 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
480 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
483 MetadataStorage<PointDataTreeT, ValueType>::add(tree, uniformValue);
484 collapseAttribute<ValueType>(tree, name, uniformValue);
492 template <
typename ValueType,
typename Po
intDataTreeT>
495 const ValueType& uniformValue)
497 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
498 "ValueType must not be derived from AttributeArray");
501 using Descriptor = AttributeSet::Descriptor;
505 auto iter = tree.cbeginLeaf();
510 const Descriptor& descriptor = iter->attributeSet().descriptor();
514 const size_t index = descriptor.find(name);
515 if (index == AttributeSet::INVALID_POS) {
519 LeafManagerT leafManager(tree);
520 tbb::parallel_for(leafManager.leafRange(),
521 CollapseAttributeOp<ValueType, PointDataTreeT>(index, uniformValue));
528 template <
typename Po
intDataTreeT>
530 const std::vector<size_t>& indices)
533 using Descriptor = AttributeSet::Descriptor;
537 auto iter = tree.cbeginLeaf();
541 const Descriptor& descriptor = iter->attributeSet().descriptor();
545 const size_t positionIndex = descriptor.find(
"P");
546 if (positionIndex!= AttributeSet::INVALID_POS &&
547 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
553 Descriptor::Ptr newDescriptor = descriptor.duplicateDrop(indices);
555 LeafManagerT leafManager(tree);
556 tbb::parallel_for(leafManager.leafRange(),
557 DropAttributesOp<PointDataTreeT>(indices, newDescriptor));
564 template <
typename Po
intDataTreeT>
566 const std::vector<Name>& names)
568 auto iter = tree.cbeginLeaf();
572 const AttributeSet& attributeSet = iter->attributeSet();
573 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
575 std::vector<size_t> indices;
577 for (
const Name& name : names) {
578 const size_t index = descriptor.find(name);
581 if (index == AttributeSet::INVALID_POS) {
583 "Cannot drop an attribute that does not exist - " << name <<
".");
586 indices.push_back(index);
596 template <
typename Po
intDataTreeT>
600 std::vector<size_t> indices{index};
605 template <
typename Po
intDataTreeT>
609 std::vector<Name> names{name};
617 template <
typename Po
intDataTreeT>
619 const std::vector<Name>& oldNames,
620 const std::vector<Name>& newNames)
622 if (oldNames.size() != newNames.size()) {
626 using Descriptor = AttributeSet::Descriptor;
628 auto iter = tree.beginLeaf();
632 const AttributeSet& attributeSet = iter->attributeSet();
633 const Descriptor::Ptr descriptor = attributeSet.
descriptorPtr();
634 auto newDescriptor = std::make_shared<Descriptor>(*descriptor);
636 for (
size_t i = 0; i < oldNames.size(); i++) {
637 const Name& oldName = oldNames[i];
638 if (descriptor->find(oldName) == AttributeSet::INVALID_POS) {
642 const Name& newName = newNames[i];
643 if (descriptor->find(newName) != AttributeSet::INVALID_POS) {
645 "Cannot rename attribute as new name already exists - " << newName <<
".");
655 newDescriptor->rename(oldName, newName);
658 for (; iter; ++iter) {
659 iter->renameAttributes(*descriptor, newDescriptor);
664 template <
typename Po
intDataTreeT>
676 template <
typename Po
intDataTreeT>
683 auto iter = tree.beginLeaf();
686 LeafManagerT leafManager(tree);
687 tbb::parallel_for(leafManager.leafRange(), CompactAttributesOp<PointDataTreeT>());
694 template <
typename Po
intDataTreeT>
709 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED Definition: PointAttribute.h:190
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:337
Attribute Group access and filtering for iteration.
Index32 Index
Definition: Types.h:61
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:269
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:336
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:305
const Indices & mIndices
Definition: PointAttribute.h:325
Typed class for storing attribute data.
Definition: AttributeArray.h:574
Write-able version of AttributeHandle.
Definition: AttributeArray.h:903
Definition: PointAttribute.h:302
const ValueType mUniformValue
Definition: PointAttribute.h:259
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:208
CollapseAttributeOp(const size_t pos, const ValueType &uniformValue)
Definition: PointAttribute.h:241
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:121
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:677
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2247
void dropAttributes(PointDataTreeT &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:565
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:277
Definition: Exceptions.h:86
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.
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1604
const size_t mPos
Definition: PointAttribute.h:293
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:193
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:192
Definition: PointAttribute.h:351
void collapse()
Set membership for the whole array and attempt to collapse.
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
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:223
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:239
void collapseAttribute(PointDataTreeT &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::Default< ValueType >::value())
Collapse the attribute into a uniform value.
Definition: PointAttribute.h:493
CollapseAttributeOp(const size_t pos, const Name &uniformValue)
Definition: PointAttribute.h:272
static const NamePair & type()
Definition: PointAttribute.h:362
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:246
const size_t mPos
Definition: PointAttribute.h:258
const bool mConstantStride
Definition: PointAttribute.h:226
Definition: Exceptions.h:40
static ValueType value()
Definition: PointAttribute.h:58
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:618
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:144
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:238
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
DropAttributesOp(const Indices &indices, AttributeSet::DescriptorPtr &descriptor)
Definition: PointAttribute.h:308
const bool mTransient
Definition: PointAttribute.h:228
Definition: PointAttribute.h:334
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Base class for storing attribute data.
Definition: AttributeArray.h:118
Definition: PointAttribute.h:56
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:195
Definition: PointAttribute.h:236
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:339
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:304
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:270
void dropAttribute(PointDataTreeT &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:606
std::vector< size_t > Indices
Definition: PointAttribute.h:306
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
Attribute array storage for string data using Descriptor Metadata.
const Index mStrideOrTotalSize
Definition: PointAttribute.h:225
Definition: Exceptions.h:92
const bool mHidden
Definition: PointAttribute.h:227
static const NamePair & type()
Definition: PointAttribute.h:353
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Definition: AttributeArrayString.h:160
const size_t mPos
Definition: PointAttribute.h:224
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:313
std::string Name
Definition: Name.h:44
Set of Attribute Arrays which tracks metadata about each array.
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:665
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:127
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:326
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:463
OPENVDB_DEPRECATED void bloscCompressAttribute(PointDataTreeT &, const Name &)
Definition: PointAttribute.h:695
const Name mUniformValue
Definition: PointAttribute.h:294