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 itkTorusInteriorExteriorSpatialFunction_hxx
19 #define itkTorusInteriorExteriorSpatialFunction_hxx
20 
21 #include "itkTorusInteriorExteriorSpatialFunction.h"
22 
23 namespace itk
24 {
25 template< unsigned int VDimension, typename TInput >
26 TorusInteriorExteriorSpatialFunction< VDimension, TInput >
TorusInteriorExteriorSpatialFunction()27 ::TorusInteriorExteriorSpatialFunction()
28 
29 {
30   m_Origin.Fill(0.0);
31 }
32 
33 template< unsigned int VDimension, typename TInput >
34 typename TorusInteriorExteriorSpatialFunction< VDimension, TInput >::OutputType
35 TorusInteriorExteriorSpatialFunction< VDimension, TInput >
Evaluate(const InputType & position) const36 ::Evaluate(const InputType & position) const
37 {
38   double x = position[0] - m_Origin[0];
39   double y = position[1] - m_Origin[1];
40   double z = position[2] - m_Origin[2];
41 
42   double k = std::pow(m_MajorRadius - std::sqrt(x * x + y * y), 2.0) + z * z;
43 
44   if ( k <= ( m_MinorRadius * m_MinorRadius ) )
45     {
46     return true;
47     }
48   else
49     {
50     return false;
51     }
52 }
53 
54 template< unsigned int VDimension, typename TInput >
55 void
56 TorusInteriorExteriorSpatialFunction< VDimension, TInput >
PrintSelf(std::ostream & os,Indent indent) const57 ::PrintSelf(std::ostream & os, Indent indent) const
58 {
59   Superclass::PrintSelf(os, indent);
60 
61   unsigned int i;
62 
63   os << indent << "Origin: [";
64   for ( i = 0; i < VDimension - 1; i++ )
65     {
66     os << m_Origin[i] << ", ";
67     }
68   os << "]" << std::endl;
69 
70   os << indent << "Major radius: " << m_MajorRadius << std::endl;
71 
72   os << indent << "Minor radius: " << m_MinorRadius << std::endl;
73 }
74 } // end namespace itk
75 
76 #endif
77