Uploaded image for project: 'OpenVDB'
  1. OpenVDB
  2. OVDB-39

Foreach Attributes for Points

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • None
    • Points
    • None

      I'd like an equivalent to tools::foreach() for point attributes, something like:

      template <typename PointDataTreeT, typename OpT>
      inline void
      foreachAttribute(PointDataTreeT& tree, const Name& name, OpT& op, bool threaded)
      {
          // early-exit if no leaf nodes
          auto iter = tree.cbeginLeaf();
          if (!iter)  return;
      
          // early-exit if attribute name does not exist
          size_t index = iter->attributeSet().find(name);
          if (index == points::INVALID_POS)   return;
      
          // perform the operation on each attribute in the grid
          tree::LeafManager<PointDataTreeT> leafManager(tree);
          leafManager.foreach(
              [&](typename PointDataTree::LeafNodeType& leaf, size_t /*idx*/) {
                  assert(leaf.hasAttribute(index));
                  op(leaf.attributeArray(index));
              },
          threaded);
      }
      

      This could be used like:

      points::foreachAttribute(tree, name,
          [&](AttributeArray& array) { array.collapse(); },
      threaded);
      

      This might allow us to lighten our leaf node API a little and move these methods more out into free functions (ABI permitting). Obviously one downside is that it relies heavily on the convention that all leaf nodes have the same attributes.

      I think it'll need a const variant - points::foreachAttribute(const Tree&) or points::foreachConstAttribute(const Tree&)? And possibly an index variant too. Also, some of the existing methods do all attributes in a leaf, so that might add an extra variant. That's already five different versions though!

      I'd prefer to call it simply points::foreach(), but I think it might not be entirely clear that it's iterating over attributes and not leaf nodes or even points?

      Thoughts?

            Unassigned Unassigned
            danrbailey danrbailey
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: