| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkConicShellInteriorExteriorSpatialFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:34 $ |
| 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 __itkConicShellInteriorExteriorSpatialFunction_txx |
| 18 |
|
#define __itkConicShellInteriorExteriorSpatialFunction_txx |
| 19 |
|
|
| 20 |
|
#include "itkConicShellInteriorExteriorSpatialFunction.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
template <unsigned int VDimension, typename TInput> |
| 26 |
|
ConicShellInteriorExteriorSpatialFunction<VDimension, TInput> |
| 27 |
|
::ConicShellInteriorExteriorSpatialFunction() |
| 28 |
|
{ |
| 29 |
|
m_Origin.Fill(0.0); |
| 30 |
|
m_OriginGradient.Fill(0.0); |
| 31 |
|
|
| 32 |
|
m_DistanceMin = 0; |
| 33 |
|
m_DistanceMax = 0; |
| 34 |
|
m_Polarity = 0; |
| 35 |
|
m_Epsilon = 0; |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
template <unsigned int VDimension, typename TInput> |
| 39 |
|
ConicShellInteriorExteriorSpatialFunction<VDimension, TInput> |
| 40 |
|
::~ConicShellInteriorExteriorSpatialFunction() |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
template <unsigned int VDimension, typename TInput> |
| 46 |
|
void |
| 47 |
|
ConicShellInteriorExteriorSpatialFunction<VDimension, TInput> |
| 48 |
|
::SetOriginGradient(GradientType grad) |
| 49 |
|
{ |
| 50 |
|
m_OriginGradient = grad; |
| 51 |
|
|
| 52 |
|
// Normalize the origin gradient |
| 53 |
|
m_OriginGradient.GetVnlVector().normalize(); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
template <unsigned int VDimension, typename TInput> |
| 57 |
LEN |
typename ConicShellInteriorExteriorSpatialFunction<VDimension, TInput>::OutputType |
| 58 |
|
ConicShellInteriorExteriorSpatialFunction<VDimension, TInput> |
| 59 |
|
::Evaluate(const InputType& position) const |
| 60 |
|
{ |
| 61 |
|
// As from the header... |
| 62 |
|
/* |
| 63 |
IND |
**** We are creating search areas from BoundaryPoint1 in which to look for |
| 64 |
IND |
**** candidate BoundaryPoint2's with which to form core atoms. Assume the |
| 65 |
IND |
**** "worst case" that BoundaryPoint2 is somewhere in that search area pointing |
| 66 |
IND |
**** directly at BoundaryPoint1. |
| 67 |
IND |
**** |
| 68 |
LEN,IND |
**** The search area (ConicShell?) from each BoundaryPoint1 has the following parameters: |
| 69 |
IND |
**** |
| 70 |
IND |
**** DistanceMax and DistanceMin from the location of the BoundaryPoint |
| 71 |
IND |
**** |
| 72 |
IND |
**** AngleMax from the line along the gradient at the boundary point. |
| 73 |
LEN,IND |
**** This is determined in n dimensions by taking the dot product of two vectors, |
| 74 |
IND |
**** (1) the normalized gradient at BoundaryPoint1 and |
| 75 |
IND |
**** (2) the normalized vector from BoundaryPoint1 to BoundaryPoint2. |
| 76 |
IND |
**** |
| 77 |
IND |
**** If the absolute value of that dot product is greater than (1 - epsilon) |
| 78 |
IND |
**** then you are in the ConicShell. This epsilon is the same one determining |
| 79 |
IND |
**** face-to-faceness in the IEEE TMI paper. |
| 80 |
IND |
****/ |
| 81 |
|
|
| 82 |
|
// Set the direction of the gradient |
| 83 |
|
// O means the direction that the gradient is pointing, |
| 84 |
|
// 1 means the opposite direction |
| 85 |
|
|
| 86 |
|
typedef Vector<double, VDimension> VectorType; |
| 87 |
|
|
| 88 |
|
// Compute the vector from the origin to the point we're testing |
| 89 |
|
VectorType vecOriginToTest = position - m_Origin; |
| 90 |
|
|
| 91 |
|
// Compute the length of this vector |
| 92 |
|
// double vecDistance = vecOriginToTest.GetVnlVector().magnitude(); |
| 93 |
|
double vecDistance = vecOriginToTest.GetNorm(); |
| 94 |
|
|
| 95 |
|
// Check to see if this an allowed distance |
| 96 |
|
if( !( (vecDistance > m_DistanceMin)&&(vecDistance < m_DistanceMax) ) ) |
| 97 |
|
return 0; // not inside the conic shell |
| 98 |
|
|
| 99 |
|
// Normalize it |
| 100 |
|
// vecOriginToTest.GetVnlVector().normalize(); |
| 101 |
|
vecOriginToTest.Normalize(); |
| 102 |
|
|
| 103 |
|
// Create a temp vector to get around const problems |
| 104 |
|
GradientType originGradient = m_OriginGradient; |
| 105 |
|
|
| 106 |
|
// Now compute the dot product |
| 107 |
LEN |
// double dotprod = dot_product(originGradient.GetVnlVector(), vecOriginToTest.GetVnlVector()); |
| 108 |
|
double dotprod = originGradient * vecOriginToTest; |
| 109 |
|
|
| 110 |
|
if(m_Polarity==1) |
| 111 |
|
{ |
| 112 |
|
dotprod = dotprod * -1; |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
// Check to see if it meet's the angle criterior |
| 116 |
|
OutputType result; |
| 117 |
|
if( dotprod > (1 - m_Epsilon) ) |
| 118 |
|
{ |
| 119 |
|
result = 1; // it's inside the shell |
| 120 |
|
} |
| 121 |
|
else |
| 122 |
|
{ |
| 123 |
|
result = 0; // it's not inside the shell |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
return result; |
| 127 |
|
|
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
template <unsigned int VDimension, typename TInput> |
| 131 |
|
void |
| 132 |
|
ConicShellInteriorExteriorSpatialFunction<VDimension, TInput> |
| 133 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 134 |
|
{ |
| 135 |
|
Superclass::PrintSelf(os,indent); |
| 136 |
|
|
| 137 |
|
unsigned int i; |
| 138 |
|
os << indent << "Origin: ["; |
| 139 |
|
for (i=0; i < VDimension - 1; i++) |
| 140 |
|
{ |
| 141 |
|
os << m_Origin[i] << ", "; |
| 142 |
|
} |
| 143 |
|
os << "]" << std::endl; |
| 144 |
|
|
| 145 |
|
os << indent << "Gradient at origin: ["; |
| 146 |
|
for (i=0; i < VDimension - 1; i++) |
| 147 |
|
{ |
| 148 |
|
os << m_OriginGradient[i] << ", "; |
| 149 |
|
} |
| 150 |
|
os << "]" << std::endl; |
| 151 |
|
|
| 152 |
|
os << indent << "DistanceMin: " << m_DistanceMin << std::endl; |
| 153 |
|
os << indent << "DistanceMax: " << m_DistanceMax << std::endl; |
| 154 |
|
os << indent << "Epsilon: " << m_Epsilon << std::endl; |
| 155 |
|
os << indent << "Polarity: " << m_Polarity << std::endl; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
} // end namespace itk |
| 159 |
|
|
| 160 |
|
#endif |
| 161 |
|
|