| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkOrthogonallyCorrected2DParametricPath.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:43 $ |
| 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 |
DEF |
=========================================================================*/ |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
#include "itkOrthogonallyCorrected2DParametricPath.h" |
| 20 |
|
#include <math.h> |
| 21 |
|
|
| 22 |
|
// not all versions of math.h seem to define M_PI: |
| 23 |
|
#ifndef M_PI |
| 24 |
|
#define M_PI 3.14159265358979323846 |
| 25 |
|
#endif |
| 26 |
|
|
| 27 |
|
|
| 28 |
EML |
|
| 29 |
|
namespace itk |
| 30 |
|
{ |
| 31 |
|
|
| 32 |
|
OrthogonallyCorrected2DParametricPath::OutputType |
| 33 |
|
OrthogonallyCorrected2DParametricPath |
| 34 |
|
::Evaluate( const InputType & inputValue ) const |
| 35 |
|
{ |
| 36 |
|
InputType input = inputValue; // we may want to remap the input |
| 37 |
|
InputType inputRange; |
| 38 |
|
InputType normalizedInput; |
| 39 |
|
OutputType output; |
| 40 |
|
int numOrthogonalCorrections; |
| 41 |
|
double softOrthogonalCorrectionTableIndex; |
| 42 |
|
double Correction, Correction1, Correction2; |
| 43 |
|
VectorType originalDerivative; |
| 44 |
|
|
| 45 |
|
numOrthogonalCorrections = m_OrthogonalCorrectionTable->Size(); |
| 46 |
|
|
| 47 |
|
// If the original path is closed, then tail input is remapped to head input |
| 48 |
|
if( m_OriginalPath->EvaluateToIndex(m_OriginalPath->EndOfInput()) == |
| 49 |
IND |
*******m_OriginalPath->EvaluateToIndex(m_OriginalPath->StartOfInput()) ) |
| 50 |
|
{ |
| 51 |
|
if( input >= m_OriginalPath->EndOfInput() ) |
| 52 |
|
{ |
| 53 |
|
// use the starting input value instead of the ending input value |
| 54 |
|
input = m_OriginalPath->StartOfInput(); |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
inputRange = m_OriginalPath->EndOfInput() - m_OriginalPath->StartOfInput(); |
| 59 |
|
normalizedInput = ( input - m_OriginalPath->StartOfInput() ) / inputRange; |
| 60 |
|
output.Fill(0); |
| 61 |
|
|
| 62 |
|
// Find the linearly interpolated offset error value for this exact time. |
| 63 |
LEN |
softOrthogonalCorrectionTableIndex = normalizedInput * numOrthogonalCorrections; |
| 64 |
|
Correction1 = m_OrthogonalCorrectionTable->ElementAt( |
| 65 |
|
int(softOrthogonalCorrectionTableIndex) ); |
| 66 |
|
Correction2 = m_OrthogonalCorrectionTable->ElementAt( |
| 67 |
|
int(softOrthogonalCorrectionTableIndex+1) % numOrthogonalCorrections ); |
| 68 |
|
Correction = Correction1 + (Correction2-Correction1)* |
| 69 |
IND |
********( softOrthogonalCorrectionTableIndex - |
| 70 |
|
int(softOrthogonalCorrectionTableIndex) ); |
| 71 |
|
|
| 72 |
|
// Find the direction of the offset |
| 73 |
|
originalDerivative = m_OriginalPath->EvaluateDerivative(input); |
| 74 |
|
originalDerivative.Normalize(); |
| 75 |
|
|
| 76 |
|
// Find the actual point along this corrected path |
| 77 |
|
output = m_OriginalPath->Evaluate(input); |
| 78 |
|
output[0] -= Correction*originalDerivative[1]; |
| 79 |
|
output[1] += Correction*originalDerivative[0]; |
| 80 |
|
return output; |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
EML |
|
| 85 |
|
void |
| 86 |
|
OrthogonallyCorrected2DParametricPath |
| 87 |
|
::SetOriginalPath( const OriginalPathType *originalPath ) |
| 88 |
|
{ |
| 89 |
|
itkDebugMacro("setting OriginalPath to " << originalPath ); |
| 90 |
|
if (this->m_OriginalPath != originalPath) |
| 91 |
|
{ |
| 92 |
|
this->m_OriginalPath = originalPath; |
| 93 |
|
// This is the important line that is not in itkSetObjectMacro |
| 94 |
|
this->m_DefaultInputStepSize = m_OriginalPath->GetDefaultInputStepSize(); |
| 95 |
|
this->Modified(); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
EML |
|
| 101 |
|
/** |
| 102 |
|
* Constructor |
| 103 |
|
*/ |
| 104 |
|
OrthogonallyCorrected2DParametricPath |
| 105 |
|
::OrthogonallyCorrected2DParametricPath() |
| 106 |
|
{ |
| 107 |
|
m_OriginalPath = NULL; |
| 108 |
|
m_OrthogonalCorrectionTable = OrthogonalCorrectionTableType::New(); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
EML |
|
| 113 |
|
/** |
| 114 |
|
* Standard "PrintSelf" method |
| 115 |
|
*/ |
| 116 |
|
void |
| 117 |
|
OrthogonallyCorrected2DParametricPath |
| 118 |
|
::PrintSelf( std::ostream& os, Indent indent) const |
| 119 |
|
{ |
| 120 |
|
Superclass::PrintSelf( os, indent ); |
| 121 |
|
os << indent << "Original Path: " << m_OriginalPath << std::endl; |
| 122 |
LEN |
os << indent << "Correction Table: " << m_OrthogonalCorrectionTable << std::endl; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
EML |
|
| 127 |
|
} // end namespaceitk |
| 128 |
|
|