KWStyle - itkVectorImageNeighborhoodAccessorFunctor.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVectorImageNeighborhoodAccessorFunctor.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
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 __itkVectorImageNeighborhoodAccessorFunctor_h
18 #define __itkVectorImageNeighborhoodAccessorFunctor_h
19
20 #include "itkVariableLengthVector.h"
21 #include "itkImageBoundaryCondition.h"
22 #include "itkNeighborhood.h"
23 #include "itkImageBase.h"
24
25 namespace itk
26 {
27  
28 /** \class VectorImageNeighborhoodAccessorFunctor
29  * \brief Provides accessor interfaces to Access pixels and is meant to be
30  * used on pointers to pixels held by the Neighborhood class.
31  *
32  * A typical user should not need to use this class. The class is internally
33  * used by the neighborhood iterators.
34  * 
35  * \note
36  * This work is part of the National Alliance for Medical Image Computing 
37  * (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
38  * for Medical Research, Grant U54 EB005149.
39 IND ***/
40 template< class TImage >
41 class VectorImageNeighborhoodAccessorFunctor
42 {
43 public:
44   typedef TImage                                ImageType;
45   typedef typename ImageType::PixelType         PixelType;
46   typedef typename ImageType::InternalPixelType InternalPixelType;
47   typedef unsigned int                          VectorLengthType;
48   typedef typename ImageType::OffsetType        OffsetType;
49
50   typedef Neighborhood< InternalPixelType *,
51           ::itk::GetImageDimension< TImage >::ImageDimension> NeighborhoodType;
52
53   typedef ImageBoundaryCondition< ImageType > const 
54 IND ***************************ImageBoundaryConditionConstPointerType;
55   
56   VectorImageNeighborhoodAccessorFunctor( VectorLengthType length ) 
57 IND ******: m_VectorLength( length ), m_OffsetMultiplier( length -1 ) { };
58   VectorImageNeighborhoodAccessorFunctor() 
59 IND ******: m_VectorLength( 0 ), m_OffsetMultiplier( 0 ) {};
60   
61   /** Set the pointer index to the start of the buffer.
62    * This must be set by the iterators to the starting location of the buffer. 
63    * Typically a neighborhood iterator iterating on a neighborhood of an Image, 
64    * say \c image will set this in its constructor. For instance:
65    * 
66    * \code
67    * ConstNeighborhoodIterator( radius, image, )
68    *   {
69 IND ****   ...
70 IND ****   m_NeighborhoodAccessorFunctor.SetBegin( image->GetBufferPointer() );
71 IND ****   }
72    * \endcode
73    */
74   inline void SetBegin( const InternalPixelType * begin ) 
75     { this->m_Begin = const_cast< InternalPixelType * >( begin ); }
76
77   /** Method to dereference a pixel pointer. This is used from the 
78    * ConstNeighborhoodIterator as the equivalent operation to (*it).
79    * This method should be preferred over the former (*it) notation. 
80    * The reason is that dereferencing a pointer to a location of 
81    * VectorImage pixel involves a different operation that simply
82    * dereferencing the pointer. Here a PixelType (array of InternalPixelType s)
83    * is created on the stack and returned.  */
84   inline PixelType Get( const InternalPixelType *pixelPointer ) const 
85     { 
86 LEN     return PixelType(pixelPointer+(pixelPointer-m_Begin)*m_OffsetMultiplier, m_VectorLength);
87     }
88   
89   /** Method to set the pixel value at a certain pixel pointer */
90   inline void Set( InternalPixelType* &pixelPointer, const PixelType &p ) const
91     {
92     InternalPixelType *truePixelPointer = 
93 IND ******pixelPointer + (pixelPointer-m_Begin)*m_OffsetMultiplier;
94     for( VectorLengthType i=0; i< m_VectorLength; i++ ) 
95       { 
96       truePixelPointer[i] = p[i];
97       }
98     }
99  
100   inline PixelType BoundaryCondition( 
101       const OffsetType& point_index,
102       const OffsetType &boundary_offset, 
103       const NeighborhoodType *data,
104       const ImageBoundaryConditionConstPointerType boundaryCondition) const
105     {
106 LEN     return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
107     }
108
109
110   /** Methods to Set/Get vector length. This should be the length of a block of
111    * pixels in the VectorImage. */
112   void SetVectorLength( VectorLengthType length )
113     { 
114     m_VectorLength = length;
115     m_OffsetMultiplier = length - 1;
116     }
117
118   /** Methods to Set/Get vector length. This should be the length of a block of
119    * pixels in the VectorImage. */
120   VectorLengthType GetVectorLength()
121     {
122     return m_VectorLength;
123     }
124    
125 private:
126 IND ***VectorLengthType m_VectorLength; 
127 IND ***VectorLengthType m_OffsetMultiplier; // m_OffsetMultiplier = m_VectorLength-1
128 IND ****************************************// (precomputed for speedup).
129 IND ***InternalPixelType *m_Begin; // Begin of the buffer. 
130 };
131
132
133 // end namespace itk
134 #endif
135

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