cmtkAnatomicalOrientation.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 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: 2749 $
00026 //
00027 //  $LastChangedDate: 2011-01-14 14:44:48 -0800 (Fri, 14 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkAnatomicalOrientation_h_included_
00034 #define __cmtkAnatomicalOrientation_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkAnatomicalOrientationBase.h>
00039 
00040 #include <System/cmtkSmartPtr.h>
00041 
00042 #include <Base/cmtkTypes.h>
00043 #include <Base/cmtkFixedVector.h>
00044 #include <Base/cmtkMetaInformationObject.h>
00045 #include <Base/cmtkAffineXform.h>
00046 
00047 namespace
00048 cmtk
00049 {
00050 
00053 
00055 class AnatomicalOrientation
00056   : public AnatomicalOrientationBase
00057 {
00058 public:
00060   typedef AnatomicalOrientation Self;
00061 
00063   typedef AnatomicalOrientationBase Superclass;
00064 
00074   static void GetOrientationFromDirections( char* orientation, const AffineXform::MatrixType& directions, const char* spaceAxes );
00075 
00077   static void GetImageToSpaceAxesPermutation( int (&imageToSpaceAxesPermutation)[3][3], const char* orientation, const char* spaceAxes );
00078 
00080   class PermutationMatrix
00081   {
00082   public:
00084     typedef PermutationMatrix Self;
00085 
00087     typedef SmartPointer<Self> SmartPtr;
00088 
00090     PermutationMatrix( const FixedVector<3,int>& sourceDims, const std::string& curOrientation, const char newOrientation[3] );
00091    
00098     template<class T>
00099     const FixedVector<3,T> GetPermutedArray( const FixedVector<3,T>& source ) const
00100     {
00101       FixedVector<3,T> target;
00102       for ( int i = 0; i < 3; i++ )
00103         {
00104         target[i] = source[this->m_Axes[i]];
00105         }
00106       return target;
00107     }
00108 
00111     AffineXform::MatrixType GetPermutedMatrix( const AffineXform::MatrixType& inMatrix ) const;
00112     
00117     void GetReorientedIndex( const int* origPoint, int* newPoint ) const
00118     {
00119       for ( int i = 0; i < 3; ++i )
00120         newPoint[i] = this->m_Multipliers[i] * origPoint[this->m_Axes[i]] + this->m_Offsets[i];
00121     }
00122 
00127     size_t NewOffsetFromPoint( const int* origPoint ) const
00128     {
00129       return ( this->m_Multipliers[0] * origPoint[this->m_Axes[0]] + this->m_Offsets[0] ) + 
00130               this->m_NewDims[0] * 
00131               ( ( this->m_Multipliers[1] * origPoint[this->m_Axes[1]] + this->m_Offsets[1] ) + 
00132                   this->m_NewDims[1] * 
00133                   ( this->m_Multipliers[2] * origPoint[this->m_Axes[2]] + this->m_Offsets[2] ) );
00134     }
00135 
00136   private:
00144     FixedVector<3,int> m_Axes;
00145 
00151     FixedVector<3,int> m_Multipliers;
00152 
00156     FixedVector<3,int> m_NewDims;
00157     
00164     FixedVector<3,int> m_Offsets;
00165   };
00166 };
00167 
00169 
00170 } // namespace cmtk
00171 
00172 #endif // #ifndef __cmtkAnatomicalOrientation_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines