Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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;
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
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 }