11 #include <boost/shared_ptr.hpp>
12 #include <boost/weak_ptr.hpp>
13 #include <boost/enable_shared_from_this.hpp>
36 template <
typename Tree>
39 typedef boost::shared_ptr<Tree>
Ptr;
44 template <
typename Tree>
47 typedef boost::weak_ptr<Tree>
Ptr;
68 unsigned int Dimensions = 3,
71 typename BoundsType =
double
74 :
public boost::enable_shared_from_this< DtNTree<T,Dimensions,Mutex,SubcellTraits,BoundsType> >
78 template <
unsigned int A,
unsigned int B>
83 template <
unsigned int A>
86 static const unsigned int value = 1;
94 static boost::shared_ptr<Z>
Get(
const boost::shared_ptr<Z>& p) {
return p ;}
97 static boost::shared_ptr<Z>
Get(
const boost::weak_ptr<Z>& p) {
return p.lock(); }
100 static void Set(boost::shared_ptr<Z>& p,
const boost::shared_ptr<Z>& to) { p = to; }
102 template <
typename Z>
103 static void Set(boost::shared_ptr<Z>& p,
const boost::weak_ptr<Z>& to) { p = to.lock(); }
105 template <
typename Z>
106 static void Set(boost::weak_ptr<Z>& p,
const boost::shared_ptr<Z>& to) { p = to; }
108 template <
typename Z>
109 static void Set(boost::weak_ptr<Z>& p,
const boost::weak_ptr<Z>& to) { p = to; }
112 typedef typename SubcellTraits<DtNTree>::Ptr
Ptr;
113 typedef typename SubcellTraits<DtNTree>::ParentPtr
ParentPtr;
127 :
minimum(std::numeric_limits<BoundsType>::min())
128 ,
maximum(std::numeric_limits<BoundsType>::max()) { }
131 Range(BoundsType min, BoundsType max)
162 for (
unsigned int bit=1, d=0; d < Dimensions; ++d, bit=bit<<1)
189 for (
unsigned int d=0; d < Dimensions; ++d)
200 for (
unsigned int d=0; d < Dimensions; ++d)
232 boost::shared_ptr<DtNTree> child;
235 typename Mutex::scoped_lock lock(
myMutex,
false);
245 return boost::shared_ptr<DtNTree>();
250 if (!lock.upgrade_to_writer())
287 return boost::shared_ptr<DtNTree>(
new DtNTree(bounds, 0));
310 :
myParent(parent.shared_from_this())
336 return boost::shared_ptr<DtNTree>(
new DtNTree(*
this, cell.
bounds()));
399 unsigned int Dimensions,
401 template <
typename>
class SubcellPolicy,
414 virtual bool matches(
const Subcell& cell) = 0;
419 virtual bool shouldCreateSubcell(
const Subcell& cell) = 0;
Represents the subcell in the parent cell.
Definition: DtNTree.h:223
virtual boost::shared_ptr< DtNTree > createSubcell(DtNTree &tree, Subcell &cell)
Factory function for creating subcells.
Definition: DtNTree.h:423
Range()
Default constructor.
Definition: DtNTree.h:126
virtual bool matches(const Subcell &cell)=0
Search will ignore cells which return false.
boost::weak_ptr< Tree > Ptr
Definition: DtNTree.h:47
Query interface.
Definition: DtNTree.h:404
virtual void visit(DtNTree &tree)
Entry point for search.
Definition: DtNTree.h:429
Generate NTree (binary tree, quadtree, octree, etc.) class.
Definition: DtNTree.h:73
virtual bool shouldCreateSubcell(const Subcell &cell)=0
Determine if an empty subcell should be created.
bool intersects(const Bounds &other) const
Returns true if the two bounds intersect each other.
Definition: DtNTree.h:198
const T & getData() const
Definition: DtNTree.h:302
DT_DLL_VRVCORE DtTaitBryan level(const DtCoordinateSystem &cs, const DtVector &localOrigin, double topoHeading)
Returns a level orientation with the topographic heading.
static const unsigned int value
Definition: DtNTree.h:81
virtual void visit(Query &query)
Default implementation of query visit.
Definition: DtNTree.h:340
T & getData()
Accessors for user data.
Definition: DtNTree.h:301
boost::shared_ptr< DtNTree > getPtr(DtNTree &tree, Query &query)
Get or create the tree for this subcell.
Definition: DtNTree.h:230
static void Set(boost::weak_ptr< Z > &p, const boost::shared_ptr< Z > &to)
Definition: DtNTree.h:106
Range(BoundsType min, BoundsType max)
Create from bounds of range.
Definition: DtNTree.h:131
boost::shared_ptr< DtNTree > getParent() const
Return the parent of this tree, if it exists.
Definition: DtNTree.h:297
Weak pointer policy.
Definition: DtNTree.h:45
static void Set(boost::weak_ptr< Z > &p, const boost::weak_ptr< Z > &to)
Definition: DtNTree.h:109
Set of ranges, one for each dimension.
Definition: DtNTree.h:154
bool upgrade_to_writer()
Definition: DtNTree.h:29
const Bounds & getBounds() const
Return the bounds of this tree.
Definition: DtNTree.h:294
T myData
User data stored in this tree.
Definition: DtNTree.h:387
SubcellTraits< DtNTree >::Ptr Ptr
Definition: DtNTree.h:112
const int myLevel
Level of this cell.
Definition: DtNTree.h:378
virtual ~Query()
Virtual destructor.
Definition: DtNTree.h:408
BoundsType maximum
Definition: DtNTree.h:150
virtual boost::shared_ptr< DtNTree > createSubcell(Subcell &cell)
Default implementation of query createSubcell.
Definition: DtNTree.h:334
static boost::shared_ptr< Z > Get(const boost::shared_ptr< Z > &p)
These functions allow shared and weak pointers to be treated the same.
Definition: DtNTree.h:94
DtNTree(DtNTree &parent, const Bounds &bounds)
Constructor for creating children trees.
Definition: DtNTree.h:309
void downgrade_to_reader()
Definition: DtNTree.h:30
double size() const
Compute the size (area, volume, etc. depending on number of dimensions).
Definition: DtNTree.h:185
static const unsigned int NumberOfIndices
Number of subcells.
Definition: DtNTree.h:120
boost::weak_ptr< Tree > ParentPtr
Definition: DtNTree.h:40
Range & range(unsigned int i)
accessors
Definition: DtNTree.h:214
OpenThreads::Mutex Mutex
Definition: DtOsgThreadingUtils.h:12
Bounds makeSubBounds(unsigned int index) const
Compute the bounds of a subcell at a given index.
Definition: DtNTree.h:158
boost::shared_ptr< Tree > Ptr
Definition: DtNTree.h:39
void init(const Bounds &b)
This class is created in an array so parameters are initialized after the constructor.
Definition: DtNTree.h:272
Null mutex default policy.
Definition: DtNTree.h:21
Subcell & getSubcell(DtNTree &tree, unsigned int i)
Interface for subclasses to get at subcell objects.
Definition: DtNTree.h:436
const Range & range(unsigned int i) const
Definition: DtNTree.h:215
double size() const
Compute the length of the range.
Definition: DtNTree.h:135
int getLevel() const
Return level of this tree.
Definition: DtNTree.h:291
Subcell mySubcells[NumberOfIndices]
Subcells.
Definition: DtNTree.h:384
const Bounds & bounds() const
Accessor for bounds of this cell.
Definition: DtNTree.h:227
static boost::shared_ptr< DtNTree > Create(const Bounds &bounds)
Factory, create a top level root cell.
Definition: DtNTree.h:285
void release()
Definition: DtNTree.h:31
scoped_lock(DtNTreeNullMutexPolicy &, bool=true)
Definition: DtNTree.h:27
static void Set(boost::shared_ptr< Z > &p, const boost::weak_ptr< Z > &to)
Definition: DtNTree.h:103
Bounds myBounds
Bounds of this subcell.
Definition: DtNTree.h:275
static void Set(boost::shared_ptr< Z > &p, const boost::shared_ptr< Z > &to)
Definition: DtNTree.h:100
boost::shared_ptr< Tree > ParentPtr
Definition: DtNTree.h:48
One dimensional range (i.e. min/max).
Definition: DtNTree.h:123
Shared pointer policy.
Definition: DtNTree.h:37
SubcellTraits< DtNTree >::ParentPtr ParentPtr
Definition: DtNTree.h:113
bool intersects(const Range &other) const
Returns true of these two ranges intersect.
Definition: DtNTree.h:141
const ParentPtr myParent
Pointer to parent node if it exists.
Definition: DtNTree.h:375
DtNTree(const Bounds &bounds, unsigned int level)
Constructor for creating root tree.
Definition: DtNTree.h:321
Compute exponents at compile time (for array length).
Definition: DtNTree.h:79
Ptr myTree
Pointer to child tree.
Definition: DtNTree.h:281
const Bounds myBounds
Bounds of this cell.
Definition: DtNTree.h:381
static boost::shared_ptr< Z > Get(const boost::weak_ptr< Z > &p)
Definition: DtNTree.h:97
Mutex myMutex
Mutex which synchronizes only the pointer, not the object pointed to.
Definition: DtNTree.h:278
BoundsType minimum
Definition: DtNTree.h:150
Range myRanges[Dimensions]
Definition: DtNTree.h:219