KWStyle - itkNthElementPixelAccessor.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkNthElementPixelAccessor.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:42 $
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 __itkNthElementPixelAccessor_h
18 #define __itkNthElementPixelAccessor_h
19
20 #include "itkMacro.h"
21
22 namespace itk
23 {
24
25 /** \class NthElementPixelAccessor
26  * \brief Give access to the N-th of a Container type 
27  *
28  * This class is intended to be used as parameter of 
29  * an ImageAdaptor to make a  Container appears as being
30  * of scalar type T, showing only the N-th component.
31  *
32  * This class is templated over the container type.
33  * Any container type that provides a method:
34  * operator[]( unsigned int ) can be used here,
35  * for example: itkPoint, itkVector, itkVectorContainer,
36  *              and std::vector.
37  *
38  * For performance, no bound checking is performed during
39  * access to the n-th element.
40  *
41  * \sa ImageAdaptor
42  * \sa PixelAccessor
43  *
44  * \ingroup ImageAdaptors
45  */
46
47 template < class T, class TContainer >
48 class ITK_EXPORT NthElementPixelAccessor
49 {
50 public:
51   /** Standard class typedefs. */
52   typedef   NthElementPixelAccessor        Self;
53
54   /** that this class will exhibit */
55   typedef T ExternalType;
56
57   /** Internal typedef. It defines the internal real
58    * representation of data */
59   typedef   TContainer    InternalType;
60
61   /** Write access to the NthElement component */
62   inline void Set( InternalType & output, const ExternalType & input ) const 
63     { output[m_ElementNumber] =  input; }
64
65   /** Read access to the NthElement component */
66   inline ExternalType Get( const InternalType & input ) const
67     { return static_cast<ExternalType>( input[m_ElementNumber] ); }
68
69   /** Get the element number to access in the container */
70   unsigned int GetElementNumber(void) const
71     { return m_ElementNumber; }
72
73   /** Set the element number to access in the container */
74   void SetElementNumber( unsigned int nth )
75     { m_ElementNumber = nth; }
76
77   /** operator!=. This is needed to convert a pixel accessor to a functor.
78    * \sa AdaptImageFilter */
79   bool operator!=(const Self& accessor) const
80     {
81 IND ******return (m_ElementNumber != accessor.m_ElementNumber);
82     }
83
84   /** Assignment operator */
85 LEN   NthElementPixelAccessor & operator=( const NthElementPixelAccessor & accessor )
86     {
87     m_ElementNumber = accessor.m_ElementNumber;
88     return *this;
89     }
90   
91   /** Constructor */
92   NthElementPixelAccessor()
93     {
94     m_ElementNumber = 0;
95     }
96
97 private:
98   // Identifier of the N-th element to be accessed
99   unsigned int    m_ElementNumber;
100
101 };
102
103   
104 }  // end namespace itk
105
106 #endif
107
108 EOF

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:27PM
© Kitware Inc.