| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkDefaultVectorPixelAccessor.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:34 $ |
| 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 |
|
#ifndef __itkDefaultVectorPixelAccessor_h |
| 18 |
|
#define __itkDefaultVectorPixelAccessor_h |
| 19 |
|
|
| 20 |
|
#include "itkMacro.h" |
| 21 |
|
#include "itkVariableLengthVector.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
/** \class DefaultVectorPixelAccessor |
| 27 |
|
* \brief Give access to partial aspects of a type |
| 28 |
|
* |
| 29 |
|
* DefaultVectorPixelAccessor is specifically meant to provide VectorImage |
| 30 |
|
* with the same \c DefaultPixelAccessor interface that |
| 31 |
|
* DefaultPixelAccessor provides to Image. |
| 32 |
|
* |
| 33 |
|
* The template paramters is the type that is contained in by the elements of |
| 34 |
|
* a vector. |
| 35 |
|
* |
| 36 |
LEN |
* The class also contains a m_VectorLength paramter, set with the SetVectorLength |
| 37 |
|
* method to set the length of the vectors. This must be set before the accessor |
| 38 |
|
* can be used. This is the length of each of the vector containers. |
| 39 |
|
* |
| 40 |
|
* \note |
| 41 |
|
* This work is part of the National Alliance for Medical Image Computing |
| 42 |
|
* (NAMIC), funded by the National Institutes of Health through the NIH Roadmap |
| 43 |
|
* for Medical Research, Grant U54 EB005149. |
| 44 |
|
* |
| 45 |
|
* \ingroup ImageAdaptors |
| 46 |
|
*/ |
| 47 |
|
template <class TType > |
| 48 |
|
class ITK_EXPORT DefaultVectorPixelAccessor |
| 49 |
|
{ |
| 50 |
|
public: |
| 51 |
|
|
| 52 |
|
typedef unsigned int VectorLengthType; |
| 53 |
|
|
| 54 |
|
/** External typedef. It defines the external aspect |
| 55 |
LEN |
* that this class will exhibit. Here it is an VariableLengthVector. The container does not |
| 56 |
LEN |
* manage the memory. In other words it is an array reference with the contents |
| 57 |
|
* pointing to the actual data in the image. */ |
| 58 |
|
typedef VariableLengthVector< TType > ExternalType; |
| 59 |
|
|
| 60 |
|
/** Internal typedef. It defines the internal real representation of data. */ |
| 61 |
|
typedef TType InternalType; |
| 62 |
|
|
| 63 |
|
/** Set output using the value in input */ |
| 64 |
|
inline void Set(InternalType & output, const ExternalType & input, |
| 65 |
|
const unsigned long offset ) const |
| 66 |
|
{ |
| 67 |
|
InternalType *truePixel = (&output) + offset*m_OffsetMultiplier; |
| 68 |
|
for( VectorLengthType i=0; i< m_VectorLength; i++ ) |
| 69 |
|
{ |
| 70 |
|
truePixel[i] = input[i]; |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
/** Get the value from input */ |
| 75 |
LEN |
inline ExternalType Get( const InternalType & input, const unsigned long offset ) const |
| 76 |
|
{ |
| 77 |
LEN |
ExternalType output( (&input)+(offset*m_OffsetMultiplier) , m_VectorLength ); |
| 78 |
|
return output; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
/** Set the length of each vector in the VectorImage */ |
| 82 |
|
void SetVectorLength( VectorLengthType l) |
| 83 |
|
{ |
| 84 |
|
m_VectorLength = l; |
| 85 |
|
m_OffsetMultiplier = (l-1); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
/** Get Vector lengths */ |
| 89 |
|
VectorLengthType GetVectorLength() const { return m_VectorLength; } |
| 90 |
|
|
| 91 |
|
DefaultVectorPixelAccessor() {} |
| 92 |
|
|
| 93 |
|
/** Constructor to initialize VectorLength at construction time */ |
| 94 |
|
DefaultVectorPixelAccessor( VectorLengthType l ) |
| 95 |
|
{ |
| 96 |
|
m_VectorLength = l; |
| 97 |
|
m_OffsetMultiplier = l-1; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
virtual ~DefaultVectorPixelAccessor() {}; |
| 101 |
|
|
| 102 |
|
private: |
| 103 |
|
VectorLengthType m_VectorLength; |
| 104 |
|
VectorLengthType m_OffsetMultiplier; |
| 105 |
|
}; |
| 106 |
|
|
| 107 |
|
} // end namespace itk |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
#endif |
| 111 |
|
|
| 112 |
EOF |
|