Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkSlowPolyLineParametricPath.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #ifndef _itkSlowPolyLineParametricPath_txx
17 #define _itkSlowPolyLineParametricPath_txx
18 
19 #include "itkSlowPolyLineParametricPath.h"
20 #include <math.h>
21 
22 
23 
24 namespace itk
25 {
26 
27 //template<unsigned int VDimension>
28 //typename SlowPolyLineParametricPath<VDimension>::VectorType
29 //SlowPolyLineParametricPath<VDimension>
30 //::EvaluateDerivative(const InputType & input) const
31 //{
32 //}
33 
34 
35 
36 /**
37  * Constructor
38  */
39 template <unsigned int VDimension>
40 SlowPolyLineParametricPath<VDimension>
41 ::SlowPolyLineParametricPath()
42 {
43  this->SetDefaultInputStepSize( 0.3 );
44 }
45 
46 
47 template<unsigned int VDimension>
48 typename SlowPolyLineParametricPath<VDimension>::OffsetType
49 SlowPolyLineParametricPath<VDimension>
50 ::IncrementInput(InputType & input) const
51 {
52  int iterationCount;
53  bool tooSmall;
54  bool tooBig;
55  InputType inputStepSize;
56  InputType finalInputValue;
57  OffsetType offset;
58  IndexType currentImageIndex;
59  IndexType nextImageIndex;
60  IndexType finalImageIndex;
61 
62  iterationCount = 0;
63  inputStepSize = this->GetDefaultInputStepSize();
64 
65  // Are we already at (or past) the end of the input?
66  finalInputValue = this->EndOfInput();
67  currentImageIndex = this->EvaluateToIndex( input );
68  finalImageIndex = this->EvaluateToIndex( finalInputValue );
69  offset = finalImageIndex - currentImageIndex;
70  if( ( offset == this->GetZeroOffset() && input != this->StartOfInput() ) ||
71  ( input >=finalInputValue ) )
72  {
73  return this->GetZeroOffset();
74  }
75 
76  do
77  {
78  if( iterationCount++ > 10000 ) {return this->GetZeroOffset(); itkExceptionMacro(<<"Too many iterations");}
79 
80  nextImageIndex = this->EvaluateToIndex( input + inputStepSize );
81  offset = nextImageIndex - currentImageIndex;
82 
83  tooBig = false;
84  tooSmall = ( offset == this->GetZeroOffset() );
85  if( tooSmall )
86  {
87  // increase the input step size, but don't go past the end of the input
88  inputStepSize *= 2;
89  if( (input + inputStepSize) >= finalInputValue ){
90  //inputStepSize = finalInputValue - input;
91  inputStepSize += this->GetDefaultInputStepSize();
92  }
93  }
94  else
95  {
96  // Search for an offset dimension that is too big
97  for( unsigned int i=0; i<VDimension && !tooBig; i++ )
98  {
99  tooBig = ( offset[i] >= 2 || offset[i] <= -2 );
100  }
101 
102  if( tooBig ){
103  //inputStepSize /= 1.5;
104  inputStepSize -= (this->GetDefaultInputStepSize()/0.5);
105  }
106  }
107  }
108  while( tooSmall || tooBig );
109 
110  input += inputStepSize;
111  return offset;
112 }
113 
114 
115 /**
116  * Standard "PrintSelf" method
117  */
118 template <unsigned int VDimension>
119 void
120 SlowPolyLineParametricPath<VDimension>
121 ::PrintSelf( std::ostream& os, Indent indent) const
122 {
123  Superclass::PrintSelf( os, indent );
124 }
125 
126 
127 
128 } // end namespaceitk
129 
130 #endif