9#ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_IMPL_HAS_BEEN_INCLUDED 
   10#define OPENVDB_POINTS_POINT_ATTRIBUTE_IMPL_HAS_BEEN_INCLUDED 
   19namespace point_attribute_internal {
 
   22template <
typename ValueType>
 
   24    const AttributeSet::Descriptor&, 
const ValueType& uniformValue)
 
   26    AttributeWriteHandle<ValueType> handle(array);
 
   27    handle.collapse(uniformValue);
 
   32    const AttributeSet::Descriptor& descriptor, 
const Name& uniformValue)
 
   34    StringAttributeWriteHandle handle(array, descriptor.getMetadata());
 
   35    handle.collapse(uniformValue);
 
   42template <
typename ValueType, 
typename CodecType>
 
   43struct AttributeTypeConversion
 
   46        return TypedAttributeArray<ValueType, CodecType>::attributeType();
 
   51template <
typename CodecType>
 
   52struct AttributeTypeConversion<
Name, CodecType>
 
   54    static const NamePair& type() { 
return StringAttributeArray::attributeType(); }
 
   61template <
typename Po
intDataTreeT, 
typename ValueType>
 
   64    static void add(PointDataTreeT&, 
const ValueType&) {}
 
   66    template<
typename AttributeListType>
 
   67    static void add(PointDataTreeT&, 
const AttributeListType&) {}
 
   71template <
typename Po
intDataTreeT>
 
   72struct MetadataStorage<PointDataTreeT, 
Name>
 
   74    static void add(PointDataTreeT& tree, 
const Name& uniformValue) {
 
   76        StringMetaInserter inserter(metadata);
 
   77        inserter.insert(uniformValue);
 
   80    template<
typename AttributeListType>
 
   81    static void add(PointDataTreeT& tree, 
const AttributeListType& data) {
 
   83        StringMetaInserter inserter(metadata);
 
   86        for (
size_t i = 0; i < data.size(); i++) {
 
   88            inserter.insert(value);
 
  102template <
typename Po
intDataTreeT>
 
  106                            const Index strideOrTotalSize,
 
  107                            const bool constantStride,
 
  110                            const bool transient)
 
  112    auto iter = 
tree.cbeginLeaf();
 
  118    const auto& descriptor = iter->attributeSet().descriptor();
 
  119    const size_t index = descriptor.find(name);
 
  123            "Cannot append an attribute with a non-unique name - " << name << 
".");
 
  128    auto newDescriptor = descriptor.duplicateAppend(name, type);
 
  133        newDescriptor->setDefaultValue(name, *defaultValue);
 
  138    const size_t pos = newDescriptor->find(name);
 
  148        [&](
typename PointDataTreeT::LeafNodeType& leaf, 
size_t ) {
 
  149            auto expected = leaf.attributeSet().descriptorPtr();
 
  151            auto attribute = leaf.appendAttribute(*expected, newDescriptor,
 
  152                pos, strideOrTotalSize, constantStride, defaultValue,
 
  155            if (hidden)     attribute->setHidden(
true);
 
  156            if (transient)  attribute->setTransient(
true);
 
 
  165template <
typename ValueType, 
typename CodecType, 
typename Po
intDataTreeT>
 
  167                            const std::string& name,
 
  168                            const ValueType& uniformValue,
 
  169                            const Index strideOrTotalSize,
 
  170                            const bool constantStride,
 
  173                            const bool transient)
 
  175    static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
 
  176        "ValueType must not be derived from AttributeArray");
 
  178    using point_attribute_internal::AttributeTypeConversion;
 
  180    using point_attribute_internal::MetadataStorage;
 
  183        strideOrTotalSize, constantStride, defaultValue, hidden, transient);
 
  190            bool(defaultValue) ? defaultValue->
value() : Default<ValueType>::value());
 
  191    if (!uniformIsDefault) {
 
  192        MetadataStorage<PointDataTreeT, ValueType>::add(
tree, uniformValue);
 
 
  201template <
typename ValueType, 
typename Po
intDataTreeT>
 
  204                                const ValueType& uniformValue)
 
  206    static_assert(!std::is_base_of<AttributeArray, ValueType>::value,
 
  207        "ValueType must not be derived from AttributeArray");
 
  209    auto iter = 
