58 #ifndef OPENVDB_TREE_VALUEACCESSOR_HAS_BEEN_INCLUDED
59 #define OPENVDB_TREE_VALUEACCESSOR_HAS_BEEN_INCLUDED
61 #include <boost/mpl/front.hpp>
62 #include <boost/mpl/pop_front.hpp>
63 #include <boost/mpl/push_back.hpp>
64 #include <boost/mpl/size.hpp>
65 #include <boost/mpl/at.hpp>
66 #include <boost/mpl/equal_to.hpp>
67 #include <boost/mpl/comparison.hpp>
68 #include <boost/mpl/vector.hpp>
69 #include <boost/mpl/assert.hpp>
70 #include <boost/mpl/erase.hpp>
71 #include <boost/mpl/find.hpp>
72 #include <boost/static_assert.hpp>
73 #include <boost/type_traits/is_const.hpp>
74 #include <tbb/null_mutex.h>
75 #include <tbb/spin_mutex.h>
76 #include <openvdb/version.h>
77 #include <openvdb/Types.h>
87 template<
typename TreeType, Index L0 = 0, Index L1 = 1>
class ValueAccessor2;
88 template<
typename TreeType, Index L0 = 0, Index L1 = 1, Index L2 = 2>
class ValueAccessor3;
89 template<
typename TreeCacheT,
typename NodeVecT,
bool AtRoot>
class CacheItem;
101 template<
typename TreeType>
105 static const bool IsConstTree = boost::is_const<TreeType>::value;
117 TreeType&
tree()
const { assert(mTree);
return *mTree; }
121 if (mTree) mTree->attachAccessor(*
this);
126 if (&other !=
this) {
127 if (mTree) mTree->releaseAccessor(*
this);
129 if (mTree) mTree->attachAccessor(*
this);
134 virtual void clear() = 0;
138 template<
typename>
friend class Tree;
170 template<
typename _TreeType,
171 Index CacheLevels = _TreeType::DEPTH-1,
172 typename MutexType = tbb::null_mutex>
176 BOOST_STATIC_ASSERT(CacheLevels < _TreeType::DEPTH);
183 typedef typename MutexType::scoped_lock
LockT;
184 using BaseT::IsConstTree;
188 mCache.insert(Coord(), &tree.root());
195 if (&other !=
this) {
196 this->BaseT::operator=(other);
197 mCache.copy(*
this, other.mCache);
207 bool isCached(
const Coord& xyz)
const { LockT lock(mMutex);
return mCache.isCached(xyz); }
213 return mCache.getValue(xyz);
217 bool isValueOn(
const Coord& xyz)
const { LockT lock(mMutex);
return mCache.isValueOn(xyz); }
223 return mCache.probeValue(xyz,value);
232 return mCache.getValueDepth(xyz);
237 bool isVoxel(
const Coord& xyz)
const { LockT lock(mMutex);
return mCache.isVoxel(xyz); }
240 void setValue(
const Coord& xyz,
const ValueType& value)
244 mCache.setValue(xyz, value);
246 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
253 mCache.setValueOnly(xyz, value);
261 mCache.newSetValue(xyz, value);
268 mCache.setValueOff(xyz, value);
274 template<
typename ModifyOp>
278 mCache.modifyValue(xyz, op);
283 template<
typename ModifyOp>
287 mCache.modifyValueAndActiveState(xyz, op);
294 mCache.setActiveState(xyz, on);
297 void setValueOn(
const Coord& xyz) { this->setActiveState(xyz,
true); }
299 void setValueOff(
const Coord& xyz) { this->setActiveState(xyz,
false); }
302 template<
typename NodeType>
306 NodeType* node = NULL;
307 mCache.getNode(node);
313 template<
typename NodeType>
317 mCache.insert(xyz, &node);
323 template<
typename NodeType>
324 void eraseNode() { LockT lock(mMutex); NodeType* node = NULL; mCache.erase(node); }
331 mCache.addLeaf(leaf);
336 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
339 mCache.addTile(level, xyz, value, state);
350 return mCache.touchLeaf(xyz);
354 template<
typename NodeT>
360 return mCache.template probeNode<NodeT>(xyz);
362 template<
typename NodeT>
366 return mCache.template probeConstNode<NodeT>(xyz);
368 template<
typename NodeT>
371 return this->
template probeConstNode<NodeT>(xyz);
376 LeafNodeT* probeLeaf(
const Coord& xyz)
381 return mCache.probeLeaf(xyz);
386 return mCache.probeConstLeaf(xyz);
388 const LeafNodeT*
probeLeaf(
const Coord& xyz)
const {
return this->probeConstLeaf(xyz); }
396 if (this->mTree) mCache.insert(Coord(), &(this->mTree->root()));
405 template<
typename>
friend class Tree;
409 virtual void release()
412 this->BaseT::release();
420 template<
typename NodeType>
421 void insert(
const Coord& xyz, NodeType* node) { mCache.insert(xyz, node); }
424 typedef typename RootNodeT::NodeChainType InvTreeT;
426 typedef typename boost::mpl::begin<InvTreeT>::type BeginT;
427 typedef typename boost::mpl::advance<BeginT,boost::mpl::int_<CacheLevels> >::type FirstT;
428 typedef typename boost::mpl::find<InvTreeT, RootNodeT>::type LastT;
429 typedef typename boost::mpl::erase<InvTreeT,FirstT,LastT>::type SubtreeT;
430 typedef CacheItem<ValueAccessor, SubtreeT, boost::mpl::size<SubtreeT>::value==1> CacheItemT;
433 mutable CacheItemT mCache;
434 mutable MutexType mMutex;
442 template<
typename TreeType>
453 template<
typename TreeType>
464 template<
typename TreeType>
475 template<
typename TreeType>
496 template<
typename TreeType>
515 template<
typename TreeCacheT,
typename NodeVecT,
bool AtRoot>
519 typedef typename boost::mpl::front<NodeVecT>::type
NodeType;
526 mHash(CoordLimits::
max()),
538 mNext(parent, other.mNext)
547 mNext.copy(parent, other.mNext);
554 return (this->isHashed(xyz) || mNext.isCached(xyz));
558 void insert(
const Coord& xyz,
const NodeType* node)
560 mHash = (node != NULL) ? xyz & ~(NodeType::DIM-1) :
Coord::max();
564 template<
typename OtherNodeType>
565 void insert(
const Coord& xyz,
const OtherNodeType* node) { mNext.insert(xyz, node); }
570 template<
typename OtherNodeType>
571 void erase(
const OtherNodeType* node) { mNext.erase(node); }
577 void getNode(
const NodeType*& node)
const { node = mNode; }
578 void getNode(
const NodeType*& node) { node = mNode; }
583 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
584 node =
const_cast<NodeType*
>(mNode);
587 template<
typename OtherNodeType>
588 void getNode(OtherNodeType*& node) { mNext.getNode(node); }
593 if (this->isHashed(xyz)) {
595 return mNode->getValueAndCache(xyz, *mParent);
597 return mNext.getValue(xyz);
602 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
603 if (NodeType::LEVEL == 0)
return;
604 if (this->isHashed(leaf->origin())) {
606 return const_cast<NodeType*
>(mNode)->addLeafAndCache(leaf, *mParent);
611 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
613 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
614 if (NodeType::LEVEL < level)
return;
615 if (this->isHashed(xyz)) {
617 return const_cast<NodeType*
>(mNode)->addTileAndCache(
618 level, xyz, value, state, *mParent);
620 mNext.addTile(level, xyz, value, state);
625 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
626 if (this->isHashed(xyz)) {
628 return const_cast<NodeType*
>(mNode)->touchLeafAndCache(xyz, *mParent);
630 return mNext.touchLeaf(xyz);
635 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
636 if (this->isHashed(xyz)) {
638 return const_cast<NodeType*
>(mNode)->probeLeafAndCache(xyz, *mParent);
640 return mNext.probeLeaf(xyz);
645 if (this->isHashed(xyz)) {
647 return mNode->probeConstLeafAndCache(xyz, *mParent);
649 return mNext.probeConstLeaf(xyz);
652 template<
typename NodeT>
655 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
657 if (this->isHashed(xyz)) {
658 if ((boost::is_same<NodeT, NodeType>::value)) {
660 return reinterpret_cast<NodeT*
>(
const_cast<NodeType*
>(mNode));
662 return const_cast<NodeType*
>(mNode)->
template probeNodeAndCache<NodeT>(xyz, *mParent);
664 return mNext.template probeNode<NodeT>(xyz);
668 template<
typename NodeT>
672 if (this->isHashed(xyz)) {
673 if ((boost::is_same<NodeT, NodeType>::value)) {
675 return reinterpret_cast<const NodeT*
>(mNode);
677 return mNode->template probeConstNodeAndCache<NodeT>(xyz, *mParent);
679 return mNext.template probeConstNode<NodeT>(xyz);
686 if (this->isHashed(xyz)) {
688 return mNode->isValueOnAndCache(xyz, *mParent);
690 return mNext.isValueOn(xyz);
696 if (this->isHashed(xyz)) {
698 return mNode->probeValueAndCache(xyz, value, *mParent);
700 return mNext.probeValue(xyz, value);
705 if (this->isHashed(xyz)) {
707 return static_cast<int>(TreeCacheT::RootNodeT::LEVEL) -
708 static_cast<int>(mNode->getValueLevelAndCache(xyz, *mParent));
710 return mNext.getValueDepth(xyz);
716 if (this->isHashed(xyz)) {
718 return mNode->getValueLevelAndCache(xyz, *mParent)==0;
720 return mNext.isVoxel(xyz);
725 void setValue(
const Coord& xyz,
const ValueType& value)
727 if (this->isHashed(xyz)) {
729 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
730 const_cast<NodeType*
>(mNode)->setValueAndCache(xyz, value, *mParent);
732 mNext.setValue(xyz, value);
737 if (this->isHashed(xyz)) {
739 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
740 const_cast<NodeType*
>(mNode)->setValueOnlyAndCache(xyz, value, *mParent);
742 mNext.setValueOnly(xyz, value);
745 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
750 template<
typename ModifyOp>
753 if (this->isHashed(xyz)) {
755 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
756 const_cast<NodeType*
>(mNode)->modifyValueAndCache(xyz, op, *mParent);
758 mNext.modifyValue(xyz, op);
764 template<
typename ModifyOp>
767 if (this->isHashed(xyz)) {
769 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
770 const_cast<NodeType*
>(mNode)->modifyValueAndActiveStateAndCache(xyz, op, *mParent);
772 mNext.modifyValueAndActiveState(xyz, op);
779 if (this->isHashed(xyz)) {
781 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
782 const_cast<NodeType*
>(mNode)->setValueOffAndCache(xyz, value, *mParent);
784 mNext.setValueOff(xyz, value);
791 if (this->isHashed(xyz)) {
793 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
794 const_cast<NodeType*
>(mNode)->setActiveStateAndCache(xyz, on, *mParent);
796 mNext.setActiveState(xyz, on);
804 bool isHashed(
const Coord& xyz)
const
806 return (xyz[0] & ~Coord::ValueType(NodeType::DIM-1)) == mHash[0]
807 && (xyz[1] & ~Coord::ValueType(NodeType::DIM-1)) == mHash[1]
808 && (xyz[2] & ~Coord::ValueType(NodeType::DIM-1)) == mHash[2];
813 const NodeType* mNode;
814 typedef typename boost::mpl::pop_front<NodeVecT>::type RestT;
815 CacheItem<TreeCacheT, RestT, boost::mpl::size<RestT>::value == 1> mNext;
820 template<
typename TreeCacheT,
typename NodeVecT>
828 CacheItem(TreeCacheT& parent): mParent(&parent), mRoot(NULL) {}
838 bool isCached(
const Coord& xyz)
const {
return this->isHashed(xyz); }
840 void insert(
const Coord&,
const RootNodeType* root) { mRoot = root; }
843 template <
typename OtherNodeType>
844 void insert(
const Coord&,
const OtherNodeType*) {}
846 void erase(
const RootNodeType*) { mRoot = NULL; }
852 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
853 node =
const_cast<RootNodeType*
>(mRoot);
855 void getNode(
const RootNodeType*& node)
const { node = mRoot; }
860 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
861 const_cast<RootNodeType*
>(mRoot)->addLeafAndCache(leaf, *mParent);
864 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
867 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
868 const_cast<RootNodeType*
>(mRoot)->addTileAndCache(level, xyz, value, state, *mParent);
874 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
875 return const_cast<RootNodeType*
>(mRoot)->touchLeafAndCache(xyz, *mParent);
881 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
882 return const_cast<RootNodeType*
>(mRoot)->probeLeafAndCache(xyz, *mParent);
888 return mRoot->probeConstLeafAndCache(xyz, *mParent);
891 template<
typename NodeType>
895 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
896 return const_cast<RootNodeType*
>(mRoot)->
template probeNodeAndCache<NodeType>(xyz, *mParent);
899 template<
typename NodeType>
903 return mRoot->template probeConstNodeAndCache<NodeType>(xyz, *mParent);
909 return mRoot->getValueDepthAndCache(xyz, *mParent);
914 return mRoot->isValueOnAndCache(xyz, *mParent);
920 return mRoot->probeValueAndCache(xyz, value, *mParent);
925 return mRoot->getValueDepthAndCache(xyz, *mParent) ==
926 static_cast<int>(RootNodeType::LEVEL);
931 return mRoot->getValueAndCache(xyz, *mParent);
934 void setValue(
const Coord& xyz,
const ValueType& value)
937 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
938 const_cast<RootNodeType*
>(mRoot)->setValueAndCache(xyz, value, *mParent);
943 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
944 const_cast<RootNodeType*
>(mRoot)->setValueOnlyAndCache(xyz, value, *mParent);
946 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
948 template<
typename ModifyOp>
952 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
953 const_cast<RootNodeType*
>(mRoot)->modifyValueAndCache(xyz, op, *mParent);
956 template<
typename ModifyOp>
960 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
961 const_cast<RootNodeType*
>(mRoot)->modifyValueAndActiveStateAndCache(xyz, op, *mParent);
967 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
968 const_cast<RootNodeType*
>(mRoot)->setValueOffAndCache(xyz, value, *mParent);
974 BOOST_STATIC_ASSERT(!TreeCacheT::IsConstTree);
975 const_cast<RootNodeType*
>(mRoot)->setActiveStateAndCache(xyz, on, *mParent);
982 bool isHashed(
const Coord&)
const {
return false; }
985 const RootNodeType* mRoot;
995 template<
typename _TreeType>
996 class ValueAccessor0:
public ValueAccessorBase<_TreeType>
1014 if (&other !=
this) this->BaseT::operator=(other);
1026 assert(BaseT::mTree);
1027 return BaseT::mTree->getValue(xyz);
1033 assert(BaseT::mTree);
1034 return BaseT::mTree->isValueOn(xyz);
1040 assert(BaseT::mTree);
1041 return BaseT::mTree->probeValue(xyz, value);
1049 assert(BaseT::mTree);
1050 return BaseT::mTree->getValueDepth(xyz);
1057 assert(BaseT::mTree);
1058 return BaseT::mTree->getValueDepth(xyz) ==
static_cast<int>(RootNodeT::LEVEL);
1062 void setValue(
const Coord& xyz,
const ValueType& value)
1065 assert(BaseT::mTree);
1066 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1067 BaseT::mTree->setValue(xyz, value);
1069 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
1075 assert(BaseT::mTree);
1076 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1077 BaseT::mTree->setValueOnly(xyz, value);
1083 assert(BaseT::mTree);
1084 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1085 BaseT::mTree->root().setValueOff(xyz, value);
1091 template<
typename ModifyOp>
1094 assert(BaseT::mTree);
1095 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1096 BaseT::mTree->modifyValue(xyz, op);
1101 template<
typename ModifyOp>
1104 assert(BaseT::mTree);
1105 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1106 BaseT::mTree->modifyValueAndActiveState(xyz, op);
1112 assert(BaseT::mTree);
1113 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1114 BaseT::mTree->setActiveState(xyz, on);
1117 void setValueOn(
const Coord& xyz) { this->setActiveState(xyz,
true); }
1119 void setValueOff(
const Coord& xyz) { this->setActiveState(xyz,
false); }
1122 template<
typename NodeT> NodeT*
getNode() {
return NULL; }
1126 template<
typename NodeT>
void insertNode(
const Coord&, NodeT&) {}
1132 assert(BaseT::mTree);
1133 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1134 BaseT::mTree->root().addLeaf(leaf);
1139 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
1141 assert(BaseT::mTree);
1142 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1143 BaseT::mTree->root().addTile(level, xyz, value, state);
1153 assert(BaseT::mTree);
1154 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1155 return BaseT::mTree->touchLeaf(xyz);
1158 template <
typename NodeT>
1161 assert(BaseT::mTree);
1162 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1163 return BaseT::mTree->template probeNode<NodeT>(xyz);
1166 template <
typename NodeT>
1169 assert(BaseT::mTree);
1170 return BaseT::mTree->template probeConstNode<NodeT>(xyz);
1175 return this->
template probeNode<LeafNodeT>(xyz);
1180 return this->
template probeConstNode<LeafNodeT>(xyz);
1185 return this->probeConstLeaf(xyz);
1193 template<
typename>
friend class Tree;
1197 virtual void release() { this->BaseT::release(); }
1208 template<
typename _TreeType, Index L0>
1209 class ValueAccessor1 :
public ValueAccessorBase<_TreeType>
1212 BOOST_STATIC_ASSERT(_TreeType::DEPTH >= 2);
1213 BOOST_STATIC_ASSERT( L0 < _TreeType::RootNodeType::LEVEL );
1220 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L0> >::type
NodeT0;
1236 if (&other !=
this) {
1237 this->BaseT::operator=(other);
1250 assert(BaseT::mTree);
1251 return this->isHashed(xyz);
1257 assert(BaseT::mTree);
1258 if (this->isHashed(xyz)) {
1260 return mNode0->getValueAndCache(xyz, this->
self());
1262 return BaseT::mTree->root().getValueAndCache(xyz, this->
self());
1268 assert(BaseT::mTree);
1269 if (this->isHashed(xyz)) {
1271 return mNode0->isValueOnAndCache(xyz, this->
self());
1273 return BaseT::mTree->root().isValueOnAndCache(xyz, this->
self());
1279 assert(BaseT::mTree);
1280 if (this->isHashed(xyz)) {
1282 return mNode0->probeValueAndCache(xyz, value, this->
self());
1284 return BaseT::mTree->root().probeValueAndCache(xyz, value, this->
self());
1292 assert(BaseT::mTree);
1293 if (this->isHashed(xyz)) {
1295 return RootNodeT::LEVEL - mNode0->getValueLevelAndCache(xyz, this->
self());
1297 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self());
1304 assert(BaseT::mTree);
1305 if (this->isHashed(xyz)) {
1307 return mNode0->getValueLevelAndCache(xyz, this->
self()) == 0;
1309 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self()) ==
1310 static_cast<int>(RootNodeT::LEVEL);
1314 void setValue(
const Coord& xyz,
const ValueType& value)
1317 assert(BaseT::mTree);
1318 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1319 if (this->isHashed(xyz)) {
1321 const_cast<NodeT0*
>(mNode0)->setValueAndCache(xyz, value, *
this);
1323 BaseT::mTree->root().setValueAndCache(xyz, value, *
this);
1326 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
1332 assert(BaseT::mTree);
1333 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1334 if (this->isHashed(xyz)) {
1336 const_cast<NodeT0*
>(mNode0)->setValueOnlyAndCache(xyz, value, *
this);
1338 BaseT::mTree->root().setValueOnlyAndCache(xyz, value, *
this);
1345 assert(BaseT::mTree);
1346 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1347 if (this->isHashed(xyz)) {
1349 const_cast<NodeT0*
>(mNode0)->setValueOffAndCache(xyz, value, *
this);
1351 BaseT::mTree->root().setValueOffAndCache(xyz, value, *
this);
1358 template<
typename ModifyOp>
1361 assert(BaseT::mTree);
1362 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1363 if (this->isHashed(xyz)) {
1365 const_cast<NodeT0*
>(mNode0)->modifyValueAndCache(xyz, op, *
this);
1367 BaseT::mTree->root().modifyValueAndCache(xyz, op, *
this);
1373 template<
typename ModifyOp>
1376 assert(BaseT::mTree);
1377 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1378 if (this->isHashed(xyz)) {
1380 const_cast<NodeT0*
>(mNode0)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
1382 BaseT::mTree->root().modifyValueAndActiveStateAndCache(xyz, op, *
this);
1389 assert(BaseT::mTree);
1390 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1391 if (this->isHashed(xyz)) {
1393 const_cast<NodeT0*
>(mNode0)->setActiveStateAndCache(xyz, on, *
this);
1395 BaseT::mTree->root().setActiveStateAndCache(xyz, on, *
this);
1399 void setValueOn(
const Coord& xyz) { this->setActiveState(xyz,
true); }
1401 void setValueOff(
const Coord& xyz) { this->setActiveState(xyz,
false); }
1404 template<
typename NodeT>
1407 const NodeT* node = NULL;
1408 this->getNode(node);
1409 return const_cast<NodeT*
>(node);
1414 template<
typename NodeT>
1415 void insertNode(
const Coord& xyz, NodeT& node) { this->insert(xyz, &node); }
1420 template<
typename NodeT>
1423 const NodeT* node = NULL;
1424 this->eraseNode(node);
1431 assert(BaseT::mTree);
1432 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1433 BaseT::mTree->root().addLeaf(leaf);
1438 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
1440 assert(BaseT::mTree);
1441 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1442 BaseT::mTree->root().addTile(level, xyz, value, state);
1453 assert(BaseT::mTree);
1454 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1455 if (this->isHashed(xyz)) {
1457 return const_cast<NodeT0*
>(mNode0)->touchLeafAndCache(xyz, *
this);
1459 return BaseT::mTree->root().touchLeafAndCache(xyz, *
this);
1464 template <
typename NodeT>
1467 assert(BaseT::mTree);
1468 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1470 if ((boost::is_same<NodeT, NodeT0>::value)) {
1471 if (this->isHashed(xyz)) {
1473 return reinterpret_cast<NodeT*
>(
const_cast<NodeT0*
>(mNode0));
1475 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
1482 return this->
template probeNode<LeafNodeT>(xyz);
1487 template <
typename NodeT>
1490 assert(BaseT::mTree);
1492 if ((boost::is_same<NodeT, NodeT0>::value)) {
1493 if (this->isHashed(xyz)) {
1495 return reinterpret_cast<const NodeT*
>(mNode0);
1497 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1504 return this->
template probeConstNode<LeafNodeT>(xyz);
1506 const LeafNodeT*
probeLeaf(
const Coord& xyz)
const {
return this->probeConstLeaf(xyz); }
1521 template<
typename>
friend class Tree;
1526 void getNode(
const NodeT0*& node) { node = mNode0; }
1527 void getNode(
const RootNodeT*& node)
1529 node = (BaseT::mTree ? &BaseT::mTree->root() : NULL);
1531 template <
typename OtherNodeType>
void getNode(
const OtherNodeType*& node) { node = NULL; }
1532 void eraseNode(
const NodeT0*) { mKey0 =
Coord::max(); mNode0 = NULL; }
1533 template <
typename OtherNodeType>
void eraseNode(
const OtherNodeType*) {}
1536 inline void copy(
const ValueAccessor1& other)
1538 mKey0 = other.mKey0;
1539 mNode0 = other.mNode0;
1544 virtual void release()
1546 this->BaseT::release();
1553 inline void insert(
const Coord& xyz,
const NodeT0* node)
1556 mKey0 = xyz & ~(NodeT0::DIM-1);
1562 template<
typename OtherNodeType>
inline void insert(
const Coord&,
const OtherNodeType*) {}
1564 inline bool isHashed(
const Coord& xyz)
const
1566 return (xyz[0] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[0]
1567 && (xyz[1] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[1]
1568 && (xyz[2] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[2];
1570 mutable Coord mKey0;
1571 mutable const NodeT0* mNode0;
1582 template<
typename _TreeType, Index L0, Index L1>
1583 class ValueAccessor2 :
public ValueAccessorBase<_TreeType>
1586 BOOST_STATIC_ASSERT(_TreeType::DEPTH >= 3);
1587 BOOST_STATIC_ASSERT( L0 < L1 && L1 < _TreeType::RootNodeType::LEVEL );
1594 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L0> >::type
NodeT0;
1595 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L1> >::type
NodeT1;
1599 mKey0(Coord::
max()), mNode0(NULL),
1600 mKey1(Coord::
max()), mNode1(NULL) {}
1611 if (&other !=
this) {
1612 this->BaseT::operator=(other);
1625 assert(BaseT::mTree);
1626 return this->isHashed1(xyz) || this->isHashed0(xyz);
1632 assert(BaseT::mTree);
1633 if (this->isHashed0(xyz)) {
1635 return mNode0->getValueAndCache(xyz, this->
self());
1636 }
else if (this->isHashed1(xyz)) {
1638 return mNode1->getValueAndCache(xyz, this->
self());
1640 return BaseT::mTree->root().getValueAndCache(xyz, this->
self());
1646 assert(BaseT::mTree);
1647 if (this->isHashed0(xyz)) {
1649 return mNode0->isValueOnAndCache(xyz, this->
self());
1650 }
else if (this->isHashed1(xyz)) {
1652 return mNode1->isValueOnAndCache(xyz, this->
self());
1654 return BaseT::mTree->root().isValueOnAndCache(xyz, this->
self());
1660 assert(BaseT::mTree);
1661 if (this->isHashed0(xyz)) {
1663 return mNode0->probeValueAndCache(xyz, value, this->
self());
1664 }
else if (this->isHashed1(xyz)) {
1666 return mNode1->probeValueAndCache(xyz, value, this->
self());
1668 return BaseT::mTree->root().probeValueAndCache(xyz, value, this->
self());
1676 assert(BaseT::mTree);
1677 if (this->isHashed0(xyz)) {
1679 return RootNodeT::LEVEL - mNode0->getValueLevelAndCache(xyz, this->
self());
1680 }
else if (this->isHashed1(xyz)) {
1682 return RootNodeT::LEVEL - mNode1->getValueLevelAndCache(xyz, this->
self());
1684 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self());
1691 assert(BaseT::mTree);
1692 if (this->isHashed0(xyz)) {
1694 return mNode0->getValueLevelAndCache(xyz, this->
self())==0;
1695 }
else if (this->isHashed1(xyz)) {
1697 return mNode1->getValueLevelAndCache(xyz, this->
self())==0;
1699 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self()) ==
1700 static_cast<int>(RootNodeT::LEVEL);
1704 void setValue(
const Coord& xyz,
const ValueType& value)
1707 assert(BaseT::mTree);
1708 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1709 if (this->isHashed0(xyz)) {
1711 const_cast<NodeT0*
>(mNode0)->setValueAndCache(xyz, value, *
this);
1712 }
else if (this->isHashed1(xyz)) {
1714 const_cast<NodeT1*
>(mNode1)->setValueAndCache(xyz, value, *
this);
1716 BaseT::mTree->root().setValueAndCache(xyz, value, *
this);
1719 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
1725 assert(BaseT::mTree);
1726 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1727 if (this->isHashed0(xyz)) {
1729 const_cast<NodeT0*
>(mNode0)->setValueOnlyAndCache(xyz, value, *
this);
1730 }
else if (this->isHashed1(xyz)) {
1732 const_cast<NodeT1*
>(mNode1)->setValueOnlyAndCache(xyz, value, *
this);
1734 BaseT::mTree->root().setValueOnlyAndCache(xyz, value, *
this);
1741 assert(BaseT::mTree);
1742 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1743 if (this->isHashed0(xyz)) {
1745 const_cast<NodeT0*
>(mNode0)->setValueOffAndCache(xyz, value, *
this);
1746 }
else if (this->isHashed1(xyz)) {
1748 const_cast<NodeT1*
>(mNode1)->setValueOffAndCache(xyz, value, *
this);
1750 BaseT::mTree->root().setValueOffAndCache(xyz, value, *
this);
1757 template<
typename ModifyOp>
1760 assert(BaseT::mTree);
1761 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1762 if (this->isHashed0(xyz)) {
1764 const_cast<NodeT0*
>(mNode0)->modifyValueAndCache(xyz, op, *
this);
1765 }
else if (this->isHashed1(xyz)) {
1767 const_cast<NodeT1*
>(mNode1)->modifyValueAndCache(xyz, op, *
this);
1769 BaseT::mTree->root().modifyValueAndCache(xyz, op, *
this);
1775 template<
typename ModifyOp>
1778 assert(BaseT::mTree);
1779 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1780 if (this->isHashed0(xyz)) {
1782 const_cast<NodeT0*
>(mNode0)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
1783 }
else if (this->isHashed1(xyz)) {
1785 const_cast<NodeT1*
>(mNode1)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
1787 BaseT::mTree->root().modifyValueAndActiveStateAndCache(xyz, op, *
this);
1794 assert(BaseT::mTree);
1795 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1796 if (this->isHashed0(xyz)) {
1798 const_cast<NodeT0*
>(mNode0)->setActiveStateAndCache(xyz, on, *
this);
1799 }
else if (this->isHashed1(xyz)) {
1801 const_cast<NodeT1*
>(mNode1)->setActiveStateAndCache(xyz, on, *
this);
1803 BaseT::mTree->root().setActiveStateAndCache(xyz, on, *
this);
1807 void setValueOn(
const Coord& xyz) { this->setActiveState(xyz,
true); }
1809 void setValueOff(
const Coord& xyz) { this->setActiveState(xyz,
false); }
1812 template<
typename NodeT>
1815 const NodeT* node = NULL;
1816 this->getNode(node);
1817 return const_cast<NodeT*
>(node);
1822 template<
typename NodeT>
1823 void insertNode(
const Coord& xyz, NodeT& node) { this->insert(xyz, &node); }
1828 template<
typename NodeT>
1831 const NodeT* node = NULL;
1832 this->eraseNode(node);
1839 assert(BaseT::mTree);
1840 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1841 if (this->isHashed1(leaf->origin())) {
1843 return const_cast<NodeT1*
>(mNode1)->addLeafAndCache(leaf, *
this);
1845 BaseT::mTree->root().addLeafAndCache(leaf, *
this);
1850 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
1852 assert(BaseT::mTree);
1853 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1854 if (this->isHashed1(xyz)) {
1856 return const_cast<NodeT1*
>(mNode1)->addTileAndCache(level, xyz, value, state, *
this);
1858 BaseT::mTree->root().addTileAndCache(level, xyz, value, state, *
this);
1869 assert(BaseT::mTree);
1870 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1871 if (this->isHashed0(xyz)) {
1873 return const_cast<NodeT0*
>(mNode0)->touchLeafAndCache(xyz, *
this);
1874 }
else if (this->isHashed1(xyz)) {
1876 return const_cast<NodeT1*
>(mNode1)->touchLeafAndCache(xyz, *
this);
1878 return BaseT::mTree->root().touchLeafAndCache(xyz, *
this);
1882 template <
typename NodeT>
1885 assert(BaseT::mTree);
1886 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
1888 if ((boost::is_same<NodeT, NodeT0>::value)) {
1889 if (this->isHashed0(xyz)) {
1891 return reinterpret_cast<NodeT*
>(
const_cast<NodeT0*
>(mNode0));
1892 }
else if (this->isHashed1(xyz)) {
1894 return const_cast<NodeT1*
>(mNode1)->
template probeNodeAndCache<NodeT>(xyz, *
this);
1896 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
1897 }
else if ((boost::is_same<NodeT, NodeT1>::value)) {
1898 if (this->isHashed1(xyz)) {
1900 return reinterpret_cast<NodeT*
>(
const_cast<NodeT1*
>(mNode1));
1902 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
1909 LeafNodeT*
probeLeaf(
const Coord& xyz) {
return this->
template probeNode<LeafNodeT>(xyz); }
1913 template <
typename NodeT>
1917 if ((boost::is_same<NodeT, NodeT0>::value)) {
1918 if (this->isHashed0(xyz)) {
1920 return reinterpret_cast<const NodeT*
>(mNode0);
1921 }
else if (this->isHashed1(xyz)) {
1923 return mNode1->template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1925 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1926 }
else if ((boost::is_same<NodeT, NodeT1>::value)) {
1927 if (this->isHashed1(xyz)) {
1929 return reinterpret_cast<const NodeT*
>(mNode1);
1931 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1940 return this->
template probeConstNode<LeafNodeT>(xyz);
1942 const LeafNodeT*
probeLeaf(
const Coord& xyz)
const {
return this->probeConstLeaf(xyz); }
1946 template <
typename NodeT>
1949 assert(BaseT::mTree);
1951 if ((boost::is_same<NodeT, NodeT0>::value)) {
1952 if (this->isHashed0(xyz)) {
1954 return reinterpret_cast<const NodeT*
>(mNode0);
1955 }
else if (this->isHashed1(xyz)) {
1957 return mNode1->template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1959 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1960 }
else if ((boost::is_same<NodeT, NodeT1>::value)) {
1961 if (this->isHashed1(xyz)) {
1963 return reinterpret_cast<const NodeT*
>(mNode1);
1965 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
1986 template<
typename>
friend class Tree;
1991 void getNode(
const NodeT0*& node) { node = mNode0; }
1992 void getNode(
const NodeT1*& node) { node = mNode1; }
1993 void getNode(
const RootNodeT*& node)
1995 node = (BaseT::mTree ? &BaseT::mTree->root() : NULL);
1997 template <
typename OtherNodeType>
void getNode(
const OtherNodeType*& node) { node = NULL; }
1999 void eraseNode(
const NodeT0*) { mKey0 =
Coord::max(); mNode0 = NULL; }
2000 void eraseNode(
const NodeT1*) { mKey1 =
Coord::max(); mNode1 = NULL; }
2001 template <
typename OtherNodeType>
void eraseNode(
const OtherNodeType*) {}
2004 inline void copy(
const ValueAccessor2& other)
2006 mKey0 = other.mKey0;
2007 mNode0 = other.mNode0;
2008 mKey1 = other.mKey1;
2009 mNode1 = other.mNode1;
2014 virtual void release()
2016 this->BaseT::release();
2024 inline void insert(
const Coord& xyz,
const NodeT0* node)
2027 mKey0 = xyz & ~(NodeT0::DIM-1);
2030 inline void insert(
const Coord& xyz,
const NodeT1* node)
2033 mKey1 = xyz & ~(NodeT1::DIM-1);
2038 template<
typename NodeT>
inline void insert(
const Coord&,
const NodeT*) {}
2040 inline bool isHashed0(
const Coord& xyz)
const
2042 return (xyz[0] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[0]
2043 && (xyz[1] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[1]
2044 && (xyz[2] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[2];
2046 inline bool isHashed1(
const Coord& xyz)
const
2048 return (xyz[0] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[0]
2049 && (xyz[1] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[1]
2050 && (xyz[2] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[2];
2052 mutable Coord mKey0;
2053 mutable const NodeT0* mNode0;
2054 mutable Coord mKey1;
2055 mutable const NodeT1* mNode1;
2069 template<
typename _TreeType, Index L0, Index L1, Index L2>
2070 class ValueAccessor3 :
public ValueAccessorBase<_TreeType>
2073 BOOST_STATIC_ASSERT(_TreeType::DEPTH >= 4);
2074 BOOST_STATIC_ASSERT(L0 < L1 && L1 < L2 && L2 < _TreeType::RootNodeType::LEVEL);
2081 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L0> >::type
NodeT0;
2082 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L1> >::type
NodeT1;
2083 typedef typename boost::mpl::at<InvTreeT, boost::mpl::int_<L2> >::type
NodeT2;
2087 mKey0(Coord::
max()), mNode0(NULL),
2088 mKey1(Coord::
max()), mNode1(NULL),
2089 mKey2(Coord::
max()), mNode2(NULL) {}
2097 if (&other !=
this) {
2098 this->BaseT::operator=(other);
2114 assert(BaseT::mTree);
2115 return this->isHashed2(xyz) || this->isHashed1(xyz) || this->isHashed0(xyz);
2121 assert(BaseT::mTree);
2122 if (this->isHashed0(xyz)) {
2124 return mNode0->getValueAndCache(xyz, this->
self());
2125 }
else if (this->isHashed1(xyz)) {
2127 return mNode1->getValueAndCache(xyz, this->
self());
2128 }
else if (this->isHashed2(xyz)) {
2130 return mNode2->getValueAndCache(xyz, this->
self());
2132 return BaseT::mTree->root().getValueAndCache(xyz, this->
self());
2138 assert(BaseT::mTree);
2139 if (this->isHashed0(xyz)) {
2141 return mNode0->isValueOnAndCache(xyz, this->
self());
2142 }
else if (this->isHashed1(xyz)) {
2144 return mNode1->isValueOnAndCache(xyz, this->
self());
2145 }
else if (this->isHashed2(xyz)) {
2147 return mNode2->isValueOnAndCache(xyz, this->
self());
2149 return BaseT::mTree->root().isValueOnAndCache(xyz, this->
self());
2155 assert(BaseT::mTree);
2156 if (this->isHashed0(xyz)) {
2158 return mNode0->probeValueAndCache(xyz, value, this->
self());
2159 }
else if (this->isHashed1(xyz)) {
2161 return mNode1->probeValueAndCache(xyz, value, this->
self());
2162 }
else if (this->isHashed2(xyz)) {
2164 return mNode2->probeValueAndCache(xyz, value, this->
self());
2166 return BaseT::mTree->root().probeValueAndCache(xyz, value, this->
self());
2174 assert(BaseT::mTree);
2175 if (this->isHashed0(xyz)) {
2177 return RootNodeT::LEVEL - mNode0->getValueLevelAndCache(xyz, this->
self());
2178 }
else if (this->isHashed1(xyz)) {
2180 return RootNodeT::LEVEL - mNode1->getValueLevelAndCache(xyz, this->
self());
2181 }
else if (this->isHashed2(xyz)) {
2183 return RootNodeT::LEVEL - mNode2->getValueLevelAndCache(xyz, this->
self());
2185 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self());
2192 assert(BaseT::mTree);
2193 if (this->isHashed0(xyz)) {
2195 return mNode0->getValueLevelAndCache(xyz, this->
self())==0;
2196 }
else if (this->isHashed1(xyz)) {
2198 return mNode1->getValueLevelAndCache(xyz, this->
self())==0;
2199 }
else if (this->isHashed2(xyz)) {
2201 return mNode2->getValueLevelAndCache(xyz, this->
self())==0;
2203 return BaseT::mTree->root().getValueDepthAndCache(xyz, this->
self()) ==
2204 static_cast<int>(RootNodeT::LEVEL);
2208 void setValue(
const Coord& xyz,
const ValueType& value)
2211 assert(BaseT::mTree);
2212 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2213 if (this->isHashed0(xyz)) {
2215 const_cast<NodeT0*
>(mNode0)->setValueAndCache(xyz, value, *
this);
2216 }
else if (this->isHashed1(xyz)) {
2218 const_cast<NodeT1*
>(mNode1)->setValueAndCache(xyz, value, *
this);
2219 }
else if (this->isHashed2(xyz)) {
2221 const_cast<NodeT2*
>(mNode2)->setValueAndCache(xyz, value, *
this);
2223 BaseT::mTree->root().setValueAndCache(xyz, value, *
this);
2226 void setValueOn(
const Coord& xyz,
const ValueType& value) { this->setValue(xyz, value); }
2232 assert(BaseT::mTree);
2233 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2234 if (this->isHashed0(xyz)) {
2236 const_cast<NodeT0*
>(mNode0)->setValueOnlyAndCache(xyz, value, *
this);
2237 }
else if (this->isHashed1(xyz)) {
2239 const_cast<NodeT1*
>(mNode1)->setValueOnlyAndCache(xyz, value, *
this);
2240 }
else if (this->isHashed2(xyz)) {
2242 const_cast<NodeT2*
>(mNode2)->setValueOnlyAndCache(xyz, value, *
this);
2244 BaseT::mTree->root().setValueOnlyAndCache(xyz, value, *
this);
2251 assert(BaseT::mTree);
2252 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2253 if (this->isHashed0(xyz)) {
2255 const_cast<NodeT0*
>(mNode0)->setValueOffAndCache(xyz, value, *
this);
2256 }
else if (this->isHashed1(xyz)) {
2258 const_cast<NodeT1*
>(mNode1)->setValueOffAndCache(xyz, value, *
this);
2259 }
else if (this->isHashed2(xyz)) {
2261 const_cast<NodeT2*
>(mNode2)->setValueOffAndCache(xyz, value, *
this);
2263 BaseT::mTree->root().setValueOffAndCache(xyz, value, *
this);
2270 template<
typename ModifyOp>
2273 assert(BaseT::mTree);
2274 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2275 if (this->isHashed0(xyz)) {
2277 const_cast<NodeT0*
>(mNode0)->modifyValueAndCache(xyz, op, *
this);
2278 }
else if (this->isHashed1(xyz)) {
2280 const_cast<NodeT1*
>(mNode1)->modifyValueAndCache(xyz, op, *
this);
2281 }
else if (this->isHashed2(xyz)) {
2283 const_cast<NodeT2*
>(mNode2)->modifyValueAndCache(xyz, op, *
this);
2285 BaseT::mTree->root().modifyValueAndCache(xyz, op, *
this);
2291 template<
typename ModifyOp>
2294 assert(BaseT::mTree);
2295 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2296 if (this->isHashed0(xyz)) {
2298 const_cast<NodeT0*
>(mNode0)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
2299 }
else if (this->isHashed1(xyz)) {
2301 const_cast<NodeT1*
>(mNode1)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
2302 }
else if (this->isHashed2(xyz)) {
2304 const_cast<NodeT2*
>(mNode2)->modifyValueAndActiveStateAndCache(xyz, op, *
this);
2306 BaseT::mTree->root().modifyValueAndActiveStateAndCache(xyz, op, *
this);
2313 assert(BaseT::mTree);
2314 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2315 if (this->isHashed0(xyz)) {
2317 const_cast<NodeT0*
>(mNode0)->setActiveStateAndCache(xyz, on, *
this);
2318 }
else if (this->isHashed1(xyz)) {
2320 const_cast<NodeT1*
>(mNode1)->setActiveStateAndCache(xyz, on, *
this);
2321 }
else if (this->isHashed2(xyz)) {
2323 const_cast<NodeT2*
>(mNode2)->setActiveStateAndCache(xyz, on, *
this);
2325 BaseT::mTree->root().setActiveStateAndCache(xyz, on, *
this);
2329 void setValueOn(
const Coord& xyz) { this->setActiveState(xyz,
true); }
2331 void setValueOff(
const Coord& xyz) { this->setActiveState(xyz,
false); }
2334 template<
typename NodeT>
2337 const NodeT* node = NULL;
2338 this->getNode(node);
2339 return const_cast<NodeT*
>(node);
2344 template<
typename NodeT>
2345 void insertNode(
const Coord& xyz, NodeT& node) { this->insert(xyz, &node); }
2350 template<
typename NodeT>
2353 const NodeT* node = NULL;
2354 this->eraseNode(node);
2361 assert(BaseT::mTree);
2362 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2363 if (this->isHashed1(leaf->origin())) {
2365 return const_cast<NodeT1*
>(mNode1)->addLeafAndCache(leaf, *
this);
2366 }
else if (this->isHashed2(leaf->origin())) {
2368 return const_cast<NodeT2*
>(mNode2)->addLeafAndCache(leaf, *
this);
2370 BaseT::mTree->root().addLeafAndCache(leaf, *
this);
2375 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state)
2377 assert(BaseT::mTree);
2378 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2379 if (this->isHashed1(xyz)) {
2381 return const_cast<NodeT1*
>(mNode1)->addTileAndCache(level, xyz, value, state, *
this);
2382 }
if (this->isHashed2(xyz)) {
2384 return const_cast<NodeT2*
>(mNode2)->addTileAndCache(level, xyz, value, state, *
this);
2386 BaseT::mTree->root().addTileAndCache(level, xyz, value, state, *
this);
2397 assert(BaseT::mTree);
2398 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2399 if (this->isHashed0(xyz)) {
2401 return const_cast<NodeT0*
>(mNode0);
2402 }
else if (this->isHashed1(xyz)) {
2404 return const_cast<NodeT1*
>(mNode1)->touchLeafAndCache(xyz, *
this);
2405 }
else if (this->isHashed2(xyz)) {
2407 return const_cast<NodeT2*
>(mNode2)->touchLeafAndCache(xyz, *
this);
2409 return BaseT::mTree->root().touchLeafAndCache(xyz, *
this);
2413 template <
typename NodeT>
2416 assert(BaseT::mTree);
2417 BOOST_STATIC_ASSERT(!BaseT::IsConstTree);
2419 if ((boost::is_same<NodeT, NodeT0>::value)) {
2420 if (this->isHashed0(xyz)) {
2422 return reinterpret_cast<NodeT*
>(
const_cast<NodeT0*
>(mNode0));
2423 }
else if (this->isHashed1(xyz)) {
2425 return const_cast<NodeT1*
>(mNode1)->
template probeNodeAndCache<NodeT>(xyz, *
this);
2426 }
else if (this->isHashed2(xyz)) {
2428 return const_cast<NodeT2*
>(mNode2)->
template probeNodeAndCache<NodeT>(xyz, *
this);
2430 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
2431 }
else if ((boost::is_same<NodeT, NodeT1>::value)) {
2432 if (this->isHashed1(xyz)) {
2434 return reinterpret_cast<NodeT*
>(
const_cast<NodeT1*
>(mNode1));
2435 }
else if (this->isHashed2(xyz)) {
2437 return const_cast<NodeT2*
>(mNode2)->
template probeNodeAndCache<NodeT>(xyz, *
this);
2439 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
2440 }
else if ((boost::is_same<NodeT, NodeT2>::value)) {
2441 if (this->isHashed2(xyz)) {
2443 return reinterpret_cast<NodeT*
>(
const_cast<NodeT2*
>(mNode2));
2445 return BaseT::mTree->root().template probeNodeAndCache<NodeT>(xyz, *
this);
2452 LeafNodeT*
probeLeaf(
const Coord& xyz) {
return this->
template probeNode<LeafNodeT>(xyz); }
2456 template <
typename NodeT>
2459 assert(BaseT::mTree);
2461 if ((boost::is_same<NodeT, NodeT0>::value)) {
2462 if (this->isHashed0(xyz)) {
2464 return reinterpret_cast<const NodeT*
>(mNode0);
2465 }
else if (this->isHashed1(xyz)) {
2467 return mNode1->template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2468 }
else if (this->isHashed2(xyz)) {
2470 return mNode2->template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2472 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2473 }
else if ((boost::is_same<NodeT, NodeT1>::value)) {
2474 if (this->isHashed1(xyz)) {
2476 return reinterpret_cast<const NodeT*
>(mNode1);
2477 }
else if (this->isHashed2(xyz)) {
2479 return mNode2->template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2481 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2482 }
else if ((boost::is_same<NodeT, NodeT2>::value)) {
2483 if (this->isHashed2(xyz)) {
2485 return reinterpret_cast<const NodeT*
>(mNode2);
2487 return BaseT::mTree->root().template probeConstNodeAndCache<NodeT>(xyz, this->
self());
2496 return this->
template probeConstNode<LeafNodeT>(xyz);
2498 const LeafNodeT*
probeLeaf(
const Coord& xyz)
const {
return this->probeConstLeaf(xyz); }
2517 template<
typename>
friend class Tree;
2525 mKey0 = other.mKey0;
2526 mNode0 = other.mNode0;
2527 mKey1 = other.mKey1;
2528 mNode1 = other.mNode1;
2529 mKey2 = other.mKey2;
2530 mNode2 = other.mNode2;
2535 virtual void release()
2537 this->BaseT::release();
2540 void getNode(
const NodeT0*& node) { node = mNode0; }
2541 void getNode(
const NodeT1*& node) { node = mNode1; }
2542 void getNode(
const NodeT2*& node) { node = mNode2; }
2543 void getNode(
const RootNodeT*& node)
2545 node = (BaseT::mTree ? &BaseT::mTree->root() : NULL);
2547 template <
typename OtherNodeType>
void getNode(
const OtherNodeType*& node) { node = NULL; }
2549 void eraseNode(
const NodeT0*) { mKey0 =
Coord::max(); mNode0 = NULL; }
2550 void eraseNode(
const NodeT1*) { mKey1 =
Coord::max(); mNode1 = NULL; }
2551 void eraseNode(
const NodeT2*) { mKey2 =
Coord::max(); mNode2 = NULL; }
2552 template <
typename OtherNodeType>
void eraseNode(
const OtherNodeType*) {}
2558 inline void insert(
const Coord& xyz,
const NodeT0* node)
2561 mKey0 = xyz & ~(NodeT0::DIM-1);
2564 inline void insert(
const Coord& xyz,
const NodeT1* node)
2567 mKey1 = xyz & ~(NodeT1::DIM-1);
2570 inline void insert(
const Coord& xyz,
const NodeT2* node)
2573 mKey2 = xyz & ~(NodeT2::DIM-1);
2578 template<
typename OtherNodeType>
2579 inline void insert(
const Coord&,
const OtherNodeType*)
2582 inline bool isHashed0(
const Coord& xyz)
const
2584 return (xyz[0] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[0]
2585 && (xyz[1] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[1]
2586 && (xyz[2] & ~Coord::ValueType(NodeT0::DIM-1)) == mKey0[2];
2588 inline bool isHashed1(
const Coord& xyz)
const
2590 return (xyz[0] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[0]
2591 && (xyz[1] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[1]
2592 && (xyz[2] & ~Coord::ValueType(NodeT1::DIM-1)) == mKey1[2];
2594 inline bool isHashed2(
const Coord& xyz)
const
2596 return (xyz[0] & ~Coord::ValueType(NodeT2::DIM-1)) == mKey2[0]
2597 && (xyz[1] & ~Coord::ValueType(NodeT2::DIM-1)) == mKey2[1]
2598 && (xyz[2] & ~Coord::ValueType(NodeT2::DIM-1)) == mKey2[2];
2600 mutable Coord mKey0;
2601 mutable const NodeT0* mNode0;
2602 mutable Coord mKey1;
2603 mutable const NodeT1* mNode1;
2604 mutable Coord mKey2;
2605 mutable const NodeT2* mNode2;
2612 #endif // OPENVDB_TREE_VALUEACCESSOR_HAS_BEEN_INCLUDED
ValueAccessor(TreeType &tree)
Definition: ValueAccessor.h:457
TreeType::LeafNodeType LeafNodeT
Definition: ValueAccessor.h:180
const LeafNodeType * probeConstLeaf(const Coord &xyz)
Definition: ValueAccessor.h:643
bool isVoxel(const Coord &xyz) const
Definition: ValueAccessor.h:1689
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:328
friend class InternalNode
Definition: ValueAccessor.h:402
LeafNodeT * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1480
int getValueDepth(const Coord &xyz)
Definition: ValueAccessor.h:703
ValueAccessorBase< TreeType > BaseT
Definition: ValueAccessor.h:2079
const LeafNodeT * probeLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:2498
NodeT * getNode()
Return the cached node of type NodeType. [Mainly for internal use].
Definition: ValueAccessor.h:1813
void getNode(const RootNodeType *&node) const
Definition: ValueAccessor.h:855
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:2249
This accessor is thread-safe (at the cost of speed) for both reading and writing to a tree...
Definition: ValueAccessor.h:497
Value accessor with two levels of node caching.
Definition: ValueAccessor.h:87
ValueAccessor2(TreeType &tree)
Constructor from a tree.
Definition: ValueAccessor.h:1598
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Definition: ValueAccessor.h:864
ValueAccessor0(const ValueAccessor0 &other)
Definition: ValueAccessor.h:1007
virtual void clear()
Remove all the cached nodes and invalidate the corresponding hash-keys.
Definition: ValueAccessor.h:2501
boost::mpl::at< InvTreeT, boost::mpl::int_< L0 > >::type NodeT0
Definition: ValueAccessor.h:2081
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: ValueAccessor.h:2271
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:2292
void setValueOff(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:964
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Definition: ValueAccessor.h:957
void setActiveState(const Coord &xyz, bool on)
Definition: ValueAccessor.h:971
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: ValueAccessor.h:1069
LeafNodeT * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1173
void setValue(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:934
const LeafNodeT * probeLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1942
NodeT * getNode()
Return the cached node of type NodeType. [Mainly for internal use].
Definition: ValueAccessor.h:2335
void clear()
Erase the nodes at this and lower levels of the cache.
Definition: ValueAccessor.h:574
virtual ~ValueAccessor()
Definition: ValueAccessor.h:481
ValueAccessor(TreeType &tree)
Definition: ValueAccessor.h:468
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1178
NodeType * getNode()
Return the cached node of type NodeType. [Mainly for internal use].
Definition: ValueAccessor.h:303
NodeT * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:1883
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinate but preserves its active state.
Definition: ValueAccessor.h:1330
CacheItem(TreeCacheT &parent)
Definition: ValueAccessor.h:828
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: ValueAccessor.h:1401
friend class LeafNode
Definition: ValueAccessor.h:2515
_TreeType TreeType
Definition: ValueAccessor.h:2075
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: ValueAccessor.h:2226
ValueAccessor(const ValueAccessor &other)
Definition: ValueAccessor.h:480
void getNode(const NodeType *&node) const
Return the cached node (if any) at this level.
Definition: ValueAccessor.h:577
RootNodeT::NodeChainType InvTreeT
Definition: ValueAccessor.h:1593
friend class LeafNode
Definition: ValueAccessor.h:403
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:2375
virtual ~ValueAccessor0()
Definition: ValueAccessor.h:1018
virtual ~ValueAccessor()
Definition: ValueAccessor.h:459
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1502
TreeType::ValueType ValueType
Definition: ValueAccessor.h:1589
void eraseNode()
Definition: ValueAccessor.h:1421
ValueAccessor(const ValueAccessor &other)
Definition: ValueAccessor.h:191
TreeType::LeafNodeType LeafNodeT
Definition: ValueAccessor.h:1002
void addLeaf(LeafNodeType *leaf)
Definition: ValueAccessor.h:857
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:1374
friend class RootNode
Definition: ValueAccessor.h:401
_TreeType TreeType
Definition: ValueAccessor.h:1588
bool isValueOn(const Coord &xyz)
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:684
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:777
TreeType::RootNodeType RootNodeT
Definition: ValueAccessor.h:1590
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:765
void setValueOnly(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:940
const NodeT * probeConstNode(const Coord &xyz) const
Definition: ValueAccessor.h:1488
void insertNode(const Coord &xyz, NodeT &node)
Definition: ValueAccessor.h:1823
ValueAccessorBase(TreeType &tree)
Definition: ValueAccessor.h:107
Definition: ValueAccessor.h:173
LeafNodeT * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1151
TreeType::LeafNodeType LeafNodeT
Definition: ValueAccessor.h:1217
void modifyValue(const Coord &xyz, const ModifyOp &op)
Definition: ValueAccessor.h:949
ValueAccessor3(const ValueAccessor3 &other)
Copy constructor.
Definition: ValueAccessor.h:2092
const NodeType * probeConstNode(const Coord &xyz)
Definition: ValueAccessor.h:900
ValueAccessorBase< TreeType > BaseT
Definition: ValueAccessor.h:1218
virtual ~ValueAccessor()
Definition: ValueAccessor.h:470
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: ValueAccessor.h:1792
NodeT * getNode()
Return the cached node of type NodeType. [Mainly for internal use].
Definition: ValueAccessor.h:1122
const NodeT * probeConstNode(const Coord &xyz) const
Definition: ValueAccessor.h:1167
std::numeric_limits< Int32 > CoordLimits
Definition: ValueAccessor.h:522
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:1837
void setValueOn(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:745
LeafNodeT * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:2395
LeafNodeType * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:623
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:284
void insert(const Coord &, const RootNodeType *root)
Definition: ValueAccessor.h:840
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:1266
NodeType * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:892
bool isVoxel(const Coord &xyz) const
Definition: ValueAccessor.h:2190
virtual void release()
Definition: ValueAccessor.h:140
LeafNodeT * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1909
CacheItem & copy(TreeCacheT &parent, const CacheItem &other)
Copy another CacheItem's node pointers and hash keys, but not its parent pointer. ...
Definition: ValueAccessor.h:542
const NodeT * probeConstNode(const Coord &xyz) const
Return a pointer to the node of the specified type that contains voxel (x, y, z), or NULL if no such ...
Definition: ValueAccessor.h:363
Value accessor with one level of node caching.
Definition: ValueAccessor.h:86
NodeT * getNode()
Return the cached node of type NodeType. [Mainly for internal use].
Definition: ValueAccessor.h:1405
virtual ~ValueAccessor()
Definition: ValueAccessor.h:448
NodeType::ValueType ValueType
Definition: ValueAccessor.h:520
bool isCached(const Coord &xyz) const
Definition: ValueAccessor.h:2112
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: ValueAccessor.h:275
void eraseNode()
Definition: ValueAccessor.h:324
bool isCached(const Coord &xyz) const
Definition: ValueAccessor.h:552
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: ValueAccessor.h:1758
boost::mpl::front< NodeVecT >::type NodeType
Definition: ValueAccessor.h:519
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:1031
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: ValueAccessor.h:1326
int getValueDepth(const Coord &xyz) const
Definition: ValueAccessor.h:229
RootNodeType::LeafNodeType LeafNodeType
Definition: ValueAccessor.h:826
friend class RootNode
Definition: ValueAccessor.h:1517
virtual ~ValueAccessor2()
Virtual destructor.
Definition: ValueAccessor.h:1619
bool isValueOn(const Coord &xyz)
Definition: ValueAccessor.h:911
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinate but don't change its active state.
Definition: ValueAccessor.h:250
void insertNode(const Coord &xyz, NodeType &node)
Definition: ValueAccessor.h:314
void eraseNode()
Definition: ValueAccessor.h:2351
virtual void clear()
Remove all the cached nodes and invalidate the corresponding hash-keys.
Definition: ValueAccessor.h:1509
boost::mpl::at< InvTreeT, boost::mpl::int_< L0 > >::type NodeT0
Definition: ValueAccessor.h:1220
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinate but preserves its active state.
Definition: ValueAccessor.h:1723
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: ValueAccessor.h:1119
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:2136
const LeafNodeT * probeLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z), or NULL if no such node exists...
Definition: ValueAccessor.h:388
NodeT * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:653
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: ValueAccessor.h:246
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:2119
boost::mpl::at< InvTreeT, boost::mpl::int_< L1 > >::type NodeT1
Definition: ValueAccessor.h:2082
TreeType::ValueType ValueType
Definition: ValueAccessor.h:1215
void eraseNode()
Definition: ValueAccessor.h:1149
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:1776
MutexType::scoped_lock LockT
Definition: ValueAccessor.h:183
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:210
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active without changing its value.
Definition: ValueAccessor.h:1807
void insertNode(const Coord &xyz, NodeT &node)
Definition: ValueAccessor.h:2345
void addLeaf(LeafNodeType *leaf)
Definition: ValueAccessor.h:600
LeafNodeType * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:633
ValueAccessor3(TreeType &tree)
Constructor from a tree.
Definition: ValueAccessor.h:2086
int getValueDepth(const Coord &xyz) const
Definition: ValueAccessor.h:1290
ValueAccessorBase(const ValueAccessorBase &other)
Definition: ValueAccessor.h:119
virtual ~ValueAccessor1()
Virtual destructor.
Definition: ValueAccessor.h:1244
LeafNodeT * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1451
LeafNodeType * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:878
NodeT * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:2414
friend class LeafNode
Definition: ValueAccessor.h:1984
ValueAccessor2(const ValueAccessor2 &other)
Copy constructor.
Definition: ValueAccessor.h:1603
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:1429
int getValueDepth(const Coord &xyz) const
Definition: ValueAccessor.h:1047
void setValue(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: ValueAccessor.h:725
TreeType::ValueType ValueType
Definition: ValueAccessor.h:2076
#define OPENVDB_VERSION_NAME
Definition: version.h:43
TreeType * mTree
Definition: ValueAccessor.h:142
const ValueType & getValue(const Coord &xyz)
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:591
NodeT * probeNode(const Coord &xyz)
Return a pointer to the node of the specified type that contains voxel (x, y, z), or NULL if no such ...
Definition: ValueAccessor.h:357
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:217
static Index numCacheLevels()
Return the number of cache levels employed by this ValueAccessor.
Definition: ValueAccessor.h:1231
Index32 Index
Definition: Types.h:59
void newSetValue(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:258
friend class InternalNode
Definition: ValueAccessor.h:1983
void insert(const Coord &, const OtherNodeType *)
Definition: ValueAccessor.h:844
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: ValueAccessor.h:1359
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive without changing its value.
Definition: ValueAccessor.h:1809
void insert(const Coord &xyz, const OtherNodeType *node)
Forward the given node to another level of the cache.
Definition: ValueAccessor.h:565
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: ValueAccessor.h:297
NodeType::LeafNodeType LeafNodeType
Definition: ValueAccessor.h:521
boost::mpl::front< NodeVecT >::type RootNodeType
Definition: ValueAccessor.h:824
bool isCached(const Coord &xyz) const
Return true if nodes along the path to the given voxel have been cached.
Definition: ValueAccessor.h:207
static Index numCacheLevels()
Return the number of cache levels employed by this accessor.
Definition: ValueAccessor.h:1010
bool isVoxel(const Coord &xyz)
Definition: ValueAccessor.h:714
bool isCached(const Coord &xyz) const
Definition: ValueAccessor.h:1248
virtual ~ValueAccessor()
Definition: ValueAccessor.h:201
friend class RootNode
Definition: ValueAccessor.h:1982
void erase(const OtherNodeType *node)
Erase the node at another level of the cache.
Definition: ValueAccessor.h:571
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:1081
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z), or NULL if no such node exists...
Definition: ValueAccessor.h:383
ValueAccessor & operator=(const ValueAccessor &other)
Definition: ValueAccessor.h:193
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1938
void eraseNode()
Definition: ValueAccessor.h:1829
_TreeType TreeType
Definition: ValueAccessor.h:178
virtual void clear()
Remove all nodes from this cache, then reinsert the root node.
Definition: ValueAccessor.h:1189
boost::mpl::at< InvTreeT, boost::mpl::int_< L0 > >::type NodeT0
Definition: ValueAccessor.h:1594
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinate but preserves its active state.
Definition: ValueAccessor.h:2230
TreeType * getTree() const
Return a pointer to the tree associated with this accessor.
Definition: ValueAccessor.h:115
bool isVoxel(const Coord &xyz) const
Definition: ValueAccessor.h:1055
ValueAccessor0 & operator=(const ValueAccessor0 &other)
Definition: ValueAccessor.h:1012
RootNodeType::ValueType ValueType
Definition: ValueAccessor.h:825
Definition: Exceptions.h:39
CacheItem(TreeCacheT &parent)
Definition: ValueAccessor.h:524
void getNode(const NodeType *&node)
Definition: ValueAccessor.h:578
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:336
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:1343
int getValueDepth(const Coord &xyz) const
Definition: ValueAccessor.h:2172
TreeType::RootNodeType RootNodeT
Definition: ValueAccessor.h:179
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:2494
ValueAccessorBase & operator=(const ValueAccessorBase &other)
Definition: ValueAccessor.h:124
TreeType::ValueType ValueType
Definition: ValueAccessor.h:1000
CacheItem(TreeCacheT &parent, const CacheItem &other)
Definition: ValueAccessor.h:829
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: ValueAccessor.h:299
TreeType::LeafNodeType LeafNodeT
Definition: ValueAccessor.h:1591
ValueAccessor with no mutex and no node caching.
Definition: ValueAccessor.h:85
RootNodeT::NodeChainType InvTreeT
Definition: ValueAccessor.h:2080
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: ValueAccessor.h:1387
const NodeT * probeNode(const Coord &xyz) const
Return a pointer to the node of the specified type that contains voxel (x, y, z), or NULL if no such ...
Definition: ValueAccessor.h:369
const ValueType & getValue(const Coord &xyz)
Definition: ValueAccessor.h:928
bool isCached(const Coord &) const
Return true if nodes along the path to the given voxel have been cached.
Definition: ValueAccessor.h:1021
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:1255
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:1850
int getValueDepth(const Coord &xyz) const
Definition: ValueAccessor.h:1674
ValueAccessor2 & operator=(const ValueAccessor2 &other)
Asignment operator.
Definition: ValueAccessor.h:1609
TreeType::LeafNodeType LeafNodeT
Definition: ValueAccessor.h:2078
virtual ~ValueAccessor3()
Virtual destructor.
Definition: ValueAccessor.h:2108
void clear()
Definition: ValueAccessor.h:848
virtual void clear()
Remove all nodes from this cache, then reinsert the root node.
Definition: ValueAccessor.h:392
TreeType::RootNodeType RootNodeT
Definition: ValueAccessor.h:2077
static Index numCacheLevels()
Return the number of cache levels employed by this ValueAccessor.
Definition: ValueAccessor.h:2105
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: ValueAccessor.h:1110
friend class Tree
Definition: ValueAccessor.h:1986
LeafNodeT * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, create one, but preserve the values and active states of all voxels.
Definition: ValueAccessor.h:347
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:1024
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:1130
boost::mpl::at< InvTreeT, boost::mpl::int_< L1 > >::type NodeT1
Definition: ValueAccessor.h:1595
const LeafNodeType * probeConstLeaf(const Coord &xyz)
Definition: ValueAccessor.h:885
NodeT * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:1465
Value accessor with three levels of node caching.
Definition: ValueAccessor.h:88
ValueAccessor(TreeType &tree)
Definition: ValueAccessor.h:186
const NodeT * probeConstNode(const Coord &xyz) const
Definition: ValueAccessor.h:2457
static Index numCacheLevels()
Return the number of cache levels employed by this ValueAccessor.
Definition: ValueAccessor.h:1606
RootNodeT::NodeChainType InvTreeT
Definition: ValueAccessor.h:1219
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: ValueAccessor.h:2311
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: ValueAccessor.h:751
friend class Tree
Definition: ValueAccessor.h:2517
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:1277
friend class InternalNode
Definition: ValueAccessor.h:1518
ValueAccessor0(TreeType &tree)
Definition: ValueAccessor.h:1005
virtual void clear()
Remove all the cached nodes and invalidate the corresponding hash-keys.
Definition: ValueAccessor.h:1972
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: ValueAccessor.h:1092
bool isCached(const Coord &xyz) const
Definition: ValueAccessor.h:838
void setValueOnly(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:735
friend class Tree
Definition: ValueAccessor.h:405
LeafNodeT * probeLeaf(const Coord &xyz)
Definition: ValueAccessor.h:2452
void getNode(RootNodeType *&node)
Definition: ValueAccessor.h:850
ValueAccessor(TreeType &tree)
Definition: ValueAccessor.h:479
int getValueDepth(const Coord &xyz)
Definition: ValueAccessor.h:906
const NodeT * probeConstNode(const Coord &xyz) const
Definition: ValueAccessor.h:1947
CacheItem & copy(TreeCacheT &parent, const CacheItem &other)
Definition: ValueAccessor.h:831
bool isCached(const Coord &xyz) const
Definition: ValueAccessor.h:1623
friend class RootNode
Definition: ValueAccessor.h:2513
void setValueOn(const Coord &xyz, const ValueType &value)
Definition: ValueAccessor.h:946
void getNode(NodeType *&node)
Definition: ValueAccessor.h:579
ValueAccessorRW(TreeType &tree)
Definition: ValueAccessor.h:500
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state and, in value, the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:1038
bool probeValue(const Coord &xyz, ValueType &value)
Return the active state and value of the voxel at the given coordinates.
Definition: ValueAccessor.h:694
boost::mpl::at< InvTreeT, boost::mpl::int_< L2 > >::type NodeT2
Definition: ValueAccessor.h:2083
void insert(const Coord &xyz, const NodeType *node)
Cache the given node at this level.
Definition: ValueAccessor.h:558
bool isVoxel(const Coord &xyz) const
Definition: ValueAccessor.h:1302
void erase(const RootNodeType *)
Definition: ValueAccessor.h:846
ValueAccessorBase< TreeType > BaseT
Definition: ValueAccessor.h:1592
void erase(const NodeType *)
Erase the node at this level.
Definition: ValueAccessor.h:568
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: ValueAccessor.h:1399
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:265
virtual ~ValueAccessorBase()
Definition: ValueAccessor.h:109
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:1139
ValueAccessor1(TreeType &tree)
Constructor from a tree.
Definition: ValueAccessor.h:1223
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: ValueAccessor.h:291
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:789
ValueAccessor(const ValueAccessor &other)
Definition: ValueAccessor.h:447
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive without changing its value.
Definition: ValueAccessor.h:2331
bool isVoxel(const Coord &xyz)
Definition: ValueAccessor.h:922
friend class LeafNode
Definition: ValueAccessor.h:1519
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:1644
const LeafNodeT * probeLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1506
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: ValueAccessor.h:1117
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
Definition: ValueAccessor.h:102
friend class Tree
Definition: ValueAccessor.h:1193
bool probeValue(const Coord &xyz, ValueType &value)
Definition: ValueAccessor.h:917
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:1630
bool isVoxel(const Coord &xyz) const
Definition: ValueAccessor.h:237
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly deleting existing node...
Definition: ValueAccessor.h:1438
const NodeT * probeConstNode(const Coord &xyz)
Definition: ValueAccessor.h:669
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinate but don't change its active state.
Definition: ValueAccessor.h:1073
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
RootNodeT::ValueType ValueType
Definition: ValueAccessor.h:181
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: ValueAccessor.h:1719
ValueAccessorBase< TreeType > BaseT
Definition: ValueAccessor.h:182
const LeafNodeT * probeLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1183
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active without changing its value.
Definition: ValueAccessor.h:2329
ValueAccessor1 & operator=(const ValueAccessor1 &other)
Asignment operator.
Definition: ValueAccessor.h:1234
friend class Tree
Definition: ValueAccessor.h:1521
LeafNodeType * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:871
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:2153
Definition: ValueAccessor.h:89
NodeT * probeNode(const Coord &xyz)
Definition: ValueAccessor.h:1159
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:220
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: ValueAccessor.h:1102
_TreeType TreeType
Definition: ValueAccessor.h:1214
TreeType::RootNodeType RootNodeT
Definition: ValueAccessor.h:1216
const NodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:1914
ValueAccessor(TreeType &tree)
Definition: ValueAccessor.h:446
ValueAccessor3 & operator=(const ValueAccessor3 &other)
Asignment operator.
Definition: ValueAccessor.h:2095
void getNode(OtherNodeType *&node)
Forward the request to another level of the cache.
Definition: ValueAccessor.h:588
void insertNode(const Coord &xyz, NodeT &node)
Definition: ValueAccessor.h:1415
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:1658
static Index numCacheLevels()
Return the number of cache levels employed by this accessor.
Definition: ValueAccessor.h:204
ValueAccessor(const ValueAccessor &other)
Definition: ValueAccessor.h:458
_TreeType TreeType
Definition: ValueAccessor.h:999
TreeType::RootNodeType RootNodeT
Definition: ValueAccessor.h:1001
ValueAccessorBase< TreeType > BaseT
Definition: ValueAccessor.h:1003
ValueAccessor1(const ValueAccessor1 &other)
Copy constructor.
Definition: ValueAccessor.h:1228
TreeType & tree() const
Return a reference to the tree associated with this accessor.
Definition: ValueAccessor.h:117
ValueAccessor(const ValueAccessor &other)
Definition: ValueAccessor.h:469
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition: ValueAccessor.h:1739
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:2359
friend class InternalNode
Definition: ValueAccessor.h:2514
void insertNode(const Coord &, NodeT &)
Definition: ValueAccessor.h:1126
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Definition: ValueAccessor.h:611
LeafNodeT * touchLeaf(const Coord &xyz)
Definition: ValueAccessor.h:1867