cmtkUniformVolume_Space.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 "cmtkUniformVolume.h"
00034 
00035 #include <Base/cmtkAnatomicalOrientation.h>
00036 #include <Base/cmtkAffineXform.h>
00037 
00038 namespace
00039 cmtk
00040 {
00041 
00042 void
00043 UniformVolume::CreateDefaultIndexToPhysicalMatrix()
00044 {
00045   this->m_IndexToPhysicalMatrix = AffineXform::MatrixType::IdentityMatrix;
00046   for ( int axis = 0; axis < 3; ++axis )
00047     for ( int i = 0; i < 3; ++i )
00048       this->m_IndexToPhysicalMatrix[axis][i] *= this->m_Delta[axis];
00049 }
00050 
00051 const UniformVolume::SmartPtr
00052 UniformVolume::GetReoriented( const char* newOrientation ) const
00053 {
00054   const std::string curOrientation = this->m_MetaInformation[META_IMAGE_ORIENTATION];
00055   DataGrid::SmartPtr temp( DataGrid::GetReoriented( newOrientation ) );
00056 
00057   AnatomicalOrientation::PermutationMatrix pmatrix( this->m_Dims, curOrientation, newOrientation );
00058   FixedVector<3,Types::Coordinate> newSize = pmatrix.GetPermutedArray( this->Size );
00059   
00060   UniformVolume::SmartPtr result( new UniformVolume( temp->GetDims(), newSize, temp->GetData() ) );
00061   result->m_Offset = pmatrix.GetPermutedArray( this->m_Offset );
00062   result->m_IndexToPhysicalMatrix = pmatrix.GetPermutedMatrix( this->m_IndexToPhysicalMatrix );
00063 
00064   result->m_MetaInformation = temp->m_MetaInformation;
00065   return result;
00066 }
00067 
00068 void
00069 UniformVolume
00070 ::ChangeCoordinateSpace( const std::string& newSpace )
00071 {
00072   const std::string currentSpace = this->m_MetaInformation[META_SPACE];
00073   if ( currentSpace == newSpace )
00074     return; // nothing to do.
00075 
00076   int axesPermutation[3][3];
00077   AnatomicalOrientation::GetImageToSpaceAxesPermutation( axesPermutation, newSpace.c_str(), currentSpace.c_str() );
00078 
00079   AffineXform::MatrixType newMatrix;
00080   for ( int j = 0; j < 3; ++j )
00081     {
00082     for ( int j2 = 0; j2 < 3; ++j2 )
00083       {
00084       if ( axesPermutation[j][j2] )
00085         {
00086         for ( int i = 0; i < 4; ++i )
00087           {
00088           newMatrix[i][j] = axesPermutation[j][j2] * this->m_IndexToPhysicalMatrix[i][j2];
00089           }
00090         }
00091       }
00092     }
00093   
00094   this->m_MetaInformation[META_SPACE] = newSpace;
00095   this->m_IndexToPhysicalMatrix = newMatrix;
00096 }
00097 
00098 std::string
00099 UniformVolume
00100 ::GetOrientationFromDirections() const
00101 {
00102   const AffineXform::MatrixType& matrix = this->m_IndexToPhysicalMatrix;
00103   char orientationString[4] = { 0,0,0,0 };
00104   AnatomicalOrientation::GetOrientationFromDirections( orientationString, matrix, this->m_MetaInformation[META_SPACE].c_str() );
00105   return std::string( orientationString );
00106 }
00107 
00108 AffineXform::MatrixType
00109 UniformVolume::GetImageToPhysicalMatrix() const
00110 {
00111   AffineXform::MatrixType matrix = this->m_IndexToPhysicalMatrix;
00112 // mDelta[3] is implicitly == 1 (homogeneous coordinates), so 4th matrix row (translation/coordinate origin) stays untouched
00113   for ( int i = 0; i < 3; ++i )
00114     for ( int j = 0; j < 3; ++j )
00115       matrix[i][j] /= this->m_Delta[i];
00116 
00117   return matrix;
00118 }
00119 
00120 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines