#pragma once#include"itkParticlePointIndexPair.h"#include"itkLightObject.h"#include"itkDataObject.h"#include"itkWeakPointer.h"#include"itkTreeContainer.h"#include"itkPoint.h"#include<list>namespaceitk{template<inta,intb>structpowstruct{staticconstintc=a*powstruct<a,b-1>::c;};template<inta>structpowstruct<a,0>{staticconstintc=1;};template<unsignedintVDimension>classPowerOfTwoPointTreeNode:publicLightObject{public:typedefPowerOfTwoPointTreeNodeSelf;typedefSmartPointer<Self>Pointer;typedefSmartPointer<constSelf>ConstPointer;typedefLightObjectSuperclass;itkTypeMacro(PowerOfTwoPointTreeNode,LightObject);itkNewMacro(Self);itkStaticConstMacro(BranchesPerNode,int,(powstruct<2,VDimension>::c));typedefPoint<double,VDimension>PointType;typedefstd::list<ParticlePointIndexPair<VDimension>>PointListType;booloperator==(constPowerOfTwoPointTreeNode&o)const{if((m_LowerBound==o.m_LowerBound)&&(m_UpperBound==o.m_UpperBound))returntrue;elsereturnfalse;}boolIsLeaf()const{if(m_Branches[0].GetPointer()!=0)returnfalse;elsereturntrue;}typenamePointListType::iteratorInsertElement(constParticlePointIndexPair<VDimension>&elem){returnm_List.insert(m_List.end(),elem);}boolContains(constPointType&p)const{for(unsignedinti=0;i<VDimension;i++){if(p[i]<m_LowerBound[i]||p[i]>m_UpperBound[i])returnfalse;}returntrue;}voidSetLowerBound(constPointType&p){m_LowerBound=p;}constPointType&GetLowerBound()const{returnm_LowerBound;}voidSetUpperBound(constPointType&p){m_UpperBound=p;}constPointType&GetUpperBound()const{returnm_UpperBound;}typenameSelf::Pointer*GetBranches(){returnm_Branches;}consttypenameSelf::Pointer*GetBranches()const{returnm_Branches;}typenameSelf::Pointer&GetBranch(unsignedinti){returnm_Branches[i];}consttypenameSelf::Pointer&GetBranch(unsignedinti)const{returnm_Branches[i];}voidSetBranch(unsignedintb,typenameSelf::Pointern){this->GetBranch(b)=n;}voidPrintSelf(std::ostream&os,Indentindent)const;constPointListType&GetList()const{returnm_List;}PointListType&GetList(){returnm_List;}protected:PowerOfTwoPointTreeNode(){}~PowerOfTwoPointTreeNode(){}PowerOfTwoPointTreeNode(constPowerOfTwoPointTreeNode&o);// purposely not implementedconstPowerOfTwoPointTreeNode&operator=(constPowerOfTwoPointTreeNode&o);private:PointTypem_LowerBound;PointTypem_UpperBound;PointListTypem_List;typenameSelf::Pointerm_Branches[powstruct<2,VDimension>::c];};template<unsignedintVDimension>classITK_EXPORTPowerOfTwoPointTree:publicDataObject{public:typedefPowerOfTwoPointTreeSelf;typedefDataObjectSuperclass;typedefSmartPointer<Self>Pointer;typedefSmartPointer<constSelf>ConstPointer;typedefWeakPointer<constSelf>ConstWeakPointer;typedefPowerOfTwoPointTreeNode<VDimension>NodeType;typedeftypenameNodeType::PointerNodePointerType;typedeftypenamePowerOfTwoPointTreeNode<VDimension>::PointTypePointType;typedeftypenameNodeType::PointListTypePointListType;typedefstd::vector<typenamePointListType::const_iterator>PointIteratorListType;itkNewMacro(Self);itkTypeMacro(PowerOfTwoPointTree,DataObject);itkStaticConstMacro(Dimension,unsignedint,VDimension);itkStaticConstMacro(BranchesPerNode,int,(powstruct<2,VDimension>::c));itkGetMacro(Depth,unsignedint);voidConstructTree(constPointType&,constPointType&,unsignedint);PointIteratorListTypeFindPointsInRegion(constPointType&,constPointType&)const;unsignedintFindPointsInRegion(constPointType&,constPointType&,PointIteratorListType&)const;NodePointerTypeGetNode(constPointType&);constNodePointerTypeGetNode(constPointType&)const;itkGetObjectMacro(Root,NodeType);itkSetObjectMacro(Root,NodeType);typenamePointListType::iteratorAddPoint(constPointType&,unsignedint,NodePointerType&);typenamePointListType::iteratorAddPoint(constPointType&p,unsignedinti){NodePointerTypenode=NodeType::New();returnthis->AddPoint(p,i,node);}boolOverlap(constNodePointerType&,constPointType&,constPointType&)const;inlineboolRegionContains(constPointType&p,constPointType&lowerbound,constPointType&upperbound)const{for(unsignedinti=0;i<VDimension;i++){if(p[i]<lowerbound[i]||p[i]>=upperbound[i])returnfalse;}returntrue;}voidPrintSelf(std::ostream&os,Indentindent)const;protected:PowerOfTwoPointTree(){m_Depth=0;}virtual~PowerOfTwoPointTree(){}voidBranchNode(NodePointerType&,unsignedint);voidFindOneNodeInRegion(constNodePointerType&,constPointType&,constPointType&,PointIteratorListType&)const;private:PowerOfTwoPointTree(constSelf&);//purposely not implementedvoidoperator=(constSelf&);//purposely not implementedNodePointerTypem_Root;unsignedintm_Depth;};}// end namespace itk#include"itkPowerOfTwoPointTree.txx"