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 itkSinRegularizedHeavisideStepFunction_hxx
19 #define itkSinRegularizedHeavisideStepFunction_hxx
20 
21 #include "itkSinRegularizedHeavisideStepFunction.h"
22 #include "itkMath.h"
23 
24 namespace itk
25 {
26 template< typename TInput, typename TOutput >
27 typename SinRegularizedHeavisideStepFunction< TInput, TOutput >::OutputType
28 SinRegularizedHeavisideStepFunction< TInput, TOutput >
Evaluate(const InputType & input) const29 ::Evaluate( const InputType& input ) const
30 {
31   if ( static_cast< RealType >( input ) >= this->GetEpsilon() )
32     {
33     return NumericTraits< OutputType >::OneValue();
34     }
35   else
36     {
37     if ( static_cast< RealType >( input ) <= -this->GetEpsilon() )
38       {
39       return NumericTraits< OutputType >::ZeroValue();
40       }
41     else
42       {
43       const RealType angleFactor = 0.5 * itk::Math::pi * this->GetOneOverEpsilon();
44       const RealType angle = input * angleFactor;
45 
46       return static_cast< OutputType >( 0.5 * ( 1.0 + std::sin( angle ) ) );
47       }
48     }
49 }
50 
51 template< typename TInput, typename TOutput >
52 typename SinRegularizedHeavisideStepFunction< TInput, TOutput >::OutputType
53 SinRegularizedHeavisideStepFunction< TInput, TOutput >
EvaluateDerivative(const InputType & input) const54 ::EvaluateDerivative(const InputType & input) const
55 {
56   if ( itk::Math::abs( static_cast< RealType >( input ) ) >= this->GetEpsilon() )
57     {
58     return NumericTraits< OutputType >::ZeroValue();
59     }
60   else
61     {
62     const RealType angleFactor = 0.5 * itk::Math::pi * this->GetOneOverEpsilon();
63     const RealType angle = input * angleFactor;
64 
65     return static_cast< OutputType >( 0.5 * angleFactor * std::cos(angle) );
66     }
67 }
68 
69 }
70 
71 #endif
72