| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkFiniteCylinderSpatialFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:35 $ |
| 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 __itkFiniteCylinderSpatialFunction_cpp |
| 18 |
DEF |
#define __itkFiniteCylinderSpatialFunction_cpp |
| 19 |
|
|
| 20 |
|
#include "itkFiniteCylinderSpatialFunction.h" |
| 21 |
|
#include <math.h> |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
template <unsigned int VDimension, typename TInput> |
| 27 |
|
FiniteCylinderSpatialFunction<VDimension, TInput> |
| 28 |
|
::FiniteCylinderSpatialFunction() |
| 29 |
|
{ |
| 30 |
|
m_Orientation.Fill(1.0); |
| 31 |
|
m_AxisLength = 1.0; // Length of cylinder axis. |
| 32 |
|
m_Radius = 1.0; // Radius of cylinder. |
| 33 |
|
m_Center.Fill(0.0); // Origin of cylinder |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
template <unsigned int VDimension, typename TInput > |
| 37 |
|
FiniteCylinderSpatialFunction<VDimension, TInput> |
| 38 |
|
::~FiniteCylinderSpatialFunction() |
| 39 |
|
{ |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
template <unsigned int VDimension, typename TInput> |
| 43 |
|
typename FiniteCylinderSpatialFunction<VDimension, TInput>::OutputType |
| 44 |
|
FiniteCylinderSpatialFunction<VDimension, TInput> |
| 45 |
|
::Evaluate(const InputType& position) const |
| 46 |
|
{ |
| 47 |
|
double halfAxisLength = 0.5 * m_AxisLength; |
| 48 |
|
Vector<double, VDimension> orientationVector; |
| 49 |
|
Vector<double, VDimension> pointVector; |
| 50 |
|
Vector<double, VDimension> medialAxisVector; |
| 51 |
|
|
| 52 |
|
for(unsigned int i = 0; i < VDimension; i++) |
| 53 |
|
{ |
| 54 |
|
pointVector[i] = position[i] - m_Center[i]; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
//take square root to normalize the orientation vector |
| 58 |
|
medialAxisVector[0] = sqrt(m_Orientation[0]); |
| 59 |
|
medialAxisVector[1] = sqrt(m_Orientation[1]); |
| 60 |
|
medialAxisVector[2] = sqrt(m_Orientation[2]); |
| 61 |
|
|
| 62 |
LEN |
//if length_test is less than the length of the cylinder (half actually, because its length from the center), than |
| 63 |
|
//the point is within the length of the cylinder along the medial axis |
| 64 |
LEN |
const double distanceFromCenter = dot_product( medialAxisVector.GetVnlVector(), pointVector.GetVnlVector() ); |
| 65 |
|
|
| 66 |
|
if(fabs(distanceFromCenter) <= (halfAxisLength) |
| 67 |
LEN |
&& m_Radius >= sqrt(pow(pointVector.GetVnlVector().magnitude(),2.0) - pow(distanceFromCenter,2.0))) |
| 68 |
|
{ |
| 69 |
|
return 1; |
| 70 |
|
} |
| 71 |
|
else return 0; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
template <unsigned int VDimension, typename TInput> |
| 75 |
|
void FiniteCylinderSpatialFunction<VDimension, TInput> |
| 76 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 77 |
|
{ |
| 78 |
|
unsigned int i; |
| 79 |
|
|
| 80 |
|
Superclass::PrintSelf(os, indent); |
| 81 |
|
|
| 82 |
|
os << indent << "Lengths of Axis: " << m_AxisLength << std::endl; |
| 83 |
|
os << indent << "Radius: " << m_Radius << std::endl; |
| 84 |
|
os << indent << "Origin of Cylinder: " << m_Center << std::endl; |
| 85 |
|
os << indent << "Orientation: " << std::endl; |
| 86 |
|
for (i = 0; i < VDimension; i++) |
| 87 |
|
{ |
| 88 |
|
os << indent << indent << m_Orientation[i] << " "; |
| 89 |
|
} |
| 90 |
|
os << std::endl; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
} // end namespace itk |
| 94 |
|
|
| 95 |
|
#endif |
| 96 |
|
|