| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
LEN |
Module: $RCSfile: itkSymmetricEllipsoidInteriorExteriorSpatialFunction.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 |
DEF |
#ifndef __itkSymmetricEllipsoidInteriorExteriorSpatialFunction_cpp |
| 18 |
DEF |
#define __itkSymmetricEllipsoidInteriorExteriorSpatialFunction_cpp |
| 19 |
|
|
| 20 |
|
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.h" |
| 21 |
|
#include <math.h> |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
template <unsigned int VDimension, typename TInput> |
| 27 |
|
SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension,TInput> |
| 28 |
|
::SymmetricEllipsoidInteriorExteriorSpatialFunction() |
| 29 |
|
{ |
| 30 |
|
m_Center.Fill(0.0); // Origin of ellipsoid |
| 31 |
|
m_Orientation.Fill(1.0); // Orientation of unique axis |
| 32 |
|
m_UniqueAxis = 10; // Length of unique axis |
| 33 |
|
m_SymmetricAxes = 5; // Length of symmetric axes |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
template <unsigned int VDimension, typename TInput> |
| 37 |
|
SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension,TInput> |
| 38 |
|
::~SymmetricEllipsoidInteriorExteriorSpatialFunction() |
| 39 |
|
{ |
| 40 |
|
|
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
template <unsigned int VDimension,typename TInput> |
| 44 |
LEN |
typename SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::OutputType |
| 45 |
|
SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension, TInput> |
| 46 |
|
::Evaluate(const InputType& position) const |
| 47 |
|
{ |
| 48 |
|
double uniqueTerm; // Term in ellipsoid equation for unique axis |
| 49 |
|
double symmetricTerm; // Term in ellipsoid equation for symmetric axes |
| 50 |
|
Vector<double, VDimension> pointVector; |
| 51 |
|
Vector<double, VDimension> symmetricVector; |
| 52 |
|
|
| 53 |
|
// Project the position onto the major axis, normalize by axis length, |
| 54 |
|
// and determine whether position is inside ellipsoid. |
| 55 |
|
for(unsigned int i = 0; i < VDimension; i++) |
| 56 |
|
{ |
| 57 |
|
pointVector[i] = position[i] - m_Center[i]; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
LEN |
uniqueTerm = pow(static_cast<double>(((pointVector * m_Orientation)/(.5*m_UniqueAxis))),static_cast<double>(2)); |
| 61 |
LEN |
symmetricVector = pointVector - (m_Orientation * (pointVector * m_Orientation)); |
| 62 |
LEN |
symmetricTerm = pow(static_cast<double>(((symmetricVector.GetNorm())/(.5*m_SymmetricAxes))),static_cast<double>(2)); |
| 63 |
|
|
| 64 |
|
if((uniqueTerm + symmetricTerm) >= 0 && (uniqueTerm + symmetricTerm) <= 1) |
| 65 |
|
{ |
| 66 |
LEN |
return 1; // Inside the ellipsoid. |
| 67 |
|
} |
| 68 |
|
//Default return value assumes outside the ellipsoid |
| 69 |
|
return 0; // Outside the ellipsoid. |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
template <unsigned int VDimension,typename TInput> |
| 73 |
|
void SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension,TInput> |
| 74 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 75 |
|
{ |
| 76 |
|
Superclass::PrintSelf(os, indent); |
| 77 |
|
|
| 78 |
|
os << indent << "Origin of Ellipsoid: "; |
| 79 |
|
os << m_Center << std::endl; |
| 80 |
|
os << indent << "Unique Axis Orientation: "; |
| 81 |
|
os << m_Orientation << std::endl; |
| 82 |
|
os << indent << "Unique Axis Length: "; |
| 83 |
|
os << m_UniqueAxis << std::endl; |
| 84 |
|
os << indent << "Symmetric Axis Length: "; |
| 85 |
|
os << m_SymmetricAxes << std::endl; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
template <unsigned int VDimension,typename TInput> |
| 89 |
|
void SymmetricEllipsoidInteriorExteriorSpatialFunction<VDimension, TInput> |
| 90 |
LEN |
::SetOrientation(VectorType orientation, double uniqueAxis, double symmetricAxes) |
| 91 |
|
{ |
| 92 |
|
m_Orientation = orientation; // Orientation of unique axis of ellipsoid |
| 93 |
|
m_SymmetricAxes = symmetricAxes; // Length of symmetric axes |
| 94 |
|
m_UniqueAxis = uniqueAxis; // Length of unique axis |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
} // end namespace itk |
| 98 |
|
|
| 99 |
|
#endif |
| 100 |
|
|