| 1 |
LEN,HRD |
/*!\verbatim***************************** MH-CRC IPL ****************************************** |
| 2 |
|
* Iowa MH-CRC IPL C++ Source File |
| 3 |
|
* Copyright (C) 2002 Iowa Mental Health Clinical Research Center |
| 4 |
|
* \endverbatim |
| 5 |
|
* \file itkOctree.cxx |
| 6 |
|
* \author Hans J. Johnson |
| 7 |
|
* \brief Implements member functions for OctreeNode Classes |
| 8 |
LEN,DEF |
*****************************************************************************************/ |
| 9 |
|
/* Local Include Files */ |
| 10 |
|
#include "itkOctree.h" |
| 11 |
HRD |
#include "itkOctreeNode.h" |
| 12 |
|
|
| 13 |
|
namespace itk { |
| 14 |
|
|
| 15 |
|
|
| 16 |
HRD |
/* |
| 17 |
LEN |
* ==================================================================================== |
| 18 |
LEN |
* ==================================================================================== |
| 19 |
LEN,IND |
****** ==================================================================================== |
| 20 |
IND |
******/ |
| 21 |
|
OctreeNode::OctreeNode(void) |
| 22 |
|
{ |
| 23 |
|
m_Parent = 0; |
| 24 |
|
m_Branch = 0; |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
OctreeNode::~OctreeNode(void) |
| 28 |
|
{ |
| 29 |
|
this->RemoveChildren(); |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
OctreeNode & OctreeNode::GetChild(const enum LeafIdentifier ChildID) const |
| 33 |
|
{ |
| 34 |
|
return *m_Branch->GetLeaf(ChildID); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
OctreeNode & OctreeNode::GetChild(const enum LeafIdentifier ChildID) |
| 38 |
|
{ |
| 39 |
|
return *m_Branch->GetLeaf(ChildID); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
int OctreeNode::GetColor(void) const |
| 43 |
|
{ |
| 44 |
|
int x = reinterpret_cast<const char *>(m_Branch) - m_Parent->GetColorTable(); |
| 45 |
|
// |
| 46 |
|
// you'll want to indicate that the branch |
| 47 |
|
// is a subtree and not in fact a color. |
| 48 |
|
if(x >= 0 && x < m_Parent->GetColorTableSize()) |
| 49 |
IND |
****return x; |
| 50 |
|
return -1; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
void OctreeNode::SetColor(int color) |
| 54 |
|
{ |
| 55 |
|
this->RemoveChildren(); |
| 56 |
|
m_Branch = reinterpret_cast<OctreeNodeBranch *> |
| 57 |
IND |
****(const_cast<char *>(m_Parent->GetColorTable()) + color); |
| 58 |
|
return; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
void OctreeNode::SetBranch(OctreeNodeBranch * NewBranch) |
| 62 |
|
{ |
| 63 |
|
this->RemoveChildren(); |
| 64 |
|
m_Branch=NewBranch; |
| 65 |
|
return; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
/** |
| 69 |
|
* \brief Determines if the current node is colored |
| 70 |
|
* \param void |
| 71 |
|
* \return bool true if this node is colored |
| 72 |
|
*/ |
| 73 |
|
bool OctreeNode::IsNodeColored(void) const |
| 74 |
|
{ |
| 75 |
|
const char *colorTable = m_Parent->GetColorTable(); |
| 76 |
|
const OctreeNodeBranch *first = |
| 77 |
IND |
****reinterpret_cast<const OctreeNodeBranch *>(&(colorTable[0])); |
| 78 |
|
const OctreeNodeBranch *last = |
| 79 |
LEN,IND |
****reinterpret_cast<const OctreeNodeBranch *>(&(colorTable[m_Parent->GetColorTableSize()-1])); |
| 80 |
|
if(this->m_Branch >= first && this->m_Branch <= last) |
| 81 |
|
return true; |
| 82 |
|
return false; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
void OctreeNode::RemoveChildren(void) |
| 86 |
|
{ |
| 87 |
|
if(m_Branch != 0 && !this->IsNodeColored()) |
| 88 |
|
{ |
| 89 |
|
delete m_Branch; |
| 90 |
|
m_Branch = reinterpret_cast<OctreeNodeBranch *> |
| 91 |
IND |
******(&(const_cast<char *>(m_Parent->GetColorTable())[0])); |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
|
| 96 |
EML |
|
| 97 |
|
} //End of itk Namespace |
| 98 |
|
|