tree.cbeginLeaf();
 
  213    const auto& descriptor = iter->attributeSet().descriptor();
 
  217    const size_t index = descriptor.find(name);
 
  224        [&](
typename PointDataTreeT::LeafNodeType& leaf, 
size_t ) {
 
  227            point_attribute_internal::collapseAttribute(
 
  228                array, descriptor, uniformValue);
 
 
  237template <
typename Po
intDataTreeT>
 
  239                            const std::vector<size_t>& indices)
 
  241    auto iter = 
tree.cbeginLeaf();
 
  245    const auto& descriptor = iter->attributeSet().descriptor();
 
  249    const size_t positionIndex = descriptor.find(
"P");
 
  251        std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
 
  257    auto newDescriptor = descriptor.duplicateDrop(indices);
 
  261        [&](
typename PointDataTreeT::LeafNodeType& leaf, 
size_t ) {
 
  262            auto expected = leaf.attributeSet().descriptorPtr();
 
  263            leaf.dropAttributes(indices, *expected, newDescriptor);
 
 
  272template <
typename Po
intDataTreeT>
 
  274                            const std::vector<Name>& names)
 
  276    auto iter = 
tree.cbeginLeaf();
 
  280    const AttributeSet& attributeSet = iter->attributeSet();
 
  283    std::vector<size_t> indices;
 
  285    for (
const Name& name : names) {
 
  286        const size_t index = descriptor.
find(name);
 
  291                "Cannot drop an attribute that does not exist - " << name << 
".");
 
  294        indices.push_back(
index);
 
 
  304template <
typename Po
intDataTreeT>
 
  308    std::vector<size_t> indices{
index};
 
 
  313template <
typename Po
intDataTreeT>
 
  317    std::vector<Name> names{name};
 
 
  325template <
typename Po
intDataTreeT>
 
  327                                const std::vector<Name>& oldNames,
 
  328                                const std::vector<Name>& newNames)
 
  330    if (oldNames.size() != newNames.size()) {
 
  336    auto iter = 
tree.beginLeaf();
 
  340    const AttributeSet& attributeSet = iter->attributeSet();
 
  341    const Descriptor::Ptr descriptor = attributeSet.
descriptorPtr();
 
  342    auto newDescriptor = std::make_shared<Descriptor>(*descriptor);
 
  344    for (
size_t i = 0; i < oldNames.size(); i++) {
 
  345        const Name& oldName = oldNames[i];
 
  350        const Name& newName = newNames[i];
 
  353                "Cannot rename attribute as new name already exists - " << newName << 
".");
 
  363        newDescriptor->rename(oldName, newName);
 
  366    for (; iter; ++iter) {
 
  367        iter->renameAttributes(*descriptor, newDescriptor);
 
 
  372template <
typename Po
intDataTreeT>
 
  384template <
typename Po
intDataTreeT>
 
  387    auto iter = 
tree.beginLeaf();
 
  392        [&](
typename PointDataTreeT::LeafNodeType& leaf, 
size_t ) {
 
  393            leaf.compactAttributes();
 
 
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Definition Exceptions.h:59
Definition Exceptions.h:65
Definition AttributeArray.h:120
Base class for storing attribute data.
Definition AttributeArray.h:94
An immutable object that stores name, type and AttributeSet position for a constant collection of att...
Definition AttributeSet.h:311
size_t find(const std::string &name) const
Return the position of the attribute array whose name is name, or INVALID_POS if no match is found.
Ordered collection of uniquely-named attribute arrays.
Definition AttributeSet.h:40
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition AttributeSet.h:109
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.
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition AttributeSet.h:103
@ INVALID_POS
Definition AttributeSet.h:42
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition LeafManager.h:86
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:484
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
Definition IndexIterator.h:35
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition PointAttributeImpl.h:385
void dropAttribute(PointDataTreeT &tree, const size_t &index)
Drop one attribute from the VDB tree (convenience method).
Definition PointAttributeImpl.h:305
void collapseAttribute(PointDataTreeT &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::Default< ValueType >::value())
Collapse the attribute into a uniform value.
Definition PointAttributeImpl.h:202
bool isGroup(const AttributeArray &array)
Definition AttributeGroup.h:64
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr, const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType)
Definition PointAttributeImpl.h:103
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition PointAttributeImpl.h:238
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition PointAttributeImpl.h:326
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition PointAttributeImpl.h:373
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition PointDataGrid.h:1586
Definition PointDataGrid.h:170
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:54
std::pair< Name, Name > NamePair
Definition AttributeArray.h:40
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Definition PointAttribute.h:31
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218