37 #ifndef OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED 40 #include <openvdb/openvdb.h> 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;
457 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
470 const AttributeSet& attributeSet = iter->attributeSet();
472 GroupInfo groupInfo(attributeSet);
476 if (descriptor->hasGroup(group))
return;
478 const bool hasUnusedGroup = groupInfo.unusedGroups() > 0;
482 if (!hasUnusedGroup) {
486 const Name groupName = descriptor->uniqueName(
"__group");
488 descriptor = descriptor->duplicateAppend(groupName, GroupAttributeArray::attributeType());
490 const size_t pos = descriptor->find(groupName);
494 AppendAttributeOp<PointDataTree> append(descriptor, pos);
495 LeafManagerT leafManager(tree);
496 tbb::parallel_for(leafManager.leafRange(), append);
507 assert(groupInfo.unusedGroups() > 0);
511 const size_t offset = groupInfo.nextUnusedOffset();
515 descriptor->setGroup(group, offset);
521 if (hasUnusedGroup)
setGroup(tree, group,
false);
528 template <
typename Po
intDataTree>
530 const std::vector<Name>& groups)
535 for (
const Name& name : groups) {
544 template <
typename Po
intDataTree>
547 using Descriptor = AttributeSet::Descriptor;
557 const AttributeSet& attributeSet = iter->attributeSet();
566 descriptor->dropGroup(group);
577 template <
typename Po
intDataTree>
579 const std::vector<Name>& groups)
581 for (
const Name& name : groups) {
594 template <
typename Po
intDataTree>
597 using Descriptor = AttributeSet::Descriptor;
605 const AttributeSet& attributeSet = iter->attributeSet();
606 GroupInfo groupInfo(attributeSet);
613 descriptor->clearGroups();
617 std::vector<size_t> indices = groupInfo.populateGroupIndices();
628 template <
typename Po
intDataTree>
631 using Descriptor = AttributeSet::Descriptor;
632 using GroupIndex = Descriptor::GroupIndex;
633 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
642 const AttributeSet& attributeSet = iter->attributeSet();
643 GroupInfo groupInfo(attributeSet);
647 if (!groupInfo.canCompactGroups())
return;
659 size_t sourceOffset, targetOffset;
661 while (groupInfo.requiresMove(sourceName, sourceOffset, targetOffset)) {
663 const GroupIndex sourceIndex = attributeSet.
groupIndex(sourceOffset);
664 const GroupIndex targetIndex = attributeSet.
groupIndex(targetOffset);
666 CopyGroupOp<PointDataTree> copy(targetIndex, sourceIndex);
667 LeafManagerT leafManager(tree);
668 tbb::parallel_for(leafManager.leafRange(), copy);
670 descriptor->setGroup(sourceName, targetOffset);
675 std::vector<size_t> indices = groupInfo.populateGroupIndices();
677 const size_t totalAttributesToDrop = groupInfo.unusedGroups() / groupInfo.groupBits();
679 assert(totalAttributesToDrop <= indices.size());
681 std::vector<size_t> indicesToDrop(indices.end() - totalAttributesToDrop, indices.end());
690 template <
typename Po
intDataTree,
typename Po
intIndexTree>
693 const std::vector<short>& membership,
697 using Descriptor = AttributeSet::Descriptor;
698 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
710 const AttributeSet& attributeSet = iter->attributeSet();
711 const Descriptor& descriptor = attributeSet.
descriptor();
713 if (!descriptor.hasGroup(group)) {
717 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
718 LeafManagerT leafManager(tree);
725 tbb::parallel_for(leafManager.leafRange(),
set);
730 tbb::parallel_for(leafManager.leafRange(),
set);
738 template <
typename Po
intDataTree>
743 using Descriptor = AttributeSet::Descriptor;
744 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
752 const AttributeSet& attributeSet = iter->attributeSet();
753 const Descriptor& descriptor = attributeSet.
descriptor();
755 if (!descriptor.hasGroup(group)) {
759 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
760 LeafManagerT leafManager(tree);
764 if (member) tbb::parallel_for(leafManager.leafRange(), SetGroupOp<PointDataTree, true>(index));
765 else tbb::parallel_for(leafManager.leafRange(), SetGroupOp<PointDataTree, false>(index));
772 template <
typename Po
intDataTree,
typename FilterT>
775 const FilterT& filter)
777 using Descriptor = AttributeSet::Descriptor;
778 using LeafManagerT =
typename tree::template LeafManager<PointDataTree>;
786 const AttributeSet& attributeSet = iter->attributeSet();
787 const Descriptor& descriptor = attributeSet.
descriptor();
789 if (!descriptor.hasGroup(group)) {
793 const Descriptor::GroupIndex index = attributeSet.
groupIndex(group);
797 SetGroupByFilterOp<PointDataTree, FilterT>
set(index, filter);
798 LeafManagerT leafManager(tree);
800 tbb::parallel_for(leafManager.leafRange(),
set);
807 template <
typename Po
intDataTree>
811 const unsigned int seed = 0)
815 RandomFilter filter(tree, targetPoints, seed);
817 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
824 template <
typename Po
intDataTree>
827 const float percentage = 10.0f,
828 const unsigned int seed = 0)
832 const int currentPoints =
static_cast<int>(
pointCount(tree));
833 const int targetPoints = int(
math::Round((percentage * currentPoints)/100.0f));
835 RandomFilter filter(tree, targetPoints, seed);
837 setGroupByFilter<PointDataTree, RandomFilter>(tree, group, filter);
849 #endif // OPENVDB_POINTS_POINT_GROUP_HAS_BEEN_INCLUDED typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:161
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:567
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:629
void dropGroups(PointDataTree &tree)
Drops all existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroup.h:595
Definition: IndexFilter.h:254
typename PointIndexTree::LeafNodeType PointIndexLeafNode
Definition: PointGroup.h:225
void setGroupByRandomTarget(PointDataTree &tree, const Name &group, const Index64 targetPoints, const unsigned int seed=0)
Definition: PointGroup.h:808
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:169
SetGroupByFilterOp(const GroupIndex &index, const FilterT &filter)
Definition: PointGroup.h:288
Definition: AttributeGroup.h:102
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:283
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
const GroupIndex & mIndex
Definition: PointGroup.h:216
Methods for counting points in VDB Point grids.
Copy a group attribute value from one group offset to another.
Definition: PointGroup.h:158
const GroupIndex & mIndex
Definition: PointGroup.h:314
std::string Name
Definition: Name.h:44
SetGroupOp(const AttributeSet::Descriptor::GroupIndex &index)
Definition: PointGroup.h:197
Definition: Exceptions.h:87
typename tree::LeafManager< PointDataTreeType > LeafManagerT
Definition: PointGroup.h:160
Index64 pointCount(const PointDataTreeT &tree, const FilterT &filter=NullFilter(), const bool inCoreOnly=false, const bool threaded=true)
Count the total number of points in a PointDataTree.
Definition: PointCount.h:115
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:194
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:224
Definition: PointAttribute.h:197
Set membership on or off for the specified group.
Definition: PointGroup.h:192
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:227
const GroupIndex mSourceIndex
Definition: PointGroup.h:186
uint8_t GroupType
Definition: AttributeGroup.h:50
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:286
Point attribute manipulation in a VDB Point Grid.
size_t unusedGroups() const
Definition: PointGroup.h:336
static size_t groupBits()
Return the number of bits in a group (typically 8)
Definition: PointGroup.h:332
Index filters primarily designed to be used with a FilterIndexIter.
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:739
typename PointIndexLeafNode::IndexArray IndexArray
Definition: PointGroup.h:226
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:195
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointGroup.h:284
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:200
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:292
typename PointDataTree::LeafNodeType LeafNodeT
Definition: PointGroup.h:285
GroupInfo(const AttributeSet &attributeSet)
Definition: PointGroup.h:328
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
Definition: PointGroup.h:357
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
Definition: AttributeGroup.h:130
void appendGroup(PointDataTree &tree, const Name &group)
Appends a new empty group to the VDB tree.
Definition: PointGroup.h:454
CopyGroupOp(const GroupIndex &targetIndex, const GroupIndex &sourceIndex)
Definition: PointGroup.h:164
Definition: Exceptions.h:40
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1181
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
void appendGroups(PointDataTree &tree, const std::vector< Name > &groups)
Appends new empty groups to the VDB tree.
Definition: PointGroup.h:529
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 operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointGroup.h:237
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:127
const GroupIndex & mIndex
Definition: PointGroup.h:276
std::vector< size_t > populateGroupIndices() const
Return vector of indices correlating to the group attribute arrays.
Definition: PointGroup.h:391
Base class for storing attribute data.
Definition: AttributeArray.h:118
uint64_t Index64
Definition: Types.h:60
Convenience class with methods for analyzing group data.
Definition: PointGroup.h:323
void setGroupByFilter(PointDataTree &tree, const Name &group, const FilterT &filter)
Sets group membership based on a provided filter.
Definition: PointGroup.h:773
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:110
std::vector< short > MembershipArray
Definition: PointGroup.h:228
const GroupIndex mTargetIndex
Definition: PointGroup.h:185
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
size_t nextUnusedOffset() const
Return the next empty group slot.
Definition: PointGroup.h:365
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: Exceptions.h:86
Definition: PointGroup.h:281
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1604
typename tree::LeafManager< PointDataTree > LeafManagerT
Definition: PointGroup.h:223
void set(Index n, bool on)
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
const MembershipArray & mMembership
Definition: PointGroup.h:275
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
std::vector< Index > IndexArray
Definition: PointMove.h:193
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:773
AttributeSet::Descriptor Descriptor
Definition: PointGroup.h:326
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:545
Set of Attribute Arrays which tracks metadata about each array.
void setGroupByRandomPercentage(PointDataTree &tree, const Name &group, const float percentage=10.0f, const unsigned int seed=0)
Definition: PointGroup.h:825
AttributeSet::Descriptor::GroupIndex GroupIndex
Definition: PointGroup.h:162
const FilterT & mFilter
Definition: PointGroup.h:315
const PointIndexTree & mIndexTree
Definition: PointGroup.h:274
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
bool requiresMove(Name &sourceName, size_t &sourceOffset, size_t &targetOffset) const
Definition: PointGroup.h:409
SetGroupFromIndexOp(const PointIndexTree &indexTree, const MembershipArray &membership, const GroupIndex &index)
Definition: PointGroup.h:230