| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkAzimuthElevationToCartesianTransform.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:33 $ |
| 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 _itkAzimuthElevationToCartesianTransform_txx |
| 18 |
DEF |
#define _itkAzimuthElevationToCartesianTransform_txx |
| 19 |
|
|
| 20 |
|
#include "itkAzimuthElevationToCartesianTransform.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
// Constructor with default arguments |
| 26 |
|
template<class TScalarType, unsigned int NDimensions> |
| 27 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 28 |
|
AzimuthElevationToCartesianTransform() |
| 29 |
|
// add this construction call when deriving from itk::Transform |
| 30 |
|
// :Superclass(SpaceDimension,ParametersDimension) |
| 31 |
|
{ |
| 32 |
|
m_MaxAzimuth = 0; |
| 33 |
|
m_MaxElevation = 0; |
| 34 |
|
m_RadiusSampleSize = 1; |
| 35 |
|
m_AzimuthAngularSeparation = 1; |
| 36 |
|
m_ElevationAngularSeparation = 1; |
| 37 |
|
m_FirstSampleDistance = 0; |
| 38 |
|
m_ForwardAzimuthElevationToPhysical = true; |
| 39 |
|
|
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
// Destructor |
| 43 |
|
template<class TScalarType, unsigned int NDimensions> |
| 44 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 45 |
|
~AzimuthElevationToCartesianTransform() |
| 46 |
|
{ |
| 47 |
|
return; |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
// Print self |
| 52 |
|
template<class TScalarType, unsigned int NDimensions> |
| 53 |
|
void |
| 54 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 55 |
|
PrintSelf(std::ostream &os, Indent indent) const |
| 56 |
|
{ |
| 57 |
|
Superclass::PrintSelf(os,indent); |
| 58 |
|
|
| 59 |
|
os << indent << "x = z*tan(Azimuth)" <<std::endl; |
| 60 |
|
os << indent << "y = z*tan(Elevation)" <<std::endl; |
| 61 |
|
os << indent << "z = sqrt(r*r * cos(Azimuth)*cos(Azimuth) " |
| 62 |
LEN |
<< " / (1 + cos(Azimuth) * cos(Azimuth) * tan(Elevation) * tan(Elevation)))" <<std::endl; |
| 63 |
|
os << indent << "Azimuth = 1 / (tan(x/y))" <<std::endl; |
| 64 |
|
os << indent << "Elevation = 1 / (tan(y/z))" <<std::endl; |
| 65 |
|
os << indent << "r = sqrt(x*x + y*y + z*z)" <<std::endl; |
| 66 |
|
os << indent << "m_MaxAzimuth = "<<m_MaxAzimuth<<std::endl; |
| 67 |
|
os << indent << "m_MaxElevation = "<<m_MaxElevation<<std::endl; |
| 68 |
|
os << indent << "m_RadiusSampleSize = "<<m_RadiusSampleSize<<std::endl; |
| 69 |
LEN |
os << indent << "m_AzimuthAngularSeparation = "<<m_AzimuthAngularSeparation<<std::endl; |
| 70 |
LEN |
os << indent << "m_ElevationAngularSeparation = "<<m_ElevationAngularSeparation<<std::endl; |
| 71 |
|
os << indent << "m_FirstSampleDistance = "<<m_FirstSampleDistance<<std::endl; |
| 72 |
LEN |
os << indent << "m_ForwardAzimuthElevationToPhysical = "<< (m_ForwardAzimuthElevationToPhysical ? "True" : "False")<<std::endl; |
| 73 |
|
|
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
template<class TScalarType, unsigned int NDimensions> |
| 78 |
LEN |
typename AzimuthElevationToCartesianTransform<TScalarType, NDimensions>::OutputPointType |
| 79 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 80 |
|
TransformPoint(const InputPointType &point) const |
| 81 |
|
{ |
| 82 |
|
OutputPointType result; |
| 83 |
LEN |
if (m_ForwardAzimuthElevationToPhysical) result = TransformAzElToCartesian(point); |
| 84 |
|
else result = TransformCartesianToAzEl(point); |
| 85 |
|
return result; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
// Transform a point, from azimuth-elevation to cartesian |
| 90 |
|
template<class TScalarType, unsigned int NDimensions> |
| 91 |
LEN |
typename AzimuthElevationToCartesianTransform<TScalarType, NDimensions>::OutputPointType |
| 92 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 93 |
|
TransformAzElToCartesian(const InputPointType &point) const |
| 94 |
|
{ |
| 95 |
|
OutputPointType result; |
| 96 |
LEN |
ScalarType Azimuth = ((2*vnl_math::pi) / 360) * (point[0]*m_AzimuthAngularSeparation |
| 97 |
|
- ((m_MaxAzimuth-1)/2.0) ); |
| 98 |
LEN |
ScalarType Elevation = ((2*vnl_math::pi) / 360) * (point[1]*m_ElevationAngularSeparation |
| 99 |
LEN |
- ((m_MaxElevation-1)/2.0) ); |
| 100 |
|
ScalarType r = (m_FirstSampleDistance + point[2]) * m_RadiusSampleSize; |
| 101 |
|
|
| 102 |
|
ScalarType cosOfAzimuth = cos(Azimuth); |
| 103 |
|
ScalarType tanOfElevation = tan(Elevation); |
| 104 |
|
result[2] = sqrt((r*r*cosOfAzimuth*cosOfAzimuth) |
| 105 |
LEN,IND |
*******************/ (1 + cosOfAzimuth * cosOfAzimuth * tanOfElevation * tanOfElevation)); |
| 106 |
|
result[0] = result[2] * tan(Azimuth); |
| 107 |
|
result[1] = result[2] * tanOfElevation; |
| 108 |
|
return result; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
// Back transform a point |
| 114 |
|
template<class TScalarType, unsigned int NDimensions> |
| 115 |
LEN |
typename AzimuthElevationToCartesianTransform<TScalarType, NDimensions>::InputPointType |
| 116 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 117 |
|
BackTransform(const OutputPointType &point) const |
| 118 |
|
{ |
| 119 |
|
InputPointType result; |
| 120 |
|
if( m_ForwardAzimuthElevationToPhysical ) |
| 121 |
|
{ |
| 122 |
|
result = static_cast<InputPointType>(TransformCartesianToAzEl(point)); |
| 123 |
|
} |
| 124 |
|
else |
| 125 |
|
{ |
| 126 |
|
result = static_cast<InputPointType>(TransformAzElToCartesian(point)); |
| 127 |
|
} |
| 128 |
|
return result; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
EML |
|
| 133 |
|
// Back transform a point |
| 134 |
|
template<class TScalarType, unsigned int NDimensions> |
| 135 |
LEN |
typename AzimuthElevationToCartesianTransform<TScalarType, NDimensions>::InputPointType |
| 136 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 137 |
|
BackTransformPoint(const OutputPointType &point) const |
| 138 |
|
{ |
| 139 |
|
OutputPointType result; |
| 140 |
|
if (m_ForwardAzimuthElevationToPhysical) |
| 141 |
|
{ |
| 142 |
|
result = static_cast<InputPointType>( TransformCartesianToAzEl(point) ); |
| 143 |
|
} |
| 144 |
|
else |
| 145 |
|
{ |
| 146 |
|
result = static_cast<InputPointType>( TransformAzElToCartesian(point) ); |
| 147 |
|
} |
| 148 |
|
return result; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 152 |
EML |
|
| 153 |
EML |
|
| 154 |
|
template<class TScalarType, unsigned int NDimensions> |
| 155 |
LEN |
typename AzimuthElevationToCartesianTransform<TScalarType, NDimensions>::OutputPointType |
| 156 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 157 |
|
TransformCartesianToAzEl(const OutputPointType &point) const |
| 158 |
|
{ |
| 159 |
|
InputPointType result; // Converted point |
| 160 |
LEN |
result[0] = (atan(point[0] / point[2])) * (360 / (2*vnl_math::pi)) + ((m_MaxAzimuth-1)/2.0); |
| 161 |
LEN |
result[1] = (atan(point[1] / point[2])) * (360 / (2*vnl_math::pi)) + ((m_MaxElevation-1)/2.0); |
| 162 |
|
result[2] = ((sqrt( point[0] * point[0] + |
| 163 |
|
point[1] * point[1] + |
| 164 |
|
point[2] * point[2]) |
| 165 |
IND |
****************/ m_RadiusSampleSize) |
| 166 |
IND |
***************- m_FirstSampleDistance); |
| 167 |
|
return result; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
// Set parameters |
| 172 |
|
template<class TScalarType, unsigned int NDimensions> |
| 173 |
|
void |
| 174 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 175 |
|
SetAzimuthElevationToCartesianParameters(const double sampleSize, |
| 176 |
|
const double firstSampleDistance, |
| 177 |
|
const long maxAzimuth, |
| 178 |
|
const long maxElevation, |
| 179 |
|
const double azimuthAngleSeparation, |
| 180 |
|
const double elevationAngleSeparation) |
| 181 |
|
{ |
| 182 |
LEN |
SetMaxAzimuth(static_cast<long>(static_cast<double>(maxAzimuth) * azimuthAngleSeparation)); |
| 183 |
LEN |
SetMaxElevation(static_cast<long>(static_cast<double>(maxElevation) * elevationAngleSeparation)); |
| 184 |
|
SetRadiusSampleSize(sampleSize); |
| 185 |
|
SetAzimuthAngularSeparation(azimuthAngleSeparation); |
| 186 |
|
SetElevationAngularSeparation(elevationAngleSeparation); |
| 187 |
|
SetFirstSampleDistance(firstSampleDistance / sampleSize); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
template<class TScalarType, unsigned int NDimensions> |
| 191 |
|
void |
| 192 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 193 |
|
SetAzimuthElevationToCartesianParameters(const double sampleSize, |
| 194 |
|
const double firstSampleDistance, |
| 195 |
|
const long maxAzimuth, |
| 196 |
|
const long maxElevation ) |
| 197 |
|
{ |
| 198 |
LEN |
SetAzimuthElevationToCartesianParameters(sampleSize, firstSampleDistance, maxAzimuth, maxElevation, 1.0, 1.0); |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
|
| 202 |
EML |
|
| 203 |
|
template<class TScalarType, unsigned int NDimensions> |
| 204 |
|
void |
| 205 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 206 |
|
SetForwardAzimuthElevationToCartesian() |
| 207 |
|
{ |
| 208 |
|
m_ForwardAzimuthElevationToPhysical = true; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
|
| 212 |
EML |
|
| 213 |
|
template<class TScalarType, unsigned int NDimensions> |
| 214 |
|
void |
| 215 |
|
AzimuthElevationToCartesianTransform<TScalarType, NDimensions>:: |
| 216 |
|
SetForwardCartesianToAzimuthElevation() |
| 217 |
|
{ |
| 218 |
|
m_ForwardAzimuthElevationToPhysical = false; |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
EML |
|
| 223 |
|
}//namespace |
| 224 |
|
#endif |
| 225 |
|
|