37 #ifndef OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 58 const AttributeSet::Descriptor& descriptor);
64 template <
typename Po
intDataTree>
72 template <
typename Po
intDataTree>
74 const std::vector<Name>& groups);
82 template <
typename Po
intDataTree>
85 const bool compact =
true);
91 template <
typename Po
intDataTree>
93 const std::vector<Name>& groups);
98 template <
typename Po
intDataTree>
104 template <
typename Po
intDataTree>
116 template <
typename Po
intDataTree,
typename Po
intIndexTree>
119 const std::vector<short>& membership,
121 const bool remove =
false);
128 template <
typename Po
intDataTree>
131 const bool member =
true);
138 template <
typename Po
intDataTree,
typename FilterT>
141 const FilterT& filter);
147 namespace point_group_internal {
151 template<
typename Po
intDataTreeType>
160 : mTargetIndex(targetIndex)
161 , mSourceIndex(sourceIndex) { }
163 void operator()(
const typename LeafManagerT::LeafRange& range)
const {
165 for (
auto leaf = range.begin(); leaf; ++leaf) {
167 GroupHandle sourceGroup = leaf->groupHandle(mSourceIndex);
170 for (
auto iter = leaf->beginIndexAll(); iter; ++iter) {
171 const bool groupOn = sourceGroup.
get(*iter);
172 targetGroup.
set(*iter, groupOn);
185 template <
typename Po
intDataTree,
bool Member>
191 SetGroupOp(
const AttributeSet::Descriptor::GroupIndex& index)
194 void operator()(
const typename LeafManagerT::LeafRange& range)
const 196 for (
auto leaf = range.begin(); leaf; ++leaf) {
214 template <
typename Po
intDataTree,
typename Po
intIndexTree,
bool Remove>
227 : mIndexTree(indexTree)
228 , mMembership(membership)
231 void operator()(
const typename LeafManagerT::LeafRange& range)
const 233 for (
auto leaf = range.begin(); leaf; ++leaf) {
239 if (!pointIndexLeaf)
continue;
249 const IndexArray& indices = pointIndexLeaf->indices();
251 for (
const Index64 i: indices) {
253 group.
set(static_cast<Index>(index), mMembership[i]);
254 }
else if (mMembership[i] ==
short(1)) {
255 group.set(static_cast<Index>(index),
short(1));
274 template <
typename Po
intDataTree,
typename FilterT,
typename IterT =
typename Po
intDataTree::LeafNodeType::ValueAllCIter>
284 , mFilter(filter) { }
286 void operator()(
const typename LeafManagerT::LeafRange& range)
const 288 for (
auto leaf = range.begin(); leaf; ++leaf) {
294 auto iter = leaf->template beginIndex<IterT, FilterT>(mFilter);
296 for (; iter; ++iter) {
297 group.
set(*iter,
true);
323 : mAttributeSet(attributeSet) { }
332 const Descriptor& descriptor = mAttributeSet.descriptor();
336 const size_t groupAttributes = descriptor.count(GroupAttributeArray::attributeType());
338 if (groupAttributes == 0)
return 0;
340 const size_t totalSlots = groupAttributes * this->groupBits();
344 const AttributeSet::Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
345 const size_t usedSlots = groupMap.size();
347 return totalSlots - usedSlots;
355 return this->unusedGroups() >= this->groupBits();
361 const Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
365 std::vector<size_t> indices;
366 indices.reserve(groupMap.size());
367 for (
const auto& namePos : groupMap) {
368 indices.push_back(namePos.second);
371 std::sort(indices.begin(), indices.end());
376 for (
const size_t& index : indices) {
377 if (index != offset)
break;
387 std::vector<size_t> indices;
389 const Descriptor::NameToPosMap& map = mAttributeSet.descriptor().map();
391 for (
const auto& namePos : map) {
392 const AttributeArray* array = mAttributeSet.getConst(namePos.first);
394 indices.push_back(namePos.second);
405 targetOffset = this->nextUnusedOffset();
407 const Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
409 for (
const auto& namePos : groupMap) {
413 if (namePos.second >= targetOffset) {
414 sourceName = namePos.first;
415 sourceOffset = namePos.second;
435 const AttributeSet::Descriptor& descriptor)
437 for (
auto it = groups.begin(); it != groups.end();) {
438 if (!descriptor.hasGroup(*it)) it = groups.erase(it);
447 template <
typename Po
intDataTree>
450 using Descriptor = AttributeSet::Descriptor;
463 const AttributeSet& attributeSet = iter->attributeSet();
465 GroupInfo groupInfo(attributeSet);
469 if (descriptor->hasGroup(group))
return;
473 if (groupInfo.unusedGroups() == 0) {
477 const Name groupName = descriptor->uniqueName(
"__group");
479 descriptor = descriptor->duplicateAppend(groupName, GroupAttributeArray::attributeType());
481 const size_t pos = descriptor->find(groupName);
485 AppendAttributeOp<PointDataTree> append(descriptor, pos);
486 tbb::parallel_for(
typename tree::template LeafManager<PointDataTree>(tree).leafRange(), append);
497 assert(groupInfo.unusedGroups() > 0);
501 const size_t offset = groupInfo.nextUnusedOffset();
505 descriptor->setGroup(group, offset);
512 template <
typename Po
intDataTree>
514 const std::vector<Name>& groups)
519 for (
const Name& name : groups) {
528 template <
typename Po
intDataTree>
531 using Descriptor = AttributeSet::Descriptor;
541 const AttributeSet& attributeSet = iter->attributeSet();
550 descriptor->dropGroup(group);
561 template <
typename Po
intDataTree>
563 const std::vector<Name>& groups)
565 for (
const Name& name : groups) {
578 template <
typename Po
intDataTree>
581 using Descriptor = AttributeSet::Descriptor;
589 const AttributeSet& attributeSet = iter->attributeSet();
590 GroupInfo groupInfo(attributeSet);
597 descriptor->clearGroups();
601 std::vector<size_t> indices = groupInfo.populateGroupIndices();
612 template <
typename Po
intDataTree>
615 using Descriptor = AttributeSet::Descriptor;
616 using GroupIndex = Descriptor::GroupIndex;
625 const AttributeSet& attributeSet = iter->attributeSet();
626 GroupInfo groupInfo(attributeSet);
630 if (!groupInfo.canCompactGroups())
return;
642 size_t sourceOffset, targetOffset;
644 while (groupInfo.requiresMove(sourceName, sourceOffset, targetOffset)) {
646 const GroupIndex sourceIndex = attributeSet.
groupIndex(sourceOffset);
647 const GroupIndex targetIndex = attributeSet.
groupIndex(targetOffset);
649 CopyGroupOp<PointDataTree> copy(targetIndex, sourceIndex);
650 tbb::parallel_for(
typename tree::template LeafManager<PointDataTree>(tree).leafRange(), copy);
652 descriptor->setGroup(sourceName, targetOffset);
657 std::vector<size_t> indices = groupInfo.populateGroupIndices();
659 const size_t totalAttributesToDrop = groupInfo.unusedGroups() / groupInfo.groupBits();
661 assert(totalAttributesToDrop <= indices.size());
663 std::vector<size_t> indicesToDrop(indices.end() - totalAttributesToDrop, indices.end());
672 template <
typename Po
intDataTree,
typename Po
intIndexTree>
675 const std::vector<short>& membership,
679 using Descriptor = AttributeSet::Descriptor;
680 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
692 const AttributeSet& attributeSet = iter->attributeSet();
693 const Descriptor& descriptor = attributeSet.
descriptor();
695 if (!descriptor.hasGroup(group)) {
699 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
706 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
711 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
719 template <
typename Po
intDataTree>
724 using Descriptor = AttributeSet::Descriptor;
725 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
733 const AttributeSet& attributeSet = iter->attributeSet();
734 const Descriptor& descriptor = attributeSet.
descriptor();
736 if (!descriptor.hasGroup(group)) {
740 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
744 if (member) tbb::parallel_for(LeafManagerT(tree).leafRange(), SetGroupOp<PointDataTree, true>(index));
745 else tbb::parallel_for(LeafManagerT(tree).leafRange(), SetGroupOp<PointDataTree, false>(index));
752 template <
typename Po
intDataTree,
typename FilterT>
755 const FilterT& filter)
757 using Descriptor = AttributeSet::Descriptor;
758 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
766 const AttributeSet& attributeSet = iter->attributeSet();
767 const Descriptor& descriptor = attributeSet.
descriptor();
769 if (!descriptor.hasGroup(group)) {
773 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
777 SetGroupByFilterOp<PointDataTree, FilterT>
set(index, filter);
778 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
785 template <
typename Po
intDataTree>
789 const unsigned int seed = 0)
793 RandomFilter filter(tree, targetPoints, seed);
795 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
802 template <
typename Po
intDataTree>
805 const float percentage = 10.0f,
806 const unsigned int seed = 0)
810 const int currentPoints =
static_cast<int>(
pointCount(tree));
811 const int targetPoints = int(
math::Round((percentage * currentPoints)/100.0f));
813 RandomFilter filter(tree, targetPoints, seed);
815 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
827 #endif // OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED void appendGroups(PointDataTree &tree, const std::vector< Name > &groups)
Appends new empty groups to the VDB tree.
Definition: PointGroup.h:513
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:194
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:127
const MembershipArray & mMembership
Definition: PointGroup.h:269
const GroupIndex mIndex
Definition: PointGroup.h:308
void setGroup(PointDataTree &tree, const Name &group, const bool member=true)
Sets membership for the specified group for all points (on/off).
Definition: PointGroup.h:720
const FilterT mFilter
Definition: PointGroup.h:309
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:155
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:278
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:207
void appendGroup(PointDataTree &tree, const Name &group)
Appends a new empty group to the VDB tree.
Definition: PointGroup.h:448
void compactGroups(PointDataTree &tree)
Compacts existing groups of a VDB Tree to use less memory if possible.
Definition: PointGroup.h:613
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
size_t nextUnusedOffset() const
Return the next empty group slot.
Definition: PointGroup.h:359
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:221
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
const GroupIndex mIndex
Definition: PointGroup.h:210
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
Definition: PointGroup.h:351
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:188
bool requiresMove(Name &sourceName, size_t &sourceOffset, size_t &targetOffset) const
Definition: PointGroup.h:403
typename PointIndexLeafNode::IndexArray IndexArray
Definition: PointGroup.h:220
Convenience class with methods for analyzing group data.
Definition: PointGroup.h:317
SetGroupByFilterOp(const GroupIndex &index, const FilterT &filter)
Definition: PointGroup.h:282
Point attribute manipulation in a VDB Point Grid.
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:218
Index filters primarily designed to be used with a FilterIndexIter.
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:156
void deleteMissingPointGroups(std::vector< std::string > &groups, const AttributeSet::Descriptor &descriptor)
Delete any group that is not present in the Descriptor.
Definition: PointGroup.h:434
Base class for storing attribute data.
Definition: AttributeArray.h:118
const GroupIndex mTargetIndex
Definition: PointGroup.h:179
SetGroupFromIndexOp(const PointIndexTree &indexTree, const MembershipArray &membership, const GroupIndex &index)
Definition: PointGroup.h:224
AttributeSet::Descriptor Descriptor
Definition: PointGroup.h:320
Definition: AttributeGroup.h:101
#define OPENVDB_VERSION_NAME
Definition: version.h:43
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:189
const PointIndexTree & mIndexTree
Definition: PointGroup.h:268
Definition: Exceptions.h:87
const GroupIndex mIndex
Definition: PointGroup.h:270
GroupInfo(const AttributeSet &attributeSet)
Definition: PointGroup.h:322
Definition: IndexFilter.h:169
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1567
Definition: Exceptions.h:39
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1182
Copy a group attribute value from one group offset to another.
Definition: PointGroup.h:152
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
void dropGroups(PointDataTree &tree)
Drops all existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroup.h:579
static size_t groupBits()
Return the number of bits in a group (typically 8)
Definition: PointGroup.h:326
size_t unusedGroups() const
Definition: PointGroup.h:330
SetGroupOp(const AttributeSet::Descriptor::GroupIndex &index)
Definition: PointGroup.h:191
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:214
Definition: PointGroup.h:215
Definition: PointAttribute.h:213
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:217
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointGroup.h:154
void setGroupByFilter(PointDataTree &tree, const Name &group, const FilterT &filter)
Sets group membership based on a provided filter.
Definition: PointGroup.h:753
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:286
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:198
uint64_t Index64
Definition: Types.h:56
uint8_t GroupType
Definition: AttributeGroup.h:49
std::string Name
Definition: Name.h:44
std::vector< size_t > populateGroupIndices() const
Return vector of indices correlating to the group attribute arrays.
Definition: PointGroup.h:385
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:163
const GroupIndex mSourceIndex
Definition: PointGroup.h:180
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:604
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:785
Set membership on or off for the specified group.
Definition: PointGroup.h:186
typename PointIndexTree::LeafNodeType PointIndexLeafNode
Definition: PointGroup.h:219
void set(Index n, bool on)
CopyGroupOp(const GroupIndex &targetIndex, const GroupIndex &sourceIndex)
Definition: PointGroup.h:158
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:277
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:231
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: PointGroup.h:275
Definition: Exceptions.h:86
std::vector< short > MembershipArray
Definition: PointGroup.h:222
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:280
Definition: AttributeGroup.h:128
typename PointDataTree::LeafNodeType LeafNodeT
Definition: PointGroup.h:279
Set of Attribute Arrays which tracks metadata about each array.
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:529
void setGroupByRandomPercentage(PointDataTree &tree, const Name &group, const float percentage=10.0f, const unsigned int seed=0)
Definition: PointGroup.h:803
void setGroupByRandomTarget(PointDataTree &tree, const Name &group, const Index64 targetPoints, const unsigned int seed=0)
Definition: PointGroup.h:786