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 #include <IO/cmtkClassStreamAffineXform.h>
00033 #include <IO/cmtkVolumeIO.h>
00034 #include <System/cmtkConsole.h>
00035
00036 namespace
00037 cmtk
00038 {
00039
00042
00043 template<class TMetricFunctionalType>
00044 ClassStream& operator <<
00045 ( ClassStream& stream, const AffineMultiChannelRegistrationFunctional<TMetricFunctionalType>& functional )
00046 {
00047 stream.Begin( "registration" );
00048
00049 stream.WriteInt( "reference_channel_count", functional.GetNumberOfReferenceChannels() );
00050 for ( size_t idx = 0; idx < functional.GetNumberOfReferenceChannels(); ++idx )
00051 {
00052 stream.WriteString( "reference_channel", functional.GetReferenceChannel( idx )->m_MetaInformation[META_FS_PATH].c_str() );
00053 }
00054
00055 stream.WriteInt( "floating_channel_count", functional.GetNumberOfFloatingChannels() );
00056 for ( size_t idx = 0; idx < functional.GetNumberOfFloatingChannels(); ++idx )
00057 {
00058 stream.WriteString( "floating_channel", functional.GetFloatingChannel( idx )->m_MetaInformation[META_FS_PATH].c_str() );
00059 }
00060
00061 stream << functional.GetTransformation();
00062 stream.End();
00063
00064 return stream;
00065 }
00066
00067 template<class TMetricFunctionalType>
00068 ClassStream& operator >>
00069 ( ClassStream& stream, AffineMultiChannelRegistrationFunctional<TMetricFunctionalType>& functional )
00070 {
00071 stream.Seek( "registration" );
00072
00073 const size_t referenceChannelCount = stream.ReadInt( "reference_channel_count", 0 );
00074 for ( size_t idx = 0; idx < referenceChannelCount; ++idx )
00075 {
00076 const char* channel = stream.ReadString( "reference_channel", NULL, true );
00077 if ( channel )
00078 {
00079 UniformVolume::SmartPtr volume( VolumeIO::ReadOriented( channel ) );
00080 if ( !volume || !volume->GetData() )
00081 {
00082 StdErr << "ERROR: Cannot read image " << channel << "\n";
00083 exit( 1 );
00084 }
00085 functional.AddReferenceChannel( volume );
00086 }
00087 }
00088
00089 const size_t floatingChannelCount = stream.ReadInt( "floating_channel_count", 0 );
00090 for ( size_t idx = 0; idx < floatingChannelCount; ++idx )
00091 {
00092 const char* channel = stream.ReadString( "floating_channel", NULL, true );
00093 if ( channel )
00094 {
00095 UniformVolume::SmartPtr volume( VolumeIO::ReadOriented( channel ) );
00096 if ( !volume || !volume->GetData() )
00097 {
00098 StdErr << "ERROR: Cannot read image " << channel << "\n";
00099 exit( 1 );
00100 }
00101 functional.AddFloatingChannel( volume );
00102 }
00103 }
00104
00105 stream >> functional.GetTransformation();
00106 stream.End();
00107
00108 return stream;
00109 }
00110
00111 template<class TMetricFunctionalType>
00112 ClassStream& operator <<
00113 ( ClassStream& stream, const SplineWarpMultiChannelRegistrationFunctional<TMetricFunctionalType>& functional )
00114 {
00115 stream.Begin( "registration" );
00116
00117 stream.WriteInt( "reference_channel_count", functional.GetNumberOfReferenceChannels() );
00118 for ( size_t idx = 0; idx < functional.GetNumberOfReferenceChannels(); ++idx )
00119 {
00120 stream.WriteString( "reference_channel", functional.GetReferenceChannel( idx )->m_MetaInformation[META_FS_PATH].c_str() );
00121 }
00122
00123 stream.WriteInt( "floating_channel_count", functional.GetNumberOfFloatingChannels() );
00124 for ( size_t idx = 0; idx < functional.GetNumberOfFloatingChannels(); ++idx )
00125 {
00126 stream.WriteString( "floating_channel", functional.GetFloatingChannel( idx )->m_MetaInformation[META_FS_PATH].c_str() );
00127 }
00128
00129 stream << functional.GetTransformation();
00130 stream.End();
00131
00132 return stream;
00133 }
00134
00135 }