Commit 1601d08f authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD #146] added dataType to WValueSetBase

 * had to adjust a number of tests
 * had to adjust a number of constructors
 * had to adjust NIfTI loader
 * added new dataType in enum
parent d71c4036
......@@ -45,6 +45,7 @@ enum dataType
W_DT_ALL = 255, /* not very useful (?) */
W_DT_INT8 = 256, /* signed char (8 bits) */
W_DT_UINT16 = 512, /* unsigned short (16 bits) */
W_DT_INT16 = 4, /* unsigned short (16 bits) alias name for W_DT_SIGNED_SHORT */
W_DT_UINT32 = 768, /* unsigned int (32 bits) */
W_DT_INT64 = 1024, /* long long (64 bits) */
W_DT_UINT64 = 1280, /* unsigned long long (64 bits) */
......
......@@ -30,6 +30,7 @@
#include <vector>
#include "WValueSetBase.h"
#include "WDataHandlerEnums.h"
/**
* Base Class for all value set types.
......@@ -47,8 +48,8 @@ public:
* Constructs a value set with values of type T. Sets order and dimension
* to allow to interprete the values as tensors of a certain order and dimension.
*/
WValueSet( char order, char dimension, const std::vector< T > data )
: WValueSetBase( order, dimension ),
WValueSet( char order, char dimension, const std::vector< T > data, dataType inDataType )
: WValueSetBase( order, dimension, inDataType ),
m_data( data )
{
}
......
......@@ -28,9 +28,10 @@
#include "WValueSetBase.h"
WValueSetBase::WValueSetBase( char order, char dimension )
WValueSetBase::WValueSetBase( char order, char dimension, dataType inDataType )
: m_order( order ),
m_dimension( dimension )
m_dimension( dimension ),
m_dataType( inDataType )
{
assert( order <= 2 );
assert( dimension >= 1 );
......
......@@ -26,6 +26,7 @@
#define WVALUESETBASE_H
#include <cstddef>
#include "WDataHandlerEnums.h"
/**
* Abstract base class to all WValueSets. This class doesn't provide any genericness.
......@@ -38,7 +39,7 @@ public:
* Despite this is an abstract class all subclasses should have an order
* and dimension.
*/
WValueSetBase( char order, char dimension );
WValueSetBase( char order, char dimension, dataType inDataType );
/**
* Dummy since each class with virtual member functions needs one.
......@@ -63,6 +64,14 @@ public:
return m_dimension;
}
/**
* \return Dimension of the values in this ValueSet
*/
virtual dataType getDataType()
{
return m_dataType;
}
protected:
/**
* The order of the tensors for this ValueSet
......@@ -74,6 +83,11 @@ protected:
*/
char m_dimension;
/**
* The data type of the values' elements.
*/
dataType m_dataType;
private:
};
......
......@@ -36,6 +36,7 @@
#include "../WGridRegular3D.h"
#include "../WValueSetBase.h"
#include "../WValueSet.hpp"
#include "../WDataHandlerEnums.h"
WLoaderNIfTI::WLoaderNIfTI( std::string fileName, boost::shared_ptr< WDataHandler > dataHandler )
......@@ -83,7 +84,7 @@ void WLoaderNIfTI::operator()()
{
std::vector< int8_t > data =
copyArray( reinterpret_cast< int8_t* >( filedata->data ), nbValues, vDim );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< int8_t >( 0, vDim, data ) );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< int8_t >( 0, vDim, data, W_DT_INT8 ) );
newGrid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( columns, rows, frames, 1., 1., 1. ) );
break;
}
......@@ -92,7 +93,7 @@ void WLoaderNIfTI::operator()()
{
std::vector< int16_t > data =
copyArray( reinterpret_cast< int16_t* >( filedata->data ), nbValues, vDim );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< int16_t >( 0, vDim, data ) );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< int16_t >( 0, vDim, data, W_DT_INT16 ) );
newGrid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( columns, rows, frames, 1., 1., 1. ) );
break;
}
......@@ -101,7 +102,7 @@ void WLoaderNIfTI::operator()()
{
std::vector< float > data =
copyArray( reinterpret_cast< float* >( filedata->data ), nbValues, vDim );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< float >( 0, vDim, data ) );
newValueSet = boost::shared_ptr< WValueSetBase >( new WValueSet< float >( 0, vDim, data, W_DT_FLOAT ) );
newGrid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( columns, rows, frames, 1., 1., 1. ) );
break;
}
......
......@@ -32,6 +32,7 @@
#include "../WDataSetSingle.h"
#include "../WValueSet.hpp"
#include "../WGrid.h"
#include "../WDataHandlerEnums.h"
class WDataSetSingleTest : public CxxTest::TestSuite
{
......@@ -46,8 +47,8 @@ public:
{
// create dummies, since they are needed in almost every test
gridDummy = boost::shared_ptr< WGrid >( new WGrid( 1 ) );
std::vector< int > data( 1, 1 );
valueSetDummy = boost::shared_ptr< WValueSet< int > >( new WValueSet< int >( 0, 1, data ) );
std::vector< int8_t > data( 1, 1 );
valueSetDummy = boost::shared_ptr< WValueSet< int8_t > >( new WValueSet< int8_t >( 0, 1, data, W_DT_INT8 ) );
}
/**
......@@ -65,7 +66,7 @@ public:
{
std::vector< double > data( 1, 3.1415 );
boost::shared_ptr< WValueSet< double > > other;
other = boost::shared_ptr< WValueSet< double > >( new WValueSet< double >( 0, 1, data ) );
other = boost::shared_ptr< WValueSet< double > >( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
TS_ASSERT_EQUALS( dataSetSingle.getValueSet(), valueSetDummy );
TS_ASSERT_DIFFERS( dataSetSingle.getValueSet(), other );
......
......@@ -28,6 +28,7 @@
#include <cxxtest/TestSuite.h>
#include "../WValueSetBase.h"
#include "../WDataHandlerEnums.h"
/**
......@@ -39,12 +40,12 @@ friend class WValueSetBaseTest;
public:
Dummy()
: WValueSetBase( 0, 1 )
: WValueSetBase( 0, 1, W_DT_INT8 )
{
}
explicit Dummy( char dimension )
: WValueSetBase( 0, dimension )
: WValueSetBase( 0, dimension, W_DT_INT8 )
{
}
......@@ -80,13 +81,21 @@ public:
/**
* Checks if the dimension using the dummy is right
*/
void testInstanziation( void )
void testDimension( void )
{
Dummy d1;
TS_ASSERT_EQUALS( d1.dimension(), 1 );
Dummy d2( 2 );
TS_ASSERT_EQUALS( d2.dimension(), 2 );
}
/**
* Checks if the dimension using the dummy is right
*/
void testDataType( void )
{
Dummy d1;
TS_ASSERT_EQUALS( d1.getDataType(), W_DT_INT8 );
}
};
#endif // WVALUESETBASE_TEST_H
......@@ -30,6 +30,7 @@
#include <cxxtest/TestSuite.h>
#include "../WValueSet.hpp"
#include "../WDataHandlerEnums.h"
/**
* UnitTests the WValueSet class
......@@ -44,7 +45,7 @@ public:
{
double a[2] = { 0.0, 3.1415 };
const std::vector< double > v( a, a + sizeof( a ) / sizeof( double ) );
TS_ASSERT_THROWS_NOTHING( WValueSet< double > valueSet( 0, 1, v ) );
TS_ASSERT_THROWS_NOTHING( WValueSet< double > valueSet( 0, 1, v, W_DT_DOUBLE ) );
}
/**
......@@ -53,12 +54,12 @@ public:
void testGetNumberOfValues( void )
{
int a[4] = { 0, -5, 1, 2 };
const std::vector< int > v( a, a + sizeof( a ) / sizeof( int ) );
WValueSet< int > first( 0, 1, v );
const std::vector< int8_t > v( a, a + sizeof( a ) / sizeof( int ) );
WValueSet< int8_t > first( 0, 1, v, W_DT_INT8 );
TS_ASSERT_EQUALS( first.size(), 4 );
WValueSet< int > second( 1, 2, v );
WValueSet< int8_t > second( 1, 2, v, W_DT_INT8 );
TS_ASSERT_EQUALS( second.size(), 2 );
WValueSet< int > third( 2, 2, v );
WValueSet< int8_t > third( 2, 2, v, W_DT_INT8 );
TS_ASSERT_EQUALS( third.size(), 1 );
}
......@@ -69,10 +70,10 @@ public:
void testRawSize( void )
{
int a[4] = { 0, -5, 1, 2 };
const std::vector< int > v( a, a + sizeof( a ) / sizeof( int ) );
WValueSet< int > first( 0, 1, v );
const std::vector< int8_t > v( a, a + sizeof( a ) / sizeof( int ) );
WValueSet< int8_t > first( 0, 1, v, W_DT_INT8 );
TS_ASSERT_EQUALS( first.rawSize(), 4 );
WValueSet< int > second( 2, 2, v );
WValueSet< int8_t > second( 2, 2, v, W_DT_INT8 );
TS_ASSERT_EQUALS( first.rawSize(), 4 );
}
......@@ -83,7 +84,7 @@ public:
{
double a[2] = { 0.0, 3.1415 };
const std::vector< double > v( a, a + sizeof( a ) / sizeof( double ) );
WValueSet< double > valueSet( 0, 1, v );
WValueSet< double > valueSet( 0, 1, v, W_DT_DOUBLE );
const double * const b = valueSet.rawData();
TS_ASSERT_EQUALS( b[0], 0.0 );
TS_ASSERT_EQUALS( b[1], 3.1415 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment