KWStyle - itkParametricPath.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkParametricPath.txx.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 =========================================================================*/
17
18
19 DEF #ifndef _itkParametricPath_txx
20 DEF #define _itkParametricPath_txx
21
22 #include "itkParametricPath.h"
23
24 namespace itk
25 {
26
27 /**
28  * Constructor
29  */
30 template <unsigned int VDimension>
31 ParametricPath<VDimension>
32 ::ParametricPath()
33 {
34   m_DefaultInputStepSize = 0.3;
35 }
36
37
38 template<unsigned int VDimension>
39 typename ParametricPath<VDimension>::IndexType
40 ParametricPath<VDimension>
41 ::EvaluateToIndex( const InputType & input ) const
42 {
43   ContinuousIndexType continuousIndex;
44   IndexType           index;
45   
46   continuousIndex = Evaluate( input );
47   
48   // Round each coordinate to the nearest integer value
49   for( unsigned int i=0; i<VDimension; i++ )
50     {
51     index[i] = (typename IndexType::IndexValueType)( continuousIndex[i] + 0.5 );
52     }
53   
54   return index;
55 }
56
57
58 EML
59 template<unsigned int VDimension>
60 typename ParametricPath<VDimension>::OffsetType
61 ParametricPath<VDimension>
62 ::IncrementInput(InputType & input) const
63 {
64   int         iterationCount;
65   bool        tooSmall;
66   bool        tooBig;
67   InputType   inputStepSize;
68   InputType   finalInputValue;
69   OffsetType  offset;
70   IndexType   currentImageIndex;
71   IndexType   nextImageIndex;
72   IndexType   finalImageIndex;
73   
74   iterationCount    = 0;
75   inputStepSize     = m_DefaultInputStepSize;
76
77   // Are we already at (or past) the end of the input?
78   finalInputValue   = this->EndOfInput();
79   currentImageIndex = this->EvaluateToIndex( input );
80   finalImageIndex   = this->EvaluateToIndex( finalInputValue );
81   offset            = finalImageIndex - currentImageIndex;
82   if(  ( offset == this->GetZeroOffset() && input != this->StartOfInput() )  ||
83 IND *******( input >=finalInputValue )  )
84     {
85     return this->GetZeroOffset();
86     }
87   
88   do
89     {
90     if( iterationCount++ > 10000 ) {itkExceptionMacro(<<"Too many iterations");}
91     
92     nextImageIndex    = this->EvaluateToIndex( input + inputStepSize );
93     offset            = nextImageIndex - currentImageIndex;
94     
95     tooBig = false;
96     tooSmall = ( offset == this->GetZeroOffset() );
97     if( tooSmall )
98       {
99       // double the input step size, but don't go past the end of the input
100       inputStepSize *= 2;
101       if(  (input + inputStepSize) >= finalInputValue  )
102         {
103         inputStepSize = finalInputValue - input;
104         }
105       }
106     else
107       {
108       // Search for an offset dimension that is too big
109       for( unsigned int i=0; i<VDimension && !tooBig; i++ )
110         {
111         tooBig = ( offset[i] >= 2 || offset[i] <= -2 );
112         }
113       
114       if( tooBig )
115         {
116         inputStepSize /= 1.5;
117         }
118       }
119     }
120   while( tooSmall || tooBig );
121   
122   input += inputStepSize;
123   return offset;
124 }
125
126 template<unsigned int VDimension>
127 typename ParametricPath<VDimension>::VectorType
128 ParametricPath<VDimension>
129 ::EvaluateDerivative(const InputType & input) const
130 {
131   InputType   inputStepSize;
132   
133   inputStepSize = m_DefaultInputStepSize;
134   if(  (input + inputStepSize) >= this->EndOfInput()  )
135     {
136     inputStepSize = this->EndOfInput() - input;
137     }
138   
139   return ( Evaluate(input + inputStepSize) - Evaluate(input) ) / inputStepSize;
140 }
141
142 template<unsigned int VDimension>
143 void
144 ParametricPath<VDimension>
145 ::PrintSelf (std::ostream &os, Indent indent) const
146 {
147   Superclass::PrintSelf(os, indent);
148   os << indent << "DefaultInputSize: " << m_DefaultInputStepSize << std::endl;
149 }
150
151 // end namespaceitk
152
153 #endif
154

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:38PM
© Kitware Inc.