cmtkXform.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkXform.h"
00034 
00035 #include <Base/cmtkVolume.h>
00036 
00037 #include <math.h>
00038 #include <stdio.h>
00039 
00040 namespace
00041 cmtk
00042 {
00043 
00046 
00047 void
00048 Xform::AllocateParameterVector
00049 ( const size_t numberOfParameters )
00050 {
00051   this->m_NumberOfParameters = numberOfParameters;
00052   if ( this->m_NumberOfParameters )
00053     {
00054     this->m_ParameterVector = CoordinateVector::SmartPtr( new CoordinateVector( this->m_NumberOfParameters ) );
00055     this->m_Parameters = this->m_ParameterVector->Elements;
00056     }
00057   else
00058     {
00059     this->m_ParameterVector = CoordinateVector::SmartPtr::Null;
00060     this->m_Parameters = NULL;
00061     }
00062 }
00063 
00064 void
00065 Xform::SetParamVector ( CoordinateVector& v ) 
00066 {
00067   if ( this->m_ParameterVector ) 
00068     {
00069     *this->m_ParameterVector = v;
00070     } 
00071   else
00072     {
00073     this->m_ParameterVector = CoordinateVector::SmartPtr( new CoordinateVector( v ) );
00074     }
00075   this->m_Parameters = this->m_ParameterVector->Elements;
00076 }
00077 
00078 void
00079 Xform::SetParamVector ( const CoordinateVector& v ) 
00080 {
00081   if ( this->m_ParameterVector ) 
00082     {
00083     *this->m_ParameterVector = v;
00084     } 
00085   else
00086     {
00087     this->m_ParameterVector = CoordinateVector::SmartPtr( new CoordinateVector( v ) );
00088     }
00089   this->m_Parameters = this->m_ParameterVector->Elements;
00090 }
00091 
00092 CoordinateVector& 
00093 Xform::GetParamVector
00094 ( CoordinateVector& v, const size_t targetOffset ) const 
00095 {
00096   v.AdjustDimension( std::max<int>( v.Dim, targetOffset + this->ParamVectorDim() ) );
00097   v.CopyToOffset( *this->m_ParameterVector, targetOffset, this->ParamVectorDim() );
00098   return v;
00099 }
00100 
00101 void
00102 Xform::GetVolumeOfInfluence
00103 ( const size_t, const Self::SpaceVectorType& fromVol, const Self::SpaceVectorType& toVol, Self::SpaceVectorType& fromVOI, Self::SpaceVectorType& toVOI, const int ) const
00104 {
00105   fromVOI = fromVol;
00106   toVOI = toVol;
00107 }
00108 
00109 Types::Coordinate
00110 Xform::GetLandmarksMSD( const MatchedLandmarkList* ll ) const
00111 {
00112   double MSD = 0;
00113 
00114   MatchedLandmarkList::const_iterator it = ll->begin();
00115   while ( it != ll->end() )
00116     {
00117     Self::SpaceVectorType source( (*it)->GetLocation() );
00118     Self::SpaceVectorType target( (*it)->GetTargetLocation() );
00119     this->ApplyInPlace( source );
00120     MSD += (source - target).SumOfSquares();
00121     ++it;
00122     }
00123   
00124   MSD /= ll->size();
00125 
00126   return MSD;
00127 }
00128 
00129 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines