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 itkDerivativeOperator_hxx
19 #define itkDerivativeOperator_hxx
20 #include "itkDerivativeOperator.h"
21 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 template< typename TPixel, unsigned int VDimension, typename TAllocator >
27 typename DerivativeOperator< TPixel, VDimension, TAllocator >
28 ::CoefficientVector
29 DerivativeOperator< TPixel, VDimension, TAllocator >
GenerateCoefficients()30 ::GenerateCoefficients()
31 {
32   unsigned int       i;
33   unsigned int       j;
34   PixelRealType      previous;
35   PixelRealType      next;
36   const unsigned int w = 2 * ( ( m_Order + 1 ) / 2 ) + 1;
37   CoefficientVector  coeff(w);
38 
39   coeff[w / 2] = 1.0;
40   for ( i = 0; i < m_Order / 2; i++ )
41     {
42     previous = coeff[1] - 2 * coeff[0];
43     for ( j = 1; j < w - 1; j++ )
44       {
45       next = coeff[j - 1]  + coeff[j + 1] - 2 * coeff[j];
46       coeff[j - 1] = previous;
47       previous = next;
48       }
49     next = coeff[j - 1] - 2 * coeff[j];
50     coeff[j - 1] = previous;
51     coeff[j] = next;
52     }
53   for ( i = 0; i < m_Order % 2; i++ )
54     {
55     previous =  0.5 * coeff[1];
56     for ( j = 1; j < w - 1; j++ )
57       {
58       next = -0.5 * coeff[j - 1] + 0.5 * coeff[j + 1];
59       coeff[j - 1] = previous;
60       previous = next;
61       }
62     next = -0.5 * coeff[j - 1];
63     coeff[j - 1] = previous;
64     coeff[j] = next;
65     }
66 
67   return coeff;
68 }
69 } // namespace itk
70 
71 #endif
72