Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions | Protected Member Functions
itk::PSMPointTree< VDimension > Class Template Reference

#include <itkPSMPointTree.h>

+ Inheritance diagram for itk::PSMPointTree< VDimension >:
+ Collaboration diagram for itk::PSMPointTree< VDimension >:

Public Types

typedef PSMPointTree Self
 
typedef DataObject Superclass
 
typedef SmartPointer< SelfPointer
 
typedef SmartPointer< const SelfConstPointer
 
typedef WeakPointer< const SelfConstWeakPointer
 
typedef PSMPointTreeNode< VDimension > NodeType
 
typedef NodeType::Pointer NodePointerType
 
typedef PSMPointTreeNode< VDimension >::PointType PointType
 
typedef NodeType::PointListType PointListType
 
typedef std::vector< typename PointListType::const_iterator > PointIteratorListType
 

Public Member Functions

 itkNewMacro (Self)
 
 itkTypeMacro (PSMPointTree, DataObject)
 
 itkStaticConstMacro (Dimension, unsigned int, VDimension)
 
 itkStaticConstMacro (BranchesPerNode, int,(powstruct< 2, VDimension >::c))
 
 itkGetMacro (Depth, unsigned int)
 
void ConstructTree (const PointType &, const PointType &, unsigned int)
 
PointIteratorListType FindPointsInRegion (const PointType &, const PointType &) const
 
unsigned int FindPointsInRegion (const PointType &, const PointType &, PointIteratorListType &) const
 
NodePointerType GetNode (const PointType &)
 
const NodePointerType GetNode (const PointType &) const
 
 itkGetObjectMacro (Root, NodeType)
 
 itkSetObjectMacro (Root, NodeType)
 
PointListType::iterator AddPoint (const PointType &, unsigned int, NodePointerType &)
 
PointListType::iterator AddPoint (const PointType &p, unsigned int i)
 
bool Overlap (const NodePointerType &, const PointType &, const PointType &) const
 
bool RegionContains (const PointType &p, const PointType &lowerbound, const PointType &upperbound) const
 
void PrintSelf (std::ostream &os, Indent indent) const
 

Protected Member Functions

void BranchNode (NodePointerType &, unsigned int)
 
void FindOneNodeInRegion (const NodePointerType &, const PointType &, const PointType &, PointIteratorListType &) const
 

Detailed Description

template<unsigned int VDimension>
class itk::PSMPointTree< VDimension >

A tree data container, templated over node type, whose nodes are associated with bounding boxes in a rectangular domain, and that has 2^D branches at each node, where D is the dimensionality of the domain. In 2D this is a quad-tree, and in 3D this is an octree, etc. The tree is constructed by specifying a region and a tree depth, then calling ConstructTree(). This class was designed for use as a multidimensional quad/octree binning structure for itkPSMNeighborhood classes.

Definition at line 174 of file itkPSMPointTree.h.

Member Typedef Documentation

template<unsigned int VDimension>
typedef NodeType::Pointer itk::PSMPointTree< VDimension >::NodePointerType

The real node type, which is a actually pointer to what we are calling NodeTypes.

Definition at line 188 of file itkPSMPointTree.h.

template<unsigned int VDimension>
typedef PSMPointTreeNode<VDimension> itk::PSMPointTree< VDimension >::NodeType

Shorthand for the object pointed to by each node.

Definition at line 185 of file itkPSMPointTree.h.

template<unsigned int VDimension>
typedef NodeType::PointListType itk::PSMPointTree< VDimension >::PointListType

Types defined by the NodeType.

Definition at line 194 of file itkPSMPointTree.h.

template<unsigned int VDimension>
typedef PSMPointTreeNode<VDimension>::PointType itk::PSMPointTree< VDimension >::PointType

Point type used by nodes for upper and lower bounds.

Definition at line 191 of file itkPSMPointTree.h.

template<unsigned int VDimension>
typedef PSMPointTree itk::PSMPointTree< VDimension >::Self

Standard class typedefs

Definition at line 178 of file itkPSMPointTree.h.

Member Function Documentation

template<unsigned int VDimension>
PSMPointTree< VDimension >::PointListType::iterator itk::PSMPointTree< VDimension >::AddPoint ( const PointType point,
unsigned int  idx,
NodePointerType node 
)

