| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkImageRegionSplitter.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:39 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
DEF |
#ifndef _itkImageRegionSplitter_txx |
| 18 |
DEF |
#define _itkImageRegionSplitter_txx |
| 19 |
|
#include "itkImageRegionSplitter.h" |
| 20 |
|
#include <math.h> |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
/** |
| 26 |
|
* |
| 27 |
|
*/ |
| 28 |
|
template <unsigned int VImageDimension> |
| 29 |
|
unsigned int |
| 30 |
|
ImageRegionSplitter<VImageDimension> |
| 31 |
|
::GetNumberOfSplits(const RegionType ®ion, unsigned int requestedNumber) |
| 32 |
|
{ |
| 33 |
|
int splitAxis; |
| 34 |
|
const SizeType ®ionSize = region.GetSize(); |
| 35 |
|
|
| 36 |
|
// split on the outermost dimension available |
| 37 |
|
splitAxis = VImageDimension - 1; |
| 38 |
|
while (regionSize[splitAxis] == 1) |
| 39 |
|
{ |
| 40 |
|
--splitAxis; |
| 41 |
|
if (splitAxis < 0) |
| 42 |
|
{ // cannot split |
| 43 |
|
itkDebugMacro(" Cannot Split"); |
| 44 |
|
return 1; |
| 45 |
|
} |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
// determine the actual number of pieces that will be generated |
| 49 |
|
SizeValueType range = regionSize[splitAxis]; |
| 50 |
|
int valuesPerPiece = (int)::ceil(range/(double)requestedNumber); |
| 51 |
|
int maxPieceUsed = (int)::ceil(range/(double)valuesPerPiece) - 1; |
| 52 |
|
|
| 53 |
|
return maxPieceUsed + 1; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
/** |
| 58 |
|
* |
| 59 |
|
*/ |
| 60 |
|
template <unsigned int VImageDimension> |
| 61 |
|
ImageRegion<VImageDimension> |
| 62 |
|
ImageRegionSplitter<VImageDimension> |
| 63 |
|
::GetSplit(unsigned int i, unsigned int numberOfPieces, |
| 64 |
|
const RegionType ®ion) |
| 65 |
|
{ |
| 66 |
|
int splitAxis; |
| 67 |
|
RegionType splitRegion; |
| 68 |
|
IndexType splitIndex; |
| 69 |
|
SizeType splitSize, regionSize; |
| 70 |
|
|
| 71 |
|
// Initialize the splitRegion to the requested region |
| 72 |
|
splitRegion = region; |
| 73 |
|
splitIndex = splitRegion.GetIndex(); |
| 74 |
|
splitSize = splitRegion.GetSize(); |
| 75 |
|
|
| 76 |
|
regionSize = region.GetSize(); |
| 77 |
|
|
| 78 |
|
// split on the outermost dimension available |
| 79 |
|
splitAxis = VImageDimension - 1; |
| 80 |
|
while (regionSize[splitAxis] == 1) |
| 81 |
|
{ |
| 82 |
|
--splitAxis; |
| 83 |
|
if (splitAxis < 0) |
| 84 |
|
{ // cannot split |
| 85 |
|
itkDebugMacro(" Cannot Split"); |
| 86 |
|
return splitRegion; |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
// determine the actual number of pieces that will be generated |
| 91 |
|
SizeValueType range = regionSize[splitAxis]; |
| 92 |
|
int valuesPerPiece = (int)::ceil(range/(double)numberOfPieces); |
| 93 |
|
int maxPieceUsed = (int)::ceil(range/(double)valuesPerPiece) - 1; |
| 94 |
|
|
| 95 |
|
// Split the region |
| 96 |
|
if ((int) i < maxPieceUsed) |
| 97 |
|
{ |
| 98 |
|
splitIndex[splitAxis] += i*valuesPerPiece; |
| 99 |
|
splitSize[splitAxis] = valuesPerPiece; |
| 100 |
|
} |
| 101 |
|
if ((int) i == maxPieceUsed) |
| 102 |
|
{ |
| 103 |
|
splitIndex[splitAxis] += i*valuesPerPiece; |
| 104 |
|
// last piece needs to process the "rest" dimension being split |
| 105 |
|
splitSize[splitAxis] = splitSize[splitAxis] - i*valuesPerPiece; |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
// set the split region ivars |
| 109 |
|
splitRegion.SetIndex( splitIndex ); |
| 110 |
|
splitRegion.SetSize( splitSize ); |
| 111 |
|
|
| 112 |
|
itkDebugMacro(" Split Piece: " << splitRegion ); |
| 113 |
|
|
| 114 |
|
return splitRegion; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
/** |
| 120 |
|
* |
| 121 |
|
*/ |
| 122 |
|
template <unsigned int VImageDimension> |
| 123 |
|
void |
| 124 |
|
ImageRegionSplitter<VImageDimension> |
| 125 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 126 |
|
{ |
| 127 |
|
Superclass::PrintSelf(os,indent); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
} // end namespace itk |
| 132 |
|
|
| 133 |
|
#endif |
| 134 |
|
|