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 itkNeighborhoodInnerProduct_hxx
19 #define itkNeighborhoodInnerProduct_hxx
20 #include "itkNeighborhoodInnerProduct.h"
21 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 template< typename TImage, typename TOperator, typename TComputation >
27 typename NeighborhoodInnerProduct< TImage, TOperator, TComputation >::OutputPixelType
28 NeighborhoodInnerProduct< TImage, TOperator, TComputation >
Compute(const ConstNeighborhoodIterator<TImage> & it,const OperatorType & op,const unsigned start,const unsigned stride)29 ::Compute(
30   const ConstNeighborhoodIterator< TImage > & it,
31   const OperatorType & op,
32   const unsigned start,
33   const unsigned stride)
34 {
35   typename OperatorType::ConstIterator o_it;
36 
37   using InputPixelType = typename TImage::PixelType;
38   using InputPixelRealType = typename NumericTraits< InputPixelType >::RealType;
39   using AccumulateRealType = typename NumericTraits< InputPixelRealType >::AccumulateType;
40 
41   AccumulateRealType sum = NumericTraits< AccumulateRealType >::ZeroValue();
42 
43   using OutputPixelValueType = typename NumericTraits<OutputPixelType>::ValueType;
44 
45   o_it = op.Begin();
46   const typename OperatorType::ConstIterator op_end = op.End();
47 
48   for ( unsigned int i = start; o_it < op_end; i += stride, ++o_it )
49     {
50     sum += static_cast< AccumulateRealType >(
51       static_cast< OutputPixelValueType >( *o_it ) *
52       static_cast< InputPixelRealType >( it.GetPixel(i) ) );
53     }
54 
55   return static_cast< OutputPixelType >( sum );
56 }
57 
58 template< typename TImage, typename TOperator, typename TComputation >
59 typename NeighborhoodInnerProduct< TImage, TOperator, TComputation >::OutputPixelType
60 NeighborhoodInnerProduct< TImage, TOperator, TComputation >
Compute(const NeighborhoodType & N,const OperatorType & op,const unsigned start,const unsigned stride)61 ::Compute(
62   /*           const ImageBoundaryCondition<TImage> *,*/
63   const NeighborhoodType & N,
64   const OperatorType & op,
65   const unsigned start,
66   const unsigned stride)
67 {
68   typename OperatorType::ConstIterator o_it;
69 
70   using InputPixelType = typename TImage::PixelType;
71   using InputPixelRealType = typename NumericTraits< InputPixelType >::RealType;
72   using AccumulateRealType = typename NumericTraits< InputPixelRealType >::AccumulateType;
73 
74   AccumulateRealType sum = NumericTraits< AccumulateRealType >::ZeroValue();
75 
76   using OutputPixelValueType = typename NumericTraits<OutputPixelType>::ValueType;
77 
78   o_it = op.Begin();
79   const typename OperatorType::ConstIterator op_end = op.End();
80 
81   for ( unsigned int i = start; o_it < op_end; i += stride, ++o_it )
82     {
83     sum += static_cast< AccumulateRealType >(
84       static_cast< OutputPixelValueType >( *o_it ) *
85       static_cast< InputPixelRealType >( N[i] ) );
86     }
87 
88   return static_cast< OutputPixelType >( sum );
89 }
90 } // end namespace itk
91 #endif
92