Associates a point and, optionally, an index with the appropriate leaf node. This method starts at the root of the tree and uses the Contains method to query branches at each node, following the first branch it finds whose bounding box contains this point. When it reaches a leaf node, the point is added to that node's list, along with the specified index (if any). This method returns an iterator pointing to the new list element (e.g., for quick deletion or reference of the point) and, optionally, will set a given smart pointer to point to the leaf node. If the specified point is not contained within the domain, then this method will throw an exception.

Definition at line 121 of file itkPSMPointTree.hxx.

124  {
125  NodePointerType it = this->m_Root;
126 
127  if ( ! it->Contains(point))
128  {
129  itkExceptionMacro("Point " << point << " is not contained within tree domain " << it->GetLowerBound() << " - " << it->GetUpperBound());
130  }
131 
132  while (! it->IsLeaf() )
133  {
134  for (unsigned int i = 0; i < BranchesPerNode; i++)
135  {
136  if (it->GetBranch(i)->Contains(point))
137  {
138  it = it->GetBranch(i);
139  break;
140  }
141  }
142  }
143  node = it;
144  return it->InsertElement( PSMPointIndexPair<VDimension>(point, idx) );
145  }
NodeType::Pointer NodePointerType
template<unsigned int VDimension>
void itk::PSMPointTree< VDimension >::BranchNode ( NodePointerType parent,
unsigned int  level 
)
protected

Add the appropriate number of empty child nodes to a given node. The second parameter is the level in the tree.

Definition at line 162 of file itkPSMPointTree.hxx.

164  {
165  // Called from a leaf node.
166  if (level > m_Depth) return;
167 
168  PointType midpoint, upper, lower;
169  int thresh[VDimension];
170  for (unsigned int dim = 0; dim < VDimension; dim++)
171  {
172  thresh[dim] = 1;
173  midpoint[dim] = ( parent->GetLowerBound()[dim] + parent->GetUpperBound()[dim] ) / 2.0;
174  }
175 
176  for (unsigned int b = 0; b < BranchesPerNode; b++)
177  {
178  for (unsigned int dim = 0; dim < VDimension; dim++)
179  {
180  // toggle use low/high lower and upper bounds
181  if ( b % ( static_cast<unsigned int>(pow(2.0, (int)dim)) ) == 0 )
182  { thresh[dim] = 1 - thresh[dim]; }
183 
184  if ( thresh[dim] == 0 )
185  {
186  lower[dim] = parent->GetLowerBound()[dim];
187  upper[dim] = midpoint[dim];
188  }
189  else
190  {
191  lower[dim] = midpoint[dim];
192  upper[dim] = parent->GetUpperBound()[dim];
193  }
194  }
195 
196  NodePointerType newNode = NodeType::New();
197  newNode->SetLowerBound(lower);
198  newNode->SetUpperBound(upper);
199 
200  parent->SetBranch(b, newNode);
201 
202  this->BranchNode(newNode, level+1);
203  }
204  }
PSMPointTreeNode< VDimension >::PointType PointType
void BranchNode(NodePointerType &, unsigned int)
NodeType::Pointer NodePointerType
template<unsigned int VDimension>
void itk::PSMPointTree< VDimension >::ConstructTree ( const PointType lowerbound,
const PointType upperbound,
unsigned int  depth 
)

Construct the tree to the specified depth. The bounding box of the root node is specified with the lower bound and upper bound points respectively.

Definition at line 148 of file itkPSMPointTree.hxx.

150  {
151  m_Depth = depth;
152 
153  NodePointerType n = NodeType::New();
154  n->SetLowerBound(lowerbound);
155  n->SetUpperBound(upperbound);
156 
157  this->SetRoot(n);
158  this->BranchNode(n, 1);
159  }
void BranchNode(NodePointerType &, unsigned int)
NodeType::Pointer NodePointerType
template<unsigned int VDimension>
void itk::PSMPointTree< VDimension >::FindOneNodeInRegion ( const NodePointerType it,
const PointType lowerbound,
const PointType upperbound,
PointIteratorListType &  pointlist 
) const
protected

Find one of the nodes that overlaps the specified region and appends all of its points to the specified list. The method is used by FindPointsInRegion and is called recursively.

Definition at line 90 of file itkPSMPointTree.hxx.

