cmtkSymmetryPlaneFunctional.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 "cmtkSymmetryPlaneFunctional.h"
00034 
00035 #include <Base/cmtkTransformedVolumeAxes.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 SymmetryPlaneFunctional::SymmetryPlaneFunctional
00045 ( UniformVolume::SmartPtr& volume ) : m_Volume( NULL )
00046 {
00047   this->SetVolume( volume );
00048   
00049   m_Metric = new VoxelMatchingNormMutInf<>( volume, volume );
00050 }
00051 
00052 SymmetryPlaneFunctional::SymmetryPlaneFunctional
00053 ( UniformVolume::SmartPtr& volume, 
00054   const Types::DataItemRange& valueRange )
00055   : m_Volume( NULL )
00056 {
00057   this->SetVolume( volume );
00058   
00059   m_Metric = new VoxelMatchingNormMutInf<>( volume, volume, valueRange, valueRange );
00060 }
00061 
00062 Types::Coordinate 
00063 SymmetryPlaneFunctional::GetParamStep 
00064 ( const size_t idx, const Types::Coordinate mmStep ) 
00065   const
00066 {
00067   switch ( idx ) 
00068     {
00069     // plane offset is a translation
00070     case 0:
00071       return mmStep;
00072       // the other two parameters are rotations
00073     case 1:
00074     case 2:
00075       return mmStep / sqrt( MathUtil::Square( 0.5 * m_Volume->Size[0] ) + MathUtil::Square( 0.5 * m_Volume->Size[1] ) + MathUtil::Square( 0.5 * m_Volume->Size[2] ) ) * 90/M_PI;
00076     }
00077   return mmStep;
00078 }
00079 
00080 SymmetryPlaneFunctional::ReturnType
00081 SymmetryPlaneFunctional::Evaluate()
00082 {
00083   const TransformedVolumeAxes gridHash( *m_Volume, this->m_ParametricPlane, m_Volume->Deltas().begin() );
00084   const Vector3D *HashX = gridHash[0], *HashY = gridHash[1], *HashZ = gridHash[2];
00085 
00086   Vector3D pFloating;
00087     
00088   m_Metric->Reset();
00089     
00090   const DataGrid::IndexType& Dims = m_Volume->GetDims();
00091   const int DimsX = Dims[0], DimsY = Dims[1], DimsZ = Dims[2];
00092 
00093   int fltIdx[3];
00094   Types::Coordinate fltFrac[3];
00095 
00096   Vector3D planeStart, rowStart;
00097 
00098   int r = 0;
00099   for ( int pZ = 0; pZ<DimsZ; ++pZ ) 
00100     {
00101     planeStart = HashZ[pZ];
00102     
00103     for ( int pY = 0; pY<DimsY; ++pY ) 
00104       {
00105       (rowStart = planeStart) += HashY[pY];
00106       
00107       for ( int pX = 0; pX<DimsX; ++pX, ++r ) 
00108         {
00109         (pFloating = rowStart) += HashX[pX];
00110         
00111         // Tell us whether the current location is still within the model
00112         // volume and get the respective voxel.
00113         if ( m_Volume->FindVoxelByIndex( pFloating, fltIdx, fltFrac ) ) 
00114           {
00115           // Compute data index of the model voxel in the model volume.
00116           int offset = fltIdx[0] + DimsX * (fltIdx[1] + DimsY * fltIdx[2]);
00117           
00118           // Continue metric computation.
00119           m_Metric->Proceed( (int) r, offset, fltFrac );
00120           }
00121         }
00122       }
00123     }
00124   
00125   return m_Metric->Get();
00126 }
00127 
00128 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines