KWStyle - itkNeighborhoodOperator.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkNeighborhoodOperator.txx.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 DEF #ifndef _itkNeighborhoodOperator_txx
18 DEF #define _itkNeighborhoodOperator_txx
19 namespace itk
20 {
21 template <class TPixel, unsigned int VDimension, class TAllocator>
22 void
23 NeighborhoodOperator<TPixel, VDimension, TAllocator>
24 ::ScaleCoefficients( PixelRealType s )
25 {
26   for (unsigned i = 0; i < this->Size(); i++)
27     {
28     this->operator[](i) = static_cast< TPixel >( this->operator[](i) * s );
29     }
30 }
31
32 template <class TPixel, unsigned int VDimension, class TAllocator>
33 void
34 NeighborhoodOperator<TPixel, VDimension, TAllocator>
35 ::FlipAxes()
36 {
37   // To flip the operator across all of its axes, all we have to do is reverse
38   // the order of all coefficients.
39   const unsigned size = this->Size();
40   unsigned i, swap_with;
41   PixelType temp;
42
43   for (i = 0; i < size/2; ++i)
44     {
45     swap_with = size - 1 - i;
46     temp = this->operator[](i);
47     this->operator[](i) = this->operator[](swap_with);
48     this->operator[](swap_with) = temp;
49     }
50 }
51
52   
53 template <class TPixel, unsigned int VDimension, class TAllocator>
54 void
55 NeighborhoodOperator<TPixel, VDimension, TAllocator>
56 ::CreateDirectional()
57 {
58   unsigned long k[VDimension];
59   CoefficientVector coefficients;
60
61   coefficients = this->GenerateCoefficients();
62   for (unsigned int i = 0; i<VDimension; ++i)
63     {
64     if (i == this->GetDirection())
65       {
66       k[i] = static_cast<unsigned long>( coefficients.size() ) >> 1;
67       }
68     else
69       {
70       k[i] = 0;
71       }
72     }
73   this->SetRadius(k);
74   this->Fill(coefficients);
75 }
76   
77 template <class TPixel, unsigned int VDimension, class TAllocator>
78 void
79 NeighborhoodOperator<TPixel, VDimension, TAllocator>
80 ::CreateToRadius(const SizeType &sz)
81 {
82   CoefficientVector coefficients;
83   coefficients = this->GenerateCoefficients();
84   this->SetRadius(sz);
85   this->Fill(coefficients);
86 }
87
88 template <class TPixel, unsigned int VDimension, class TAllocator>
89 void
90 NeighborhoodOperator<TPixel, VDimension, TAllocator>
91 ::CreateToRadius(const unsigned long sz)
92 {
93   SizeType k;
94   for (unsigned int i = 0; i< VDimension; i++)
95     {
96     k[i] = sz;
97     }
98   this->CreateToRadius(k);
99 }
100
101 template <class TPixel, unsigned int VDimension, class TAllocator>
102 void
103 NeighborhoodOperator<TPixel, VDimension, TAllocator>
104 ::FillCenteredDirectional(const CoefficientVector &coeff)
105 {
106   unsigned int i;
107   unsigned long start;
108   std::slice* temp_slice;
109   CoefficientVector::const_iterator it;
110
111   // Initialize all coefficients to zero
112   this->InitializeToZero();
113   
114   // Collect slice information
115   const unsigned long stride = this->GetStride(m_Direction);
116   const unsigned long size   = this->GetSize(m_Direction);
117   for (i = 0, start = 0; i <VDimension; ++i)
118     {
119     if (i != m_Direction)
120       {
121       start += this->GetStride(i) * (this->GetSize(i) >> 1);
122       }
123     }
124     
125   // Compare the neighborhood size with the coefficient array size..
126   const int sizediff = ( (int)size - (int)coeff.size() ) >>1;
127  
128   // Create a slice iterator centered in the neighborhood.
129   if (sizediff >= 0)
130     {
131     temp_slice = new std::slice(start + sizediff * stride, coeff.size(),
132 IND ********************************stride);
133     it = coeff.begin();
134     }
135   else
136     {
137     temp_slice = new std::slice(start, size, stride);
138     it = coeff.begin() - sizediff;
139     }
140
141   SliceIteratorType data(this, *temp_slice);
142   delete temp_slice;
143
144   // Copy the coefficients into the neighborhood, truncating them if there
145   // are too many.
146   for (data = data.Begin(); data < data.End(); ++data, ++it)
147     {
148     *data = static_cast<TPixel>(*it);
149     }
150 }
151
152 }// namespace itk
153
154 #endif
155

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