OpenWalnut  1.4.0
WITKImageConversion_test.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WITKIMAGECONVERSION_TEST_H
00026 #define WITKIMAGECONVERSION_TEST_H
00027 
00028 #include <vector>
00029 
00030 #include <boost/shared_ptr.hpp>
00031 
00032 #include <cxxtest/TestSuite.h>
00033 
00034 #include "../../common/WLogger.h"
00035 #include "../WITKImageConversion.h"
00036 
00037 /**
00038  * Test functionality of WITKConversion class.
00039  */
00040 class WITKImageConversionTest : public CxxTest::TestSuite
00041 {
00042 public:
00043     /**
00044      * Setup logger and other stuff for each test.
00045      */
00046     void setUp()
00047     {
00048         WLogger::startup();
00049     }
00050 
00051     /**
00052      * Converting a dataset into an itk image and then converting it back into a
00053      * dataset should yield the same dataset.
00054      */
00055     void testConversion()
00056     {
00057 #ifdef OW_USE_ITK
00058         // build a dataset
00059         boost::shared_ptr< std::vector< int > > values( new std::vector< int >( 27, 0 ) );
00060         for( int k = 0; k < 27; ++k )
00061         {
00062             ( *values )[ k ] = 27 - k;
00063         }
00064         boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3 ) );
00065         boost::shared_ptr< WValueSet< int > > v( new WValueSet< int >( 0, 1, values, W_DT_SIGNED_INT ) );
00066         boost::shared_ptr< WDataSetScalar > ds( new WDataSetScalar( v, g ) );
00067 
00068         itk::Image< int, 3 >::Pointer i = makeImageFromDataSet< int >( ds );
00069         boost::shared_ptr< WDataSetScalar > newds = makeDataSetFromImage< int >( i );
00070 
00071         TS_ASSERT_SAME_DATA( boost::dynamic_pointer_cast< WValueSet< int > >( ds->getValueSet() )->rawData(),
00072                              boost::dynamic_pointer_cast< WValueSet< int > >( newds->getValueSet() )->rawData(), sizeof( int ) * 27 );
00073 #endif  // OW_USE_ITK
00074     }
00075 };
00076 
00077 #endif  // WITKIMAGECONVERSION_TEST_H