| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSphereSpatialFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkSphereSpatialFunction_txx |
| 18 |
|
#define __itkSphereSpatialFunction_txx |
| 19 |
|
|
| 20 |
|
#include "itkSphereSpatialFunction.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
template <unsigned int VImageDimension,typename TInput> |
| 26 |
|
SphereSpatialFunction<VImageDimension,TInput> |
| 27 |
|
::SphereSpatialFunction() |
| 28 |
|
{ |
| 29 |
|
m_Radius = 1.0; |
| 30 |
|
|
| 31 |
|
m_Center.Fill(0.0); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
template <unsigned int VImageDimension,typename TInput> |
| 35 |
|
SphereSpatialFunction<VImageDimension,TInput> |
| 36 |
|
::~SphereSpatialFunction() |
| 37 |
|
{ |
| 38 |
|
|
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
template <unsigned int VImageDimension,typename TInput> |
| 42 |
|
typename SphereSpatialFunction<VImageDimension,TInput>::OutputType |
| 43 |
|
SphereSpatialFunction<VImageDimension,TInput> |
| 44 |
|
::Evaluate(const InputType& position) const |
| 45 |
|
{ |
| 46 |
|
double acc = 0; |
| 47 |
|
|
| 48 |
|
for(unsigned int i = 0; i < VImageDimension; i++) |
| 49 |
|
{ |
| 50 |
|
acc += (position[i] - m_Center[i]) * (position[i] - m_Center[i]); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
acc -= m_Radius*m_Radius; |
| 54 |
|
|
| 55 |
|
if(acc <= 0) // inside the sphere |
| 56 |
|
{ |
| 57 |
|
return 1; |
| 58 |
|
} |
| 59 |
|
else |
| 60 |
|
{ |
| 61 |
|
return 0; // outside the sphere |
| 62 |
|
} |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
template <unsigned int VImageDimension,typename TInput> |
| 66 |
|
void |
| 67 |
|
SphereSpatialFunction<VImageDimension,TInput> |
| 68 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 69 |
|
{ |
| 70 |
|
Superclass::PrintSelf(os,indent); |
| 71 |
|
|
| 72 |
|
unsigned int i; |
| 73 |
|
os << indent << "Center: ["; |
| 74 |
|
for (i=0; i < VImageDimension - 1; i++) |
| 75 |
|
{ |
| 76 |
|
os << m_Center[i] << ", "; |
| 77 |
|
} |
| 78 |
|
os << "]" << std::endl; |
| 79 |
|
|
| 80 |
|
os << indent << "Radius: " << m_Radius << std::endl; |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
} // end namespace itk |
| 84 |
|
|
| 85 |
|
#endif |
| 86 |
|
|