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 "cmtkClassStreamAffineXform.h"
00034
00035 namespace
00036 cmtk
00037 {
00038
00041
00042 ClassStream&
00043 operator << ( ClassStream& stream, const AffineXform& affineXform )
00044 {
00045 stream.Begin( "affine_xform" );
00046 stream.WriteCoordinateArray( "xlate", affineXform.RetXlate(), 3 );
00047 stream.WriteCoordinateArray( "rotate", affineXform.RetAngles(), 3 );
00048 if ( affineXform.GetUseLogScaleFactors() )
00049 stream.WriteCoordinateArray( "log_scale", affineXform.RetScales(), 3 );
00050 else
00051 stream.WriteCoordinateArray( "scale", affineXform.RetScales(), 3 );
00052 stream.WriteCoordinateArray( "shear", affineXform.RetShears(), 3 );
00053 stream.WriteCoordinateArray( "center", affineXform.RetCenter(), 3 );
00054 stream.End();
00055
00056 return stream;
00057 }
00058
00059 ClassStream&
00060 operator >> ( ClassStream& stream, AffineXform::SmartPtr& affineXform )
00061 {
00062 try
00063 {
00064 affineXform = AffineXform::SmartPtr( new AffineXform );
00065 stream >> (*affineXform);
00066 }
00067 catch (...)
00068 {
00069 affineXform = AffineXform::SmartPtr::Null;
00070 }
00071 return stream;
00072 }
00073
00074 ClassStream&
00075 operator >> ( ClassStream& stream, AffineXform& affineXform )
00076 {
00077 CoordinateVector pVector( 15 );
00078 Types::Coordinate* parameters = pVector.Elements;
00079
00080 const char *referenceStudy = NULL;
00081 const char *floatingStudy = NULL;
00082
00083 if ( stream.Seek( "affine_xform", true ) != TYPEDSTREAM_OK )
00084 {
00085 stream.Rewind();
00086 if ( stream.Seek( "registration", true ) != TYPEDSTREAM_OK )
00087 {
00088 throw Exception( "Did not find 'registration' section in affine xform archive" );
00089 }
00090
00091 referenceStudy = stream.ReadString( "reference_study", NULL );
00092 floatingStudy = stream.ReadString( "floating_study", NULL );
00093
00094 if ( stream.Seek( "affine_xform", false ) != TYPEDSTREAM_OK )
00095 {
00096 throw Exception( "Did not find 'affine_xform' section in affine xform archive" );
00097 }
00098 }
00099
00100 if ( stream.ReadCoordinateArray( "xlate", parameters, 3 ) != TYPEDSTREAM_OK )
00101 {
00102 parameters[0] = parameters[1] = parameters[2] = 0;
00103 }
00104 if ( stream.ReadCoordinateArray( "rotate", parameters+3, 3 ) != TYPEDSTREAM_OK )
00105 {
00106 parameters[3] = parameters[4] = parameters[5] = 0;
00107 }
00108 bool logScaleFactors = false;
00109 if ( stream.ReadCoordinateArray( "scale", parameters+6, 3 ) != TYPEDSTREAM_OK )
00110 {
00111 if ( stream.ReadCoordinateArray( "log_scale", parameters+6, 3 ) == TYPEDSTREAM_OK )
00112 {
00113 logScaleFactors = true;
00114 }
00115 else
00116 {
00117 parameters[6] = parameters[7] = parameters[8] = 1;
00118 }
00119 }
00120 if ( stream.ReadCoordinateArray( "shear", parameters+9, 3 ) != TYPEDSTREAM_OK )
00121 {
00122 parameters[9] = parameters[10] = parameters[11] = 0;
00123 }
00124 if ( stream.ReadCoordinateArray( "center", parameters+12, 3 ) != TYPEDSTREAM_OK )
00125 {
00126 parameters[12] = parameters[13] = parameters[14] = 0;
00127 }
00128 stream.End();
00129
00130 affineXform.SetUseLogScaleFactors( logScaleFactors );
00131 affineXform.SetParamVector( pVector );
00132
00133 affineXform.m_MetaInformation[META_SPACE] = AnatomicalOrientation::ORIENTATION_STANDARD;
00134
00135 if ( referenceStudy )
00136 affineXform.SetMetaInfo( META_XFORM_FIXED_IMAGE_PATH, referenceStudy );
00137
00138 if ( floatingStudy )
00139 affineXform.SetMetaInfo( META_XFORM_MOVING_IMAGE_PATH, floatingStudy );
00140
00141 return stream;
00142 }
00143
00144 }