/usr/include/InsightToolkit/Common/itkImageRegionMultidimensionalSplitter.txx is in libinsighttoolkit3-dev 3.20.1+git20120521-6build1.
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 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkImageRegionMultidimensionalSplitter.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 __itkImageRegionMultidimensionalSplitter_txx
#define __itkImageRegionMultidimensionalSplitter_txx
#include "itkImageRegionMultidimensionalSplitter.h"
#include <math.h>
namespace itk
{
/**
*
*/
template <unsigned int VImageDimension>
unsigned int
ImageRegionMultidimensionalSplitter<VImageDimension>
::GetNumberOfSplits(const RegionType ®ion, unsigned int requestedNumber)
{
const SizeType ®ionSize = region.GetSize();
// requested number of splits per dimension
double splitsPerDimension =
vcl_ceil( vcl_pow((double) requestedNumber, 1.0/(double) VImageDimension));
// if a given dimension has fewer pixels that splitsPerDimension, then
// only split number of pixels times
unsigned int i, numPieces;
numPieces = 1;
for (i=0; i < VImageDimension; ++i)
{
if (regionSize[i] < splitsPerDimension)
{
numPieces *= regionSize[i];
}
else
{
numPieces *= (unsigned int) splitsPerDimension;
}
}
return numPieces;
}
/**
*
*/
template <unsigned int VImageDimension>
ImageRegion<VImageDimension>
ImageRegionMultidimensionalSplitter<VImageDimension>
::GetSplit(unsigned int i, unsigned int numberOfPieces,
const RegionType ®ion)
{
RegionType splitRegion;
IndexType splitIndex;
SizeType splitSize, regionSize;
// Initialize the splitRegion to the requested region
splitRegion = region;
splitIndex = splitRegion.GetIndex();
splitSize = splitRegion.GetSize();
regionSize = region.GetSize();
// requested number of splits per dimension
double splitsPerDimension =
vcl_ceil( vcl_pow((double) numberOfPieces, 1.0/(double) VImageDimension));
// if a given dimension has fewer pixels that splitsPerDimension, then
// only split number of pixels times
unsigned int splits[VImageDimension], pixelsPerSplit[VImageDimension];
unsigned int j, numPieces;
unsigned int ijk[VImageDimension];
unsigned int offsetTable[VImageDimension];
numPieces = 1;
for (j=0; j < VImageDimension; ++j)
{
offsetTable[j] = numPieces;
if (regionSize[j] < splitsPerDimension)
{
splits[j] = regionSize[j];
pixelsPerSplit[j] = 1;
numPieces *= regionSize[j];
}
else
{
splits[j] = (unsigned int) splitsPerDimension;
pixelsPerSplit[j] = Math::Ceil<unsigned int>( regionSize[j] / (double) splits[j] );
numPieces *= (unsigned int) splitsPerDimension;
}
}
// determine which split we are in
unsigned int offset = i;
for (j=VImageDimension-1; j > 0; j--)
{
ijk[j] = offset / offsetTable[j];
offset -= (ijk[j] * offsetTable[j]);
}
ijk[0] = offset;
// compute the split
for (j=0; j < VImageDimension; j++)
{
splitIndex[j] += ijk[j]*pixelsPerSplit[j];
if (ijk[j] < splits[j] - 1)
{
splitSize[j] = pixelsPerSplit[j];
}
else
{
// this dimension is falling off the edge of the image
splitSize[j] = splitSize[j] - ijk[j]*pixelsPerSplit[j];
}
}
// set the split region ivars
splitRegion.SetIndex( splitIndex );
splitRegion.SetSize( splitSize );
itkDebugMacro(" Split Piece: " << std::endl << splitRegion );
return splitRegion;
}
/**
*
*/
template <unsigned int VImageDimension>
void
ImageRegionMultidimensionalSplitter<VImageDimension>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
}
} // end namespace itk
#endif
|