| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkFrustumSpatialFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:36 $ |
| 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 __itkFrustumSpatialFunction_txx |
| 18 |
|
#define __itkFrustumSpatialFunction_txx |
| 19 |
|
|
| 20 |
|
#include "itkFrustumSpatialFunction.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
template <unsigned int VImageDimension,typename TInput> |
| 26 |
|
FrustumSpatialFunction<VImageDimension,TInput>::FrustumSpatialFunction() |
| 27 |
|
{ |
| 28 |
|
for (unsigned int i = 0; i < m_Apex.GetPointDimension(); i++) |
| 29 |
|
{ |
| 30 |
|
m_Apex[i] = 0.0; |
| 31 |
|
} |
| 32 |
|
m_AngleZ = 0.0; |
| 33 |
|
m_ApertureAngleX = 0.0; |
| 34 |
|
m_ApertureAngleY = 0.0; |
| 35 |
|
m_TopPlane = 0.0; |
| 36 |
|
m_BottomPlane = 0.0; |
| 37 |
|
m_RotationPlane = RotateInXZPlane; |
| 38 |
|
|
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
template <unsigned int VImageDimension,typename TInput> |
| 42 |
|
FrustumSpatialFunction<VImageDimension,TInput>::~FrustumSpatialFunction() |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
template <unsigned int VImageDimension,typename TInput> |
| 48 |
|
typename FrustumSpatialFunction<VImageDimension,TInput>::OutputType |
| 49 |
|
FrustumSpatialFunction<VImageDimension,TInput> |
| 50 |
|
::Evaluate(const InputType& position) const |
| 51 |
|
{ |
| 52 |
|
|
| 53 |
|
typedef InputType PointType; |
| 54 |
TDA |
typedef typename PointType::VectorType VectorType; |
| 55 |
|
|
| 56 |
|
VectorType relativePosition = position - m_Apex; |
| 57 |
|
const double distanceToApex = relativePosition.GetNorm(); |
| 58 |
|
|
| 59 |
|
// Check Top and Bottom planes.. If the angle is negative, the |
| 60 |
|
// top plane may be less than the bottom plane, but is ok. |
| 61 |
|
if( m_TopPlane <= m_BottomPlane ) |
| 62 |
|
{ |
| 63 |
|
if( distanceToApex < m_TopPlane || |
| 64 |
|
distanceToApex > m_BottomPlane ) |
| 65 |
|
{ |
| 66 |
|
return 0; |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
else |
| 70 |
IND |
**{ |
| 71 |
|
if( distanceToApex > m_TopPlane || |
| 72 |
|
distanceToApex < m_BottomPlane ) |
| 73 |
|
{ |
| 74 |
|
return 0; |
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
if( m_RotationPlane == RotateInXZPlane ) |
| 79 |
|
{ |
| 80 |
|
const double dx = relativePosition[0]; |
| 81 |
|
const double dy = relativePosition[1]; |
| 82 |
|
const double dz = relativePosition[2]; |
| 83 |
|
|
| 84 |
|
const double distanceXZ = sqrt( dx * dx + dz * dz ); |
| 85 |
|
|
| 86 |
|
const double deg2rad = atan( 1.0f ) / 45.0; |
| 87 |
|
|
| 88 |
|
// Check planes along Y |
| 89 |
|
const double angleY = atan2( dy, distanceXZ ); |
| 90 |
|
if( fabs( angleY ) > m_ApertureAngleY * deg2rad ) |
| 91 |
|
{ |
| 92 |
|
return 0; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
// Check planes along X |
| 96 |
|
const double angleX = atan2( dx, dz ); |
| 97 |
|
|
| 98 |
|
if( cos( angleX + ( 180.0 + m_AngleZ ) * deg2rad ) < |
| 99 |
|
cos( deg2rad * m_ApertureAngleX ) ) |
| 100 |
|
{ |
| 101 |
|
return 0; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
return 1; |
| 105 |
|
} |
| 106 |
|
else if( m_RotationPlane == RotateInYZPlane ) |
| 107 |
|
{ |
| 108 |
|
const double dx = relativePosition[0]; |
| 109 |
|
const double dy = relativePosition[1]; |
| 110 |
|
const double dz = relativePosition[2]; |
| 111 |
|
|
| 112 |
|
const double distanceYZ = sqrt( dy * dy + dz * dz ); |
| 113 |
|
|
| 114 |
|
const double deg2rad = atan( 1.0f ) / 45.0; |
| 115 |
|
|
| 116 |
|
// Check planes along X |
| 117 |
|
const double angleX = atan2( dx, distanceYZ ); |
| 118 |
|
if( fabs( angleX ) > m_ApertureAngleX * deg2rad ) |
| 119 |
|
{ |
| 120 |
|
return 0; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
// Check planes along Y |
| 124 |
|
const double angleY = atan2( dy, dz ); |
| 125 |
|
|
| 126 |
|
if( cos( angleY + ( 180.0 + m_AngleZ ) * deg2rad ) < |
| 127 |
|
cos( deg2rad * m_ApertureAngleY ) ) |
| 128 |
|
{ |
| 129 |
|
return 0; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
return 1; |
| 133 |
|
} |
| 134 |
|
else |
| 135 |
|
{ |
| 136 |
|
itkExceptionMacro( << "Rotation plane not set!" ); |
| 137 |
|
} |
| 138 |
|
return 0; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
template <unsigned int VImageDimension,typename TInput> |
| 142 |
|
void |
| 143 |
|
FrustumSpatialFunction<VImageDimension,TInput>:: |
| 144 |
|
PrintSelf(std::ostream& os, Indent indent) const |
| 145 |
|
{ |
| 146 |
|
Superclass::PrintSelf(os,indent); |
| 147 |
|
|
| 148 |
|
os << indent << "Apex: " << m_Apex << std::endl; |
| 149 |
|
os << indent << "AngleZ: " << m_AngleZ << std::endl; |
| 150 |
|
os << indent << "ApertureAngleX: " << m_ApertureAngleX << std::endl; |
| 151 |
|
os << indent << "ApertureAngleY: " << m_ApertureAngleY << std::endl; |
| 152 |
|
os << indent << "TopPlane: " << m_TopPlane << std::endl; |
| 153 |
|
os << indent << "BottomPlane: " << m_BottomPlane << std::endl; |
| 154 |
|
os << indent << "RotationPlane: " << m_RotationPlane << std::endl; |
| 155 |
|
} |
| 156 |
|
} // end namespace itk |
| 157 |
|
|
| 158 |
|
#endif |
| 159 |
|
|