93  {
94  // If this node is a leaf node, then add to the list if there is overlap.
95  if (it ->IsLeaf())
96  {
97  if ( this->Overlap(it, lowerbound, upperbound) )
98  {
99  // Add all node's points to the list that are within the given region.
100  for (typename PointListType::const_iterator pit = it->GetList().begin();
101  pit != it->GetList().end(); pit++)
102  {
103  if (this->RegionContains(pit->Point, lowerbound, upperbound) )
104  {
105  pointlist.push_back(pit);
106  }
107  }
108  }
109  }
110  else // Otherwise, call this method on each branch.
111  {
112  for (unsigned int i = 0; i < BranchesPerNode; i++)
113  {
114  this->FindOneNodeInRegion(it->GetBranch(i), lowerbound, upperbound, pointlist);
115  }
116  }
117  }
void FindOneNodeInRegion(const NodePointerType &, const PointType &, const PointType &, PointIteratorListType &) const
bool Overlap(const NodePointerType &, const PointType &, const PointType &) const
template<unsigned int VDimension>
PSMPointTree< VDimension >::PointIteratorListType itk::PSMPointTree< VDimension >::FindPointsInRegion ( const PointType lowerbound,
const PointType upperbound 
) const

Return a list of PointListType iterators (effectively pointers to points, see PSMPointTreeNode) to points and their associated indicies that are stored in this tree and are contained within the specified bounding box region. The bounding box is specified with two points, in this order: a lower bound followed by an upper bound.

Definition at line 69 of file itkPSMPointTree.hxx.

70  {
71  PointIteratorListType pointlist;
72  NodePointerType it = this->m_Root;
73 
74  // If no overlap with the root node exists, then return an empty list...
75  if ( this->Overlap(it, lowerbound, upperbound) && ! it->IsLeaf() )
76  {
77  // otherwise, descend into the child nodes and compile the list.
78  for (unsigned int i = 0; i < BranchesPerNode; i++)
79  {
80  this->FindOneNodeInRegion(it->GetBranch(i), lowerbound, upperbound, pointlist);
81  }
82  }
83 
84  return pointlist;
85  }
NodeType::Pointer NodePointerType
void FindOneNodeInRegion(const NodePointerType &, const PointType &, const PointType &, PointIteratorListType &) const
bool Overlap(const NodePointerType &, const PointType &, const PointType &) const
template<unsigned int VDimension>
NodePointerType itk::PSMPointTree< VDimension >::GetNode ( const PointType )

Return the node associated with the domain region that contains the given point.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkGetMacro ( Depth  ,
unsigned  int 
)

Set/Get the depth of the tree. This is the number of levels in the tree.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkGetObjectMacro ( Root  ,
NodeType   
)

Set/Get the root node of the tree.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkNewMacro ( Self  )

Method for creation through the object factory.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkStaticConstMacro ( Dimension  ,
unsigned  int,
VDimension   
)

Dimensionality of the domain.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkStaticConstMacro ( BranchesPerNode  ,
int  ,
(powstruct< 2, VDimension >::c)   
)

Number of children per node.

template<unsigned int VDimension>
itk::PSMPointTree< VDimension >::itkTypeMacro ( PSMPointTree< VDimension >  ,
DataObject   
)

Run-time type information (and related methods).

template<unsigned int VDimension>
bool itk::PSMPointTree< VDimension >::Overlap ( const NodePointerType node,
const PointType lowerbound,
const PointType upperbound 
) const

Returns true if the specified node region overlaps the given region and false otherwise.

Definition at line 49 of file itkPSMPointTree.hxx.

51  {
52  // Check for overlap in all dimensions. If any one dimension has no overlap,
53  // these two regions do not overlap.
54  for (unsigned int i = 0; i < Dimension; i++)
55  {
56  // Does this region contain either node endpoint or does the node region
57  // contain both of this region's endpoints?
58  if (! ((node->GetLowerBound()[i] >= lowerbound[i] && node->GetLowerBound()[i] <= upperbound[i])
59  || (node->GetUpperBound()[i] >= lowerbound[i] && node->GetUpperBound()[i] <= upperbound[i])
60  || (node->GetLowerBound()[i] <= lowerbound[i] && node->GetUpperBound()[i] >= upperbound[i] ) ))
61  return false;
62  }
63  return true;
64  }

The documentation for this class was generated from the following files: