33 template <
typename Tree>
36 typedef std::shared_ptr<Tree>
Ptr;
41 template <
typename Tree>
44 typedef std::weak_ptr<Tree>
Ptr;
65 unsigned int Dimensions = 3,
68 typename BoundsType =
double
71 :
public std::enable_shared_from_this< DtNTree<T,Dimensions,Mutex,SubcellTraits,BoundsType> >
75 template <
unsigned int A,
unsigned int B>
80 template <
unsigned int A>
83 static const unsigned int value = 1;
91 static std::shared_ptr<Z>
Get(
const std::shared_ptr<Z>& p) {
return p ;}
94 static std::shared_ptr<Z>
Get(
const std::weak_ptr<Z>& p) {
return p.lock(); }
97 static void Set(std::shared_ptr<Z>& p,
const std::shared_ptr<Z>& to) { p = to; }
100 static void Set(std::shared_ptr<Z>& p,
const std::weak_ptr<Z>& to) { p = to.lock(); }
102 template <
typename Z>
103 static void Set(std::weak_ptr<Z>& p,
const std::shared_ptr<Z>& to) { p = to; }
105 template <
typename Z>
106 static void Set(std::weak_ptr<Z>& p,
const std::weak_ptr<Z>& to) { p = to; }
109 typedef typename SubcellTraits<DtNTree>::Ptr
Ptr;
110 typedef typename SubcellTraits<DtNTree>::ParentPtr
ParentPtr;
124 :
minimum(std::numeric_limits<BoundsType>::min())
125 ,
maximum(std::numeric_limits<BoundsType>::max()) { }
128 Range(BoundsType min, BoundsType max)
159 for (
unsigned int bit=1, d=0; d < Dimensions; ++d, bit=bit<<1)
186 for (
unsigned int d=0; d < Dimensions; ++d)
197 for (
unsigned int d=0; d < Dimensions; ++d)
229 std::shared_ptr<DtNTree> child;
232 typename Mutex::scoped_lock lock(
myMutex,
false);
242 return std::shared_ptr<DtNTree>();
247 if (!lock.upgrade_to_writer())
284 return std::shared_ptr<DtNTree>(
new DtNTree(bounds, 0));
307 :
myParent(parent.shared_from_this())
333 return std::shared_ptr<DtNTree>(
new DtNTree(*
this, cell.
bounds()));
396 unsigned int Dimensions,
398 template <
typename>
class SubcellPolicy,
411 virtual bool matches(
const Subcell& cell) = 0;
416 virtual bool shouldCreateSubcell(
const Subcell& cell) = 0;
Represents the subcell in the parent cell.
Definition: DtNTree.h:220
static void Set(std::weak_ptr< Z > &p, const std::weak_ptr< Z > &to)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:106
std::weak_ptr< Tree > Ptr
Definition: DtNTree.h:44
Range()
Default constructor.
Definition: DtNTree.h:123
std::shared_ptr< DtNTree > getParent() const
Return the parent of this tree, if it exists.
Definition: DtNTree.h:294
virtual bool matches(const Subcell &cell)=0
Search will ignore cells which return false. For a given tree, matches will be called on ALL the subc...
Query interface. Queries are templates of a general search on the tree. Users implement various parts...
Definition: DtNTree.h:401
virtual void visit(DtNTree &tree)
Entry point for search.
Definition: DtNTree.h:426
std::shared_ptr< Tree > Ptr
Definition: DtNTree.h:36
Generate NTree (binary tree, quadtree, octree, etc.) class. This consists of the tree itself and a qu...
Definition: DtNTree.h:70
virtual bool shouldCreateSubcell(const Subcell &cell)=0
Determine if an empty subcell should be created. This function will be called when the query is has d...
bool intersects(const Bounds &other) const
Returns true if the two bounds intersect each other.
Definition: DtNTree.h:195
static std::shared_ptr< DtNTree > Create(const Bounds &bounds)
Factory, create a top level root cell.
Definition: DtNTree.h:282
const T & getData() const
Accessors for user data.
Definition: DtNTree.h:299
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:78
virtual void visit(Query &query)
Default implementation of query visit.
Definition: DtNTree.h:337
T & getData()
Accessors for user data.
Definition: DtNTree.h:298
static void Set(std::shared_ptr< Z > &p, const std::shared_ptr< Z > &to)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:97
Range(BoundsType min, BoundsType max)
Create from bounds of range.
Definition: DtNTree.h:128
virtual std::shared_ptr< DtNTree > createSubcell(DtNTree &tree, Subcell &cell)
Factory function for creating subcells. Reimplement this function to have this query create your own ...
Definition: DtNTree.h:420
Weak pointer policy.
Definition: DtNTree.h:42
static std::shared_ptr< Z > Get(const std::shared_ptr< Z > &p)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:91
Set of ranges, one for each dimension.
Definition: DtNTree.h:151
bool upgrade_to_writer()
Definition: DtNTree.h:26
const Bounds & getBounds() const
Return the bounds of this tree.
Definition: DtNTree.h:291
T myData
User data stored in this tree.
Definition: DtNTree.h:384
static std::shared_ptr< Z > Get(const std::weak_ptr< Z > &p)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:94
SubcellTraits< DtNTree >::Ptr Ptr
Definition: DtNTree.h:109
const int myLevel
Level of this cell.
Definition: DtNTree.h:375
virtual ~Query()
Virtual destructor.
Definition: DtNTree.h:405
BoundsType maximum
Definition: DtNTree.h:147
static void Set(std::weak_ptr< Z > &p, const std::shared_ptr< Z > &to)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:103
std::shared_ptr< Tree > ParentPtr
Definition: DtNTree.h:45
DtNTree(DtNTree &parent, const Bounds &bounds)
Constructor for creating children trees.
Definition: DtNTree.h:306
virtual std::shared_ptr< DtNTree > createSubcell(Subcell &cell)
Default implementation of query createSubcell.
Definition: DtNTree.h:331
void downgrade_to_reader()
Definition: DtNTree.h:27
static void Set(std::shared_ptr< Z > &p, const std::weak_ptr< Z > &to)
These functions allow shared and weak pointers to be treated the same. Weak pointers cannot be direct...
Definition: DtNTree.h:100
double size() const
Compute the size (area, volume, etc. depending on number of dimensions).
Definition: DtNTree.h:182
static const unsigned int NumberOfIndices
Number of subcells.
Definition: DtNTree.h:117
Range & range(unsigned int i)
accessors
Definition: DtNTree.h:211
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:155
std::weak_ptr< Tree > ParentPtr
Definition: DtNTree.h:37
void init(const Bounds &b)
This class is created in an array so parameters are initialized after the constructor.
Definition: DtNTree.h:269
Null mutex default policy. Using this policy will result in no locking (i.e. tree is not threadsafe)...
Definition: DtNTree.h:18
Subcell & getSubcell(DtNTree &tree, unsigned int i)
Interface for subclasses to get at subcell objects.
Definition: DtNTree.h:433
const Range & range(unsigned int i) const
accessors
Definition: DtNTree.h:212
double size() const
Compute the length of the range.
Definition: DtNTree.h:132
int getLevel() const
Return level of this tree.
Definition: DtNTree.h:288
Subcell mySubcells[NumberOfIndices]
Subcells.
Definition: DtNTree.h:381
const Bounds & bounds() const
Accessor for bounds of this cell.
Definition: DtNTree.h:224
void release()
Definition: DtNTree.h:28
scoped_lock(DtNTreeNullMutexPolicy &, bool=true)
Definition: DtNTree.h:24
Bounds myBounds
Bounds of this subcell.
Definition: DtNTree.h:272
One dimensional range (i.e. min/max).
Definition: DtNTree.h:120
Shared pointer policy.
Definition: DtNTree.h:34
SubcellTraits< DtNTree >::ParentPtr ParentPtr
Definition: DtNTree.h:110
bool intersects(const Range &other) const
Returns true of these two ranges intersect.
Definition: DtNTree.h:138
const ParentPtr myParent
Pointer to parent node if it exists.
Definition: DtNTree.h:372
DtNTree(const Bounds &bounds, unsigned int level)
Constructor for creating root tree.
Definition: DtNTree.h:318
Compute exponents at compile time (for array length).
Definition: DtNTree.h:76
Ptr myTree
Pointer to child tree.
Definition: DtNTree.h:278
const Bounds myBounds
Bounds of this cell.
Definition: DtNTree.h:378
Mutex myMutex
Mutex which synchronizes only the pointer, not the object pointed to.
Definition: DtNTree.h:275
BoundsType minimum
Definition: DtNTree.h:147
std::shared_ptr< DtNTree > getPtr(DtNTree &tree, Query &query)
Get or create the tree for this subcell.
Definition: DtNTree.h:227
Range myRanges[Dimensions]
Definition: DtNTree.h:216