cmtkAnatomicalOrientationPermutationMatrix.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: 2430 $
00026 //
00027 //  $LastChangedDate: 2010-10-08 21:24:30 -0700 (Fri, 08 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torsten_at_home $
00030 //
00031 */
00032 
00033 #include "cmtkAnatomicalOrientation.h"
00034 
00035 #include <string>
00036 #include <iostream>
00037 
00038 namespace
00039 cmtk
00040 {
00041 
00044 
00045 AnatomicalOrientation::PermutationMatrix::PermutationMatrix
00046 ( const FixedVector<3,int>& sourceDims, const std::string& curOrientation, const char newOrientation[3] ) 
00047 {
00048   // Build a permutation matrix and store it in compressed form 
00049   for ( int i = 0; i < 3; i++ )
00050     {
00051     for ( int j = 0; j < 3; j++ )
00052       {
00053       if ( newOrientation[i] == curOrientation[j] )
00054         {
00055         this->m_Axes[i] = j; 
00056         this->m_Multipliers[i] = 1;
00057         this->m_Offsets[i] = 0;
00058         break;
00059         }
00060       else if ( AnatomicalOrientation::OnSameAxis( newOrientation[i], curOrientation[j] ) )
00061         {
00062         this->m_Axes[i] = j; 
00063         this->m_Multipliers[i] = -1;
00064         this->m_Offsets[i] = sourceDims[j] - 1;
00065         break;
00066         }
00067       }
00068     }
00069 
00070   this->m_NewDims = this->GetPermutedArray( sourceDims );
00071 }
00072 
00073 AffineXform::MatrixType
00074 AnatomicalOrientation::PermutationMatrix::GetPermutedMatrix( const AffineXform::MatrixType& inMatrix ) const
00075 {
00076   AffineXform::MatrixType permutation;
00077 
00078   for ( int j = 0; j < 3; ++j )
00079     {
00080     for ( int i = 0; i < 3; ++i )
00081       {
00082       if ( i == this->m_Axes[j] )
00083         permutation[i][j] = this->m_Multipliers[j];
00084       else
00085         permutation[i][j] = 0;
00086       }
00087 
00088     permutation[3][j] = this->m_Offsets[j];
00089     }
00090 
00091   return permutation.GetInverse() * inMatrix;
00092 }
00093 
00094 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines