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 "cmtkAnatomicalOrientation.h"
00034
00035 #include <System/cmtkConsole.h>
00036
00037 #include <math.h>
00038
00039 namespace
00040 cmtk
00041 {
00042
00045
00046 void
00047 AnatomicalOrientation
00048 ::GetOrientationFromDirections( char* orientation, const AffineXform::MatrixType& directions, const char* spaceAxes )
00049 {
00050 const Types::Coordinate spacing[3] =
00051 {
00052 sqrt( directions[0][0]*directions[0][0] + directions[0][1]*directions[0][1] + directions[0][2]*directions[0][2] ),
00053 sqrt( directions[1][0]*directions[1][0] + directions[1][1]*directions[1][1] + directions[1][2]*directions[1][2] ),
00054 sqrt( directions[2][0]*directions[2][0] + directions[2][1]*directions[2][1] + directions[2][2]*directions[2][2] )
00055 };
00056
00057
00058 bool axisUsed[3] = { false, false, false };
00059
00060 for ( int axis = 0; axis < 3; ++axis )
00061 {
00062
00063 int maxDim = 0;
00064 while ( axisUsed[maxDim] ) ++maxDim;
00065
00066
00067 Types::Coordinate max = fabs( directions[axis][0] / spacing[axis] );
00068 for ( int dim = 1; dim < 3; ++dim )
00069 {
00070 const Types::Coordinate positive = fabs( directions[axis][dim] / spacing[axis] );
00071 if ( (positive > max) && !axisUsed[dim] )
00072 {
00073 max = positive;
00074 maxDim = dim;
00075 }
00076 else
00077 {
00078 if ( positive == max )
00079 {
00080 maxDim = 3;
00081 }
00082 }
00083 }
00084
00085 if ( maxDim == 3 )
00086 {
00087 StdErr << "WARNING: image seems to have an oblique orientation. This is not going to end well...\n";
00088 }
00089
00090 orientation[axis] = (directions[axis][maxDim] > 0) ? spaceAxes[maxDim] : Self::OppositeDirection( spaceAxes[maxDim] );
00091 axisUsed[maxDim] = true;
00092 }
00093 orientation[3] = 0;
00094 }
00095
00096 void
00097 AnatomicalOrientation
00098 ::GetImageToSpaceAxesPermutation( int (&imageToSpaceAxesPermutation)[3][3], const char* orientation, const char* spaceAxes )
00099 {
00100 for ( int j = 0; j < 3; ++j )
00101 {
00102 for ( int i = 0; i < 3; ++i )
00103 {
00104 if ( orientation[j] == spaceAxes[i] )
00105 imageToSpaceAxesPermutation[j][i] = 1;
00106 else
00107 if ( Self::OnSameAxis( orientation[j], spaceAxes[i] ) )
00108 imageToSpaceAxesPermutation[j][i] = -1;
00109 else
00110 imageToSpaceAxesPermutation[j][i] = 0;
00111 }
00112 }
00113 }
00114
00115 }