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
intDataTree>
79 const Index strideOrTotalSize = 1,
80 const bool constantStride =
true,
82 const bool hidden =
false,
83 const bool transient =
false);
95 template <
typename ValueType,
typename CodecType,
typename Po
intDataTree>
97 const std::string& name,
98 const ValueType& uniformValue =
99 point_attribute_internal::Default<ValueType>::value(),
100 const Index strideOrTotalSize = 1,
101 const bool constantStride =
true,
103 const bool hidden =
false,
104 const bool transient =
false);
116 template <
typename ValueType,
typename Po
intDataTree>
118 const std::string& name,
119 const ValueType& uniformValue =
120 point_attribute_internal::Default<ValueType>::value(),
121 const Index strideOrTotalSize = 1,
122 const bool constantStride =
true,
124 const bool hidden =
false,
125 const bool transient =
false);
132 template <
typename ValueType,
typename Po
intDataTree>
135 const ValueType& uniformValue =
136 point_attribute_internal::Default<ValueType>::value());
142 template <
typename Po
intDataTree>
144 const std::vector<size_t>& indices);
150 template <
typename Po
intDataTree>
152 const std::vector<Name>& names);
158 template <
typename Po
intDataTree>
160 const size_t& index);
166 template <
typename Po
intDataTree>
179 template <
typename Po
intDataTree>
181 const std::vector<Name>& oldNames,
182 const std::vector<Name>& newNames);
191 template <
typename Po
intDataTree>
194 const Name& newName);
199 template <
typename Po
intDataTree>
206 template <
typename Po
intDataTree>
213 namespace point_attribute_internal {
215 template<
typename Po
intDataTreeType>
223 const Index strideOrTotalSize = 1,
224 const bool constantStride =
true,
225 const bool hidden =
false,
226 const bool transient =
false)
227 : mDescriptor(descriptor)
229 , mStrideOrTotalSize(strideOrTotalSize)
230 , mConstantStride(constantStride)
232 , mTransient(transient) { }
236 for (
auto leaf = range.begin(); leaf; ++leaf) {
237 const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
240 expected, mDescriptor, mPos, mStrideOrTotalSize, mConstantStride);
242 if (mHidden) attribute->setHidden(
true);
243 if (mTransient) attribute->setTransient(
true);
261 template <
typename ValueType,
typename Po
intDataTreeType>
268 const ValueType& uniformValue)
270 , mUniformValue(uniformValue) { }
274 for (
auto leaf = range.begin(); leaf; ++leaf) {
275 assert(leaf->hasAttribute(mPos));
292 template <
typename Po
intDataTreeType>
299 const Name& uniformValue)
301 , mUniformValue(uniformValue) { }
305 for (
auto leaf = range.begin(); leaf; ++leaf) {
306 assert(leaf->hasAttribute(mPos));
309 const AttributeSet::Descriptor& descriptor = leaf->attributeSet().descriptor();
327 template<
typename Po
intDataTreeType>
337 , mDescriptor(descriptor) { }
341 for (
auto leaf = range.begin(); leaf; ++leaf) {
343 const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
345 leaf->dropAttributes(mIndices, expected, mDescriptor);
359 template<
typename Po
intDataTreeType>
366 for (
auto leaf = range.begin(); leaf; ++leaf) {
367 leaf->compactAttributes();
376 template<
typename Po
intDataTreeType>
384 : mIndices(indices) { }
388 for (
auto leaf = range.begin(); leaf; ++leaf) {
390 for (
const size_t index : mIndices) {
407 template <
typename ValueType,
typename CodecType>
416 template <
typename CodecType>
419 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
426 template <
typename Po
intDataTree,
typename ValueType>
431 template<
typename AttributeListType>
436 template <
typename Po
intDataTree>
442 inserter.
insert(uniformValue);
445 template<
typename AttributeListType>
451 for (
size_t i = 0; i < data.size(); i++) {
465 template <
typename Po
intDataTree>
469 const Index strideOrTotalSize,
470 const bool constantStride,
473 const bool transient)
475 using Descriptor = AttributeSet::Descriptor;
485 const Descriptor& descriptor = iter->attributeSet().descriptor();
486 const size_t index = descriptor.find(name);
488 if (index != AttributeSet::INVALID_POS) {
490 "Cannot append an attribute with a non-unique name - " << name <<
".");
495 Descriptor::Ptr newDescriptor = descriptor.duplicateAppend(name, type);
499 if (metaDefaultValue) {
500 newDescriptor->setDefaultValue(name, *metaDefaultValue);
505 const size_t pos = newDescriptor->find(name);
510 AppendAttributeOp<PointDataTree> append(newDescriptor, pos, strideOrTotalSize,
511 constantStride, hidden,
transient);
512 tbb::parallel_for(leafManager.
leafRange(), append);
519 template <
typename ValueType,
typename CodecType,
typename Po
intDataTree>
521 const std::string& name,
522 const ValueType& uniformValue,
523 const Index strideOrTotalSize,
524 const bool constantStride,
527 const bool transient)
529 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
530 "ValueType must not be derived from AttributeArray");
536 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
537 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
540 MetadataStorage<PointDataTree, ValueType>::add(tree, uniformValue);
541 collapseAttribute<ValueType>(tree, name, uniformValue);
549 template <
typename ValueType,
typename Po
intDataTree>
551 const std::string& name,
552 const ValueType& uniformValue,
553 const Index strideOrTotalSize,
554 const bool constantStride,
557 const bool transient)
559 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
560 "ValueType must not be derived from AttributeArray");
562 appendAttribute<ValueType, NullCodec>(tree, name, uniformValue, strideOrTotalSize,
563 constantStride, metaDefaultValue, hidden,
transient);
570 template <
typename ValueType,
typename Po
intDataTree>
573 const ValueType& uniformValue)
575 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
576 "ValueType must not be derived from AttributeArray");
579 using Descriptor = AttributeSet::Descriptor;
588 const Descriptor& descriptor = iter->attributeSet().descriptor();
592 const size_t index = descriptor.find(name);
593 if (index == AttributeSet::INVALID_POS) {
597 LeafManagerT leafManager(tree);
598 tbb::parallel_for(leafManager.leafRange(),
599 CollapseAttributeOp<ValueType, PointDataTree>(index, uniformValue));
606 template <
typename Po
intDataTree>
608 const std::vector<size_t>& indices)
611 using Descriptor = AttributeSet::Descriptor;
619 const Descriptor& descriptor = iter->attributeSet().descriptor();
623 const size_t positionIndex = descriptor.find(
"P");
624 if (positionIndex!= AttributeSet::INVALID_POS &&
625 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
631 Descriptor::Ptr newDescriptor = descriptor.duplicateDrop(indices);
632 tbb::parallel_for(LeafManagerT(tree).leafRange(),
633 DropAttributesOp<PointDataTree>(indices, newDescriptor));
640 template <
typename Po
intDataTree>
642 const std::vector<Name>& names)
648 const AttributeSet& attributeSet = iter->attributeSet();
649 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
651 std::vector<size_t> indices;
653 for (
const Name& name : names) {
654 const size_t index = descriptor.find(name);
657 if (index == AttributeSet::INVALID_POS) {
659 "Cannot drop an attribute that does not exist - " << name <<
".");
662 indices.push_back(index);
672 template <
typename Po
intDataTree>
676 std::vector<size_t> indices{index};
681 template <
typename Po
intDataTree>
685 std::vector<Name> names{name};
693 template <
typename Po
intDataTree>
695 const std::vector<Name>& oldNames,
696 const std::vector<Name>& newNames)
698 if (oldNames.size() != newNames.size()) {
702 using Descriptor = AttributeSet::Descriptor;
708 const AttributeSet& attributeSet = iter->attributeSet();
709 const Descriptor& descriptor = attributeSet.
descriptor();
710 auto newDescriptor = std::make_shared<Descriptor>(descriptor);
712 for (
size_t i = 0; i < oldNames.size(); i++) {
713 const Name& oldName = oldNames[i];
714 if (descriptor.find(oldName) == AttributeSet::INVALID_POS) {
718 const Name& newName = newNames[i];
719 if (descriptor.find(newName) != AttributeSet::INVALID_POS) {
721 "Cannot rename attribute as new name already exists - " << newName <<
".");
731 newDescriptor->rename(oldName, newName);
734 for (; iter; ++iter) {
735 iter->renameAttributes(descriptor, newDescriptor);
740 template <
typename Po
intDataTree>
752 template <
typename Po
intDataTree>
762 tbb::parallel_for(LeafManagerT(tree).leafRange(), CompactAttributesOp<PointDataTree>());
769 template <
typename Po
intDataTree>
776 using Descriptor = AttributeSet::Descriptor;
782 const Descriptor& descriptor = iter->attributeSet().descriptor();
786 const size_t index = descriptor.find(name);
787 if (index == AttributeSet::INVALID_POS) {
793 std::vector<size_t> indices{index};
795 tbb::parallel_for(LeafManagerT(tree).leafRange(),
796 BloscCompressAttributesOp<PointDataTree>(indices));
806 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
Definition: PointAttribute.h:328
Definition: AttributeArrayString.h:160
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1179
Definition: Exceptions.h:86
Typed class for storing attribute data.
Definition: AttributeArray.h:441
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:296
const bool mConstantStride
Definition: PointAttribute.h:252
Attribute Group access and filtering for iteration.
Base class for storing attribute data.
Definition: AttributeArray.h:118
std::string Name
Definition: Name.h:44
const size_t mPos
Definition: PointAttribute.h:284
void collapse()
Set membership for the whole array and attempt to collapse.
void appendAttribute(PointDataTree &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:550
static const NamePair & type()
Definition: PointAttribute.h:410
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:365
std::vector< size_t > Indices
Definition: PointAttribute.h:381
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2020
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:694
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:770
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:339
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:386
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:234
const size_t mPos
Definition: PointAttribute.h:250
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:753
static const NamePair & type()
Definition: PointAttribute.h:419
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:264
std::vector< size_t > Indices
Definition: PointAttribute.h:332
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:219
DropAttributesOp(const Indices &indices, AttributeSet::DescriptorPtr &descriptor)
Definition: PointAttribute.h:334
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:352
void dropAttribute(PointDataTree &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:682
void collapseAttribute(PointDataTree &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::Default< ValueType >::value())
Collapse the attribute into a uniform value.
Definition: PointAttribute.h:571
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
const bool mTransient
Definition: PointAttribute.h:254
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...
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:295
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: Exceptions.h:92
void dropAttributes(PointDataTree &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:641
Definition: Exceptions.h:40
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1181
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
Definition: PointAttribute.h:377
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:362
Definition: PointAttribute.h:408
const Name mUniformValue
Definition: PointAttribute.h:320
const ValueType mUniformValue
Definition: PointAttribute.h:285
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:363
Definition: PointAttribute.h:56
Write-able version of AttributeHandle.
Definition: AttributeArray.h:713
const bool mHidden
Definition: PointAttribute.h:253
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:379
const Indices & mIndices
Definition: PointAttribute.h:351
CollapseAttributeOp(const size_t pos, const ValueType &uniformValue)
Definition: PointAttribute.h:267
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:272
const size_t mPos
Definition: PointAttribute.h:319
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:218
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointAttribute.h:330
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:265
void renameAttribute(PointDataTree &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:741
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:331
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1616
Attribute array storage for string data using Descriptor Metadata.
static ValueType value()
Definition: PointAttribute.h:58
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:380
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:249
BloscCompressAttributesOp(const Indices &indices)
Definition: PointAttribute.h:383
Index32 Index
Definition: Types.h:61
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Definition: PointAttribute.h:360
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:303
Definition: PointAttribute.h:262
const Index mStrideOrTotalSize
Definition: PointAttribute.h:251
Definition: PointAttribute.h:216
const Indices & mIndices
Definition: PointAttribute.h:400
Set of Attribute Arrays which tracks metadata about each array.
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
virtual bool compress()=0
Compress the attribute array.
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:221
CollapseAttributeOp(const size_t pos, const Name &uniformValue)
Definition: PointAttribute.h:298
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