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 itkVectorNeighborhoodInnerProduct_hxx
19 #define itkVectorNeighborhoodInnerProduct_hxx
20 #include "itkVectorNeighborhoodInnerProduct.h"
21 
22 namespace itk
23 {
24 template< typename TImage >
25 typename VectorNeighborhoodInnerProduct< TImage >::PixelType
26 VectorNeighborhoodInnerProduct< TImage >
operator ()(const std::slice & s,const ConstNeighborhoodIterator<TImage> & it,const OperatorType & op) const27 ::operator()(const std::slice & s,
28              const ConstNeighborhoodIterator< TImage > & it,
29              const OperatorType & op) const
30 {
31   PixelType    sum;
32   unsigned int j;
33 
34   typename OperatorType::ConstIterator o_it;
35 
36   for ( j = 0; j < VectorDimension; ++j )
37     {
38     sum[j] = NumericTraits< ScalarValueType >::ZeroValue();
39     }
40 
41   o_it = op.Begin();
42   const typename OperatorType::ConstIterator op_end = op.End();
43 
44   const auto start  = static_cast< unsigned int >( s.start() );
45   const auto stride = static_cast< unsigned int >( s.stride() );
46   for ( unsigned int i = start; o_it < op_end; i += stride, ++o_it )
47     {
48     for ( j = 0; j < VectorDimension; ++j )
49       {
50       sum[j] += *o_it * ( it.GetPixel(i) )[j];
51       }
52     }
53 
54   return sum;
55 }
56 
57 template< typename TImage >
58 typename VectorNeighborhoodInnerProduct< TImage >::PixelType
59 VectorNeighborhoodInnerProduct< TImage >
operator ()(const std::slice & s,const NeighborhoodType & it,const OperatorType & op) const60 ::operator()(const std::slice & s,
61              const NeighborhoodType & it,
62              const OperatorType & op) const
63 {
64   PixelType    sum;
65   unsigned int j;
66 
67   typename OperatorType::ConstIterator o_it;
68 
69   for ( j = 0; j < VectorDimension; ++j )
70     {
71     sum[j] = NumericTraits< ScalarValueType >::ZeroValue();
72     }
73 
74   o_it = op.Begin();
75   const typename OperatorType::ConstIterator op_end = op.End();
76 
77   const auto start  = static_cast< unsigned int >( s.start() );
78   const auto stride = static_cast< unsigned int >( s.stride() );
79   for ( unsigned int i = start; o_it < op_end; i += stride, ++o_it )
80     {
81     for ( j = 0; j < VectorDimension; ++j )
82       {
83       sum[j] += *o_it * it[i][j];
84       }
85     }
86 
87   return sum;
88 }
89 } // end namespace itk
90 #endif
91