HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PointAttribute.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2012-2017 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
29 ///////////////////////////////////////////////////////////////////////////
30 
31 /// @author Dan Bailey, Khang Ngo
32 ///
33 /// @file points/PointAttribute.h
34 ///
35 /// @brief Point attribute manipulation in a VDB Point Grid.
36 
37 #ifndef OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
39 
40 #include <openvdb/openvdb.h>
41 
42 #include "AttributeArrayString.h"
43 #include "AttributeSet.h"
44 #include "AttributeGroup.h"
45 #include "PointDataGrid.h"
46 
47 
48 namespace openvdb {
50 namespace OPENVDB_VERSION_NAME {
51 namespace points {
52 
53 namespace point_attribute_internal {
54 
55 template <typename ValueType>
56 inline ValueType defaultValue() { return zeroVal<ValueType>(); }
57 
58 } // namespace point_attribute_internal
59 
60 
61 /// @brief Appends a new attribute to the VDB tree
62 /// (this method does not require a templated AttributeType)
63 ///
64 /// @param tree the PointDataTree to be appended to.
65 /// @param name name for the new attribute.
66 /// @param type the type of the attibute.
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 metaDefaultValue metadata default attribute value
70 /// @param hidden mark attribute as hidden
71 /// @param transient mark attribute as transient
72 template <typename PointDataTree>
73 inline void appendAttribute(PointDataTree& tree,
74  const Name& name,
75  const NamePair& type,
76  const Index strideOrTotalSize = 1,
77  const bool constantStride = true,
78  Metadata::Ptr metaDefaultValue = Metadata::Ptr(),
79  const bool hidden = false,
80  const bool transient = false);
81 
82 /// @brief Appends a new attribute to the VDB tree.
83 ///
84 /// @param tree the PointDataTree to be appended to.
85 /// @param name name for the new attribute
86 /// @param uniformValue the initial value of the attribute
87 /// @param strideOrTotalSize the stride of the attribute
88 /// @param constantStride if @c false, stride is interpreted as total size of the array
89 /// @param metaDefaultValue metadata default attribute value
90 /// @param hidden mark attribute as hidden
91 /// @param transient mark attribute as transient
92 template <typename ValueType, typename CodecType, typename PointDataTree>
93 inline void appendAttribute(PointDataTree& tree,
94  const std::string& name,
95  const ValueType& uniformValue =
96  point_attribute_internal::defaultValue<ValueType>(),
97  const Index strideOrTotalSize = 1,
98  const bool constantStride = true,
99  Metadata::Ptr metaDefaultValue = Metadata::Ptr(),
100  const bool hidden = false,
101  const bool transient = false);
102 
103 /// @brief Appends a new attribute to the VDB tree.
104 ///
105 /// @param tree the PointDataTree to be appended to.
106 /// @param name name for the new attribute.
107 /// @param uniformValue the initial value of the attribute
108 /// @param strideOrTotalSize the stride of the attribute
109 /// @param constantStride if @c false, stride is interpreted as total size of the array
110 /// @param metaDefaultValue metadata default attribute value
111 /// @param hidden mark attribute as hidden
112 /// @param transient mark attribute as transient
113 template <typename ValueType, typename PointDataTree>
114 inline void appendAttribute(PointDataTree& tree,
115  const std::string& name,
116  const ValueType& uniformValue =
117  point_attribute_internal::defaultValue<ValueType>(),
118  const Index strideOrTotalSize = 1,
119  const bool constantStride = true,
120  Metadata::Ptr metaDefaultValue = Metadata::Ptr(),
121  const bool hidden = false,
122  const bool transient = false);
123 
124 /// @brief Collapse the attribute into a uniform value
125 ///
126 /// @param tree the PointDataTree in which to collapse the attribute.
127 /// @param name name for the attribute.
128 /// @param uniformValue value of the attribute
129 template <typename ValueType, typename PointDataTree>
130 inline void collapseAttribute( PointDataTree& tree,
131  const Name& name,
132  const ValueType& uniformValue =
133  point_attribute_internal::defaultValue<ValueType>());
134 
135 /// @brief Drops attributes from the VDB tree.
136 ///
137 /// @param tree the PointDataTree to be dropped from.
138 /// @param indices indices of the attributes to drop.
139 template <typename PointDataTree>
140 inline void dropAttributes( PointDataTree& tree,
141  const std::vector<size_t>& indices);
142 
143 /// @brief Drops attributes from the VDB tree.
144 ///
145 /// @param tree the PointDataTree to be dropped from.
146 /// @param names names of the attributes to drop.
147 template <typename PointDataTree>
148 inline void dropAttributes( PointDataTree& tree,
149  const std::vector<Name>& names);
150 
151 /// @brief Drop one attribute from the VDB tree (convenience method).
152 ///
153 /// @param tree the PointDataTree to be dropped from.
154 /// @param index index of the attribute to drop.
155 template <typename PointDataTree>
156 inline void dropAttribute( PointDataTree& tree,
157  const size_t& index);
158 
159 /// @brief Drop one attribute from the VDB tree (convenience method).
160 ///
161 /// @param tree the PointDataTree to be dropped from.
162 /// @param name name of the attribute to drop.
163 template <typename PointDataTree>
164 inline void dropAttribute( PointDataTree& tree,
165  const Name& name);
166 
167 /// @brief Rename attributes in a VDB tree.
168 ///
169 /// @param tree the PointDataTree.
170 /// @param oldNames a list of old attribute names to rename from.
171 /// @param newNames a list of new attribute names to rename to.
172 ///
173 /// @note Number of oldNames must match the number of newNames.
174 ///
175 /// @note Duplicate names and renaming group attributes are not allowed.
176 template <typename PointDataTree>
177 inline void renameAttributes(PointDataTree& tree,
178  const std::vector<Name>& oldNames,
179  const std::vector<Name>& newNames);
180 
181 /// @brief Rename an attribute in a VDB tree.
182 ///
183 /// @param tree the PointDataTree.
184 /// @param oldName the old attribute name to rename from.
185 /// @param newName the new attribute name to rename to.
186 ///
187 /// @note newName must not already exist and must not be a group attribute.
188 template <typename PointDataTree>
189 inline void renameAttribute(PointDataTree& tree,
190  const Name& oldName,
191  const Name& newName);
192 
193 /// @brief Compact attributes in a VDB tree (if possible).
194 ///
195 /// @param tree the PointDataTree.
196 template <typename PointDataTree>
197 inline void compactAttributes(PointDataTree& tree);
198 
199 /// @brief Apply Blosc compression to one attribute in the VDB tree.
200 ///
201 /// @param tree the PointDataTree.
202 /// @param name name of the attribute to compress.
203 template <typename PointDataTree>
204 inline void bloscCompressAttribute( PointDataTree& tree,
205  const Name& name);
206 
207 ////////////////////////////////////////
208 
209 
210 namespace point_attribute_internal {
211 
212 template<typename PointDataTreeType>
214 
216  using LeafRangeT = typename LeafManagerT::LeafRange;
217 
219  const size_t pos,
220  const Index strideOrTotalSize = 1,
221  const bool constantStride = true,
222  const bool hidden = false,
223  const bool transient = false)
224  : mDescriptor(descriptor)
225  , mPos(pos)
226  , mStrideOrTotalSize(strideOrTotalSize)
227  , mConstantStride(constantStride)
228  , mHidden(hidden)
229  , mTransient(transient) { }
230 
231  void operator()(const LeafRangeT& range) const {
232 
233  for (auto leaf = range.begin(); leaf; ++leaf) {
234  const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
235 
236  AttributeArray::Ptr attribute = leaf->appendAttribute(
238 
239  if (mHidden) attribute->setHidden(true);
240  if (mTransient) attribute->setTransient(true);
241  }
242  }
243 
244  //////////
245 
247  const size_t mPos;
249  const bool mConstantStride;
250  const bool mHidden;
251  const bool mTransient;
252 }; // class AppendAttributeOp
253 
254 
255 ////////////////////////////////////////
256 
257 
258 template <typename ValueType, typename PointDataTreeType>
260 
262  using LeafRangeT = typename LeafManagerT::LeafRange;
263 
264  CollapseAttributeOp(const size_t pos,
265  const ValueType& uniformValue)
266  : mPos(pos)
267  , mUniformValue(uniformValue) { }
268 
269  void operator()(const LeafRangeT& range) const {
270 
271  for (auto leaf = range.begin(); leaf; ++leaf) {
272  assert(leaf->hasAttribute(mPos));
273  AttributeArray& array = leaf->attributeArray(mPos);
274  AttributeWriteHandle<ValueType> handle(array);
275  handle.collapse(mUniformValue);
276  }
277  }
278 
279  //////////
280 
281  const size_t mPos;
282  const ValueType mUniformValue;
283 }; // class CollapseAttributeOp
284 
285 
286 ////////////////////////////////////////
287 
288 
289 template <typename PointDataTreeType>
290 struct CollapseAttributeOp<Name, PointDataTreeType> {
291 
293  using LeafRangeT = typename LeafManagerT::LeafRange;
294 
295  CollapseAttributeOp(const size_t pos,
296  const Name& uniformValue)
297  : mPos(pos)
298  , mUniformValue(uniformValue) { }
299 
300  void operator()(const LeafRangeT& range) const {
301 
302  for (auto leaf = range.begin(); leaf; ++leaf) {
303  assert(leaf->hasAttribute(mPos));
304  AttributeArray& array = leaf->attributeArray(mPos);
305 
306  const AttributeSet::Descriptor& descriptor = leaf->attributeSet().descriptor();
307  const MetaMap& metadata = descriptor.getMetadata();
308 
309  StringAttributeWriteHandle handle(array, metadata);
310  handle.collapse(mUniformValue);
311  }
312  }
313 
314  //////////
315 
316  const size_t mPos;
318 }; // class CollapseAttributeOp
319 
320 
321 ////////////////////////////////////////
322 
323 
324 template<typename PointDataTreeType>
326 
328  using LeafRangeT = typename LeafManagerT::LeafRange;
329  using Indices = std::vector<size_t>;
330 
332  AttributeSet::DescriptorPtr& descriptor)
333  : mIndices(indices)
334  , mDescriptor(descriptor) { }
335 
336  void operator()(const LeafRangeT& range) const {
337 
338  for (auto leaf = range.begin(); leaf; ++leaf) {
339 
340  const AttributeSet::Descriptor& expected = leaf->attributeSet().descriptor();
341 
342  leaf->dropAttributes(mIndices, expected, mDescriptor);
343  }
344  }
345 
346  //////////
347 
350 }; // class DropAttributesOp
351 
352 
353 ////////////////////////////////////////
354 
355 
356 template<typename PointDataTreeType>
358 
360  using LeafRangeT = typename LeafManagerT::LeafRange;
361 
362  void operator()(const LeafRangeT& range) const {
363  for (auto leaf = range.begin(); leaf; ++leaf) {
364  leaf->compactAttributes();
365  }
366  }
367 }; // class CompactAttributesOp
368 
369 
370 ////////////////////////////////////////
371 
372 
373 template<typename PointDataTreeType>
375 
377  using LeafRangeT = typename LeafManagerT::LeafRange;
378  using Indices = std::vector<size_t>;
379 
381  : mIndices(indices) { }
382 
383  void operator()(const LeafRangeT& range) const {
384 
385  for (auto leaf = range.begin(); leaf; ++leaf) {
386 
387  for (const size_t index : mIndices) {
388 
389  AttributeArray& array = leaf->attributeArray(index);
390  array.compress();
391  }
392  }
393  }
394 
395  //////////
396 
398 }; // class BloscCompressAttributesOp
399 
400 
401 ////////////////////////////////////////
402 
403 
404 template <typename ValueType, typename CodecType>
406 {
407  static const NamePair& type() {
409  }
410 };
411 
412 
413 template <typename CodecType>
414 struct AttributeTypeConversion<Name, CodecType>
415 {
416  static const NamePair& type() { return StringAttributeArray::attributeType(); }
417 };
418 
419 
420 ////////////////////////////////////////
421 
422 
423 template <typename PointDataTree, typename ValueType>
425 {
426  static void add(PointDataTree&, const ValueType&) {}
427 
428  template<typename AttributeListType>
429  static void add(PointDataTree&, const AttributeListType&) {}
430 };
431 
432 
433 template <typename PointDataTree>
435 {
436  static void add(PointDataTree& tree, const Name& uniformValue) {
437  MetaMap& metadata = makeDescriptorUnique(tree)->getMetadata();
438  StringMetaInserter inserter(metadata);
439  inserter.insert(uniformValue);
440  }
441 
442  template<typename AttributeListType>
443  static void add(PointDataTree& tree, const AttributeListType& data) {
444  MetaMap& metadata = makeDescriptorUnique(tree)->getMetadata();
445  StringMetaInserter inserter(metadata);
446  Name value;
447 
448  for (size_t i = 0; i < data.size(); i++) {
449  data.get(value, i);
450  inserter.insert(value);
451  }
452  }
453 };
454 
455 
456 } // namespace point_attribute_internal
457 
458 
459 ////////////////////////////////////////
460 
461 
462 template <typename PointDataTree>
463 inline void appendAttribute(PointDataTree& tree,
464  const Name& name,
465  const NamePair& type,
466  const Index strideOrTotalSize,
467  const bool constantStride,
468  Metadata::Ptr metaDefaultValue,
469  const bool hidden,
470  const bool transient)
471 {
472  using Descriptor = AttributeSet::Descriptor;
473 
475 
476  auto iter = tree.cbeginLeaf();
477 
478  if (!iter) return;
479 
480  // do not append a non-unique attribute
481 
482  const Descriptor& descriptor = iter->attributeSet().descriptor();
483  const size_t index = descriptor.find(name);
484 
485  if (index != AttributeSet::INVALID_POS) {
486  OPENVDB_THROW(KeyError,
487  "Cannot append an attribute with a non-unique name - " << name << ".");
488  }
489 
490  // create a new attribute descriptor
491 
492  Descriptor::Ptr newDescriptor = descriptor.duplicateAppend(name, type);
493 
494  // store the attribute default value in the descriptor metadata
495 
496  if (metaDefaultValue) {
497  newDescriptor->setDefaultValue(name, *metaDefaultValue);
498  }
499 
500  // extract new pos
501 
502  const size_t pos = newDescriptor->find(name);
503 
504  // insert attributes using the new descriptor
505 
506  tree::LeafManager<PointDataTree> leafManager(tree);
507  AppendAttributeOp<PointDataTree> append(newDescriptor, pos, strideOrTotalSize,
508  constantStride, hidden, transient);
509  tbb::parallel_for(leafManager.leafRange(), append);
510 }
511 
512 
513 ////////////////////////////////////////
514 
515 
516 template <typename ValueType, typename CodecType, typename PointDataTree>
517 inline void appendAttribute(PointDataTree& tree,
518  const std::string& name,
519  const ValueType& uniformValue,
520  const Index strideOrTotalSize,
521  const bool constantStride,
522  Metadata::Ptr metaDefaultValue,
523  const bool hidden,
524  const bool transient)
525 {
527  "ValueType must not be derived from AttributeArray");
528 
532 
534  strideOrTotalSize, constantStride, metaDefaultValue, hidden, transient);
535 
536  if (!math::isExactlyEqual(uniformValue, defaultValue<ValueType>())) {
537  MetadataStorage<PointDataTree, ValueType>::add(tree, uniformValue);
538  collapseAttribute<ValueType>(tree, name, uniformValue);
539  }
540 }
541 
542 
543 ////////////////////////////////////////
544 
545 
546 template <typename ValueType, typename PointDataTree>
547 inline void appendAttribute(PointDataTree& tree,
548  const std::string& name,
549  const ValueType& uniformValue,
550  const Index strideOrTotalSize,
551  const bool constantStride,
552  Metadata::Ptr metaDefaultValue,
553  const bool hidden,
554  const bool transient)
555 {
557  "ValueType must not be derived from AttributeArray");
558 
559  appendAttribute<ValueType, NullCodec>(tree, name, uniformValue, strideOrTotalSize,
560  constantStride, metaDefaultValue, hidden, transient);
561 }
562 
563 
564 ////////////////////////////////////////
565 
566 
567 template <typename ValueType, typename PointDataTree>
568 inline void collapseAttribute( PointDataTree& tree,
569  const Name& name,
570  const ValueType& uniformValue)
571 {
573  "ValueType must not be derived from AttributeArray");
574 
575  using LeafManagerT = typename tree::LeafManager<PointDataTree>;
576  using Descriptor = AttributeSet::Descriptor;
577 
579 
580  auto iter = tree.cbeginLeaf();
581 
582  if (!iter) return;
583 
584 
585  const Descriptor& descriptor = iter->attributeSet().descriptor();
586 
587  // throw if attribute name does not exist
588 
589  const size_t index = descriptor.find(name);
590  if (index == AttributeSet::INVALID_POS) {
591  OPENVDB_THROW(KeyError, "Cannot find attribute name in PointDataTree.");
592  }
593 
594  LeafManagerT leafManager(tree);
595  tbb::parallel_for(leafManager.leafRange(),
596  CollapseAttributeOp<ValueType, PointDataTree>(index, uniformValue));
597 }
598 
599 
600 ////////////////////////////////////////
601 
602 
603 template <typename PointDataTree>
604 inline void dropAttributes( PointDataTree& tree,
605  const std::vector<size_t>& indices)
606 {
607  using LeafManagerT = typename tree::LeafManager<PointDataTree>;
608  using Descriptor = AttributeSet::Descriptor;
609 
611 
612  auto iter = tree.cbeginLeaf();
613 
614  if (!iter) return;
615 
616  const Descriptor& descriptor = iter->attributeSet().descriptor();
617 
618  // throw if position index present in the indices as this attribute is mandatory
619 
620  const size_t positionIndex = descriptor.find("P");
621  if (positionIndex!= AttributeSet::INVALID_POS &&
622  std::find(indices.begin(), indices.end(), positionIndex) != indices.end()) {
623  OPENVDB_THROW(KeyError, "Cannot drop mandatory position attribute.");
624  }
625 
626  // insert attributes using the new descriptor
627 
628  Descriptor::Ptr newDescriptor = descriptor.duplicateDrop(indices);
629  tbb::parallel_for(LeafManagerT(tree).leafRange(),
630  DropAttributesOp<PointDataTree>(indices, newDescriptor));
631 }
632 
633 
634 ////////////////////////////////////////
635 
636 
637 template <typename PointDataTree>
638 inline void dropAttributes( PointDataTree& tree,
639  const std::vector<Name>& names)
640 {
641  auto iter = tree.cbeginLeaf();
642 
643  if (!iter) return;
644 
645  const AttributeSet& attributeSet = iter->attributeSet();
646  const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
647 
648  std::vector<size_t> indices;
649 
650  for (const Name& name : names) {
651  const size_t index = descriptor.find(name);
652 
653  // do not attempt to drop an attribute that does not exist
654  if (index == AttributeSet::INVALID_POS) {
655  OPENVDB_THROW(KeyError,
656  "Cannot drop an attribute that does not exist - " << name << ".");
657  }
658 
659  indices.push_back(index);
660  }
661 
662  dropAttributes(tree, indices);
663 }
664 
665 
666 ////////////////////////////////////////
667 
668 
669 template <typename PointDataTree>
670 inline void dropAttribute( PointDataTree& tree,
671  const size_t& index)
672 {
673  std::vector<size_t> indices{index};
674  dropAttributes(tree, indices);
675 }
676 
677 
678 template <typename PointDataTree>
679 inline void dropAttribute( PointDataTree& tree,
680  const Name& name)
681 {
682  std::vector<Name> names{name};
683  dropAttributes(tree, names);
684 }
685 
686 
687 ////////////////////////////////////////
688 
689 
690 template <typename PointDataTree>
691 inline void renameAttributes( PointDataTree& tree,
692  const std::vector<Name>& oldNames,
693  const std::vector<Name>& newNames)
694 {
695  if (oldNames.size() != newNames.size()) {
696  OPENVDB_THROW(ValueError, "Mis-matching sizes of name vectors, cannot rename attributes.");
697  }
698 
699  using Descriptor = AttributeSet::Descriptor;
700 
701  auto iter = tree.beginLeaf();
702 
703  if (!iter) return;
704 
705  const AttributeSet& attributeSet = iter->attributeSet();
706  const Descriptor& descriptor = attributeSet.descriptor();
707  auto newDescriptor = std::make_shared<Descriptor>(descriptor);
708 
709  for (size_t i = 0; i < oldNames.size(); i++) {
710  const Name& oldName = oldNames[i];
711  if (descriptor.find(oldName) == AttributeSet::INVALID_POS) {
712  OPENVDB_THROW(KeyError, "Cannot find requested attribute - " << oldName << ".");
713  }
714 
715  const Name& newName = newNames[i];
716  if (descriptor.find(newName) != AttributeSet::INVALID_POS) {
717  OPENVDB_THROW(KeyError,
718  "Cannot rename attribute as new name already exists - " << newName << ".");
719  }
720 
721  const AttributeArray* array = attributeSet.getConst(oldName);
722  assert(array);
723 
724  if (isGroup(*array)) {
725  OPENVDB_THROW(KeyError, "Cannot rename group attribute - " << oldName << ".");
726  }
727 
728  newDescriptor->rename(oldName, newName);
729  }
730 
731  for (; iter; ++iter) {
732  iter->renameAttributes(descriptor, newDescriptor);
733  }
734 }
735 
736 
737 template <typename PointDataTree>
738 inline void renameAttribute(PointDataTree& tree,
739  const Name& oldName,
740  const Name& newName)
741 {
742  renameAttributes(tree, {oldName}, {newName});
743 }
744 
745 
746 ////////////////////////////////////////
747 
748 
749 template <typename PointDataTree>
751 {
752  using LeafManagerT = typename tree::LeafManager<PointDataTree>;
753 
755 
756  auto iter = tree.beginLeaf();
757  if (!iter) return;
758 
759  tbb::parallel_for(LeafManagerT(tree).leafRange(), CompactAttributesOp<PointDataTree>());
760 }
761 
762 
763 ////////////////////////////////////////
764 
765 
766 template <typename PointDataTree>
768  const Name& name)
769 {
771 
772  using LeafManagerT = typename tree::LeafManager<PointDataTree>;
773  using Descriptor = AttributeSet::Descriptor;
774 
775  auto iter = tree.cbeginLeaf();
776 
777  if (!iter) return;
778 
779  const Descriptor& descriptor = iter->attributeSet().descriptor();
780 
781  // throw if index cannot be found in descriptor
782 
783  const size_t index = descriptor.find(name);
784  if (index == AttributeSet::INVALID_POS) {
785  OPENVDB_THROW(KeyError, "Cannot find requested attribute - " << name << ".");
786  }
787 
788  // blosc compress attributes
789 
790  std::vector<size_t> indices{index};
791 
792  tbb::parallel_for(LeafManagerT(tree).leafRange(),
793  BloscCompressAttributesOp<PointDataTree>(indices));
794 }
795 
796 ////////////////////////////////////////
797 
798 
799 } // namespace points
800 } // namespace OPENVDB_VERSION_NAME
801 } // namespace openvdb
802 
803 #endif // OPENVDB_POINTS_POINT_ATTRIBUTE_HAS_BEEN_INCLUDED
804 
805 // Copyright (c) 2012-2017 DreamWorks Animation LLC
806 // All rights reserved. This software is distributed under the
807 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: ImfName.h:53
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
GLsizei GLenum const void * indices
Definition: glcorearb.h:405
GLenum GLint * range
Definition: glcorearb.h:1924
AppendAttributeOp(AttributeSet::DescriptorPtr &descriptor, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true, const bool hidden=false, const bool transient=false)
void bloscCompressAttribute(PointDataTree &tree, const Name &name)
Apply Blosc compression to one attribute in the VDB tree.
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:391
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1182
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
void collapseAttribute(PointDataTree &tree, const Name &name, const ValueType &uniformValue=point_attribute_internal::defaultValue< ValueType >())
Collapse the attribute into a uniform value.
png_uint_32 i
Definition: png.h:2877
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
void collapse()
Replace the existing array with a uniform value (zero if none provided).
DropAttributesOp(const Indices &indices, AttributeSet::DescriptorPtr &descriptor)
bool isGroup(const AttributeArray &array)
void appendAttribute(PointDataTree &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType) ...
Base class for storing attribute data.
#define OPENVDB_VERSION_NAME
Definition: version.h:43
virtual bool compress()=0
Compress the attribute array.
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1180
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Attribute array storage for string data using Descriptor Metadata.
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...
void collapse()
Set membership for the whole array and attempt to collapse.
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
GLboolean * data
Definition: glcorearb.h:130
std::pair< Name, Name > NamePair
GLuint const GLchar * name
Definition: glcorearb.h:785
GLsizei const GLfloat * value
Definition: glcorearb.h:823
Set of Attribute Arrays which tracks metadata about each array.
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Attribute Group access and filtering for iteration.
GLuint index
Definition: glcorearb.h:785
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
void renameAttribute(PointDataTree &tree, const Name &oldName, const Name &newName)
Rename an attribute in a VDB tree.
void dropAttribute(PointDataTree &tree, const size_t &index)
Drop one attribute from the VDB tree (convenience method).
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 >>> PointDataTree
Point index tree configured to match the default VDB configurations.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
void insert(const Name &name)
Insert the string into the metadata.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
static void add(PointDataTree &, const AttributeListType &)
T::Ptr getMetadata(const Name &)
Return a pointer to a TypedMetadata object of type T and with the given name. If no such field exists...
Definition: MetaMap.h:165