Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkPathFunctions.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkPathFunctions.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-06 00:08:10 $
00007   Version:   $Revision: 1.9 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkPathFunctions_h
00018 #define __itkPathFunctions_h
00019 
00020 
00021 #include "itkPath.h"
00022 #include "itkChainCodePath.h"
00023 #include "itkFourierSeriesPath.h"
00024 #include "itkOffset.h"
00025 #include <math.h>
00026 
00027 namespace itk
00028 {
00033 template <class TChainCodePath, class TPathInput>
00034 void MakeChainCodeTracePath( TChainCodePath & chainPath,
00035                              const TPathInput & inPath,
00036                              bool restrictMovement = false )
00037 {
00038   typedef typename TChainCodePath::OffsetType OffsetType;
00039   typedef typename TChainCodePath::InputType  ChainInputType;
00040   typedef typename TChainCodePath::OutputType ChainOutputType;
00041   typedef typename TPathInput::InputType      InPathInputType;
00042   typedef typename TPathInput::OutputType     InPathOutputType;
00043 
00044   OffsetType offset, tempOffset, zeroOffset;
00045   InPathInputType inPathInput;
00046   int dimension = OffsetType::GetOffsetDimension();
00047   
00048   zeroOffset.Fill(0);
00049   
00050   chainPath.Clear();
00051   inPathInput = inPath.StartOfInput();
00052   chainPath.SetStart(  inPath.EvaluateToIndex( inPathInput )  );
00053   
00054   for(ChainInputType chainInput=0;;)
00055     {
00056     offset  = inPath.IncrementInput(inPathInput);
00057     if( zeroOffset == offset ) { break; }
00058     
00059     if( ! restrictMovement )
00060       {
00061       chainPath.InsertStep( chainInput++, offset );
00062       }
00063     else
00064       {
00065       for( int d=0; d<dimension; d++ )
00066         {
00067         tempOffset.Fill(0);
00068         tempOffset[d] = offset[d];
00069         chainPath.InsertStep( chainInput++, tempOffset );
00070         }
00071       }
00072     }
00073 }
00074 
00081 template <class TFourierSeriesPath, class TChainCodePath>
00082 void MakeFourierSeriesPathTraceChainCode( TFourierSeriesPath & FSPath,
00083                              const TChainCodePath & chainPath,
00084                              unsigned int numHarmonics = 8 )
00085 {
00086   typedef typename TFourierSeriesPath::IndexType  IndexType;
00087   typedef typename TFourierSeriesPath::OffsetType OffsetType;
00088   typedef typename TFourierSeriesPath::VectorType VectorType;
00090 
00091   typedef typename TFourierSeriesPath::InputType  FSInputType;
00092   typedef typename TFourierSeriesPath::OutputType FSOutputType;
00093   typedef typename TChainCodePath::InputType      ChainInputType;
00094   typedef typename TChainCodePath::OutputType     ChainOutputType;
00095   
00096   IndexType   index;
00097   VectorType  indexVector;
00098   VectorType  cosCoefficient;
00099   VectorType  sinCoefficient;
00100   FSInputType theta;
00101   int         dimension =     OffsetType::GetOffsetDimension();
00102   unsigned    numSteps  =     chainPath.NumberOfSteps();
00103   
00104   const double PI = 4.0 * vcl_atan( 1.0 );
00105 
00106   FSPath.Clear();
00107   
00108   // Adjust our private copy of numHarmonics if necessary
00109   if( numHarmonics <= 1 )
00110     numHarmonics = 2;
00111   else if( numHarmonics*2 > numSteps )
00112     numHarmonics = numSteps / 2;
00113   
00114   for( unsigned n=0; n<numHarmonics; n++ )
00115     {
00116     index = chainPath.GetStart();
00117     cosCoefficient.Fill(0.0);
00118     sinCoefficient.Fill(0.0);
00119     
00120     for( ChainInputType step=0; step<numSteps; step++ )
00121       {
00122       index += chainPath.Evaluate( step );
00123       theta = 2 * n * PI * ( double(step+1)) / numSteps;
00124       
00125       // turn the current index into a vector
00126       for( int d=0; d<dimension; d++ )
00127         {
00128         indexVector[d] = index[d];
00129         }
00130       cosCoefficient += indexVector * (vcl_cos(theta)/numSteps);
00131       sinCoefficient += indexVector * (vcl_sin(theta)/numSteps);
00132       }
00133     
00134     FSPath.AddHarmonic( cosCoefficient, sinCoefficient );
00135     }
00136 }
00137 
00138 } // end namespace itk
00139 
00140 #endif
00141 

Generated at Fri Apr 16 19:16:40 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000