freTransformFunctionMedia.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freTransformFunctionMedia.txx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freTransformFunctionMedia_txx
00023 #define __freTransformFunctionMedia_txx
00024 
00025 #include "freTransformFunctionMedia.h"
00026 
00027 namespace FREE
00028 {
00029 
00033 
00034 
00035 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00036 void
00037 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00038 SetFieldRegion(const RegionType &region)
00039 {
00040   m_FieldRegion = region;
00041 };
00042 
00043 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00044 void
00045 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00046 Reset()
00047 {
00048   m_Transform = 0;
00049   
00050   m_FieldSpacing.Fill(1.0);
00051   m_FieldOrigin.Fill(0.0);
00052 
00053   typename RegionType::IndexType index;
00054   index.Fill(0);
00055   typename RegionType::SizeType size;
00056   size.Fill(1);
00057   m_FieldRegion = RegionType(index, size);
00058 };
00059 
00060 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00061 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00062 ~TransformFunctionMedia()
00063 {
00064   Reset();
00065 };
00066 
00067 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00068 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00069 TransformFunctionMedia()
00070 {
00071   Reset();
00072 };
00073 
00074 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
00075 typename TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::TransformFieldPointer
00076 TransformFunctionMedia<TScalarType, NInputDimensions, NOutputDimensions>::
00077 GenerateField()
00078 {
00079   if (m_Transform.IsNull()) throwExceptionMacro("Error cannot generate field. Transform function has no transformation set.");
00080 
00081   TransformFieldPointer smpField = TransformFieldType::New();
00082 
00083   try
00084   {
00085     //Create field
00086     smpField->SetOrigin(m_FieldOrigin);
00087     smpField->SetSpacing(m_FieldSpacing);
00088     smpField->SetRegions(m_FieldRegion);
00089     smpField->Allocate();
00090 
00091     typename TransformFieldType::ValueType zeroVector;
00092     for (int i=0; i<TransformFieldType::ImageDimension; i++)
00093         zeroVector.SetNthComponent(i,0);
00094     smpField->FillBuffer(zeroVector);
00095 
00096     // get Iterator to roam the field
00097     typedef itk::ImageRegionIterator<TransformFieldType> IteratorType;
00098     IteratorType iterator(smpField,m_FieldRegion);
00099 
00100     //process the field
00101     typedef typename TransformFieldType::PointType PointType;
00102     PointType actPoint;
00103     for (iterator.GoToBegin(); !(iterator.IsAtEnd()); ++iterator)
00104     {
00105         smpField->TransformIndexToPhysicalPoint(iterator.GetIndex(),actPoint);
00106         PointType transPoint = m_Transform->TransformPoint(actPoint);
00107         iterator.Set(transPoint-actPoint);
00108     }
00109   }
00110   catchAllNPassMacro("Unknown error when computing transformation field.");
00111 
00112   return smpField;
00113 }
00114 
00115 } //end of namespace free
00116 
00117 #endif

Generated at Sat Oct 13 17:58:55 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000