/usr/include/InsightToolkit/Common/itkOctree.txx is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkOctree.txx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkOctree_txx
#define __itkOctree_txx
#include "itkOctree.h"
namespace itk
{
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
Octree<TPixel,ColorTableSize,MappingFunctionType>::
Octree(void): m_Plane(UNKNOWN_PLANE), m_Width(0),m_Depth(0),m_Tree()
{
m_TrueDims[0]=0;
m_TrueDims[1]=1;
m_TrueDims[2]=2;
m_Tree.SetParentOctree(this);
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
Octree<TPixel,ColorTableSize,MappingFunctionType>::
~Octree(void) {/*Nothing to be done here*/};
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
void
Octree<TPixel,ColorTableSize,MappingFunctionType>::
SetTrueDims(const unsigned int Dim0, const unsigned int Dim1,
const unsigned int Dim2)
{
this->m_TrueDims[0]=Dim0;
this->m_TrueDims[1]=Dim1;
this->m_TrueDims[2]=Dim2;
}
/** This is moving bits to get the values of the 8 octants
* Possible values are the 3 bits to be set.
* 0 000 Contains origin
* 1 001
* 2 010
* 3 011
* 4 100
* 5 101
* 6 110
* 7 111 Contains extents
* ....^^^
* ....|| \This value is 1 if requested X voxel is greater than X
* .... centerline of subcube
* ....| \This value is 1 if requested Y voxel is greater than Y
* .......centerline of subcube
* .... \This value is 1 if requested Z voxel is greater than Z centerline
* .......of subcube
* \author Hans J. Johnson, adapted from Vincent A. Magnotta
* \param VoxX The desired voxel
* \param VoxY The desired voxel
* \param VoxZ The desired voxel
* \param CenterLineX The division line between octants
* \param CenterLineY The division line between octants
* \param CenterLineZ The division line between octants
* \return The octant that the voxel falls into.
*/
inline unsigned int OCTREE_OCTANT(const int VoxX, const int CenterLineX,
const int VoxY, const int CenterLineY,
const int VoxZ, const int CenterLineZ)
{
return (
(
(static_cast<unsigned int>(((VoxZ)>=(CenterLineZ)))<<2)
| (static_cast<unsigned int>(((VoxY)>=(CenterLineY)))<<1)
)
| (static_cast<unsigned int>((VoxX)>=(CenterLineX)))
);
}
/**
* \defgroup Octant directional identifying functions
* These functions determine if the directions are in the "lower" or
* "upper" portion of the Octree in the given directions.
* @{
*/
inline unsigned int XF(const unsigned int octantID)
{
return octantID&1; //Just return 1 if 0th bit is a one
}
inline unsigned int YF(const unsigned int octantID)
{
return (octantID>>1)&1; //Just return 1 if 1st bit is a one
}
inline unsigned int ZF(const unsigned int octantID)
{
return (octantID>>2)&1; //Just return 1 if 2nd bit is a one
}
/** @} */ // End of defgroup
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
unsigned int
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetValue(const unsigned int Dim0,
const unsigned int Dim1,
const unsigned int Dim2)
{
if ((Dim2 >= this->m_TrueDims[2]) ||
(Dim1 >= this->m_TrueDims[1]) || (Dim0 >= this->m_TrueDims[0]))
{
return 0;
}
//Define CurrentOctreeNode at the Octree head Node
OctreeNode * CurrentOctreeNode = &m_Tree;
//Define the origin of current OctreeNode
unsigned int ox = 0, oy = 0, oz = 0;
//Define the halfwidth, this will be changed inside of while loop
unsigned int halfwidth = this->m_Width;
while ((CurrentOctreeNode->IsNodeColored()) == false)
{
//NOTE: halfwidth=halfwidth/2 is the same as halfwidth >> 1
halfwidth=halfwidth >> 1;
const unsigned int octantID =
OCTREE_OCTANT (Dim0, ox + halfwidth, Dim1,
oy + halfwidth, Dim2, oz + halfwidth);
//Determine new origin for next child.
ox = ox + XF(octantID) * halfwidth;
oy = oy + YF(octantID) * halfwidth;
oz = oz + ZF(octantID) * halfwidth;
CurrentOctreeNode =
&CurrentOctreeNode->GetChild(static_cast<enum LeafIdentifier>(octantID));
}
return CurrentOctreeNode->GetColor();
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
OctreeNodeBranch *
Octree<TPixel,ColorTableSize,MappingFunctionType>::
maskToOctree (const TPixel* Mask, unsigned width, unsigned x,
unsigned y, unsigned z, unsigned xsize,
unsigned ysize, unsigned zsize)
{
if ((x >= xsize) || (y >= ysize) || (z >= zsize))
{
return reinterpret_cast<OctreeNodeBranch *>(m_ColorTable
+B2_MASKFILE_BLACK);
}
if (width == 1)
{
return reinterpret_cast<OctreeNodeBranch *>
(m_ColorTable + m_MappingFunction.Evaluate(&Mask[z * ysize * xsize + y * xsize + x]));
}
width /= 2;
OctreeNodeBranch *nodeArray[8];
nodeArray[0] = this->maskToOctree (Mask, width, x, y, z,
xsize, ysize, zsize);
nodeArray[1] = this->maskToOctree (Mask, width, x + width, y, z,
xsize, ysize, zsize);
nodeArray[2] = this->maskToOctree (Mask, width, x, y + width, z,
xsize, ysize, zsize);
nodeArray[3] = this->maskToOctree (Mask, width, x + width, y + width, z,
xsize, ysize, zsize);
nodeArray[4] = this->maskToOctree (Mask, width, x, y, z + width,
xsize, ysize, zsize);
nodeArray[5] = this->maskToOctree (Mask, width, x + width, y, z + width,
xsize, ysize, zsize);
nodeArray[6] = this->maskToOctree (Mask, width, x, y + width, z + width,
xsize, ysize, zsize);
nodeArray[7] = this->maskToOctree (Mask, width, x + width, y + width,
z + width, xsize, ysize, zsize);
if((nodeArray[0] == nodeArray[1]) &&
(nodeArray[0] == nodeArray[2]) &&
(nodeArray[0] == nodeArray[3]) &&
(nodeArray[0] == nodeArray[4]) &&
(nodeArray[0] == nodeArray[5]) &&
(nodeArray[0] == nodeArray[6]) &&
(nodeArray[0] == nodeArray[7]))
{
return nodeArray[0];
}
else
{
OctreeNodeBranch *q = new OctreeNodeBranch(this);
OctreeNode *newbranch;
newbranch = q->GetLeaf(ZERO);
newbranch->SetBranch(nodeArray[ZERO]);
newbranch = q->GetLeaf(ONE);
newbranch->SetBranch(nodeArray[ONE]);
newbranch = q->GetLeaf(TWO);
newbranch->SetBranch(nodeArray[TWO]);
newbranch = q->GetLeaf(THREE);
newbranch->SetBranch(nodeArray[THREE]);
newbranch = q->GetLeaf(FOUR);
newbranch->SetBranch(nodeArray[FOUR]);
newbranch = q->GetLeaf(FIVE);
newbranch->SetBranch(nodeArray[FIVE]);
newbranch = q->GetLeaf(SIX);
newbranch->SetBranch(nodeArray[SIX]);
newbranch = q->GetLeaf(SEVEN);
newbranch->SetBranch(nodeArray[SEVEN]);
return (q);
}
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
void
Octree<TPixel,ColorTableSize,MappingFunctionType>::
BuildFromBuffer(const void *frombuffer,const int xsize,const int ysize,const int zsize)
{
unsigned maxSize = xsize >= ysize ?
(xsize >= zsize ? xsize : zsize) :
(ysize >= zsize ? ysize : zsize);
unsigned width = 1;
unsigned depth = 0;
while(width < maxSize)
{
width *= 2;
depth++;
}
this->SetDepth(depth);
this->SetWidth(width);
m_TrueDims[0] = xsize;
m_TrueDims[1] = ysize;
m_TrueDims[2] = zsize;
const TPixel *bufcast = static_cast<const TPixel *>(frombuffer);
OctreeNodeBranch *branch =
this->maskToOctree(bufcast,width,0,0,0,
xsize,ysize,zsize);
m_Tree.SetBranch(branch);
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
void
Octree<TPixel,ColorTableSize,MappingFunctionType>::
BuildFromImage(ImageType *fromImage)
{
const typename Image<TPixel,3>::RegionType ®ion =
fromImage->GetLargestPossibleRegion();
unsigned int xsize,ysize,zsize;
xsize = region.GetSize(0);
ysize = region.GetSize(1);
zsize = region.GetSize(2);
this->BuildFromBuffer(static_cast<void *>(fromImage->GetBufferPointer()),
xsize,ysize,zsize);
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
typename Octree<TPixel,ColorTableSize,MappingFunctionType>::ImageTypePointer
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetImage()
{
unsigned int i,j,k;
typename ImageType::SizeType imageSize = {{0,0,0}};
typedef typename ImageType::SizeType::SizeValueType SizeValueType;
SizeValueType sizes[3];
sizes[0] = m_TrueDims[0];
sizes[1] = m_TrueDims[1];
sizes[2] = m_TrueDims[2];
imageSize.SetSize(sizes);
const typename ImageType::IndexType imageIndex = {{0,0,0}};
typename ImageType::RegionType region;
region.SetSize(imageSize);
region.SetIndex(imageIndex);
typename ImageType::Pointer img = ImageType::New();
img->SetLargestPossibleRegion(region);
img->SetBufferedRegion(region);
img->SetRequestedRegion(region);
img->Allocate();
typename ImageType::IndexType setIndex;
for(i = 0; i < m_TrueDims[0]; i++)
{
setIndex[0] = i;
for(j = 0; j < m_TrueDims[0]; j++)
{
setIndex[1] = j;
for(k = 0; k < m_TrueDims[0]; k++)
{
setIndex[2] = k;
img->SetPixel(setIndex,(TPixel)this->GetValue(i,j,k));
}
}
}
return img;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
OctreeNode *
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetTree()
{
return &m_Tree;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
void
Octree<TPixel,ColorTableSize,MappingFunctionType>::
SetWidth(unsigned int width)
{
m_Width = width;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
void
Octree<TPixel,ColorTableSize,MappingFunctionType>::
SetDepth(unsigned int depth)
{
m_Depth = depth;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
unsigned int
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetWidth()
{
return m_Width;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
unsigned int
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetDepth()
{
return m_Depth;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
const char *
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetColorTable() const
{
return m_ColorTable;
}
template <class TPixel,unsigned int ColorTableSize,class MappingFunctionType>
int
Octree<TPixel,ColorTableSize,MappingFunctionType>::
GetColorTableSize() const
{
return ColorTableSize;
}
}
#endif
|