OpenWalnut  1.4.0
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 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 #include <cxxtest/TestSuite.h>
35 
36 #include "../../common/WLogger.h"
37 #include "../WITKImageConversion.h"
38 
39 /**
40  * Test functionality of WITKConversion class.
41  */
42 class WITKImageConversionTest : public CxxTest::TestSuite
43 {
44 public:
45  /**
46  * Setup logger and other stuff for each test.
47  */
48  void setUp()
49  {
51  }
52 
53  /**
54  * Converting a dataset into an itk image and then converting it back into a
55  * dataset should yield the same dataset.
56  */
58  {
59 #ifdef OW_USE_ITK
60  // build a dataset
61  boost::shared_ptr< std::vector< int > > values( new std::vector< int >( 27, 0 ) );
62  for( int k = 0; k < 27; ++k )
63  {
64  ( *values )[ k ] = 27 - k;
65  }
66  boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3 ) );
67  boost::shared_ptr< WValueSet< int > > v( new WValueSet< int >( 0, 1, values, W_DT_SIGNED_INT ) );
68  boost::shared_ptr< WDataSetScalar > ds( new WDataSetScalar( v, g ) );
69 
70  itk::Image< int, 3 >::Pointer i = makeImageFromDataSet< int >( ds );
71  boost::shared_ptr< WDataSetScalar > newds = makeDataSetFromImage< int >( i );
72 
73  TS_ASSERT_SAME_DATA( boost::dynamic_pointer_cast< WValueSet< int > >( ds->getValueSet() )->rawData(),
74  boost::dynamic_pointer_cast< WValueSet< int > >( newds->getValueSet() )->rawData(), sizeof( int ) * 27 );
75 #endif // OW_USE_ITK
76  }
77 };
78 
79 #endif // WITKIMAGECONVERSION_TEST_H
A grid that has parallelepiped cells which all have the same proportion.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
Definition: WLogger.cpp:41
Test functionality of WITKConversion class.
Base Class for all value set types.
Definition: WValueSet.h:48
void setUp()
Setup logger and other stuff for each test.
This data set type contains scalars as values.
void testConversion()
Converting a dataset into an itk image and then converting it back into a dataset should yield the sa...