OpenWalnut  1.5.0dev
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 <memory>
29 #include <vector>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../../common/WLogger.h"
34 #include "../WITKImageConversion.h"
35 
36 /**
37  * Test functionality of WITKConversion class.
38  */
39 class WITKImageConversionTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Setup logger and other stuff for each test.
44  */
45  void setUp()
46  {
48  }
49 
50  /**
51  * Converting a dataset into an itk image and then converting it back into a
52  * dataset should yield the same dataset.
53  */
55  {
56 #ifdef OW_USE_ITK
57  // build a dataset
58  std::shared_ptr< std::vector< int > > values( new std::vector< int >( 27, 0 ) );
59  for( int k = 0; k < 27; ++k )
60  {
61  ( *values )[ k ] = 27 - k;
62  }
63  std::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3 ) );
64  std::shared_ptr< WValueSet< int > > v( new WValueSet< int >( 0, 1, values, W_DT_SIGNED_INT ) );
65  std::shared_ptr< WDataSetScalar > ds( new WDataSetScalar( v, g ) );
66 
67  itk::Image< int, 3 >::Pointer i = makeImageFromDataSet< int >( ds );
68  std::shared_ptr< WDataSetScalar > newds = makeDataSetFromImage< int >( i );
69 
70  TS_ASSERT_SAME_DATA( std::dynamic_pointer_cast< WValueSet< int > >( ds->getValueSet() )->rawData(),
71  std::dynamic_pointer_cast< WValueSet< int > >( newds->getValueSet() )->rawData(), sizeof( int ) * 27 );
72 #endif // OW_USE_ITK
73  }
74 };
75 
76 #endif // WITKIMAGECONVERSION_TEST_H
This data set type contains scalars as values.
A grid that has parallelepiped cells which all have the same proportion.
Test functionality of WITKConversion class.
void setUp()
Setup logger and other stuff for each test.
void testConversion()
Converting a dataset into an itk image and then converting it back into a dataset should yield the sa...
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
Base Class for all value set types.
Definition: WValueSet.h:47
const T * rawData() const
Sometimes we need raw access to the data array, for e.g.
Definition: WValueSet.h:240