10 #ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED 26 namespace point_attribute_internal {
28 template <
typename ValueType>
31 static inline ValueType
value() {
return zeroVal<ValueType>(); }
48 template <
typename Po
intDataTreeT>
52 const Index strideOrTotalSize = 1,
53 const bool constantStride =
true,
55 const bool hidden =
false,
56 const bool transient =
false);
68 template <
typename ValueType,
69 typename CodecType = NullCodec,
72 const std::string& name,
73 const ValueType& uniformValue =
74 point_attribute_internal::Default<ValueType>::value(),
75 const Index strideOrTotalSize = 1,
76 const bool constantStride =
true,
78 const bool hidden =
false,
79 const bool transient =
false);
86 template <
typename ValueType,
typename Po
intDataTreeT>
89 const ValueType& uniformValue =
90 point_attribute_internal::Default<ValueType>::value());
96 template <
typename Po
intDataTreeT>
98 const std::vector<size_t>& indices);
104 template <
typename Po
intDataTreeT>
106 const std::vector<Name>& names);
112 template <
typename Po
intDataTreeT>
114 const size_t& index);
120 template <
typename Po
intDataTreeT>
133 template <
typename Po
intDataTreeT>
135 const std::vector<Name>& oldNames,
136 const std::vector<Name>& newNames);
145 template <
typename Po
intDataTreeT>
148 const Name& newName);
153 template <
typename Po
intDataTreeT>
160 namespace point_attribute_internal {
163 template <
typename ValueType>
165 const AttributeSet::Descriptor&,
const ValueType& uniformValue)
173 const AttributeSet::Descriptor& descriptor,
const Name& uniformValue)
183 template <
typename ValueType,
typename CodecType>
192 template <
typename CodecType>
195 static const NamePair&
type() {
return StringAttributeArray::attributeType(); }
202 template <
typename Po
intDataTreeT,
typename ValueType>
205 static void add(PointDataTreeT&,
const ValueType&) {}
207 template<
typename AttributeListType>
208 static void add(PointDataTreeT&,
const AttributeListType&) {}
212 template <
typename Po
intDataTreeT>
215 static void add(PointDataTreeT& tree,
const Name& uniformValue) {
218 inserter.
insert(uniformValue);
221 template<
typename AttributeListType>
222 static void add(PointDataTreeT& tree,
const AttributeListType& data) {
227 for (
size_t i = 0; i < data.size(); i++) {
241 template <
typename Po
intDataTreeT>
245 const Index strideOrTotalSize,
246 const bool constantStride,
249 const bool transient)
251 auto iter = tree.cbeginLeaf();
257 const auto& descriptor = iter->attributeSet().descriptor();
258 const size_t index = descriptor.find(name);
260 if (index != AttributeSet::INVALID_POS) {
262 "Cannot append an attribute with a non-unique name - " << name <<
".");
267 auto newDescriptor = descriptor.duplicateAppend(name, type);
271 if (metaDefaultValue) {
272 newDescriptor->setDefaultValue(name, *metaDefaultValue);
277 const size_t pos = newDescriptor->find(name);
288 auto expected = leaf.attributeSet().descriptorPtr();
290 auto attribute = leaf.appendAttribute(*expected, newDescriptor,
291 pos, strideOrTotalSize, constantStride, &lock);
293 if (hidden) attribute->setHidden(
true);
294 if (
transient) attribute->setTransient(
true);
303 template <
typename ValueType,
typename CodecType,
typename Po
intDataTreeT>
305 const std::string& name,
306 const ValueType& uniformValue,
307 const Index strideOrTotalSize,
308 const bool constantStride,
311 const bool transient)
313 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
314 "ValueType must not be derived from AttributeArray");
320 appendAttribute(tree, name, AttributeTypeConversion<ValueType, CodecType>::type(),
321 strideOrTotalSize, constantStride, metaDefaultValue, hidden,
transient);
324 MetadataStorage<PointDataTreeT, ValueType>::add(tree, uniformValue);
325 collapseAttribute<ValueType>(tree, name, uniformValue);
333 template <
typename ValueType,
typename Po
intDataTreeT>
336 const ValueType& uniformValue)
338 static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
339 "ValueType must not be derived from AttributeArray");
341 auto iter = tree.cbeginLeaf();
345 const auto& descriptor = iter->attributeSet().descriptor();
349 const size_t index = descriptor.find(name);
350 if (index == AttributeSet::INVALID_POS) {
357 assert(leaf.hasAttribute(index));
360 array, descriptor, uniformValue);
369 template <
typename Po
intDataTreeT>
371 const std::vector<size_t>& indices)
373 auto iter = tree.cbeginLeaf();
377 const auto& descriptor = iter->attributeSet().descriptor();
381 const size_t positionIndex = descriptor.find(
"P");
382 if (positionIndex!= AttributeSet::INVALID_POS &&
383 std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
389 auto newDescriptor = descriptor.duplicateDrop(indices);
394 auto expected = leaf.attributeSet().descriptorPtr();
395 leaf.dropAttributes(indices, *expected, newDescriptor);
404 template <
typename Po
intDataTreeT>
406 const std::vector<Name>& names)
408 auto iter = tree.cbeginLeaf();
412 const AttributeSet& attributeSet = iter->attributeSet();
413 const AttributeSet::Descriptor& descriptor = attributeSet.
descriptor();
415 std::vector<size_t> indices;
417 for (
const Name& name : names) {
418 const size_t index = descriptor.find(name);
421 if (index == AttributeSet::INVALID_POS) {
423 "Cannot drop an attribute that does not exist - " << name <<
".");
426 indices.push_back(index);
436 template <
typename Po
intDataTreeT>
440 std::vector<size_t> indices{index};
445 template <
typename Po
intDataTreeT>
449 std::vector<Name> names{name};
457 template <
typename Po
intDataTreeT>
459 const std::vector<Name>& oldNames,
460 const std::vector<Name>& newNames)
462 if (oldNames.size() != newNames.size()) {
466 using Descriptor = AttributeSet::Descriptor;
468 auto iter = tree.beginLeaf();
472 const AttributeSet& attributeSet = iter->attributeSet();
473 const Descriptor::Ptr descriptor = attributeSet.
descriptorPtr();
474 auto newDescriptor = std::make_shared<Descriptor>(*descriptor);
476 for (
size_t i = 0; i < oldNames.size(); i++) {
477 const Name& oldName = oldNames[i];
478 if (descriptor->find(oldName) == AttributeSet::INVALID_POS) {
482 const Name& newName = newNames[i];
483 if (descriptor->find(newName) != AttributeSet::INVALID_POS) {
485 "Cannot rename attribute as new name already exists - " << newName <<
".");
495 newDescriptor->rename(oldName, newName);
498 for (; iter; ++iter) {
499 iter->renameAttributes(*descriptor, newDescriptor);
504 template <
typename Po
intDataTreeT>
516 template <
typename Po
intDataTreeT>
519 auto iter = tree.beginLeaf();
525 leaf.compactAttributes();
534 template <
typename Po
intDataTreeT>
549 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED Attribute Group access and filtering for iteration.
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:458
void dropAttribute(PointDataTreeT &tree, const Name &name)
Drop one attribute from the VDB tree (convenience method).
Definition: PointAttribute.h:446
OPENVDB_DEPRECATED void bloscCompressAttribute(PointDataTreeT &, const Name &)
Definition: PointAttribute.h:535
void collapse()
Set membership for the whole array and attempt to collapse.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
std::string Name
Definition: Name.h:17
Base class for storing attribute data.
Definition: AttributeArray.h:92
Definition: AttributeArray.h:119
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:98
Definition: PointAttribute.h:29
Definition: Exceptions.h:59
void collapseAttribute(AttributeArray &array, const AttributeSet::Descriptor &descriptor, const Name &uniformValue)
Definition: PointAttribute.h:172
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition: PointAttribute.h:505
Definition: AttributeArrayString.h:141
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.
Typed class for storing attribute data.
Definition: AttributeArray.h:566
Definition: Exceptions.h:65
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:66
static const NamePair & type()
Definition: PointAttribute.h:195
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
Definition: Exceptions.h:13
Definition: PointAttribute.h:184
Write-able version of AttributeHandle.
Definition: AttributeArray.h:920
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
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:304
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2284
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:185
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:496
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1587
Index32 Index
Definition: Types.h:31
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:517
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
static ValueType value()
Definition: PointAttribute.h:31
Attribute array storage for string data using Descriptor Metadata.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
static const NamePair & type()
Definition: PointAttribute.h:186
void dropAttributes(PointDataTreeT &tree, const std::vector< Name > &names)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:405
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
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:189
Set of Attribute Arrays which tracks metadata about each array.
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:35
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:104