37 #ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED 40 #include <openvdb/openvdb.h> 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,
99 const std::string& name,
100 const ValueType& uniformValue =
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 =
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 template <
typename Po
intDataTreeT>
194 namespace point_attribute_internal {
196 template<
typename Po
intDataTreeT>
204 const Index strideOrTotalSize = 1,
205 const bool constantStride =
true,
206 const bool hidden =
false,
207 const bool transient =
false)
208 : mDescriptor(descriptor)
210 , mStrideOrTotalSize(strideOrTotalSize)
211 , mConstantStride(constantStride)
213 , mTransient(transient) { }
217 for (
auto leaf = range.begin(); leaf; ++leaf) {
218 const AttributeSet::Descriptor::Ptr expected = leaf->attributeSet().descriptorPtr();
221 *expected, mDescriptor, mPos, mStrideOrTotalSize, mConstantStride);
223 if (mHidden) attribute->setHidden(
true);
224 if (mTransient) attribute->setTransient(
true);
242 template <
typename ValueType,
typename Po
intDataTreeT>
249 const ValueType& uniformValue)
251 , mUniformValue(uniformValue) { }
255 for (
auto leaf = range.begin(); leaf; ++leaf) {
256 assert(leaf->hasAttribute(mPos));
273 template <
typename Po
intDataTreeT>
280 const Name& uniformValue)
282 , mUniformValue(uniformValue) { }
286 for (
auto leaf = range.begin(); leaf; ++leaf) {
287 assert(leaf->hasAttribute(mPos));
290 const AttributeSet::Descriptor& descriptor = leaf->attributeSet().descriptor();
308 template<
typename Po
intDataTreeT>
318 , mDescriptor(descriptor) { }
322 for (
auto leaf = range.begin(); leaf; ++leaf) {
324 const AttributeSet::Descriptor::Ptr expected = leaf->attributeSet().descriptorPtr();
326 leaf->dropAttributes(mIndices, *expected, mDescriptor);
340 template<
typename Po
intDataTreeT>
347 for (
auto leaf = range.begin(); leaf; ++leaf) {
348 leaf->compactAttributes();
357 template<
typename Po
intDataTreeT>
365 : mIndices(indices) { }
369 for (
auto leaf = range.begin(); leaf; ++leaf) {
371 for (
const size_t index : mIndices) {
388 template <
typename ValueType,
typename CodecType>
397 template <
typename CodecType>
400 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
407 template <
typename Po
intDataTreeT,
typename ValueType>
410 static void add(PointDataTreeT&,
const ValueType&) {}
412 template<
typename AttributeListType>
413 static void add(PointDataTreeT&,
const AttributeListType&) {}
417 template <
typename Po
intDataTreeT>
420 static void add(PointDataTreeT& tree,
const Name& uniformValue) {
423 inserter.
insert(uniformValue);
426 template<
typename AttributeListType>
427 static void add(PointDataTreeT& tree,
const AttributeListType& data) {
432 for (
size_t i = 0; i < data.size(); i++) {
446 template <
typename Po
intDataTreeT>
450 const Index strideOrTotalSize,
451 const bool constantStride,
454 const bool transient)
456 using Descriptor = AttributeSet::Descriptor;
460 auto iter = tree.cbeginLeaf();
466 const Descriptor& descriptor = iter->attributeSet().descriptor();
467 const size_t index = descriptor.find(name);
469 if (index != AttributeSet::INVALID_POS) {
471 "Cannot append an attribute with a non-unique name - " << name <<
".");
476 Descriptor::Ptr newDescriptor = descriptor.duplicateAppend(name, type);
480 if (metaDefaultValue) {
481 newDescriptor->setDefaultValue(name, *metaDefaultValue);
486 const size_t pos = newDescriptor->find(name);
491 AppendAttributeOp<PointDataTreeT> append(newDescriptor, pos, strideOrTotalSize,
492 constantStride, hidden,
transient);
493 tbb::parallel_for(leafManager.
leafRange(), append);
500 template <
typename ValueType,
typename CodecType,
typename Po
intDataTreeT>
502 const std::string& name,
503 const ValueType& uniformValue,
504 const Index strideOrTotalSize,
505 const bool constantStride,
508 const bool transient)
510 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
511 "ValueType must not be derived from AttributeArray");
517 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
518 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
521 MetadataStorage<PointDataTreeT, ValueType>::add(tree, uniformValue);
522 collapseAttribute<ValueType>(tree, name, uniformValue);
530 template <
typename ValueType,
typename Po
intDataTreeT>
533 const ValueType& uniformValue)
535 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
536 "ValueType must not be derived from AttributeArray");
539 using Descriptor = AttributeSet::Descriptor;
543 auto iter = tree.cbeginLeaf();
548 const Descriptor& descriptor = iter->attributeSet().descriptor();
552 const size_t index = descriptor.find(name);
553 if (index == AttributeSet::INVALID_POS) {
557 LeafManagerT leafManager(tree);
558 tbb::parallel_for(leafManager.leafRange(),
559 CollapseAttributeOp<ValueType, PointDataTreeT>(index, uniformValue));
566 template <
typename Po
intDataTreeT>
568 const std::vector<size_t>& indices)
571 using Descriptor = AttributeSet::Descriptor;
575 auto iter = tree.cbeginLeaf();
579 const Descriptor& descriptor = iter->attributeSet().descriptor();
583 const size_t positionIndex = descriptor.find(
"P");
584 if (positionIndex!= AttributeSet::INVALID_POS &&
585 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
591 Descriptor::Ptr newDescriptor = descriptor.duplicateDrop(indices);
593 LeafManagerT leafManager(tree);
594 tbb::parallel_for(leafManager.leafRange(),
595 DropAttributesOp<PointDataTreeT>(indices, newDescriptor));
602 template <
typename Po
intDataTreeT>
604 const std::vector<Name>& names)
606 auto iter = tree.cbeginLeaf();
610 const AttributeSet& attributeSet = iter->attributeSet();
611 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
613 std::vector<size_t> indices;
615 for (
const Name& name : names) {
616 const size_t index = descriptor.find(name);
619 if (index == AttributeSet::INVALID_POS) {
621 "Cannot drop an attribute that does not exist - " << name <<
".");
624 indices.push_back(index);
634 template <
typename Po
intDataTreeT>
638 std::vector<size_t> indices{index};
643 template <
typename Po
intDataTreeT>
647 std::vector<Name> names{name};
655 template <
typename Po
intDataTreeT>
657 const std::vector<Name>& oldNames,
658 const std::vector<Name>& newNames)
660 if (oldNames.size() != newNames.size()) {
664 using Descriptor = AttributeSet::Descriptor;
666 auto iter = tree.beginLeaf();
670 const AttributeSet& attributeSet = iter->attributeSet();
671 const Descriptor::Ptr descriptor = attributeSet.
descriptorPtr();
672 auto newDescriptor = std::make_shared<Descriptor>(*descriptor);
674 for (
size_t i = 0; i < oldNames.size(); i++) {
675 const Name& oldName = oldNames[i];
676 if (descriptor->find(oldName) == AttributeSet::INVALID_POS) {
680 const Name& newName = newNames[i];
681 if (descriptor->find(newName) != AttributeSet::INVALID_POS) {
683 "Cannot rename attribute as new name already exists - " << newName <<
".");
693 newDescriptor->rename(oldName, newName);
696 for (; iter; ++iter) {
697 iter->renameAttributes(*descriptor, newDescriptor);
702 template <
typename Po
intDataTreeT>
714 template <
typename Po
intDataTreeT>
721 auto iter = tree.beginLeaf();
724 LeafManagerT leafManager(tree);
725 tbb::parallel_for(leafManager.leafRange(), CompactAttributesOp<PointDataTreeT>());
732 template <
typename Po
intDataTreeT>
739 using Descriptor = AttributeSet::Descriptor;
741 auto iter = tree.cbeginLeaf();
745 const Descriptor& descriptor = iter->attributeSet().descriptor();
749 const size_t index = descriptor.find(name);
750 if (index == AttributeSet::INVALID_POS) {
756 std::vector<size_t> indices{index};
758 LeafManagerT leafManager(tree);
759 tbb::parallel_for(leafManager.leafRange(),
760 BloscCompressAttributesOp<PointDataTreeT>(indices));
770 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:656
Write-able version of AttributeHandle.
Definition: AttributeArray.h:715
Attribute Group access and filtering for iteration.
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...
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:311
void collapse()
Set membership for the whole array and attempt to collapse.
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:344
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
Definition: PointAttribute.h:309
Definition: PointAttribute.h:56
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
DropAttributesOp(const Indices &indices, AttributeSet::DescriptorPtr &descriptor)
Definition: PointAttribute.h:315
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2031
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
const bool mConstantStride
Definition: PointAttribute.h:233
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:276
std::string Name
Definition: Name.h:44
const bool mHidden
Definition: PointAttribute.h:234
const size_t mPos
Definition: PointAttribute.h:231
Definition: AttributeArrayString.h:160
void dropAttribute(PointDataTreeT &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:644
const bool mTransient
Definition: PointAttribute.h:235
const Indices & mIndices
Definition: PointAttribute.h:381
Definition: PointAttribute.h:197
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:202
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:333
const Index mStrideOrTotalSize
Definition: PointAttribute.h:232
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:703
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:346
Definition: PointAttribute.h:341
const Name mUniformValue
Definition: PointAttribute.h:301
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: PointAttribute.h:358
static const NamePair & type()
Definition: PointAttribute.h:400
Definition: Exceptions.h:92
CollapseAttributeOp(const size_t pos, const Name &uniformValue)
Definition: PointAttribute.h:279
std::vector< size_t > Indices
Definition: PointAttribute.h:362
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
std::vector< size_t > Indices
Definition: PointAttribute.h:313
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:284
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:501
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:277
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:200
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:199
Definition: Exceptions.h:40
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:361
Definition: PointAttribute.h:389
BloscCompressAttributesOp(const Indices &indices)
Definition: PointAttribute.h:364
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:320
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:245
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:127
Index32 Index
Definition: Types.h:61
Base class for storing attribute data.
Definition: AttributeArray.h:118
static ValueType value()
Definition: PointAttribute.h:58
static const NamePair & type()
Definition: PointAttribute.h:391
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:215
Definition: PointAttribute.h:243
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
void dropAttributes(PointDataTreeT &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:603
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:343
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:312
typename tree::LeafManager< PointDataTreeT > LeafManagerT
Definition: PointAttribute.h:360
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
const ValueType mUniformValue
Definition: PointAttribute.h:266
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:253
Definition: Exceptions.h:86
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1604
Attribute array storage for string data using Descriptor Metadata.
const Indices & mIndices
Definition: PointAttribute.h:332
Definition: AttributeArray.h:367
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:715
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
AttributeSet::DescriptorPtr & mDescriptor
Definition: PointAttribute.h:230
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
void bloscCompressAttribute(PointDataTreeT &tree, const Name &name)
Apply Blosc compression to one attribute in the VDB tree.
Definition: PointAttribute.h:733
CollapseAttributeOp(const size_t pos, const ValueType &uniformValue)
Definition: PointAttribute.h:248
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointAttribute.h:246
const size_t mPos
Definition: PointAttribute.h:300
const size_t mPos
Definition: PointAttribute.h:265
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:531
void operator()(const LeafRangeT &range) const
Definition: PointAttribute.h:367
Set of Attribute Arrays which tracks metadata about each array.
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
virtual bool compress()=0
Compress the attribute array.
Typed class for storing attribute data.
Definition: AttributeArray.h:441