cmtkClassStreamMultiChannelRegistration.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2004-2009 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 2398 $
00025 //
00026 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
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 /*forward*/ );
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 /*forward*/ );
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 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines