OpenVDB 13.0.1
Loading...
Searching...
No Matches
PointAttribute.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @author Dan Bailey, Khang Ngo
5///
6/// @file points/PointAttribute.h
7///
8/// @brief Point attribute manipulation in a VDB Point Grid.
9
10#ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
12
13#include <openvdb/openvdb.h>
14#include <openvdb/util/Assert.h>
15
17#include "AttributeSet.h"
18#include "AttributeGroup.h"
19#include "PointDataGrid.h"
20
21
22namespace openvdb {
24namespace OPENVDB_VERSION_NAME {
25namespace points {
26
27/// @cond OPENVDB_DOCS_INTERNAL
28
29namespace point_attribute_internal {
30
31template <typename ValueType>
32struct Default
33{
34 static inline ValueType value() { return zeroVal<ValueType>(); }
35};
36
37} // namespace point_attribute_internal
38
39/// @endcond
40
41/// @brief Appends a new attribute to the VDB tree
42/// (this method does not require a templated AttributeType)
43///
44/// @param tree the PointDataTree to be appended to.
45/// @param name name for the new attribute.
46/// @param type the type of the attibute.
47/// @param strideOrTotalSize the stride of the attribute
48/// @param constantStride if @c false, stride is interpreted as total size of the array
49/// @param defaultValue metadata default attribute value
50/// @param hidden mark attribute as hidden
51/// @param transient mark attribute as transient
52template <typename PointDataTreeT>
53inline void appendAttribute(PointDataTreeT& tree,
54 const Name& name,
55 const NamePair& type,
56 const Index strideOrTotalSize = 1,
57 const bool constantStride = true,
58 const Metadata* defaultValue = nullptr,
59 const bool hidden = false,
60 const bool transient = false);
61
62/// @brief Appends a new attribute to the VDB tree.
63///
64/// @param tree the PointDataTree to be appended to.
65/// @param name name for the new attribute
66/// @param uniformValue the initial value of the attribute
67/// @param strideOrTotalSize the stride of the attribute
68/// @param constantStride if @c false, stride is interpreted as total size of the array
69/// @param defaultValue metadata default attribute value
70/// @param hidden mark attribute as hidden
71/// @param transient mark attribute as transient
72template <typename ValueType,
73 typename CodecType = NullCodec,
74 typename PointDataTreeT>
75inline void appendAttribute(PointDataTreeT& tree,
76 const std::string& name,
77 const ValueType& uniformValue =
78 point_attribute_internal::Default<ValueType>::value(),
79 const Index strideOrTotalSize = 1,
80 const bool constantStride = true,
81 const TypedMetadata<ValueType>* defaultValue = nullptr,
82 const bool hidden = false,
83 const bool transient = false);
84
85/// @brief Collapse the attribute into a uniform value
86///
87/// @param tree the PointDataTree in which to collapse the attribute.
88/// @param name name for the attribute.
89/// @param uniformValue value of the attribute
90template <typename ValueType, typename PointDataTreeT>
91inline void collapseAttribute( PointDataTreeT& tree,
92 const Name& name,
93 const ValueType& uniformValue =
94 point_attribute_internal::Default<ValueType>::value());
95
96/// @brief Drops attributes from the VDB tree.
97///
98/// @param tree the PointDataTree to be dropped from.
99/// @param indices indices of the attributes to drop.
100template <typename PointDataTreeT>
101inline void dropAttributes( PointDataTreeT& tree,
102 const std::vector<size_t>& indices);
103
104/// @brief Drops attributes from the VDB tree.
105///
106/// @param tree the PointDataTree to be dropped from.
107/// @param names names of the attributes to drop.
108template <typename PointDataTreeT>
109inline void dropAttributes( PointDataTreeT& tree,
110 const std::vector<Name>& names);
111
112/// @brief Drop one attribute from the VDB tree (convenience method).
113///
114/// @param tree the PointDataTree to be dropped from.
115/// @param index index of the attribute to drop.
116template <typename PointDataTreeT>
117inline void dropAttribute( PointDataTreeT& tree,
118 const size_t& index);
119
120/// @brief Drop one attribute from the VDB tree (convenience method).
121///
122/// @param tree the PointDataTree to be dropped from.
123/// @param name name of the attribute to drop.
124template <typename PointDataTreeT>
125inline void dropAttribute( PointDataTreeT& tree,
126 const Name& name);
127
128/// @brief Rename attributes in a VDB tree.
129///
130/// @param tree the PointDataTree.
131/// @param oldNames a list of old attribute names to rename from.
132/// @param newNames a list of new attribute names to rename to.
133///
134/// @note Number of oldNames must match the number of newNames.
135///
136/// @note Duplicate names and renaming group attributes are not allowed.
137template <typename PointDataTreeT>
138inline void renameAttributes(PointDataTreeT& tree,
139 const std::vector<Name>& oldNames,
140 const std::vector<Name>& newNames);
141
142/// @brief Rename an attribute in a VDB tree.
143///
144/// @param tree the PointDataTree.
145/// @param oldName the old attribute name to rename from.
146/// @param newName the new attribute name to rename to.
147///
148/// @note newName must not already exist and must not be a group attribute.
149template <typename PointDataTreeT>
150inline void renameAttribute(PointDataTreeT& tree,
151 const Name& oldName,
152 const Name& newName);
153
154/// @brief Compact attributes in a VDB tree (if possible).
155///
156/// @param tree the PointDataTree.
157template <typename PointDataTreeT>
158inline void compactAttributes(PointDataTreeT& tree);
159
160
161} // namespace points
162} // namespace OPENVDB_VERSION_NAME
163} // namespace openvdb
164
165#include "impl/PointAttributeImpl.h"
166
167#endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
Attribute array storage for string data using Descriptor Metadata.
Attribute Group access and filtering for iteration.
Set of Attribute Arrays which tracks metadata about each array.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Base class for storing metadata information in a grid.
Definition Metadata.h:25
Templated metadata class to hold specific types.
Definition Metadata.h:123
@ Default
Definition NanoVDB.h:397
Definition IndexIterator.h:35
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
void dropAttribute(PointDataTreeT &tree, const size_t &index)
Drop one attribute from the VDB tree (convenience method).
void collapseAttribute(PointDataTreeT &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::Default< ValueType >::value())
Collapse the attribute into a uniform value.
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)
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
void renameAttribute(PointDataTreeT &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
Definition PointDataGrid.h:170
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:34
std::pair< Name, Name > NamePair
Definition AttributeArray.h:40
Definition Exceptions.h:13
Definition AttributeArray.h:437
#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