cmtkImageSymmetryPlaneFunctional.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 "cmtkImageSymmetryPlaneFunctional.h"
00034 
00035 #include <Base/cmtkTransformedVolumeAxes.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 ImageSymmetryPlaneFunctional::ImageSymmetryPlaneFunctional
00045 ( UniformVolume::SmartConstPtr& volume ) 
00046   : ImageSymmetryPlaneFunctionalBase( volume ),
00047     m_Metric( new ImagePairSimilarityMeasureMSD( this->m_Volume, this->m_Volume ) )
00048 {
00049 }
00050 
00051 ImageSymmetryPlaneFunctional::ImageSymmetryPlaneFunctional
00052 ( UniformVolume::SmartConstPtr& volume, 
00053   const Types::DataItemRange& valueRange )
00054   : ImageSymmetryPlaneFunctionalBase( volume, valueRange ),
00055     m_Metric( new ImagePairSimilarityMeasureMSD( this->m_Volume, this->m_Volume ) )
00056 {
00057 }
00058 
00059 ImageSymmetryPlaneFunctional::ReturnType
00060 ImageSymmetryPlaneFunctional::Evaluate()
00061 {
00062   const TransformedVolumeAxes gridHash( *m_Volume, this->m_ParametricPlane, m_Volume->Deltas().begin() );
00063   const Vector3D *HashX = gridHash[0], *HashY = gridHash[1], *HashZ = gridHash[2];
00064 
00065   Vector3D pFloating;
00066     
00067   Self::MetricType& metric = *m_Metric;
00068   metric.Reset();
00069     
00070   const DataGrid::IndexType& Dims = m_Volume->GetDims();
00071   const int DimsX = Dims[0], DimsY = Dims[1], DimsZ = Dims[2];
00072 
00073   int fltIdx[3];
00074   Types::Coordinate fltFrac[3];
00075 
00076   Vector3D planeStart, rowStart;
00077 
00078   int r = 0;
00079   for ( int pZ = 0; pZ<DimsZ; ++pZ ) 
00080     {
00081     planeStart = HashZ[pZ];
00082     
00083     for ( int pY = 0; pY<DimsY; ++pY ) 
00084       {
00085       (rowStart = planeStart) += HashY[pY];
00086       
00087       for ( int pX = 0; pX<DimsX; ++pX, ++r ) 
00088         {
00089         (pFloating = rowStart) += HashX[pX];
00090         
00091         // Is the current location still within the floating image, then get the respective voxel.
00092         if ( m_Volume->FindVoxelByIndex( pFloating, fltIdx, fltFrac ) )
00093           {
00094           // Continue metric computation.
00095           metric.Increment( metric.GetSampleX( r ), metric.GetSampleY( fltIdx, fltFrac ) );
00096           }
00097         }
00098       }
00099     }
00100   
00101   return metric.Get();
00102 }
00103 
00104 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines