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 #include "cmtkSplineWarpXformITKIO.h"
00032
00033 #include <IO/cmtkAffineXformITKIO.h>
00034 #include <Base/cmtkTransformChangeToSpaceAffine.h>
00035
00036 #include <fstream>
00037 #include <string>
00038 #include <typeinfo>
00039
00040 void
00041 cmtk::SplineWarpXformITKIO
00042 ::Write( const std::string& filename, const SplineWarpXform& xform, const UniformVolume& refVolume, const UniformVolume& fltVolume )
00043 {
00044 std::ofstream stream( filename.c_str() );
00045 if ( stream.good() )
00046 {
00047
00048 stream << "#Insight Transform File V1.0\n"
00049 << "# Transform 0\n";
00050
00051
00052 if ( typeid( Types::Coordinate ) == typeid( double ) )
00053 {
00054 stream << "Transform: BSplineDeformableTransform_double_3_3\n";
00055 }
00056 else
00057 {
00058 stream << "Transform: BSplineDeformableTransform_float_3_3\n";
00059 }
00060
00061
00062 stream << "Parameters:";
00063
00064 Vector3D v, vx;
00065 const AffineXform::SmartPtr bulkXform = xform.GetInitialAffineXform();
00066
00067 for ( size_t cp = 0; cp < xform.GetNumberOfControlPoints(); ++cp )
00068 {
00069 xform.GetOriginalControlPointPositionByOffset( v, cp );
00070 if ( bulkXform )
00071 bulkXform->ApplyInPlace( v );
00072 xform.GetShiftedControlPointPositionByOffset( vx, cp );
00073
00074 vx -= v;
00075 stream << " " << vx[0] << " " << vx[1] << " " << vx[2];
00076 }
00077 stream << "\n";
00078
00079
00080 Vector3D origin( xform.m_Offset * refVolume.GetImageToPhysicalMatrix() );
00081
00082
00083
00084
00085
00086
00087 stream << "FixedParameters: "
00088 << xform.m_Dims[0] << " " << xform.m_Dims[1] << " " << xform.m_Dims[2] << " "
00089 << origin[0] << " " << origin[1] << " " << origin[2] << " "
00090 << xform.Spacing[0] << " " << xform.Spacing[1] << " " << xform.Spacing[2] << " "
00091 << "1 0 0 0 1 0 0 0 1\n";
00092
00093 if ( bulkXform )
00094 {
00095 TransformChangeToSpaceAffine toNative( *(bulkXform), refVolume, fltVolume, AnatomicalOrientationBase::SPACE_ITK );
00096 AffineXformITKIO::Write( stream, toNative.GetTransformation(), 1 );
00097 }
00098
00099 stream.close();
00100 }
00101 }
00102