18 #ifndef __itkPSMPointTree_hxx 19 #define __itkPSMPointTree_hxx 20 #include "itkPSMPointTree.h" 27 template <
unsigned int VDimension>
28 void PSMPointTreeNode<VDimension>
29 ::PrintSelf(std::ostream& os, Indent indent)
const 31 os << indent <<
"PSMPointTreeNode: ";
32 os <<
"m_LowerBound = " << m_LowerBound;
33 os <<
"\tm_UpperBound = " << m_UpperBound;
34 os <<
"\tBranchesPerNode = " << BranchesPerNode;
35 os <<
"\tIsLeaf() = " << this->IsLeaf() << std::endl;
37 for (
typename PointListType::const_iterator it = m_List.begin();
38 it != m_List.end(); it++)
39 { os <<
"\t (" << it->Index <<
", " << it->Point <<
")" << std::endl; }
41 for (
unsigned int i = 0; i < BranchesPerNode; i++)
43 if (m_Branches[i].GetPointer() != 0) m_Branches[i]->PrintSelf(os, indent);
47 template <
unsigned int VDimension>
54 for (
unsigned int i = 0; i < Dimension; i++)
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] ) ))
66 template <
unsigned int VDimension>
67 typename PSMPointTree<VDimension>::PointIteratorListType
71 PointIteratorListType pointlist;
75 if ( this->Overlap(it, lowerbound, upperbound) && ! it->IsLeaf() )
78 for (
unsigned int i = 0; i < BranchesPerNode; i++)
80 this->FindOneNodeInRegion(it->GetBranch(i), lowerbound, upperbound, pointlist);
87 template <
unsigned int VDimension>
92 PointIteratorListType &pointlist)
const 97 if ( this->Overlap(it, lowerbound, upperbound) )
100 for (
typename PointListType::const_iterator pit = it->GetList().begin();
101 pit != it->GetList().end(); pit++)
103 if (this->RegionContains(pit->Point, lowerbound, upperbound) )
105 pointlist.push_back(pit);
112 for (
unsigned int i = 0; i < BranchesPerNode; i++)
114 this->FindOneNodeInRegion(it->GetBranch(i), lowerbound, upperbound, pointlist);
119 template <
unsigned int VDimension>
127 if ( ! it->Contains(point))
129 itkExceptionMacro(
"Point " << point <<
" is not contained within tree domain " << it->GetLowerBound() <<
" - " << it->GetUpperBound());
132 while (! it->IsLeaf() )
134 for (
unsigned int i = 0; i < BranchesPerNode; i++)
136 if (it->GetBranch(i)->Contains(point))
138 it = it->GetBranch(i);
147 template <
unsigned int VDimension>
149 const PointType &upperbound,
unsigned int depth)
154 n->SetLowerBound(lowerbound);
155 n->SetUpperBound(upperbound);
158 this->BranchNode(n, 1);
161 template <
unsigned int VDimension>
166 if (level > m_Depth)
return;
169 int thresh[VDimension];
170 for (
unsigned int dim = 0; dim < VDimension; dim++)
173 midpoint[dim] = ( parent->GetLowerBound()[dim] + parent->GetUpperBound()[dim] ) / 2.0;
176 for (
unsigned int b = 0; b < BranchesPerNode; b++)
178 for (
unsigned int dim = 0; dim < VDimension; dim++)
181 if ( b % ( static_cast<unsigned int>(pow(2.0, (
int)dim)) ) == 0 )
182 { thresh[dim] = 1 - thresh[dim]; }
184 if ( thresh[dim] == 0 )
186 lower[dim] = parent->GetLowerBound()[dim];
187 upper[dim] = midpoint[dim];
191 lower[dim] = midpoint[dim];
192 upper[dim] = parent->GetUpperBound()[dim];
197 newNode->SetLowerBound(lower);
198 newNode->SetUpperBound(upper);
200 parent->SetBranch(b, newNode);
202 this->BranchNode(newNode, level+1);
206 template <
unsigned int VDimension>
209 os << indent <<
"BranchesPerNode = " << BranchesPerNode << std::endl;
210 os << indent <<
"m_Depth = " << m_Depth << std::endl;
211 os << indent <<
"m_Root: ";
212 m_Root->PrintSelf(os, indent);
213 Superclass::PrintSelf(os, indent);
void BranchNode(NodePointerType &, unsigned int)
Struct containing a Point and an index value associated with a point. This object is used mainly by P...
NodeType::Pointer NodePointerType
void FindOneNodeInRegion(const NodePointerType &, const PointType &, const PointType &, PointIteratorListType &) const
PointListType::iterator AddPoint(const PointType &, unsigned int, NodePointerType &)
void ConstructTree(const PointType &, const PointType &, unsigned int)
PointIteratorListType FindPointsInRegion(const PointType &, const PointType &) const