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