|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright Insight Software Consortium |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | +#ifndef __itkImageRegionSplitterBase_h |
| 19 | +#define __itkImageRegionSplitterBase_h |
| 20 | + |
| 21 | +#include "itkImageRegion.h" |
| 22 | +#include "itkObjectFactory.h" |
| 23 | + |
| 24 | +namespace itk |
| 25 | +{ |
| 26 | + |
| 27 | +/** \class ImageRegionSplitterBase |
| 28 | + * \brief Divide an image region into several pieces. |
| 29 | + * |
| 30 | + * ImageRegionSplitterBase is an abstract interface to divides an |
| 31 | + * ImageRegion into smaller regions. ImageRegionSplitterBase is used |
| 32 | + * by the ImageSource, StreamingImageFilter, streaming ImageIO |
| 33 | + * classes to divide a region into a series of smaller subregions. |
| 34 | + * |
| 35 | + * This object has two basic methods: \c GetNumberOfSplits() and |
| 36 | + * \c GetSplit(). |
| 37 | + * |
| 38 | + * \c GetNumberOfSplits() is used to determine how may subregions a given |
| 39 | + * region can be divided. You call GetNumberOfSplits with an argument |
| 40 | + * that is the number of subregions you want. If the image region can |
| 41 | + * support that number of subregions, that number is returned. |
| 42 | + * Otherwise, the maximum number of splits less then or equal to the |
| 43 | + * argumen be returned. For example, if a region splitter class only divides |
| 44 | + * a region into horizontal slabs, then the maximum number of splits |
| 45 | + * will be the number of rows in the region. |
| 46 | + * |
| 47 | + * \c GetSplit() returns the ith of N subregions (as an ImageRegion object). |
| 48 | + * |
| 49 | + * \sa ImageRegionSplitterDirection |
| 50 | + * \sa ImageRegionSplitterSlowDimension |
| 51 | + * |
| 52 | + * \ingroup ITKSystemObjects |
| 53 | + * \ingroup DataProcessing |
| 54 | + * \ingroup ITKCommon |
| 55 | + */ |
| 56 | + |
| 57 | +class ITKCommon_EXPORT ImageRegionSplitterBase |
| 58 | + :public Object |
| 59 | +{ |
| 60 | +public: |
| 61 | + /** Standard class typedefs. */ |
| 62 | + typedef ImageRegionSplitterBase Self; |
| 63 | + typedef Object Superclass; |
| 64 | + typedef SmartPointer< Self > Pointer; |
| 65 | + typedef SmartPointer< const Self > ConstPointer; |
| 66 | + |
| 67 | + /** Run-time type information (and related methods). */ |
| 68 | + itkTypeMacro(ImageRegionSplitterBase, Object); |
| 69 | + |
| 70 | + /** How many pieces can the specified region be split? A given region |
| 71 | + * cannot always be divided into the requested number of pieces. For |
| 72 | + * instance, if the \c numberOfPieces exceeds the number of pixels along |
| 73 | + * a certain dimensions, then some splits will not be possible. This |
| 74 | + * method returns a number less than or equal to the requested number |
| 75 | + * of pieces. */ |
| 76 | + template <unsigned int VImageDimension> |
| 77 | + unsigned int GetNumberOfSplits(const ImageRegion<VImageDimension> & region, |
| 78 | + unsigned int requestedNumber) const |
| 79 | + { |
| 80 | + return this->GetNumberOfSplitsInternal( VImageDimension, |
| 81 | + region.GetIndex().m_Index, |
| 82 | + region.GetSize().m_Size, |
| 83 | + requestedNumber); |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + /** \brief Get a region definition that represents the ith piece a |
| 88 | + * specified region. |
| 89 | + * |
| 90 | + * The \c numberOfPieces must be equal to what \c GetNumberOfSplits() |
| 91 | + * returns. The return value is the maximum number of splits |
| 92 | + * available. If \c i is greater than or equal to the return value |
| 93 | + * the value of the region is undefined. |
| 94 | + */ |
| 95 | + template <unsigned int VImageDimension> |
| 96 | + unsigned int GetSplit( unsigned int i, |
| 97 | + unsigned int numberOfPieces, |
| 98 | + ImageRegion<VImageDimension> & region ) const |
| 99 | + { |
| 100 | + return this->GetSplitInternal( VImageDimension, |
| 101 | + i, |
| 102 | + numberOfPieces, |
| 103 | + region.GetModifiableIndex().m_Index, |
| 104 | + region.GetModifiableSize().m_Size ); |
| 105 | + } |
| 106 | + |
| 107 | +protected: |
| 108 | + ImageRegionSplitterBase(); |
| 109 | + |
| 110 | + /** Templetless method to compute the number of possible splits for |
| 111 | + * any number of dimensions. */ |
| 112 | + virtual unsigned int GetNumberOfSplitsInternal( unsigned int dim, |
| 113 | + const IndexValueType regionIndex[], |
| 114 | + const SizeValueType regionSize[], |
| 115 | + unsigned int requestedNumber ) const = 0; |
| 116 | + |
| 117 | + /** Templetless method to compute an actual split for any number of |
| 118 | + * dimensions. \c dim is the size of the \c regionIndex and \c |
| 119 | + * regionSize arrays. |
| 120 | + */ |
| 121 | + virtual unsigned int GetSplitInternal( unsigned int dim, |
| 122 | + unsigned int i, |
| 123 | + unsigned int numberOfPieces, |
| 124 | + IndexValueType regionIndex[], |
| 125 | + SizeValueType regionSize[] ) const = 0; |
| 126 | + |
| 127 | + void PrintSelf(std::ostream & os, Indent indent) const; |
| 128 | + |
| 129 | +private: |
| 130 | + ImageRegionSplitterBase(const ImageRegionSplitterBase &); //purposely not implemented |
| 131 | + void operator=(const ImageRegionSplitterBase &); //purposely not implemented |
| 132 | +}; |
| 133 | +} // end namespace itk |
| 134 | + |
| 135 | +#endif |
0 commit comments