37 #ifndef OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 64 const AttributeSet::Descriptor& descriptor);
70 template <
typename Po
intDataTree>
78 template <
typename Po
intDataTree>
80 const std::vector<Name>& groups);
88 template <
typename Po
intDataTree>
91 const bool compact =
true);
97 template <
typename Po
intDataTree>
99 const std::vector<Name>& groups);
104 template <
typename Po
intDataTree>
110 template <
typename Po
intDataTree>
122 template <
typename Po
intDataTree,
typename Po
intIndexTree>
125 const std::vector<short>& membership,
127 const bool remove =
false);
134 template <
typename Po
intDataTree>
137 const bool member =
true);
144 template <
typename Po
intDataTree,
typename FilterT>
147 const FilterT& filter);
153 namespace point_group_internal {
157 template<
typename Po
intDataTreeType>
166 : mTargetIndex(targetIndex)
167 , mSourceIndex(sourceIndex) { }
169 void operator()(
const typename LeafManagerT::LeafRange& range)
const {
171 for (
auto leaf = range.begin(); leaf; ++leaf) {
173 GroupHandle sourceGroup = leaf->groupHandle(mSourceIndex);
176 for (
auto iter = leaf->beginIndexAll(); iter; ++iter) {
177 const bool groupOn = sourceGroup.
get(*iter);
178 targetGroup.
set(*iter, groupOn);
191 template <
typename Po
intDataTree,
bool Member>
197 SetGroupOp(
const AttributeSet::Descriptor::GroupIndex& index)
200 void operator()(
const typename LeafManagerT::LeafRange& range)
const 202 for (
auto leaf = range.begin(); leaf; ++leaf) {
220 template <
typename Po
intDataTree,
typename Po
intIndexTree,
bool Remove>
233 : mIndexTree(indexTree)
234 , mMembership(membership)
237 void operator()(
const typename LeafManagerT::LeafRange& range)
const 239 for (
auto leaf = range.begin(); leaf; ++leaf) {
245 if (!pointIndexLeaf)
continue;
255 const IndexArray& indices = pointIndexLeaf->indices();
257 for (
const Index64 i: indices) {
259 group.
set(static_cast<Index>(index), mMembership[i]);
260 }
else if (mMembership[i] ==
short(1)) {
261 group.set(static_cast<Index>(index),
short(1));
280 template <
typename Po
intDataTree,
typename FilterT,
typename IterT =
typename Po
intDataTree::LeafNodeType::ValueAllCIter>
290 , mFilter(filter) { }
292 void operator()(
const typename LeafManagerT::LeafRange& range)
const 294 for (
auto leaf = range.begin(); leaf; ++leaf) {
300 auto iter = leaf->template beginIndex<IterT, FilterT>(mFilter);
302 for (; iter; ++iter) {
303 group.
set(*iter,
true);
329 : mAttributeSet(attributeSet) { }
338 const Descriptor& descriptor = mAttributeSet.descriptor();
342 const size_t groupAttributes = descriptor.count(GroupAttributeArray::attributeType());
344 if (groupAttributes == 0)
return 0;
346 const size_t totalSlots = groupAttributes * this->groupBits();
350 const AttributeSet::Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
351 const size_t usedSlots = groupMap.size();
353 return totalSlots - usedSlots;
361 return this->unusedGroups() >= this->groupBits();
367 const Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
371 std::vector<size_t> indices;
372 indices.reserve(groupMap.size());
373 for (
const auto& namePos : groupMap) {
374 indices.push_back(namePos.second);
377 std::sort(indices.begin(), indices.end());
382 for (
const size_t& index : indices) {
383 if (index != offset)
break;
393 std::vector<size_t> indices;
395 const Descriptor::NameToPosMap& map = mAttributeSet.descriptor().map();
397 for (
const auto& namePos : map) {
398 const AttributeArray* array = mAttributeSet.getConst(namePos.first);
400 indices.push_back(namePos.second);
411 targetOffset = this->nextUnusedOffset();
413 const Descriptor::NameToPosMap& groupMap = mAttributeSet.descriptor().groupMap();
415 for (
const auto& namePos : groupMap) {
419 if (namePos.second >= targetOffset) {
420 sourceName = namePos.first;
421 sourceOffset = namePos.second;
441 const AttributeSet::Descriptor& descriptor)
443 for (
auto it = groups.begin(); it != groups.end();) {
444 if (!descriptor.hasGroup(*it)) it = groups.erase(it);
453 template <
typename Po
intDataTree>
456 using Descriptor = AttributeSet::Descriptor;
469 const AttributeSet& attributeSet = iter->attributeSet();
471 GroupInfo groupInfo(attributeSet);
475 if (descriptor->hasGroup(group))
return;
479 if (groupInfo.unusedGroups() == 0) {
483 const Name groupName = descriptor->uniqueName(
"__group");
485 descriptor = descriptor->duplicateAppend(groupName, GroupAttributeArray::attributeType());
487 const size_t pos = descriptor->find(groupName);
491 AppendAttributeOp<PointDataTree> append(descriptor, pos);
492 tbb::parallel_for(
typename tree::template LeafManager<PointDataTree>(tree).leafRange(), append);
503 assert(groupInfo.unusedGroups() > 0);
507 const size_t offset = groupInfo.nextUnusedOffset();
511 descriptor->setGroup(group, offset);
518 template <
typename Po
intDataTree>
520 const std::vector<Name>& groups)
525 for (
const Name& name : groups) {
534 template <
typename Po
intDataTree>
537 using Descriptor = AttributeSet::Descriptor;
547 const AttributeSet& attributeSet = iter->attributeSet();
556 descriptor->dropGroup(group);
567 template <
typename Po
intDataTree>
569 const std::vector<Name>& groups)
571 for (
const Name& name : groups) {
584 template <
typename Po
intDataTree>
587 using Descriptor = AttributeSet::Descriptor;
595 const AttributeSet& attributeSet = iter->attributeSet();
596 GroupInfo groupInfo(attributeSet);
603 descriptor->clearGroups();
607 std::vector<size_t> indices = groupInfo.populateGroupIndices();
618 template <
typename Po
intDataTree>
621 using Descriptor = AttributeSet::Descriptor;
622 using GroupIndex = Descriptor::GroupIndex;
631 const AttributeSet& attributeSet = iter->attributeSet();
632 GroupInfo groupInfo(attributeSet);
636 if (!groupInfo.canCompactGroups())
return;
648 size_t sourceOffset, targetOffset;
650 while (groupInfo.requiresMove(sourceName, sourceOffset, targetOffset)) {
652 const GroupIndex sourceIndex = attributeSet.
groupIndex(sourceOffset);
653 const GroupIndex targetIndex = attributeSet.
groupIndex(targetOffset);
655 CopyGroupOp<PointDataTree> copy(targetIndex, sourceIndex);
656 tbb::parallel_for(
typename tree::template LeafManager<PointDataTree>(tree).leafRange(), copy);
658 descriptor->setGroup(sourceName, targetOffset);
663 std::vector<size_t> indices = groupInfo.populateGroupIndices();
665 const size_t totalAttributesToDrop = groupInfo.unusedGroups() / groupInfo.groupBits();
667 assert(totalAttributesToDrop <= indices.size());
669 std::vector<size_t> indicesToDrop(indices.end() - totalAttributesToDrop, indices.end());
678 template <
typename Po
intDataTree,
typename Po
intIndexTree>
681 const std::vector<short>& membership,
685 using Descriptor = AttributeSet::Descriptor;
686 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
698 const AttributeSet& attributeSet = iter->attributeSet();
699 const Descriptor& descriptor = attributeSet.
descriptor();
701 if (!descriptor.hasGroup(group)) {
705 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
712 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
717 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
725 template <
typename Po
intDataTree>
730 using Descriptor = AttributeSet::Descriptor;
731 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
739 const AttributeSet& attributeSet = iter->attributeSet();
740 const Descriptor& descriptor = attributeSet.
descriptor();
742 if (!descriptor.hasGroup(group)) {
746 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
750 if (member) tbb::parallel_for(LeafManagerT(tree).leafRange(), SetGroupOp<PointDataTree, true>(index));
751 else tbb::parallel_for(LeafManagerT(tree).leafRange(), SetGroupOp<PointDataTree, false>(index));
758 template <
typename Po
intDataTree,
typename FilterT>
761 const FilterT& filter)
763 using Descriptor = AttributeSet::Descriptor;
764 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
772 const AttributeSet& attributeSet = iter->attributeSet();
773 const Descriptor& descriptor = attributeSet.
descriptor();
775 if (!descriptor.hasGroup(group)) {
779 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
783 SetGroupByFilterOp<PointDataTree, FilterT>
set(index, filter);
784 tbb::parallel_for(LeafManagerT(tree).leafRange(),
set);
791 template <
typename Po
intDataTree>
795 const unsigned int seed = 0)
799 RandomFilter filter(tree, targetPoints, seed);
801 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
808 template <
typename Po
intDataTree>
811 const float percentage = 10.0f,
812 const unsigned int seed = 0)
816 const int currentPoints =
static_cast<int>(
pointCount(tree));
817 const int targetPoints = int(
math::Round((percentage * currentPoints)/100.0f));
819 RandomFilter filter(tree, targetPoints, seed);
821 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
833 #endif // OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:195
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:212
void compactGroups(PointDataTree &tree)
Compacts existing groups of a VDB Tree to use less memory if possible.
Definition: PointGroup.h:619
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:241
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:769
void set(Index n, bool on)
const GroupIndex mIndex
Definition: PointGroup.h:314
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:224
void dropGroups(PointDataTree &tree)
Drops all existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroup.h:585
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:127
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:161
Set membership on or off for the specified group.
Definition: PointGroup.h:192
SetGroupByFilterOp(const GroupIndex &index, const FilterT &filter)
Definition: PointGroup.h:288
Definition: AttributeGroup.h:130
bool requiresMove(Name &sourceName, size_t &sourceOffset, size_t &targetOffset) const
Definition: PointGroup.h:409
uint64_t Index64
Definition: Types.h:59
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:169
typename PointDataTree::LeafNodeType LeafNodeT
Definition: PointGroup.h:285
Definition: PointGroup.h:281
std::vector< size_t > populateGroupIndices() const
Return vector of indices correlating to the group attribute arrays.
Definition: PointGroup.h:391
Definition: Exceptions.h:86
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:292
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:108
Various point counting methods using a VDB Point Grid.
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:604
AttributeSet::Descriptor Descriptor
Definition: PointGroup.h:326
Definition: Exceptions.h:85
const GroupIndex mSourceIndex
Definition: PointGroup.h:186
Definition: AttributeGroup.h:102
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:200
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
std::vector< short > MembershipArray
Definition: PointGroup.h:228
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:286
uint8_t GroupType
Definition: AttributeGroup.h:50
Point attribute manipulation in a VDB Point Grid.
Definition: IndexFilter.h:187
Convenience class with methods for analyzing group data.
Definition: PointGroup.h:323
Index filters primarily designed to be used with a FilterIndexIter.
GroupInfo(const AttributeSet &attributeSet)
Definition: PointGroup.h:328
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:726
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointGroup.h:160
size_t unusedGroups() const
Definition: PointGroup.h:336
size_t nextUnusedOffset() const
Return the next empty group slot.
Definition: PointGroup.h:365
CopyGroupOp(const GroupIndex &targetIndex, const GroupIndex &sourceIndex)
Definition: PointGroup.h:164
Base class for storing attribute data.
Definition: AttributeArray.h:118
const GroupIndex mTargetIndex
Definition: PointGroup.h:185
const GroupIndex mIndex
Definition: PointGroup.h:276
void appendGroup(PointDataTree &tree, const Name &group)
Appends a new empty group to the VDB tree.
Definition: PointGroup.h:454
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:237
typename PointIndexLeafNode::IndexArray IndexArray
Definition: PointGroup.h:226
Definition: Exceptions.h:39
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1181
void deleteMissingPointGroups(std::vector< std::string > &groups, const AttributeSet::Descriptor &descriptor)
Delete any group that is not present in the Descriptor.
Definition: PointGroup.h:440
void appendGroups(PointDataTree &tree, const std::vector< Name > &groups)
Appends new empty groups to the VDB tree.
Definition: PointGroup.h:519
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
Definition: PointGroup.h:357
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:223
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Definition: PointAttribute.h:213
void setGroupByRandomTarget(PointDataTree &tree, const Name &group, const Index64 targetPoints, const unsigned int seed=0)
Definition: PointGroup.h:792
std::string Name
Definition: Name.h:44
Copy a group attribute value from one group offset to another.
Definition: PointGroup.h:158
const FilterT mFilter
Definition: PointGroup.h:315
void setGroupByFilter(PointDataTree &tree, const Name &group, const FilterT &filter)
Sets group membership based on a provided filter.
Definition: PointGroup.h:759
SetGroupOp(const AttributeSet::Descriptor::GroupIndex &index)
Definition: PointGroup.h:197
const PointIndexTree & mIndexTree
Definition: PointGroup.h:274
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:284
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:227
const MembershipArray & mMembership
Definition: PointGroup.h:275
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1618
Definition: PointGroup.h:221
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
static size_t groupBits()
Return the number of bits in a group (typically 8)
Definition: PointGroup.h:332
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:283
void setGroupByRandomPercentage(PointDataTree &tree, const Name &group, const float percentage=10.0f, const unsigned int seed=0)
Definition: PointGroup.h:809
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:162
SetGroupFromIndexOp(const PointIndexTree &indexTree, const MembershipArray &membership, const GroupIndex &index)
Definition: PointGroup.h:230
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:535
Set of Attribute Arrays which tracks metadata about each array.
const GroupIndex mIndex
Definition: PointGroup.h:216
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
typename PointIndexTree::LeafNodeType PointIndexLeafNode
Definition: PointGroup.h:225
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
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:194