35 #ifndef OPENVDB_TREE_ROOTNODE_HAS_BEEN_INCLUDED
36 #define OPENVDB_TREE_ROOTNODE_HAS_BEEN_INCLUDED
42 #include <boost/type_traits/remove_const.hpp>
43 #include <boost/type_traits/remove_pointer.hpp>
44 #include <boost/type_traits/is_pointer.hpp>
45 #include <boost/type_traits/is_const.hpp>
46 #include <boost/mpl/contains.hpp>
47 #include <boost/mpl/if.hpp>
48 #include <boost/mpl/vector.hpp>
49 #include <boost/mpl/at.hpp>
50 #include <boost/mpl/push_back.hpp>
51 #include <boost/mpl/size.hpp>
52 #include <tbb/parallel_for.h>
53 #include <openvdb/Exceptions.h>
54 #include <openvdb/Types.h>
55 #include <openvdb/io/Compression.h>
56 #include <openvdb/math/Math.h>
57 #include <openvdb/math/BBox.h>
58 #include <openvdb/util/NodeMasks.h>
59 #include <openvdb/version.h>
68 template<
typename HeadType,
int HeadLevel>
struct NodeChain;
74 template<
typename ChildType>
82 static const Index LEVEL = 1 + ChildType::LEVEL;
86 BOOST_STATIC_ASSERT(boost::mpl::size<NodeChainType>::value == LEVEL + 1);
90 template<
typename OtherValueType>
98 template<
typename OtherNodeType>
108 explicit RootNode(
const ValueType& background);
118 template<
typename OtherChildType>
129 template<
typename OtherChildType>
131 const ValueType& background,
const ValueType& foreground,
TopologyCopy);
143 template<
typename OtherChildType>
155 template<
typename OtherChildType>
162 Tile(): value(
zeroVal<ValueType>()), active(false) {}
163 Tile(
const ValueType& v,
bool b): value(v), active(b) {}
173 NodeStruct(): child(NULL) {}
174 NodeStruct(ChildType& c): child(&c) {}
175 NodeStruct(
const Tile& t): child(NULL), tile(t) {}
178 bool isChild()
const {
return child != NULL; }
179 bool isTile()
const {
return child == NULL; }
180 bool isTileOff()
const {
return isTile() && !tile.active; }
181 bool isTileOn()
const {
return isTile() && tile.active; }
183 void set(ChildType& c) {
delete child; child = &c; }
184 void set(
const Tile& t) {
delete child; child = NULL; tile = t; }
185 ChildType& steal(
const Tile& t) { ChildType* c = child; child = NULL; tile = t;
return *c; }
188 typedef std::map<Coord, NodeStruct> MapType;
189 typedef typename MapType::iterator MapIter;
190 typedef typename MapType::const_iterator MapCIter;
192 typedef std::set<Coord> CoordSet;
193 typedef typename CoordSet::iterator CoordSetIter;
194 typedef typename CoordSet::const_iterator CoordSetCIter;
196 static void setTile(
const MapIter& i,
const Tile& t) { i->second.set(t); }
197 static void setChild(
const MapIter& i, ChildType& c) { i->second.set(c); }
198 static Tile& getTile(
const MapIter& i) {
return i->second.tile; }
199 static const Tile& getTile(
const MapCIter& i) {
return i->second.tile; }
200 static ChildType& getChild(
const MapIter& i) {
return *(i->second.child); }
201 static const ChildType& getChild(
const MapCIter& i) {
return *(i->second.child); }
202 static ChildType& stealChild(
const MapIter& i,
const Tile& t) {
return i->second.steal(t);}
203 static const ChildType& stealChild(
const MapCIter& i,
const Tile& t) {
return i->second.steal(t);}
205 static bool isChild(
const MapCIter& i) {
return i->second.isChild(); }
206 static bool isChild(
const MapIter& i) {
return i->second.isChild(); }
207 static bool isTile(
const MapCIter& i) {
return i->second.isTile(); }
208 static bool isTile(
const MapIter& i) {
return i->second.isTile(); }
209 static bool isTileOff(
const MapCIter& i) {
return i->second.isTileOff(); }
210 static bool isTileOff(
const MapIter& i) {
return i->second.isTileOff(); }
211 static bool isTileOn(
const MapCIter& i) {
return i->second.isTileOn(); }
212 static bool isTileOn(
const MapIter& i) {
return i->second.isTileOn(); }
215 static inline bool test(
const MapIter&) {
return true; }
216 static inline bool test(
const MapCIter&) {
return true; }
219 static inline bool test(
const MapIter& i) {
return isTileOn(i); }
220 static inline bool test(
const MapCIter& i) {
return isTileOn(i); }
222 struct ValueOffPred {
223 static inline bool test(
const MapIter& i) {
return isTileOff(i); }
224 static inline bool test(
const MapCIter& i) {
return isTileOff(i); }
226 struct ValueAllPred {
227 static inline bool test(
const MapIter& i) {
return isTile(i); }
228 static inline bool test(
const MapCIter& i) {
return isTile(i); }
231 static inline bool test(
const MapIter& i) {
return isChild(i); }
232 static inline bool test(
const MapCIter& i) {
return isChild(i); }
234 struct ChildOffPred {
235 static inline bool test(
const MapIter& i) {
return isTile(i); }
236 static inline bool test(
const MapCIter& i) {
return isTile(i); }
239 template<
typename _RootNodeT,
typename _MapIterT,
typename FilterPredT>
243 typedef _RootNodeT RootNodeT;
244 typedef _MapIterT MapIterT;
248 return (mParentNode == other.mParentNode) && (mIter == other.mIter);
250 bool operator!=(
const BaseIter& other)
const {
return !(*
this == other); }
252 RootNodeT* getParentNode()
const {
return mParentNode; }
254 RootNodeT& parent()
const
256 if (!mParentNode)
OPENVDB_THROW(ValueError,
"iterator references a null parent node");
260 bool test()
const { assert(mParentNode);
return mIter != mParentNode->mTable.end(); }
261 operator bool()
const {
return this->test(); }
263 void increment() { ++mIter; this->skip(); }
264 bool next() { this->increment();
return this->test(); }
265 void increment(
Index n) {
for (
int i = 0; i < n && this->next(); ++i) {} }
271 return !mParentNode ? 0U :
Index(std::distance(mParentNode->mTable.begin(), mIter));
274 bool isValueOn()
const {
return RootNodeT::isTileOn(mIter); }
275 bool isValueOff()
const {
return RootNodeT::isTileOff(mIter); }
276 void setValueOn(
bool on =
true)
const { mIter->second.tile.active = on; }
277 void setValueOff()
const { mIter->second.tile.active =
false; }
280 Coord getCoord()
const {
return mIter->first; }
282 void getCoord(Coord& xyz)
const { xyz = this->getCoord(); }
285 BaseIter(): mParentNode(NULL) {}
286 BaseIter(RootNodeT& parent,
const MapIterT& iter): mParentNode(&parent), mIter(iter) {}
288 void skip() {
while (this->test() && !FilterPredT::test(mIter)) ++mIter; }
290 RootNodeT* mParentNode;
294 template<
typename RootNodeT,
typename MapIterT,
typename FilterPredT,
typename ChildNodeT>
295 class ChildIter:
public BaseIter<RootNodeT, MapIterT, FilterPredT>
298 typedef BaseIter<RootNodeT, MapIterT, FilterPredT> BaseT;
299 typedef RootNodeT NodeType;
300 typedef NodeType ValueType;
301 typedef ChildNodeT ChildNodeType;
302 typedef typename boost::remove_const<NodeType>::type NonConstNodeType;
303 typedef typename boost::remove_const<ValueType>::type NonConstValueType;
304 typedef typename boost::remove_const<ChildNodeType>::type NonConstChildNodeType;
308 ChildIter(RootNodeT& parent,
const MapIterT& iter): BaseT(parent, iter) { BaseT::skip(); }
310 ChildIter& operator++() { BaseT::increment();
return *
this; }
312 ChildNodeT& getValue()
const {
return getChild(mIter); }
313 ChildNodeT&
operator*()
const {
return this->getValue(); }
314 ChildNodeT* operator->()
const {
return &this->getValue(); }
317 template<
typename RootNodeT,
typename MapIterT,
typename FilterPredT,
typename ValueT>
318 class ValueIter:
public BaseIter<RootNodeT, MapIterT, FilterPredT>
321 typedef BaseIter<RootNodeT, MapIterT, FilterPredT> BaseT;
322 typedef RootNodeT NodeType;
323 typedef ValueT ValueType;
324 typedef typename boost::remove_const<NodeType>::type NonConstNodeType;
325 typedef typename boost::remove_const<ValueT>::type NonConstValueType;
329 ValueIter(RootNodeT& parent,
const MapIterT& iter): BaseT(parent, iter) { BaseT::skip(); }
331 ValueIter& operator++() { BaseT::increment();
return *
this; }
333 ValueT& getValue()
const {
return getTile(mIter).value; }
334 ValueT&
operator*()
const {
return this->getValue(); }
335 ValueT* operator->()
const {
return &(this->getValue()); }
337 void setValue(
const ValueT& v)
const { assert(isTile(mIter)); getTile(mIter).value = v; }
339 template<
typename ModifyOp>
340 void modifyValue(
const ModifyOp& op)
const
342 assert(isTile(mIter));
343 op(getTile(mIter).value);
347 template<
typename RootNodeT,
typename MapIterT,
typename ChildNodeT,
typename ValueT>
348 class DenseIter:
public BaseIter<RootNodeT, MapIterT, NullPred>
351 typedef BaseIter<RootNodeT, MapIterT, NullPred> BaseT;
352 typedef RootNodeT NodeType;
353 typedef ValueT ValueType;
354 typedef ChildNodeT ChildNodeType;
355 typedef typename boost::remove_const<NodeType>::type NonConstNodeType;
356 typedef typename boost::remove_const<ValueT>::type NonConstValueType;
357 typedef typename boost::remove_const<ChildNodeT>::type NonConstChildNodeType;
361 DenseIter(RootNodeT& parent,
const MapIterT& iter): BaseT(parent, iter) {}
363 DenseIter& operator++() { BaseT::increment();
return *
this; }
365 bool isChildNode()
const {
return isChild(mIter); }
367 ChildNodeT* probeChild(NonConstValueType& value)
const
369 if (isChild(mIter))
return &getChild(mIter);
370 value = getTile(mIter).value;
373 bool probeChild(ChildNodeT*& child, NonConstValueType& value)
const
375 child = this->probeChild(value);
376 return child != NULL;
378 bool probeValue(NonConstValueType& value)
const {
return !this->probeChild(value); }
380 void setChild(ChildNodeT& c)
const { RootNodeT::setChild(mIter, c); }
381 void setChild(ChildNodeT* c)
const { assert(c != NULL); RootNodeT::setChild(mIter, *c); }
382 void setValue(
const ValueT& v)
const
384 if (isTile(mIter)) getTile(mIter).value = v;
388 else stealChild(mIter, Tile(v,
true));
393 typedef ChildIter<RootNode, MapIter, ChildOnPred, ChildType>
ChildOnIter;
394 typedef ChildIter<const RootNode, MapCIter, ChildOnPred, const ChildType>
ChildOnCIter;
395 typedef ValueIter<RootNode, MapIter, ChildOffPred, const ValueType>
ChildOffIter;
396 typedef ValueIter<const RootNode, MapCIter, ChildOffPred, ValueType>
ChildOffCIter;
397 typedef DenseIter<RootNode, MapIter, ChildType, ValueType>
ChildAllIter;
398 typedef DenseIter<const RootNode, MapCIter, const ChildType, const ValueType>
ChildAllCIter;
400 typedef ValueIter<RootNode, MapIter, ValueOnPred, ValueType>
ValueOnIter;
401 typedef ValueIter<const RootNode, MapCIter, ValueOnPred, const ValueType>
ValueOnCIter;
402 typedef ValueIter<RootNode, MapIter, ValueOffPred, ValueType>
ValueOffIter;
403 typedef ValueIter<const RootNode, MapCIter, ValueOffPred, const ValueType>
ValueOffCIter;
404 typedef ValueIter<RootNode, MapIter, ValueAllPred, ValueType>
ValueAllIter;
405 typedef ValueIter<const RootNode, MapCIter, ValueAllPred, const ValueType>
ValueAllCIter;
408 ChildOnCIter
cbeginChildOn()
const {
return ChildOnCIter(*
this, mTable.begin()); }
409 ChildOffCIter
cbeginChildOff()
const {
return ChildOffCIter(*
this, mTable.begin()); }
410 ChildAllCIter
cbeginChildAll()
const {
return ChildAllCIter(*
this, mTable.begin()); }
414 ChildOnIter
beginChildOn() {
return ChildOnIter(*
this, mTable.begin()); }
415 ChildOffIter
beginChildOff() {
return ChildOffIter(*
this, mTable.begin()); }
416 ChildAllIter
beginChildAll() {
return ChildAllIter(*
this, mTable.begin()); }
418 ValueOnCIter
cbeginValueOn()
const {
return ValueOnCIter(*
this, mTable.begin()); }
419 ValueOffCIter
cbeginValueOff()
const {
return ValueOffCIter(*
this, mTable.begin()); }
420 ValueAllCIter
cbeginValueAll()
const {
return ValueAllCIter(*
this, mTable.begin()); }
424 ValueOnIter
beginValueOn() {
return ValueOnIter(*
this, mTable.begin()); }
425 ValueOffIter
beginValueOff() {
return ValueOffIter(*
this, mTable.begin()); }
426 ValueAllIter
beginValueAll() {
return ValueAllIter(*
this, mTable.begin()); }
436 void evalActiveBoundingBox(CoordBBox& bbox,
bool visitVoxels =
true)
const;
453 void setBackground(
const ValueType& value,
bool updateChildNodes);
459 bool isBackgroundTile(
const Tile&)
const;
461 bool isBackgroundTile(
const MapIter&)
const;
463 bool isBackgroundTile(
const MapCIter&)
const;
467 size_t numBackgroundTiles()
const;
470 size_t eraseBackgroundTiles();
471 void clear() { this->clearTable(); }
474 bool empty()
const {
return mTable.size() == numBackgroundTiles(); }
479 bool expand(
const Coord& xyz);
482 static void getNodeLog2Dims(std::vector<Index>& dims);
488 Index getWidth()
const {
return this->getMaxIndex()[0] - this->getMinIndex()[0]; }
489 Index getHeight()
const {
return this->getMaxIndex()[1] - this->getMinIndex()[1]; }
490 Index getDepth()
const {
return this->getMaxIndex()[2] - this->getMinIndex()[2]; }
493 Coord getMinIndex()
const;
495 Coord getMaxIndex()
const;
497 void getIndexRange(CoordBBox& bbox)
const;
501 template<
typename OtherChildType>
505 template<
typename OtherChildType>
510 template<
typename OtherChildType>
517 Index64 onLeafVoxelCount()
const;
518 Index64 offLeafVoxelCount()
const;
521 bool isValueOn(
const Coord& xyz)
const;
523 bool hasActiveTiles()
const;
525 const ValueType& getValue(
const Coord& xyz)
const;
526 bool probeValue(
const Coord& xyz, ValueType& value)
const;
531 int getValueDepth(
const Coord& xyz)
const;
534 void setActiveState(
const Coord& xyz,
bool on);
536 void setValueOnly(
const Coord& xyz,
const ValueType& value);
538 void setValueOn(
const Coord& xyz,
const ValueType& value);
540 void setValueOff(
const Coord& xyz);
542 void setValueOff(
const Coord& xyz,
const ValueType& value);
546 template<
typename ModifyOp>
547 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
549 template<
typename ModifyOp>
550 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
558 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
565 template<
typename DenseT>
566 void copyToDense(
const CoordBBox& bbox, DenseT& dense)
const;
572 bool writeTopology(std::ostream&,
bool toHalf =
false)
const;
573 bool readTopology(std::istream&,
bool fromHalf =
false);
575 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
576 void readBuffers(std::istream&,
bool fromHalf =
false);
577 void readBuffers(std::istream&,
const CoordBBox&,
bool fromHalf =
false);
587 template<
typename AccessorT>
588 const ValueType& getValueAndCache(
const Coord& xyz, AccessorT&)
const;
593 template<
typename AccessorT>
594 bool isValueOnAndCache(
const Coord& xyz, AccessorT&)
const;
600 template<
typename AccessorT>
601 void setValueAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
607 template<
typename AccessorT>
608 void setValueOnlyAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
615 template<
typename ModifyOp,
typename AccessorT>
616 void modifyValueAndCache(
const Coord& xyz,
const ModifyOp& op, AccessorT&);
622 template<
typename ModifyOp,
typename AccessorT>
623 void modifyValueAndActiveStateAndCache(
const Coord& xyz,
const ModifyOp& op, AccessorT&);
629 template<
typename AccessorT>
630 void setValueOffAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
636 template<
typename AccessorT>
637 void setActiveStateAndCache(
const Coord& xyz,
bool on, AccessorT&);
644 template<
typename AccessorT>
645 bool probeValueAndCache(
const Coord& xyz, ValueType& value, AccessorT&)
const;
652 template<
typename AccessorT>
653 int getValueDepthAndCache(
const Coord& xyz, AccessorT&)
const;
656 void clip(
const CoordBBox&);
661 void prune(
const ValueType& tolerance = zeroVal<ValueType>());
665 void addLeaf(LeafNodeType* leaf);
669 template<
typename AccessorT>
670 void addLeafAndCache(LeafNodeType* leaf, AccessorT&);
680 template<
typename NodeT>
681 NodeT* stealNode(
const Coord& xyz,
const ValueType& value,
bool state);
685 void addTile(
const Coord& xyz,
const ValueType& value,
bool state);
690 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state);
694 template<
typename AccessorT>
695 void addTileAndCache(
Index level,
const Coord& xyz,
const ValueType&,
bool state, AccessorT&);
702 LeafNodeType* touchLeaf(
const Coord& xyz);
706 template<
typename AccessorT>
707 LeafNodeType* touchLeafAndCache(
const Coord& xyz, AccessorT& acc);
710 template <
typename NodeT>
713 NodeT* probeNode(
const Coord& xyz);
714 template <
typename NodeT>
715 const NodeT* probeConstNode(
const Coord& xyz)
const;
719 template<
typename NodeT,
typename AccessorT>
722 NodeT* probeNodeAndCache(
const Coord& xyz, AccessorT& acc);
723 template<
typename NodeT,
typename AccessorT>
724 const NodeT* probeConstNodeAndCache(
const Coord& xyz, AccessorT& acc)
const;
728 LeafNodeType* probeLeaf(
const Coord& xyz);
731 const LeafNodeType* probeConstLeaf(
const Coord& xyz)
const;
732 const LeafNodeType* probeLeaf(
const Coord& xyz)
const;
736 template<
typename AccessorT>
739 LeafNodeType* probeLeafAndCache(
const Coord& xyz, AccessorT& acc);
740 template<
typename AccessorT>
741 const LeafNodeType* probeConstLeafAndCache(
const Coord& xyz, AccessorT& acc)
const;
742 template<
typename AccessorT>
743 const LeafNodeType* probeLeafAndCache(
const Coord& xyz, AccessorT& acc)
const;
752 template<
typename ArrayT>
void getNodes(ArrayT& array);
775 template<
typename ArrayT>
void getNodes(ArrayT& array)
const;
779 void voxelizeActiveTiles();
788 template<MergePolicy Policy>
void merge(
RootNode& other);
803 template<
typename OtherChildType>
819 template<
typename OtherChildType>
832 template<
typename OtherChildType>
835 template<
typename CombineOp>
838 template<
typename CombineOp,
typename OtherRootNode >
839 void combine2(
const RootNode& other0,
const OtherRootNode& other1,
840 CombineOp& op,
bool prune =
false);
847 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
849 template<
typename VisitorOp>
void visit(VisitorOp&);
850 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
852 template<
typename OtherRootNodeType,
typename VisitorOp>
853 void visit2(OtherRootNodeType& other, VisitorOp&);
854 template<
typename OtherRootNodeType,
typename VisitorOp>
855 void visit2(OtherRootNodeType& other, VisitorOp&)
const;
867 inline void clearTable();
869 void resetTable(MapType& table) { mTable.swap(table); table.clear(); }
871 void resetTable(
const MapType&)
const {}
874 Index getChildCount()
const;
875 Index getTileCount()
const;
876 Index getActiveTileCount()
const;
877 Index getInactiveTileCount()
const;
880 static Coord coordToKey(
const Coord& xyz) {
return xyz & ~(ChildType::DIM - 1); }
883 void insertKeys(CoordSet&)
const;
886 bool hasKey(
const Coord& key)
const {
return mTable.find(key) != mTable.end(); }
888 MapIter findKey(
const Coord& key) {
return mTable.find(key); }
891 MapCIter findKey(
const Coord& key)
const {
return mTable.find(key); }
894 MapIter findCoord(
const Coord& xyz) {
return mTable.find(coordToKey(xyz)); }
897 MapCIter findCoord(
const Coord& xyz)
const {
return mTable.find(coordToKey(xyz)); }
899 MapIter findOrAddCoord(
const Coord& xyz);
908 template<
typename OtherChildType>
909 static void enforceSameConfiguration(
const RootNode<OtherChildType>& other);
916 template<
typename OtherChildType>
917 static void enforceCompatibleValueTypes(
const RootNode<OtherChildType>& other);
919 template<
typename CombineOp,
typename OtherRootNode >
920 void doCombine2(
const RootNode&,
const OtherRootNode&, CombineOp&,
bool prune);
922 template<
typename RootNodeT,
typename VisitorOp,
typename ChildAllIterT>
923 static inline void doVisit(RootNodeT&, VisitorOp&);
925 template<
typename RootNodeT,
typename OtherRootNodeT,
typename VisitorOp,
926 typename ChildAllIterT,
typename OtherChildAllIterT>
927 static inline void doVisit2(RootNodeT&, OtherRootNodeT&, VisitorOp&);
931 ValueType mBackground;
958 template<
typename HeadT,
int HeadLevel>
961 typedef typename boost::mpl::push_back<SubtreeT, HeadT>::type
Type;
965 template<
typename HeadT>
967 typedef typename boost::mpl::vector<typename HeadT::ChildNodeType, HeadT>::type
Type;
975 template<
typename ChildT1,
typename NodeT2>
979 static const bool value =
false;
982 template<
typename ChildT1,
typename ChildT2>
984 static const bool value = ChildT1::template SameConfiguration<ChildT2>::value;
992 template<
typename ChildT>
1000 template<
typename ChildT>
1008 template<
typename ChildT>
1009 template<
typename OtherChildType>
1012 const ValueType& backgd,
const ValueType& foregd,
TopologyCopy):
1017 enforceSameConfiguration(other);
1019 const Tile bgTile(backgd,
false), fgTile(foregd,
true);
1022 for (
typename OtherRootT::MapCIter i=other.mTable.begin(), e=other.mTable.end(); i != e; ++i) {
1023 mTable[i->first] = OtherRootT::isTile(i)
1024 ? NodeStruct(OtherRootT::isTileOn(i) ? fgTile : bgTile)
1025 : NodeStruct(*(
new ChildT(OtherRootT::getChild(i), backgd, foregd,
TopologyCopy())));
1030 template<
typename ChildT>
1031 template<
typename OtherChildType>
1039 enforceSameConfiguration(other);
1041 const Tile bgTile(backgd,
false), fgTile(backgd,
true);
1043 for (
typename OtherRootT::MapCIter i=other.mTable.begin(), e=other.mTable.end(); i != e; ++i) {
1044 mTable[i->first] = OtherRootT::isTile(i)
1045 ? NodeStruct(OtherRootT::isTileOn(i) ? fgTile : bgTile)
1046 : NodeStruct(*(
new ChildT(OtherRootT::getChild(i), backgd,
TopologyCopy())));
1057 template<
typename RootT,
typename OtherRootT,
bool Compatible = false>
1064 self.enforceSameConfiguration(other);
1065 self.enforceCompatibleValueTypes(other);
1067 std::ostringstream ostr;
1068 ostr <<
"cannot convert a " <<
typeid(OtherRootT).name()
1069 <<
" to a " <<
typeid(RootT).name();
1075 template<
typename RootT,
typename OtherRootT>
1080 typedef typename RootT::ValueType ValueT;
1081 typedef typename RootT::ChildNodeType ChildT;
1082 typedef typename RootT::NodeStruct NodeStruct;
1083 typedef typename RootT::Tile Tile;
1084 typedef typename OtherRootT::ValueType OtherValueT;
1085 typedef typename OtherRootT::MapCIter OtherMapCIter;
1086 typedef typename OtherRootT::Tile OtherTile;
1090 static inline ValueT convertValue(
const OtherValueT& val) {
return ValueT(val); }
1093 self.mBackground = Local::convertValue(other.mBackground);
1098 for (OtherMapCIter i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
1099 if (other.isTile(i)) {
1101 const OtherTile& otherTile = other.getTile(i);
1102 self.mTable[i->first] = NodeStruct(
1103 Tile(Local::convertValue(otherTile.value), otherTile.active));
1106 self.mTable[i->first] = NodeStruct(*(
new ChildT(other.getChild(i))));
1114 template<
typename ChildT>
1115 inline RootNode<ChildT>&
1118 if (&other !=
this) {
1119 mBackground = other.mBackground;
1124 for (MapCIter i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
1126 isTile(i) ? NodeStruct(getTile(i)) : NodeStruct(*(
new ChildT(getChild(i))));
1133 template<
typename ChildT>
1134 template<
typename OtherChildType>
1139 typedef typename OtherRootT::ValueType OtherValueT;
1149 template<
typename ChildT>
1155 if (updateChildNodes) {
1158 for (MapIter iter=mTable.begin(); iter!=mTable.end(); ++iter) {
1159 ChildT *child = iter->second.child;
1161 child->resetBackground(mBackground, background);
1163 Tile& tile = getTile(iter);
1164 if (tile.active)
continue;
1166 tile.value = background;
1173 mBackground = background;
1176 template<
typename ChildT>
1183 template<
typename ChildT>
1190 template<
typename ChildT>
1198 template<
typename ChildT>
1203 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1204 if (this->isBackgroundTile(i)) ++count;
1210 template<
typename ChildT>
1214 std::set<Coord> keysToErase;
1215 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1216 if (this->isBackgroundTile(i)) keysToErase.insert(i->first);
1218 for (std::set<Coord>::iterator i = keysToErase.begin(), e = keysToErase.end(); i != e; ++i) {
1221 return keysToErase.size();
1228 template<
typename ChildT>
1232 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1233 keys.insert(i->first);
1238 template<
typename ChildT>
1239 inline typename RootNode<ChildT>::MapIter
1240 RootNode<ChildT>::findOrAddCoord(
const Coord& xyz)
1242 const Coord key = coordToKey(xyz);
1243 std::pair<MapIter, bool> result = mTable.insert(
1244 typename MapType::value_type(key, NodeStruct(Tile(mBackground,
false))));
1245 return result.first;
1249 template<
typename ChildT>
1253 const Coord key = coordToKey(xyz);
1254 std::pair<MapIter, bool> result = mTable.insert(
1255 typename MapType::value_type(key, NodeStruct(Tile(mBackground,
false))));
1256 return result.second;
1263 template<
typename ChildT>
1268 ChildT::getNodeLog2Dims(dims);
1272 template<
typename ChildT>
1276 return mTable.empty() ? Coord(0) : mTable.begin()->first;
1279 template<
typename ChildT>
1283 return mTable.empty() ? Coord(0) : mTable.rbegin()->first + Coord(ChildT::DIM - 1);
1287 template<
typename ChildT>
1291 bbox.min() = this->getMinIndex();
1292 bbox.max() = this->getMaxIndex();
1299 template<
typename ChildT>
1300 template<
typename OtherChildType>
1305 typedef typename OtherRootT::MapType OtherMapT;
1306 typedef typename OtherRootT::MapIter OtherIterT;
1307 typedef typename OtherRootT::MapCIter OtherCIterT;
1309 if (!hasSameConfiguration(other))
return false;
1312 OtherMapT copyOfOtherTable = other.mTable;
1315 for (MapCIter thisIter = mTable.begin(); thisIter != mTable.end(); ++thisIter) {
1316 if (this->isBackgroundTile(thisIter))
continue;
1319 OtherCIterT otherIter = other.findKey(thisIter->first);
1320 if (otherIter == other.mTable.end())
return false;
1323 if (isChild(thisIter)) {
1324 if (OtherRootT::isTile(otherIter))
return false;
1326 if (!getChild(thisIter).hasSameTopology(&OtherRootT::getChild(otherIter)))
return false;
1328 if (OtherRootT::isChild(otherIter))
return false;
1329 if (getTile(thisIter).active != OtherRootT::getTile(otherIter).active)
return false;
1336 copyOfOtherTable.erase(otherIter->first);
1339 for (OtherIterT i = copyOfOtherTable.begin(), e = copyOfOtherTable.end(); i != e; ++i) {
1346 template<
typename ChildT>
1347 template<
typename OtherChildType>
1351 std::vector<Index> thisDims, otherDims;
1354 return (thisDims == otherDims);
1358 template<
typename ChildT>
1359 template<
typename OtherChildType>
1363 std::vector<Index> thisDims, otherDims;
1366 if (thisDims != otherDims) {
1367 std::ostringstream ostr;
1368 ostr <<
"grids have incompatible configurations (" << thisDims[0];
1369 for (
size_t i = 1, N = thisDims.size(); i < N; ++i) ostr <<
" x " << thisDims[i];
1370 ostr <<
" vs. " << otherDims[0];
1371 for (
size_t i = 1, N = otherDims.size(); i < N; ++i) ostr <<
" x " << otherDims[i];
1378 template<
typename ChildT>
1379 template<
typename OtherChildType>
1383 typedef typename OtherChildType::ValueType OtherValueType;
1388 template<
typename ChildT>
1389 template<
typename OtherChildType>
1393 typedef typename OtherChildType::ValueType OtherValueType;
1395 std::ostringstream ostr;
1396 ostr <<
"values of type " << typeNameAsString<OtherValueType>()
1397 <<
" cannot be converted to type " << typeNameAsString<ValueType>();
1406 template<
typename ChildT>
1411 for (MapCIter iter=mTable.begin(); iter!=mTable.end(); ++iter) {
1412 if (
const ChildT *child = iter->second.child) {
1413 sum += child->memUsage();
1420 template<
typename ChildT>
1424 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1425 delete i->second.child;
1431 template<
typename ChildT>
1435 for (MapCIter iter=mTable.begin(); iter!=mTable.end(); ++iter) {
1436 if (
const ChildT *child = iter->second.child) {
1437 child->evalActiveBoundingBox(bbox, visitVoxels);
1438 }
else if (isTileOn(iter)) {
1439 bbox.expand(iter->first, ChildT::DIM);
1445 template<
typename ChildT>
1449 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1450 if (isChild(i)) ++sum;
1456 template<
typename ChildT>
1458 RootNode<ChildT>::getTileCount()
const
1461 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1462 if (isTile(i)) ++sum;
1468 template<
typename ChildT>
1470 RootNode<ChildT>::getActiveTileCount()
const
1473 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1474 if (isTileOn(i)) ++sum;
1480 template<
typename ChildT>
1482 RootNode<ChildT>::getInactiveTileCount()
const
1485 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1486 if (isTileOff(i)) ++sum;
1492 template<
typename ChildT>
1497 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1498 if (isChild(i)) sum += getChild(i).leafCount();
1504 template<
typename ChildT>
1509 if (ChildT::LEVEL != 0) {
1510 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1511 if (isChild(i)) sum += getChild(i).nonLeafCount();
1518 template<
typename ChildT>
1523 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1525 sum += getChild(i).onVoxelCount();
1526 }
else if (isTileOn(i)) {
1527 sum += ChildT::NUM_VOXELS;
1534 template<
typename ChildT>
1539 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1541 sum += getChild(i).offVoxelCount();
1542 }
else if (isTileOff(i) && !this->isBackgroundTile(i)) {
1543 sum += ChildT::NUM_VOXELS;
1550 template<
typename ChildT>
1555 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1556 if (isChild(i)) sum += getChild(i).onLeafVoxelCount();
1562 template<
typename ChildT>
1567 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1568 if (isChild(i)) sum += getChild(i).offLeafVoxelCount();
1573 template<
typename ChildT>
1578 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1580 sum += getChild(i).onTileCount();
1581 }
else if (isTileOn(i)) {
1591 template<
typename ChildT>
1595 MapCIter iter = this->findCoord(xyz);
1596 if (iter == mTable.end() || isTileOff(iter))
return false;
1597 return isTileOn(iter) ?
true : getChild(iter).isValueOn(xyz);
1600 template<
typename ChildT>
1604 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
1605 if (isChild(i) ? getChild(i).hasActiveTiles() : getTile(i).active)
return true;
1610 template<
typename ChildT>
1611 template<
typename AccessorT>
1615 MapCIter iter = this->findCoord(xyz);
1616 if (iter == mTable.end() || isTileOff(iter))
return false;
1617 if (isTileOn(iter))
return true;
1618 acc.insert(xyz, &getChild(iter));
1619 return getChild(iter).isValueOnAndCache(xyz, acc);
1623 template<
typename ChildT>
1624 inline const typename ChildT::ValueType&
1627 MapCIter iter = this->findCoord(xyz);
1628 return iter == mTable.end() ? mBackground
1629 : (isTile(iter) ? getTile(iter).value : getChild(iter).getValue(xyz));
1632 template<
typename ChildT>
1633 template<
typename AccessorT>
1634 inline const typename ChildT::ValueType&
1637 MapCIter iter = this->findCoord(xyz);
1638 if (iter == mTable.end())
return mBackground;
1639 if (isChild(iter)) {
1640 acc.insert(xyz, &getChild(iter));
1641 return getChild(iter).getValueAndCache(xyz, acc);
1643 return getTile(iter).value;
1647 template<
typename ChildT>
1651 MapCIter iter = this->findCoord(xyz);
1652 return iter == mTable.end() ? -1
1653 : (isTile(iter) ? 0 : int(LEVEL) - int(getChild(iter).getValueLevel(xyz)));
1656 template<
typename ChildT>
1657 template<
typename AccessorT>
1661 MapCIter iter = this->findCoord(xyz);
1662 if (iter == mTable.end())
return -1;
1663 if (isTile(iter))
return 0;
1664 acc.insert(xyz, &getChild(iter));
1665 return int(LEVEL) - int(getChild(iter).getValueLevelAndCache(xyz, acc));
1669 template<
typename ChildT>
1673 MapIter iter = this->findCoord(xyz);
1674 if (iter != mTable.end() && !isTileOff(iter)) {
1675 if (isTileOn(iter)) {
1676 setChild(iter, *
new ChildT(xyz, getTile(iter).value,
true));
1678 getChild(iter).setValueOff(xyz);
1683 template<
typename ChildT>
1687 ChildT* child = NULL;
1688 MapIter iter = this->findCoord(xyz);
1689 if (iter == mTable.end()) {
1691 child =
new ChildT(xyz, mBackground);
1692 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1696 }
else if (isChild(iter)) {
1697 child = &getChild(iter);
1698 }
else if (on != getTile(iter).active) {
1699 child =
new ChildT(xyz, getTile(iter).value, !on);
1700 setChild(iter, *child);
1702 if (child) child->setActiveState(xyz, on);
1705 template<
typename ChildT>
1706 template<
typename AccessorT>
1710 ChildT* child = NULL;
1711 MapIter iter = this->findCoord(xyz);
1712 if (iter == mTable.end()) {
1714 child =
new ChildT(xyz, mBackground);
1715 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1719 }
else if (isChild(iter)) {
1720 child = &getChild(iter);
1721 }
else if (on != getTile(iter).active) {
1722 child =
new ChildT(xyz, getTile(iter).value, !on);
1723 setChild(iter, *child);
1726 acc.insert(xyz, child);
1727 child->setActiveStateAndCache(xyz, on, acc);
1732 template<
typename ChildT>
1736 ChildT* child = NULL;
1737 MapIter iter = this->findCoord(xyz);
1738 if (iter == mTable.end()) {
1740 child =
new ChildT(xyz, mBackground);
1741 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1743 }
else if (isChild(iter)) {
1744 child = &getChild(iter);
1746 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1747 setChild(iter, *child);
1749 if (child) child->setValueOff(xyz, value);
1752 template<
typename ChildT>
1753 template<
typename AccessorT>
1757 ChildT* child = NULL;
1758 MapIter iter = this->findCoord(xyz);
1759 if (iter == mTable.end()) {
1761 child =
new ChildT(xyz, mBackground);
1762 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1764 }
else if (isChild(iter)) {
1765 child = &getChild(iter);
1767 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1768 setChild(iter, *child);
1771 acc.insert(xyz, child);
1772 child->setValueOffAndCache(xyz, value, acc);
1777 template<
typename ChildT>
1781 ChildT* child = NULL;
1782 MapIter iter = this->findCoord(xyz);
1783 if (iter == mTable.end()) {
1784 child =
new ChildT(xyz, mBackground);
1785 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1786 }
else if (isChild(iter)) {
1787 child = &getChild(iter);
1789 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1790 setChild(iter, *child);
1792 if (child) child->setValueOn(xyz, value);
1795 template<
typename ChildT>
1796 template<
typename AccessorT>
1800 ChildT* child = NULL;
1801 MapIter iter = this->findCoord(xyz);
1802 if (iter == mTable.end()) {
1803 child =
new ChildT(xyz, mBackground);
1804 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1805 }
else if (isChild(iter)) {
1806 child = &getChild(iter);
1808 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1809 setChild(iter, *child);
1812 acc.insert(xyz, child);
1813 child->setValueAndCache(xyz, value, acc);
1818 template<
typename ChildT>
1822 ChildT* child = NULL;
1823 MapIter iter = this->findCoord(xyz);
1824 if (iter == mTable.end()) {
1825 child =
new ChildT(xyz, mBackground);
1826 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1827 }
else if (isChild(iter)) {
1828 child = &getChild(iter);
1830 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1831 setChild(iter, *child);
1833 if (child) child->setValueOnly(xyz, value);
1836 template<
typename ChildT>
1837 template<
typename AccessorT>
1841 ChildT* child = NULL;
1842 MapIter iter = this->findCoord(xyz);
1843 if (iter == mTable.end()) {
1844 child =
new ChildT(xyz, mBackground);
1845 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1846 }
else if (isChild(iter)) {
1847 child = &getChild(iter);
1849 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1850 setChild(iter, *child);
1853 acc.insert(xyz, child);
1854 child->setValueOnlyAndCache(xyz, value, acc);
1859 template<
typename ChildT>
1860 template<
typename ModifyOp>
1864 ChildT* child = NULL;
1865 MapIter iter = this->findCoord(xyz);
1866 if (iter == mTable.end()) {
1867 child =
new ChildT(xyz, mBackground);
1868 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1869 }
else if (isChild(iter)) {
1870 child = &getChild(iter);
1874 bool createChild = isTileOff(iter);
1878 const ValueType& tileVal = getTile(iter).value;
1879 ValueType modifiedVal = tileVal;
1884 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1885 setChild(iter, *child);
1888 if (child) child->modifyValue(xyz, op);
1891 template<
typename ChildT>
1892 template<
typename ModifyOp,
typename AccessorT>
1896 ChildT* child = NULL;
1897 MapIter iter = this->findCoord(xyz);
1898 if (iter == mTable.end()) {
1899 child =
new ChildT(xyz, mBackground);
1900 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1901 }
else if (isChild(iter)) {
1902 child = &getChild(iter);
1906 bool createChild = isTileOff(iter);
1910 const ValueType& tileVal = getTile(iter).value;
1911 ValueType modifiedVal = tileVal;
1916 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
1917 setChild(iter, *child);
1921 acc.insert(xyz, child);
1922 child->modifyValueAndCache(xyz, op, acc);
1927 template<
typename ChildT>
1928 template<
typename ModifyOp>
1932 ChildT* child = NULL;
1933 MapIter iter = this->findCoord(xyz);
1934 if (iter == mTable.end()) {
1935 child =
new ChildT(xyz, mBackground);
1936 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1937 }
else if (isChild(iter)) {
1938 child = &getChild(iter);
1940 const Tile& tile = getTile(iter);
1941 bool modifiedState = tile.active;
1942 ValueType modifiedVal = tile.value;
1943 op(modifiedVal, modifiedState);
1947 child =
new ChildT(xyz, tile.value, tile.active);
1948 setChild(iter, *child);
1951 if (child) child->modifyValueAndActiveState(xyz, op);
1954 template<
typename ChildT>
1955 template<
typename ModifyOp,
typename AccessorT>
1958 const Coord& xyz,
const ModifyOp& op, AccessorT& acc)
1960 ChildT* child = NULL;
1961 MapIter iter = this->findCoord(xyz);
1962 if (iter == mTable.end()) {
1963 child =
new ChildT(xyz, mBackground);
1964 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
1965 }
else if (isChild(iter)) {
1966 child = &getChild(iter);
1968 const Tile& tile = getTile(iter);
1969 bool modifiedState = tile.active;
1970 ValueType modifiedVal = tile.value;
1971 op(modifiedVal, modifiedState);
1975 child =
new ChildT(xyz, tile.value, tile.active);
1976 setChild(iter, *child);
1980 acc.insert(xyz, child);
1981 child->modifyValueAndActiveStateAndCache(xyz, op, acc);
1986 template<
typename ChildT>
1990 MapCIter iter = this->findCoord(xyz);
1991 if (iter == mTable.end()) {
1992 value = mBackground;
1994 }
else if (isChild(iter)) {
1995 return getChild(iter).probeValue(xyz, value);
1997 value = getTile(iter).value;
1998 return isTileOn(iter);
2001 template<
typename ChildT>
2002 template<
typename AccessorT>
2006 MapCIter iter = this->findCoord(xyz);
2007 if (iter == mTable.end()) {
2008 value = mBackground;
2010 }
else if (isChild(iter)) {
2011 acc.insert(xyz, &getChild(iter));
2012 return getChild(iter).probeValueAndCache(xyz, value, acc);
2014 value = getTile(iter).value;
2015 return isTileOn(iter);
2022 template<
typename ChildT>
2026 if (bbox.empty())
return;
2029 for (
int x = bbox.min().x(); x <= bbox.max().x(); x = tileMax.x() + 1) {
2031 for (
int y = bbox.min().y(); y <= bbox.max().y(); y = tileMax.y() + 1) {
2033 for (
int z = bbox.min().z(); z <= bbox.max().z(); z = tileMax.z() + 1) {
2037 Coord tileMin = coordToKey(xyz);
2038 tileMax = tileMin.offsetBy(ChildT::DIM - 1);
2040 if (xyz != tileMin || Coord::lessThan(bbox.max(), tileMax)) {
2044 ChildT* child = NULL;
2045 MapIter iter = this->findKey(tileMin);
2046 if (iter == mTable.end()) {
2049 child =
new ChildT(xyz, mBackground);
2050 mTable[tileMin] = NodeStruct(*child);
2051 }
else if (isTile(iter)) {
2054 const Tile& tile = getTile(iter);
2055 child =
new ChildT(xyz, tile.value, tile.active);
2056 mTable[tileMin] = NodeStruct(*child);
2057 }
else if (isChild(iter)) {
2058 child = &getChild(iter);
2069 MapIter iter = this->findOrAddCoord(tileMin);
2070 setTile(iter, Tile(value, active));
2077 template<
typename ChildT>
2078 template<
typename DenseT>
2082 typedef typename DenseT::ValueType DenseValueType;
2084 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
2085 const Coord&
min = dense.bbox().min();
2087 for (Coord xyz = bbox.min(); xyz[0] <= bbox.max()[0]; xyz[0] = nodeBBox.max()[0] + 1) {
2088 for (xyz[1] = bbox.min()[1]; xyz[1] <= bbox.max()[1]; xyz[1] = nodeBBox.max()[1] + 1) {
2089 for (xyz[2] = bbox.min()[2]; xyz[2] <= bbox.max()[2]; xyz[2] = nodeBBox.max()[2] + 1) {
2092 nodeBBox = CoordBBox::createCube(coordToKey(xyz), ChildT::DIM);
2097 MapCIter iter = this->findKey(nodeBBox.min());
2098 if (iter != mTable.end() && isChild(iter)) {
2099 getChild(iter).copyToDense(sub, dense);
2101 const ValueType value = iter==mTable.end() ? mBackground : getTile(iter).value;
2102 sub.translate(-min);
2103 DenseValueType* a0 = dense.data() + zStride*sub.min()[2];
2104 for (
Int32 x=sub.min()[0], ex=sub.max()[0]+1; x<ex; ++x) {
2105 DenseValueType* a1 = a0 + x*xStride;
2106 for (
Int32 y=sub.min()[1], ey=sub.max()[1]+1; y<ey; ++y) {
2107 DenseValueType* a2 = a1 + y*yStride;
2108 for (
Int32 z=sub.min()[2], ez=sub.max()[2]+1; z<ez; ++z, a2 += zStride) {
2109 *a2 = DenseValueType(value);
2122 template<
typename ChildT>
2127 os.write(reinterpret_cast<const char*>(&mBackground),
sizeof(ValueType));
2130 os.write(reinterpret_cast<const char*>(&truncatedVal),
sizeof(ValueType));
2134 const Index numTiles = this->getTileCount(), numChildren = this->getChildCount();
2135 os.write(reinterpret_cast<const char*>(&numTiles),
sizeof(
Index));
2136 os.write(reinterpret_cast<const char*>(&numChildren),
sizeof(
Index));
2138 if (numTiles == 0 && numChildren == 0)
return false;
2141 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2142 if (isChild(i))
continue;
2143 os.write(reinterpret_cast<const char*>(i->first.asPointer()), 3 *
sizeof(
Int32));
2144 os.write(reinterpret_cast<const char*>(&getTile(i).value),
sizeof(ValueType));
2145 os.write(reinterpret_cast<const char*>(&getTile(i).active),
sizeof(
bool));
2148 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2149 if (isTile(i))
continue;
2150 os.write(reinterpret_cast<const char*>(i->first.asPointer()), 3 *
sizeof(
Int32));
2151 getChild(i).writeTopology(os, toHalf);
2158 template<
typename ChildT>
2170 is.read(reinterpret_cast<char*>(&mBackground),
sizeof(ValueType));
2172 is.read(reinterpret_cast<char*>(&inside),
sizeof(ValueType));
2177 Coord rangeMin, rangeMax;
2178 is.read(reinterpret_cast<char*>(rangeMin.asPointer()), 3 *
sizeof(
Int32));
2179 is.read(reinterpret_cast<char*>(rangeMax.asPointer()), 3 *
sizeof(
Int32));
2182 Index tableSize = 0, log2Dim[4] = { 0, 0, 0, 0 };
2184 for (
int i = 0; i < 3; ++i) {
2185 offset[i] = rangeMin[i] >> ChildT::TOTAL;
2186 rangeMin[i] = offset[i] << ChildT::TOTAL;
2188 tableSize += log2Dim[i];
2189 rangeMax[i] = (((1 << log2Dim[i]) + offset[i]) << ChildT::TOTAL) - 1;
2191 log2Dim[3] = log2Dim[1] + log2Dim[2];
2192 tableSize = 1U << tableSize;
2200 for (
Index i = 0; i < tableSize; ++i) {
2204 origin[0] = (n >> log2Dim[3]) + offset[0];
2205 n &= (1U << log2Dim[3]) - 1;
2206 origin[1] = (n >> log2Dim[2]) + offset[1];
2207 origin[2] = (n & ((1U << log2Dim[2]) - 1)) + offset[1];
2208 origin <<= ChildT::TOTAL;
2210 if (childMask.isOn(i)) {
2212 #ifdef OPENVDB_2_ABI_COMPATIBLE
2213 ChildT* child =
new ChildT(origin, mBackground);
2215 ChildT* child =
new ChildT(
PartialCreate(), origin, mBackground);
2217 child->readTopology(is);
2218 mTable[origin] = NodeStruct(*child);
2223 is.read(reinterpret_cast<char*>(&value),
sizeof(ValueType));
2225 mTable[origin] = NodeStruct(Tile(value, valueMask.
isOn(i)));
2234 is.read(reinterpret_cast<char*>(&mBackground),
sizeof(ValueType));
2237 Index numTiles = 0, numChildren = 0;
2238 is.read(reinterpret_cast<char*>(&numTiles),
sizeof(
Index));
2239 is.read(reinterpret_cast<char*>(&numChildren),
sizeof(
Index));
2241 if (numTiles == 0 && numChildren == 0)
return false;
2248 for (
Index n = 0; n < numTiles; ++n) {
2249 is.read(reinterpret_cast<char*>(vec), 3 *
sizeof(
Int32));
2250 is.read(reinterpret_cast<char*>(&value),
sizeof(ValueType));
2251 is.read(reinterpret_cast<char*>(&active),
sizeof(
bool));
2252 mTable[Coord(vec)] = NodeStruct(Tile(value, active));
2256 for (
Index n = 0; n < numChildren; ++n) {
2257 is.read(reinterpret_cast<char*>(vec), 3 *
sizeof(
Int32));
2259 #ifdef OPENVDB_2_ABI_COMPATIBLE
2260 ChildT* child =
new ChildT(origin, mBackground);
2262 ChildT* child =
new ChildT(
PartialCreate(), origin, mBackground);
2264 child->readTopology(is, fromHalf);
2265 mTable[Coord(vec)] = NodeStruct(*child);
2272 template<
typename ChildT>
2276 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2277 if (isChild(i)) getChild(i).writeBuffers(os, toHalf);
2282 template<
typename ChildT>
2286 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2287 if (isChild(i)) getChild(i).readBuffers(is, fromHalf);
2292 template<
typename ChildT>
2296 const Tile bgTile(mBackground,
false);
2298 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2304 ChildT& child = getChild(i);
2305 child.readBuffers(is, clipBBox, fromHalf);
2309 this->
clip(clipBBox);
2316 template<
typename ChildT>
2320 const Tile bgTile(mBackground,
false);
2324 MapType copyOfTable(mTable);
2325 for (MapIter i = copyOfTable.begin(), e = copyOfTable.end(); i != e; ++i) {
2326 const Coord& xyz = i->first;
2327 CoordBBox tileBBox(xyz, xyz.offsetBy(ChildT::DIM - 1));
2328 if (!clipBBox.hasOverlap(tileBBox)) {
2330 setTile(this->findCoord(xyz), bgTile);
2332 }
else if (!clipBBox.isInside(tileBBox)) {
2336 getChild(i).clip(clipBBox, mBackground);
2340 tileBBox.intersect(clipBBox);
2341 const Tile& origTile = getTile(i);
2342 setTile(this->findCoord(xyz), bgTile);
2343 this->fill(tileBBox, origTile.value, origTile.active);
2356 template<
typename ChildT>
2361 ValueType value = zeroVal<ValueType>();
2362 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2363 if (this->isTile(i))
continue;
2364 this->getChild(i).prune(tolerance);
2365 if (this->getChild(i).isConstant(value, state, tolerance)) {
2366 this->setTile(i, Tile(value, state));
2369 this->eraseBackgroundTiles();
2376 template<
typename ChildT>
2377 template<
typename NodeT>
2381 if ((NodeT::LEVEL == ChildT::LEVEL && !(boost::is_same<NodeT, ChildT>::value)) ||
2382 NodeT::LEVEL > ChildT::LEVEL)
return NULL;
2384 MapIter iter = this->findCoord(xyz);
2385 if (iter == mTable.end() || isTile(iter))
return NULL;
2386 return (boost::is_same<NodeT, ChildT>::value)
2387 ?
reinterpret_cast<NodeT*
>(&stealChild(iter, Tile(value, state)))
2388 : getChild(iter).template stealNode<NodeT>(xyz, value, state);
2396 template<
typename ChildT>
2400 if (leaf == NULL)
return;
2401 ChildT* child = NULL;
2402 const Coord& xyz = leaf->origin();
2403 MapIter iter = this->findCoord(xyz);
2404 if (iter == mTable.end()) {
2405 if (ChildT::LEVEL>0) {
2406 child =
new ChildT(xyz, mBackground,
false);
2408 child =
reinterpret_cast<ChildT*
>(leaf);
2410 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2411 }
else if (isChild(iter)) {
2412 if (ChildT::LEVEL>0) {
2413 child = &getChild(iter);
2415 child =
reinterpret_cast<ChildT*
>(leaf);
2416 setChild(iter, *child);
2419 if (ChildT::LEVEL>0) {
2420 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2422 child =
reinterpret_cast<ChildT*
>(leaf);
2424 setChild(iter, *child);
2426 child->addLeaf(leaf);
2430 template<
typename ChildT>
2431 template<
typename AccessorT>
2435 if (leaf == NULL)
return;
2436 ChildT* child = NULL;
2437 const Coord& xyz = leaf->origin();
2438 MapIter iter = this->findCoord(xyz);
2439 if (iter == mTable.end()) {
2440 if (ChildT::LEVEL>0) {
2441 child =
new ChildT(xyz, mBackground,
false);
2443 child =
reinterpret_cast<ChildT*
>(leaf);
2445 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2446 }
else if (isChild(iter)) {
2447 if (ChildT::LEVEL>0) {
2448 child = &getChild(iter);
2450 child =
reinterpret_cast<ChildT*
>(leaf);
2451 setChild(iter, *child);
2454 if (ChildT::LEVEL>0) {
2455 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2457 child =
reinterpret_cast<ChildT*
>(leaf);
2459 setChild(iter, *child);
2461 acc.insert(xyz, child);
2462 child->addLeafAndCache(leaf, acc);
2465 template<
typename ChildT>
2469 MapIter iter = this->findCoord(xyz);
2470 if (iter == mTable.end()) {
2471 mTable[this->coordToKey(xyz)] = NodeStruct(Tile(value, state));
2473 setTile(iter, Tile(value, state));
2477 template<
typename ChildT>
2480 const ValueType& value,
bool state)
2482 if (LEVEL >= level) {
2483 MapIter iter = this->findCoord(xyz);
2484 if (iter == mTable.end()) {
2485 if (LEVEL > level) {
2486 ChildT* child =
new ChildT(xyz, mBackground,
false);
2487 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2488 child->addTile(level, xyz, value, state);
2490 mTable[this->coordToKey(xyz)] = NodeStruct(Tile(value, state));
2492 }
else if (isChild(iter)) {
2493 if (LEVEL > level) {
2494 getChild(iter).addTile(level, xyz, value, state);
2496 setTile(iter, Tile(value, state));
2499 if (LEVEL > level) {
2500 ChildT* child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2501 setChild(iter, *child);
2502 child->addTile(level, xyz, value, state);
2504 setTile(iter, Tile(value, state));
2511 template<
typename ChildT>
2512 template<
typename AccessorT>
2515 bool state, AccessorT& acc)
2517 if (LEVEL >= level) {
2518 MapIter iter = this->findCoord(xyz);
2519 if (iter == mTable.end()) {
2520 if (LEVEL > level) {
2521 ChildT* child =
new ChildT(xyz, mBackground,
false);
2522 acc.insert(xyz, child);
2523 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2524 child->addTileAndCache(level, xyz, value, state, acc);
2526 mTable[this->coordToKey(xyz)] = NodeStruct(Tile(value, state));
2528 }
else if (isChild(iter)) {
2529 if (LEVEL > level) {
2530 ChildT* child = &getChild(iter);
2531 acc.insert(xyz, child);
2532 child->addTileAndCache(level, xyz, value, state, acc);
2534 setTile(iter, Tile(value, state));
2537 if (LEVEL > level) {
2538 ChildT* child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2539 acc.insert(xyz, child);
2540 setChild(iter, *child);
2541 child->addTileAndCache(level, xyz, value, state, acc);
2543 setTile(iter, Tile(value, state));
2553 template<
typename ChildT>
2554 inline typename ChildT::LeafNodeType*
2557 ChildT* child = NULL;
2558 MapIter iter = this->findCoord(xyz);
2559 if (iter == mTable.end()) {
2560 child =
new ChildT(xyz, mBackground,
false);
2561 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2562 }
else if (isChild(iter)) {
2563 child = &getChild(iter);
2565 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2566 setChild(iter, *child);
2568 return child->touchLeaf(xyz);
2572 template<
typename ChildT>
2573 template<
typename AccessorT>
2574 inline typename ChildT::LeafNodeType*
2577 ChildT* child = NULL;
2578 MapIter iter = this->findCoord(xyz);
2579 if (iter == mTable.end()) {
2580 child =
new ChildT(xyz, mBackground,
false);
2581 mTable[this->coordToKey(xyz)] = NodeStruct(*child);
2582 }
else if (isChild(iter)) {
2583 child = &getChild(iter);
2585 child =
new ChildT(xyz, getTile(iter).value, isTileOn(iter));
2586 setChild(iter, *child);
2588 acc.insert(xyz, child);
2589 return child->touchLeafAndCache(xyz, acc);
2596 template<
typename ChildT>
2597 template<
typename NodeT>
2601 if ((NodeT::LEVEL == ChildT::LEVEL && !(boost::is_same<NodeT, ChildT>::value)) ||
2602 NodeT::LEVEL > ChildT::LEVEL)
return NULL;
2604 MapIter iter = this->findCoord(xyz);
2605 if (iter == mTable.end() || isTile(iter))
return NULL;
2606 ChildT* child = &getChild(iter);
2607 return (boost::is_same<NodeT, ChildT>::value)
2608 ?
reinterpret_cast<NodeT*
>(child)
2609 : child->template probeNode<NodeT>(xyz);
2614 template<
typename ChildT>
2615 template<
typename NodeT>
2619 if ((NodeT::LEVEL == ChildT::LEVEL && !(boost::is_same<NodeT, ChildT>::value)) ||
2620 NodeT::LEVEL > ChildT::LEVEL)
return NULL;
2622 MapCIter iter = this->findCoord(xyz);
2623 if (iter == mTable.end() || isTile(iter))
return NULL;
2624 const ChildT* child = &getChild(iter);
2625 return (boost::is_same<NodeT, ChildT>::value)
2626 ?
reinterpret_cast<const NodeT*
>(child)
2627 : child->template probeConstNode<NodeT>(xyz);
2632 template<
typename ChildT>
2633 inline typename ChildT::LeafNodeType*
2636 return this->
template probeNode<LeafNodeType>(xyz);
2640 template<
typename ChildT>
2641 inline const typename ChildT::LeafNodeType*
2644 return this->
template probeConstNode<LeafNodeType>(xyz);
2648 template<
typename ChildT>
2649 template<
typename AccessorT>
2650 inline typename ChildT::LeafNodeType*
2653 return this->
template probeNodeAndCache<LeafNodeType>(xyz, acc);
2657 template<
typename ChildT>
2658 template<
typename AccessorT>
2659 inline const typename ChildT::LeafNodeType*
2662 return this->
template probeConstNodeAndCache<LeafNodeType>(xyz, acc);
2666 template<
typename ChildT>
2667 template<
typename AccessorT>
2668 inline const typename ChildT::LeafNodeType*
2671 return this->probeConstLeafAndCache(xyz, acc);
2675 template<
typename ChildT>
2676 template<
typename NodeT,
typename AccessorT>
2680 if ((NodeT::LEVEL == ChildT::LEVEL && !(boost::is_same<NodeT, ChildT>::value)) ||
2681 NodeT::LEVEL > ChildT::LEVEL)
return NULL;
2683 MapIter iter = this->findCoord(xyz);
2684 if (iter == mTable.end() || isTile(iter))
return NULL;
2685 ChildT* child = &getChild(iter);
2686 acc.insert(xyz, child);
2687 return (boost::is_same<NodeT, ChildT>::value)
2688 ?
reinterpret_cast<NodeT*
>(child)
2689 : child->template probeNodeAndCache<NodeT>(xyz, acc);
2694 template<
typename ChildT>
2695 template<
typename NodeT,
typename AccessorT>
2699 if ((NodeT::LEVEL == ChildT::LEVEL && !(boost::is_same<NodeT, ChildT>::value)) ||
2700 NodeT::LEVEL > ChildT::LEVEL)
return NULL;
2702 MapCIter iter = this->findCoord(xyz);
2703 if (iter == mTable.end() || isTile(iter))
return NULL;
2704 const ChildT* child = &getChild(iter);
2705 acc.insert(xyz, child);
2706 return (boost::is_same<NodeT, ChildT>::value)
2707 ?
reinterpret_cast<const NodeT*
>(child)
2708 : child->template probeConstNodeAndCache<NodeT>(xyz, acc);
2715 template<
typename ChildT>
2716 template<
typename ArrayT>
2720 typedef typename ArrayT::value_type NodePtr;
2721 BOOST_STATIC_ASSERT(boost::is_pointer<NodePtr>::value);
2722 typedef typename boost::remove_pointer<NodePtr>::type NodeType;
2723 typedef typename boost::remove_const<NodeType>::type NonConstNodeType;
2724 typedef typename boost::mpl::contains<NodeChainType, NonConstNodeType>::type result;
2725 BOOST_STATIC_ASSERT(result::value);
2726 typedef typename boost::mpl::if_<boost::is_const<NodeType>,
2727 const ChildT, ChildT>::type ArrayChildT;
2729 for (MapIter iter=mTable.begin(); iter!=mTable.end(); ++iter) {
2730 if (ChildT* child = iter->second.child) {
2732 if (boost::is_same<NodePtr, ArrayChildT*>::value) {
2733 array.push_back(reinterpret_cast<NodePtr>(iter->second.child));
2735 child->getNodes(array);
2742 template<
typename ChildT>
2743 template<
typename ArrayT>
2747 typedef typename ArrayT::value_type NodePtr;
2748 BOOST_STATIC_ASSERT(boost::is_pointer<NodePtr>::value);
2749 typedef typename boost::remove_pointer<NodePtr>::type NodeType;
2750 BOOST_STATIC_ASSERT(boost::is_const<NodeType>::value);
2751 typedef typename boost::remove_const<NodeType>::type NonConstNodeType;
2752 typedef typename boost::mpl::contains<NodeChainType, NonConstNodeType>::type result;
2753 BOOST_STATIC_ASSERT(result::value);
2755 for (MapCIter iter=mTable.begin(); iter!=mTable.end(); ++iter) {
2756 if (
const ChildNodeType *child = iter->second.child) {
2758 if (boost::is_same<NodePtr, const ChildT*>::value) {
2759 array.push_back(reinterpret_cast<NodePtr>(iter->second.child));
2761 child->getNodes(array);
2772 template<
typename ChildT>
2776 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2777 if (this->isTileOff(i))
continue;
2778 ChildT* child = i->second.child;
2780 child =
new ChildT(i->first, this->getTile(i).value,
true);
2781 i->second.child = child;
2783 child->voxelizeActiveTiles();
2791 template<
typename ChildT>
2792 template<MergePolicy Policy>
2802 for (MapIter i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
2803 MapIter j = mTable.find(i->first);
2804 if (other.isChild(i)) {
2805 if (j == mTable.end()) {
2806 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2807 child.resetBackground(other.mBackground, mBackground);
2808 mTable[i->first] = NodeStruct(child);
2809 }
else if (isTile(j)) {
2811 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2812 child.resetBackground(other.mBackground, mBackground);
2816 getChild(j).template merge<MERGE_ACTIVE_STATES>(getChild(i),
2817 other.mBackground, mBackground);
2819 }
else if (other.isTileOn(i)) {
2820 if (j == mTable.end()) {
2821 mTable[i->first] = i->second;
2822 }
else if (!isTileOn(j)) {
2824 setTile(j, Tile(other.getTile(i).value,
true));
2831 for (MapIter i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
2832 MapIter j = mTable.find(i->first);
2833 if (other.isChild(i)) {
2834 if (j == mTable.end()) {
2835 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2836 child.resetBackground(other.mBackground, mBackground);
2837 mTable[i->first] = NodeStruct(child);
2838 }
else if (isTile(j)) {
2839 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2840 child.resetBackground(other.mBackground, mBackground);
2843 getChild(j).template merge<MERGE_NODES>(
2844 getChild(i), other.mBackground, mBackground);
2851 for (MapIter i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
2852 MapIter j = mTable.find(i->first);
2853 if (other.isChild(i)) {
2854 if (j == mTable.end()) {
2856 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2857 child.resetBackground(other.mBackground, mBackground);
2858 mTable[i->first] = NodeStruct(child);
2859 }
else if (isTile(j)) {
2861 ChildNodeType& child = stealChild(i, Tile(other.mBackground,
false));
2862 child.resetBackground(other.mBackground, mBackground);
2863 const Tile tile = getTile(j);
2867 child.template merge<MERGE_ACTIVE_STATES_AND_NODES>(
2868 tile.value, tile.active);
2872 getChild(j).template merge<MERGE_ACTIVE_STATES_AND_NODES>(getChild(i),
2873 other.mBackground, mBackground);
2875 }
else if (other.isTileOn(i)) {
2876 if (j == mTable.end()) {
2878 mTable[i->first] = i->second;
2879 }
else if (isTileOff(j)) {
2881 setTile(j, Tile(other.getTile(i).value,
true));
2882 }
else if (isChild(j)) {
2884 const Tile& tile = getTile(i);
2885 getChild(j).template merge<MERGE_ACTIVE_STATES_AND_NODES>(
2886 tile.value, tile.active);
2903 template<
typename ChildT>
2904 template<
typename OtherChildType>
2909 typedef typename OtherRootT::MapCIter OtherCIterT;
2911 enforceSameConfiguration(other);
2913 for (OtherCIterT i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
2914 MapIter j = mTable.find(i->first);
2915 if (other.isChild(i)) {
2916 if (j == mTable.end()) {
2917 mTable[i->first] = NodeStruct(
2918 *(
new ChildT(other.getChild(i), mBackground,
TopologyCopy())));
2919 }
else if (this->isChild(j)) {
2920 this->getChild(j).topologyUnion(other.getChild(i));
2922 ChildT* child =
new ChildT(
2923 other.getChild(i), this->getTile(j).value,
TopologyCopy());
2924 if (this->isTileOn(j)) child->setValuesOn();
2925 this->setChild(j, *child);
2927 }
else if (other.isTileOn(i)) {
2928 if (j == mTable.end()) {
2929 mTable[i->first] = NodeStruct(Tile(mBackground,
true));
2930 }
else if (this->isChild(j)) {
2931 this->getChild(j).setValuesOn();
2932 }
else if (this->isTileOff(j)) {
2933 this->setTile(j, Tile(this->getTile(j).value,
true));
2939 template<
typename ChildT>
2940 template<
typename OtherChildType>
2945 typedef typename OtherRootT::MapCIter OtherCIterT;
2947 enforceSameConfiguration(other);
2949 std::set<Coord> tmp;
2950 for (MapIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
2951 OtherCIterT j = other.mTable.find(i->first);
2952 if (this->isChild(i)) {
2953 if (j == other.mTable.end() || other.isTileOff(j)) {
2954 tmp.insert(i->first);
2955 }
else if (other.isChild(j)) {
2956 this->getChild(i).topologyIntersection(other.getChild(j), mBackground);
2958 }
else if (this->isTileOn(i)) {
2959 if (j == other.mTable.end() || other.isTileOff(j)) {
2960 this->setTile(i, Tile(this->getTile(i).value,
false));
2961 }
else if (other.isChild(j)) {
2963 new ChildT(other.getChild(j), this->getTile(i).value,
TopologyCopy());
2964 this->setChild(i, *child);
2968 for (std::set<Coord>::iterator i = tmp.begin(), e = tmp.end(); i != e; ++i) {
2969 MapIter it = this->findCoord(*i);
2970 setTile(it, Tile());
2975 template<
typename ChildT>
2976 template<
typename OtherChildType>
2981 typedef typename OtherRootT::MapCIter OtherCIterT;
2983 enforceSameConfiguration(other);
2985 for (OtherCIterT i = other.mTable.begin(), e = other.mTable.end(); i != e; ++i) {
2986 MapIter j = mTable.find(i->first);
2987 if (other.isChild(i)) {
2988 if (j == mTable.end() || this->isTileOff(j)) {
2990 }
else if (this->isChild(j)) {
2991 this->getChild(j).topologyDifference(other.getChild(i), mBackground);
2992 }
else if (this->isTileOn(j)) {
2994 ChildT* child =
new ChildT(j->first, this->getTile(j).value,
true);
2995 child->topologyDifference(other.getChild(i), mBackground);
2996 this->setChild(j, *child);
2998 }
else if (other.isTileOn(i)) {
2999 if (j == mTable.end() || this->isTileOff(j)) {
3001 }
else if (this->isChild(j)) {
3004 }
else if (this->isTileOn(j)) {
3005 this->setTile(j, Tile(this->getTile(j).value,
false));
3014 template<
typename ChildT>
3015 template<
typename CombineOp>
3022 this->insertKeys(keys);
3023 other.insertKeys(keys);
3025 for (CoordSetCIter i = keys.begin(), e = keys.end(); i != e; ++i) {
3026 MapIter iter = findOrAddCoord(*i), otherIter = other.findOrAddCoord(*i);
3027 if (isTile(iter) && isTile(otherIter)) {
3030 op(args.
setARef(getTile(iter).value)
3031 .setAIsActive(isTileOn(iter))
3032 .setBRef(getTile(otherIter).value)
3033 .setBIsActive(isTileOn(otherIter)));
3036 }
else if (isChild(iter) && isTile(otherIter)) {
3038 ChildT& child = getChild(iter);
3039 child.combine(getTile(otherIter).value, isTileOn(otherIter), op);
3041 }
else if (isTile(iter) && isChild(otherIter)) {
3046 ChildT& child = getChild(otherIter);
3047 child.combine(getTile(iter).value, isTileOn(iter), swappedOp);
3050 setChild(iter, stealChild(otherIter, Tile()));
3054 ChildT &child = getChild(iter), &otherChild = getChild(otherIter);
3055 child.combine(otherChild, op);
3057 if (prune && isChild(iter)) getChild(iter).prune();
3061 op(args.
setARef(mBackground).setBRef(other.mBackground));
3062 mBackground = args.
result();
3074 template<
typename CombineOp,
typename RootT,
typename OtherRootT,
bool Compatible = false>
3077 static inline void combine2(RootT&
self,
const RootT&,
const OtherRootT& other1,
3082 self.enforceSameConfiguration(other1);
3083 self.enforceCompatibleValueTypes(other1);
3085 std::ostringstream ostr;
3086 ostr <<
"cannot combine a " <<
typeid(OtherRootT).name()
3087 <<
" into a " <<
typeid(RootT).name();
3093 template<
typename CombineOp,
typename RootT,
typename OtherRootT>
3096 static inline void combine2(RootT&
self,
const RootT& other0,
const OtherRootT& other1,
3097 CombineOp& op,
bool prune)
3099 self.doCombine2(other0, other1, op, prune);
3104 template<
typename ChildT>
3105 template<
typename CombineOp,
typename OtherRootNode>
3108 CombineOp& op,
bool prune)
3110 typedef typename OtherRootNode::ValueType OtherValueType;
3114 *
this, other0, other1, op, prune);
3118 template<
typename ChildT>
3119 template<
typename CombineOp,
typename OtherRootNode>
3122 CombineOp& op,
bool prune)
3124 enforceSameConfiguration(other1);
3126 typedef typename OtherRootNode::ValueType OtherValueT;
3127 typedef typename OtherRootNode::Tile OtherTileT;
3128 typedef typename OtherRootNode::NodeStruct OtherNodeStructT;
3129 typedef typename OtherRootNode::MapCIter OtherMapCIterT;
3134 other0.insertKeys(keys);
3135 other1.insertKeys(keys);
3137 const NodeStruct bg0(Tile(other0.mBackground,
false));
3138 const OtherNodeStructT bg1(OtherTileT(other1.mBackground,
false));
3140 for (CoordSetCIter i = keys.begin(), e = keys.end(); i != e; ++i) {
3141 MapIter thisIter = this->findOrAddCoord(*i);
3142 MapCIter iter0 = other0.findKey(*i);
3143 OtherMapCIterT iter1 = other1.findKey(*i);
3144 const NodeStruct& ns0 = (iter0 != other0.mTable.end()) ? iter0->second : bg0;
3145 const OtherNodeStructT& ns1 = (iter1 != other1.mTable.end()) ? iter1->second : bg1;
3146 if (ns0.isTile() && ns1.isTile()) {
3149 op(args.
setARef(ns0.tile.value)
3150 .setAIsActive(ns0.isTileOn())
3151 .setBRef(ns1.tile.value)
3152 .setBIsActive(ns1.isTileOn()));
3155 if (!isChild(thisIter)) {
3157 const Coord& childOrigin =
3158 ns0.isChild() ? ns0.child->origin() : ns1.child->origin();
3159 setChild(thisIter, *(
new ChildT(childOrigin, getTile(thisIter).value)));
3161 ChildT& child = getChild(thisIter);
3166 child.combine2(ns0.tile.value, *ns1.child, ns0.isTileOn(), op);
3167 }
else if (ns1.isTile()) {
3170 child.combine2(*ns0.child, ns1.tile.value, ns1.isTileOn(), op);
3174 child.combine2(*ns0.child, *ns1.child, op);
3177 if (prune && isChild(thisIter)) getChild(thisIter).prune();
3181 op(args.
setARef(other0.mBackground).setBRef(other1.mBackground));
3182 mBackground = args.
result();
3189 template<
typename ChildT>
3190 template<
typename BBoxOp>
3194 const bool descent = op.template descent<LEVEL>();
3195 for (MapCIter i = mTable.begin(), e = mTable.end(); i != e; ++i) {
3196 if (this->isTileOff(i))
continue;
3197 if (this->isChild(i) && descent) {
3198 this->getChild(i).visitActiveBBox(op);
3201 op.operator()<LEVEL>(CoordBBox::createCube(i->first, ChildT::DIM));
3203 op.template operator()<LEVEL>(CoordBBox::createCube(i->first, ChildT::DIM));
3210 template<
typename ChildT>
3211 template<
typename VisitorOp>
3215 doVisit<RootNode, VisitorOp, ChildAllIter>(*
this, op);
3219 template<
typename ChildT>
3220 template<
typename VisitorOp>
3224 doVisit<const RootNode, VisitorOp, ChildAllCIter>(*
this, op);
3228 template<
typename ChildT>
3229 template<
typename RootNodeT,
typename VisitorOp,
typename ChildAllIterT>
3233 typename RootNodeT::ValueType val;
3234 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
3235 if (op(iter))
continue;
3236 if (
typename ChildAllIterT::ChildNodeType* child = iter.probeChild(val)) {
3246 template<
typename ChildT>
3247 template<
typename OtherRootNodeType,
typename VisitorOp>
3251 doVisit2<
RootNode, OtherRootNodeType, VisitorOp, ChildAllIter,
3252 typename OtherRootNodeType::ChildAllIter>(*
this, other, op);
3256 template<
typename ChildT>
3257 template<
typename OtherRootNodeType,
typename VisitorOp>
3261 doVisit2<
const RootNode, OtherRootNodeType, VisitorOp, ChildAllCIter,
3262 typename OtherRootNodeType::ChildAllCIter>(*
this, other, op);
3266 template<
typename ChildT>
3269 typename OtherRootNodeT,
3271 typename ChildAllIterT,
3272 typename OtherChildAllIterT>
3276 enforceSameConfiguration(other);
3278 typename RootNodeT::ValueType val;
3279 typename OtherRootNodeT::ValueType otherVal;
3284 RootNodeT copyOfSelf(
self.mBackground);
3285 copyOfSelf.mTable =
self.mTable;
3286 OtherRootNodeT copyOfOther(other.mBackground);
3287 copyOfOther.mTable = other.mTable;
3291 self.insertKeys(keys);
3292 other.insertKeys(keys);
3293 for (CoordSetCIter i = keys.begin(), e = keys.end(); i != e; ++i) {
3294 copyOfSelf.findOrAddCoord(*i);
3295 copyOfOther.findOrAddCoord(*i);
3298 ChildAllIterT iter = copyOfSelf.beginChildAll();
3299 OtherChildAllIterT otherIter = copyOfOther.beginChildAll();
3301 for ( ; iter && otherIter; ++iter, ++otherIter)
3303 const size_t skipBranch =
static_cast<size_t>(op(iter, otherIter));
3305 typename ChildAllIterT::ChildNodeType* child =
3306 (skipBranch & 1U) ? NULL : iter.probeChild(val);
3307 typename OtherChildAllIterT::ChildNodeType* otherChild =
3308 (skipBranch & 2U) ? NULL : otherIter.probeChild(otherVal);
3310 if (child != NULL && otherChild != NULL) {
3311 child->visit2Node(*otherChild, op);
3312 }
else if (child != NULL) {
3313 child->visit2(otherIter, op);
3314 }
else if (otherChild != NULL) {
3315 otherChild->visit2(iter, op,
true);
3320 copyOfSelf.eraseBackgroundTiles();
3321 copyOfOther.eraseBackgroundTiles();
3325 self.resetTable(copyOfSelf.mTable);
3326 other.resetTable(copyOfOther.mTable);
3333 #endif // OPENVDB_TREE_ROOTNODE_HAS_BEEN_INCLUDED
static void copyWithValueConversion(RootT &self, const OtherRootT &other)
Definition: RootNode.h:1060
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: RootNode.h:1862
bool hasSameTopology(const RootNode< OtherChildType > &other) const
Return true if the given tree has the same node and active value topology as this tree (but possibly ...
Definition: RootNode.h:1302
bool isValueOn(const Coord &xyz) const
Definition: RootNode.h:1593
T truncateRealToHalf(const T &val)
Return the given value truncated to 16-bit float precision.
Definition: Compression.h:125
void addLeaf(LeafNodeType *leaf)
Add the given leaf node to this tree, creating a new branch if necessary. If a leaf node with the sam...
Definition: RootNode.h:2398
void visit2(OtherRootNodeType &other, VisitorOp &)
Definition: RootNode.h:3249
const ValueType & getValue(const Coord &xyz) const
Definition: RootNode.h:1625
ChildOffCIter beginChildOff() const
Definition: RootNode.h:412
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:497
Index getHeight() const
Definition: RootNode.h:489
RootNode(const RootNode &other)
Definition: RootNode.h:110
LeafNodeType * touchLeafAndCache(const Coord &xyz, AccessorT &acc)
Same as touchLeaf() but, if necessary, update the given accessor with pointers to the nodes along the...
ValueAllCIter cbeginValueAll() const
Definition: RootNode.h:420
void clip(const CoordBBox &)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: RootNode.h:2318
Index getDepth() const
Definition: RootNode.h:490
NodeChain< RootNode, LEVEL >::Type NodeChainType
NodeChainType is a list of this tree's node types, from LeafNodeType to RootNode. ...
Definition: RootNode.h:85
size_t eraseBackgroundTiles()
Remove all background tiles.
Definition: RootNode.h:1212
ValueOnCIter cbeginValueOn() const
Definition: RootNode.h:418
ValueIter< const RootNode, MapCIter, ValueOffPred, const ValueType > ValueOffCIter
Definition: RootNode.h:403
boost::mpl::vector< typename HeadT::ChildNodeType, HeadT >::type Type
Definition: RootNode.h:967
uint64_t Index64
Definition: Types.h:58
static void combine2(RootT &self, const RootT &other0, const OtherRootT &other1, CombineOp &op, bool prune)
Definition: RootNode.h:3096
OPENVDB_API void setGridBackgroundValuePtr(std::ios_base &, const void *background)
Specify (a pointer to) the background value of the grid currently being read from or written to the g...
ChildAllIter beginChildAll()
Definition: RootNode.h:416
Definition: RootNode.h:71
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: RootNode.h:1265
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
ValueOffCIter beginValueOff() const
Definition: RootNode.h:422
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition: RootNode.h:2718
size_t numBackgroundTiles() const
Return the number of background tiles.
Definition: RootNode.h:1200
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Definition: RootNode.h:70
void setValueAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: RootNode.h:1798
void readBuffers(std::istream &, bool fromHalf=false)
Definition: RootNode.h:2284
bool resultIsActive() const
Definition: Types.h:358
ValueIter< const RootNode, MapCIter, ChildOffPred, ValueType > ChildOffCIter
Definition: RootNode.h:396
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
bool readTopology(std::istream &, bool fromHalf=false)
Definition: RootNode.h:2160
void setValueOn(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: RootNode.h:1779
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
ValueOffCIter cbeginValueOff() const
Definition: RootNode.h:419
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:347
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of all voxels, both active and inactive, that intersect a given bou...
Definition: RootNode.h:2080
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return NULL.
Definition: RootNode.h:2642
static CoordBBox getNodeBoundingBox()
Return the bounding box of this RootNode, i.e., an infinite bounding box.
Definition: RootNode.h:439
void voxelizeActiveTiles()
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition: RootNode.h:2774
void addTile(const Coord &xyz, const ValueType &value, bool state)
Add a tile containing voxel (x, y, z) at the root level, deleting the existing branch if necessary...
Definition: RootNode.h:2467
ValueIter< RootNode, MapIter, ChildOffPred, const ValueType > ChildOffIter
Definition: RootNode.h:395
int32_t Int32
Definition: Types.h:61
ChildAllCIter beginChildAll() const
Definition: RootNode.h:413
ChildType::ValueType ValueType
Definition: RootNode.h:80
void prune(const ValueType &tolerance=zeroVal< ValueType >())
Reduce the memory footprint of this tree by replacing with tiles any nodes whose values are all the s...
Definition: RootNode.h:2358
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:151
RootNode & operator=(const RootNode &other)
Copy a root node of the same type as this node.
Definition: RootNode.h:1116
static void combine2(RootT &self, const RootT &, const OtherRootT &other1, CombineOp &, bool)
Definition: RootNode.h:3077
ChildIter< RootNode, MapIter, ChildOnPred, ChildType > ChildOnIter
Definition: RootNode.h:393
int getValueDepthAndCache(const Coord &xyz, AccessorT &) const
Definition: RootNode.h:1659
void topologyDifference(const RootNode< OtherChildType > &other)
Difference this tree's set of active values with the active values of the other tree, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this tree and inactive in the other tree.
Definition: RootNode.h:2978
ChildOnCIter cbeginChildOn() const
Definition: RootNode.h:408
ChildOnIter beginChildOn()
Definition: RootNode.h:414
ChildType::LeafNodeType LeafNodeType
Definition: RootNode.h:79
ChildOffIter beginChildOff()
Definition: RootNode.h:415
void combine2(const RootNode &other0, const OtherRootNode &other1, CombineOp &op, bool prune=false)
Definition: RootNode.h:3107
NodeT * probeNodeAndCache(const Coord &xyz, AccessorT &acc)
Same as probeNode() but, if necessary, update the given accessor with pointers to the nodes along the...
Definition: RootNode.h:2678
int getValueDepth(const Coord &xyz) const
Return the tree depth (0 = root) at which the value of voxel (x, y, z) resides.
Definition: RootNode.h:1649
Index getWidth() const
Definition: RootNode.h:488
NodeT * stealNode(const Coord &xyz, const ValueType &value, bool state)
Return a pointer to the node of type NodeT that contains voxel (x, y, z) and replace it with a tile o...
Definition: RootNode.h:2379
~RootNode()
Definition: RootNode.h:158
bool probeValue(const Coord &xyz, ValueType &value) const
Definition: RootNode.h:1988
static bool hasSameConfiguration(const RootNode< OtherChildType > &other)
Return false if the other node's dimensions don't match this node's.
Definition: RootNode.h:1349
NodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: RootNode.h:960
bool isBackgroundTile(const Tile &) const
Return true if the given tile is inactive and has the background value.
Definition: RootNode.h:1178
NodeChain::Type is a boost::mpl::vector that lists the types of th...
Definition: RootNode.h:68
DenseIter< RootNode, MapIter, ChildType, ValueType > ChildAllIter
Definition: RootNode.h:397
ValueConverter::Type is the type of a RootNode having the same child hierarchy as this node but a ...
Definition: RootNode.h:91
#define OPENVDB_VERSION_NAME
Definition: version.h:43
ChildOnCIter beginChildOn() const
Definition: RootNode.h:411
ValueAllIter beginValueAll()
Definition: RootNode.h:426
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
SameConfiguration::value is true if and only if OtherNodeType is the type of a RootNod...
Definition: RootNode.h:99
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: RootNode.h:1671
void combine(RootNode &other, CombineOp &, bool prune=false)
Definition: RootNode.h:3017
Index32 Index
Definition: Types.h:59
Index32 leafCount() const
Definition: RootNode.h:1494
DenseIter< const RootNode, MapCIter, const ChildType, const ValueType > ChildAllCIter
Definition: RootNode.h:398
Definition: Exceptions.h:87
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given box to a constant value, if necessary subdividing tiles that intersect ...
Definition: RootNode.h:2024
ValueOnIter beginValueOn()
Definition: RootNode.h:424
bool empty() const
Return true if this node's table is either empty or contains only background tiles.
Definition: RootNode.h:474
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:309
Coord getMinIndex() const
Return the smallest index of the current tree.
Definition: RootNode.h:1274
LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc)
Same as probeLeaf() but, if necessary, update the given accessor with pointers to the nodes along the...
void addLeafAndCache(LeafNodeType *leaf, AccessorT &)
Same as addLeaf() but, if necessary, update the given accessor with pointers to the nodes along the p...
Definition: RootNode.h:2433
Index64 offVoxelCount() const
Definition: RootNode.h:1536
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Definition: RootNode.h:1708
void topologyIntersection(const RootNode< OtherChildType > &other)
Intersects this tree's set of active values with the active values of the other tree, whose ValueType may be different.
Definition: RootNode.h:2942
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: RootNode.h:1894
ValueIter< RootNode, MapIter, ValueAllPred, ValueType > ValueAllIter
Definition: RootNode.h:404
Definition: Exceptions.h:39
Index64 onVoxelCount() const
Definition: RootNode.h:1520
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: RootNode.h:1930
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: RootNode.h:1755
ChildOffCIter cbeginChildOff() const
Definition: RootNode.h:409
const ValueType & background() const
Return this node's background value.
Definition: RootNode.h:456
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
RootNode()
Construct a new tree with a background value of 0.
Definition: RootNode.h:994
ValueIter< const RootNode, MapCIter, ValueOnPred, const ValueType > ValueOnCIter
Definition: RootNode.h:401
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
NodeT * probeNode(const Coord &xyz)
Return a pointer to the node that contains voxel (x, y, z). If no such node exists, return NULL.
Definition: RootNode.h:2599
void clear()
Definition: RootNode.h:471
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Expand the specified bbox so it includes the active tiles of this root node as well as all the active...
Definition: RootNode.h:1433
void load(std::istream &is)
Definition: NodeMasks.h:1235
LeafNodeType * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, create one that preserves the values and active states of all voxels.
Definition: RootNode.h:2555
const AValueType & result() const
Get the output value.
Definition: Types.h:339
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return NULL.
Definition: RootNode.h:2634
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:107
ChildAllCIter cbeginChildAll() const
Definition: RootNode.h:410
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: RootNode.h:1820
ValueAllCIter beginValueAll() const
Definition: RootNode.h:423
ChildIter< const RootNode, MapCIter, ChildOnPred, const ChildType > ChildOnCIter
Definition: RootNode.h:394
Definition: RootNode.h:69
RootNode(const RootNode< OtherChildType > &other)
Construct a new tree that reproduces the topology and active states of a tree of a different ValueTyp...
Definition: RootNode.h:119
const NodeT * probeConstNode(const Coord &xyz) const
Return a pointer to the node that contains voxel (x, y, z). If no such node exists, return NULL.
Definition: RootNode.h:2617
Index64 onTileCount() const
Definition: RootNode.h:1575
Index getTableSize() const
Return the number of entries in this node's table.
Definition: RootNode.h:486
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
bool hasActiveTiles() const
Definition: RootNode.h:1602
static void copyWithValueConversion(RootT &self, const OtherRootT &other)
Definition: RootNode.h:1078
void writeBuffers(std::ostream &, bool toHalf=false) const
Definition: RootNode.h:2274
Index64 onLeafVoxelCount() const
Definition: RootNode.h:1552
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: RootNode.h:1685
void topologyUnion(const RootNode< OtherChildType > &other)
Union this tree's set of active values with the active values of the other tree, whose ValueType may ...
Definition: RootNode.h:2906
static Index getLevel()
Definition: RootNode.h:481
Index64 offLeafVoxelCount() const
Definition: RootNode.h:1564
boost::mpl::push_back< SubtreeT, HeadT >::type Type
Definition: RootNode.h:961
bool expand(const Coord &xyz)
Expand this node's table so that (x, y, z) is included in the index range.
Definition: RootNode.h:1251
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:391
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Definition: RootNode.h:1613
ValueOffIter beginValueOff()
Definition: RootNode.h:425
CanConvertType::value is true if a value of type ToType can be constructed from a v...
Definition: Types.h:184
ValueIter< const RootNode, MapCIter, ValueAllPred, const ValueType > ValueAllCIter
Definition: RootNode.h:405
ValueOnCIter beginValueOn() const
Definition: RootNode.h:421
bool probeValueAndCache(const Coord &xyz, ValueType &value, AccessorT &) const
Definition: RootNode.h:2004
ValueIter< RootNode, MapIter, ValueOnPred, ValueType > ValueOnIter
Definition: RootNode.h:400
uint32_t Index32
Definition: Types.h:57
ChildType ChildNodeType
Definition: RootNode.h:78
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: RootNode.h:75
static bool hasCompatibleValueType(const RootNode< OtherChildType > &other)
Definition: RootNode.h:1381
RootNode< typename ChildType::template ValueConverter< OtherValueType >::Type > Type
Definition: RootNode.h:92
Index32 nonLeafCount() const
Definition: RootNode.h:1506
void visit(VisitorOp &)
Definition: RootNode.h:3213
void getIndexRange(CoordBBox &bbox) const
Return the current index range. Both min and max are inclusive.
Definition: RootNode.h:1289
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:85
const NodeT * probeConstNodeAndCache(const Coord &xyz, AccessorT &acc) const
Same as probeNode() but, if necessary, update the given accessor with pointers to the nodes along the...
Definition: RootNode.h:2697
static Index getChildDim()
Definition: RootNode.h:483
void setBackground(const ValueType &value, bool updateChildNodes)
Change inactive tiles or voxels with a value equal to +/- the old background to the specified value (...
Definition: RootNode.h:1151
Index64 memUsage() const
Return the total amount of memory in bytes occupied by this node and its children.
Definition: RootNode.h:1408
void addTileAndCache(Index level, const Coord &xyz, const ValueType &, bool state, AccessorT &)
Same as addTile() but, if necessary, update the given accessor with pointers to the nodes along the p...
Definition: RootNode.h:2514
void merge(RootNode &other)
Efficiently merge another tree into this tree using one of several schemes.
Definition: RootNode.h:2794
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: RootNode.h:1957
Coord getMaxIndex() const
Return the largest index of the current tree.
Definition: RootNode.h:1281
const LeafNodeType * probeConstLeafAndCache(const Coord &xyz, AccessorT &acc) const
Same as probeLeaf() but, if necessary, update the given accessor with pointers to the nodes along the...
bool isOn(Index32 i) const
Definition: NodeMasks.h:1194
Definition: version.h:100
void visitActiveBBox(BBoxOp &) const
Call the templated functor BBoxOp with bounding box information for all active tiles and leaf nodes i...
Definition: RootNode.h:3192
ValueIter< RootNode, MapIter, ValueOffPred, ValueType > ValueOffIter
Definition: RootNode.h:402
bool writeTopology(std::ostream &, bool toHalf=false) const
Definition: RootNode.h:2124
Definition: NodeMasks.h:928
void setValueOnlyAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: RootNode.h:1839