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
19 #ifndef itkLevelSetEquationTermBase_hxx
20 #define itkLevelSetEquationTermBase_hxx
21
22 #include "itkLevelSetEquationTermBase.h"
23 #include "itkNumericTraits.h"
24 #include "itkMath.h"
25
26 namespace itk
27 {
28 // ----------------------------------------------------------------------------
29 template< typename TInputImage, typename TLevelSetContainer >
30 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
LevelSetEquationTermBase()31 ::LevelSetEquationTermBase()
32 {
33 this->m_CurrentLevelSetId = LevelSetIdentifierType();
34
35 this->m_Coefficient = NumericTraits< LevelSetOutputRealType >::OneValue();
36 this->m_CFLContribution = NumericTraits< LevelSetOutputRealType >::ZeroValue();
37 this->m_TermName = "";
38 }
39
40 // ----------------------------------------------------------------------------
41 template< typename TInputImage, typename TLevelSetContainer >
42 const typename LevelSetEquationTermBase< TInputImage, TLevelSetContainer >::RequiredDataType &
43 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
GetRequiredData() const44 ::GetRequiredData() const
45 {
46 return this->m_RequiredData;
47 }
48
49 // ----------------------------------------------------------------------------
50 template< typename TInputImage, typename TLevelSetContainer >
51 void
52 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
SetLevelSetContainer(LevelSetContainerType * iContainer)53 ::SetLevelSetContainer( LevelSetContainerType* iContainer )
54 {
55 if( iContainer )
56 {
57 this->m_LevelSetContainer = iContainer;
58 this->m_Heaviside = iContainer->GetHeaviside();
59 this->Modified();
60 }
61 else
62 {
63 itkGenericExceptionMacro( << "iContainer is nullptr" );
64 }
65 }
66
67 // ----------------------------------------------------------------------------
68 template< typename TInputImage, typename TLevelSetContainer >
69 typename
70 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
71 ::LevelSetOutputRealType
72 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
Evaluate(const LevelSetInputIndexType & iP)73 ::Evaluate( const LevelSetInputIndexType& iP )
74 {
75 if( itk::Math::abs( this->m_Coefficient ) > NumericTraits< LevelSetOutputRealType >::epsilon() )
76 {
77 return this->m_Coefficient * this->Value( iP );
78 }
79 else
80 {
81 return NumericTraits< LevelSetOutputRealType >::ZeroValue();
82 }
83 }
84 // ----------------------------------------------------------------------------
85
86 // ----------------------------------------------------------------------------
87 template< typename TInputImage, typename TLevelSetContainer >
88 typename
89 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
90 ::LevelSetOutputRealType
91 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
Evaluate(const LevelSetInputIndexType & iP,const LevelSetDataType & iData)92 ::Evaluate( const LevelSetInputIndexType& iP,
93 const LevelSetDataType& iData )
94 {
95 if( itk::Math::abs( this->m_Coefficient ) > NumericTraits< LevelSetOutputRealType >::epsilon() )
96 {
97 return this->m_Coefficient * this->Value( iP, iData );
98 }
99 else
100 {
101 return NumericTraits< LevelSetOutputRealType >::ZeroValue();
102 }
103 }
104 // ----------------------------------------------------------------------------
105
106 // ----------------------------------------------------------------------------
107 template< typename TInputImage, typename TLevelSetContainer >
108 void
109 LevelSetEquationTermBase< TInputImage, TLevelSetContainer >
SetUp()110 ::SetUp()
111 {
112 this->m_CFLContribution = NumericTraits< LevelSetOutputRealType >::ZeroValue();
113
114 if( this->m_CurrentLevelSetPointer.IsNull() )
115 {
116 if( this->m_LevelSetContainer.IsNull() )
117 {
118 itkGenericExceptionMacro( <<"m_LevelSetContainer is nullptr" );
119 }
120 this->m_CurrentLevelSetPointer = this->m_LevelSetContainer->GetLevelSet( this->m_CurrentLevelSetId );
121
122 if( this->m_CurrentLevelSetPointer.IsNull() )
123 {
124 itkWarningMacro(
125 << "m_CurrentLevelSetId does not exist in the level set container" );
126 }
127 }
128
129 if( !this->m_Heaviside.IsNotNull() )
130 {
131 itkWarningMacro( << "m_Heaviside is nullptr" );
132 }
133 }
134 // ----------------------------------------------------------------------------
135
136 }
137
138 #endif // itkLevelSetEquationTermBase_hxx
139