OpenWalnut  1.3.1
WITKImageConversion_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WITKIMAGECONVERSION_TEST_H
26 #define WITKIMAGECONVERSION_TEST_H
27 
28 #include <vector>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include <cxxtest/TestSuite.h>
33 
34 #include "../../common/WLogger.h"
35 #include "../WITKImageConversion.h"
36 
37 /**
38  * Test functionality of WITKConversion class.
39  */
40 class WITKImageConversionTest : public CxxTest::TestSuite
41 {
42 public:
43  /**
44  * Setup logger and other stuff for each test.
45  */
46  void setUp()
47  {
49  }
50 
51  /**
52  * Converting a dataset into an itk image and then converting it back into a
53  * dataset should yield the same dataset.
54  */
56  {
57 #ifdef OW_USE_ITK
58  // build a dataset
59  boost::shared_ptr< std::vector< int > > values( new std::vector< int >( 27, 0 ) );
60  for( int k = 0; k < 27; ++k )
61  {
62  ( *values )[ k ] = 27 - k;
63  }
64  boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3 ) );
65  boost::shared_ptr< WValueSet< int > > v( new WValueSet< int >( 0, 1, values, W_DT_SIGNED_INT ) );
66  boost::shared_ptr< WDataSetScalar > ds( new WDataSetScalar( v, g ) );
67 
68  itk::Image< int, 3 >::Pointer i = makeImageFromDataSet< int >( ds );
69  boost::shared_ptr< WDataSetScalar > newds = makeDataSetFromImage< int >( i );
70 
71  TS_ASSERT_SAME_DATA( boost::shared_dynamic_cast< WValueSet< int > >( ds->getValueSet() )->rawData(),
72  boost::shared_dynamic_cast< WValueSet< int > >( newds->getValueSet() )->rawData(), sizeof( int ) * 27 );
73 #endif // OW_USE_ITK
74  }
75 };
76 
77 #endif // WITKIMAGECONVERSION_TEST_H