Commit 4f0dad66 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents b8351def 87253ac7
......@@ -26,7 +26,7 @@
#include <string>
#include <vector>
#include "../../common/WAssert.h"
#include "../common/WAssert.h"
#include "WFiberAccumulator.h"
......
......@@ -51,22 +51,15 @@ WReaderFiberVTK::~WReaderFiberVTK() throw()
boost::shared_ptr< WDataSetFibers > WReaderFiberVTK::read()
{
try
{
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream() );
m_ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
if( !m_ifs || m_ifs->bad() )
{
throw WDHIOFailure( std::string( "internal error while opening" ) );
}
readHeader();
readPoints();
readLines();
}
catch( WDHException e )
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream() );
m_ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
if( !m_ifs || m_ifs->bad() )
{
wlog::error( "WReaderFiberVTK" ) << "Abort loading VTK fiber file: " << m_fname << ", due to: " << e.what();
throw WDHIOFailure( std::string( "internal error while opening" ) );
}
readHeader();
readPoints();
readLines();
boost::shared_ptr< WDataSetFibers > fibers = boost::shared_ptr< WDataSetFibers >( new WDataSetFibers( m_points,
m_fiberStartIndices,
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WLOADERFIBERS_TEST_H
#define WLOADERFIBERS_TEST_H
#include <sstream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/shared_ptr.hpp>
#include <cxxtest/TestSuite.h>
#include "../../../common/test/WStreamPosTraits.h"
#include "../../../common/math/test/WFiberTraits.h"
#include "../WLoaderFibers.h"
/**
* Unit tests the WLoaderFibers class.
*/
class WLoaderFibersTest : public CxxTest::TestSuite
{
public:
/**
* A valid "header" of a VTK file consists of 4 lines of text (this is
* arbitrary specified by me, the author of this class)
* 1. VTK version stuff
* 2. VTK description header stuff (max 256 chars)
* 3. BINARY or ASCII
* 4. DATASET type
*
* Further description about the DATASET e.g. ORIGIN in case of
* STRUCTURED_POINTS does not belong to the header.
*
* FYI: It makes really sense to restrict the header to 4 lines since since
* every VTK file must have at least 4 lines describing in ASCII what comes
* next.
*/
void testReadHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
std::vector< std::string > expected;
expected.push_back( "# vtk DataFile Version 3.0" );
expected.push_back( "Neural Pathways aka as fibers." );
expected.push_back( "BINARY" );
expected.push_back( "DATASET POLYDATA" );
loader.readHeader();
TS_ASSERT_EQUALS( loader.m_header, expected );
}
/**
* A valid .fib header starts with "# vtk DataFile Version 3.0".
*/
void testUnsupportedVTKFileFormatString( void )
{
WLoaderFibers loader( "fixtures/Fibers/unsupported_format_version_string.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
std::string( "Unsupported format version string: # vtk DataFile Version 9.0" ) );
}
/**
* If the internal VTK header is too big an error is thrown
*/
void testReadHeaderOnTooBigVTKHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/invalid_header_length.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
std::string( "VTK header too big: 261" ) );
}
/**
* ATM we only support BINARY VTK files.
*/
void testBinaryOrAscii( void )
{
WLoaderFibers loader( "fixtures/Fibers/ascii.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
std::string( "VTK files in 'ASCII' format are not yet supported" ) );
}
/**
* If the header not introduces a POLYDATA DATASET an exception should be
* thrown.
*/
void testCheckDatasetType( void )
{
WLoaderFibers loader( "fixtures/Fibers/invalid_dataset.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
std::string( "Invalid VTK DATASET type: STRUCTURED_POINTS" ) );
}
/**
* After reading the header the position in the stream should have
* changed
*/
void testStreamPosIsValidAfterReadHeaderCall( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loader.readHeader();
TS_ASSERT_EQUALS( loader.m_ifs->tellg(), 82 );
}
/**
* If there is no header at all an exception should be thrown.
*/
void testNoHeaderThere( void )
{
WLoaderFibers loader( "fixtures/Fibers/no_header.fib" );
TS_ASSERT_THROWS( loader.readHeader(), WDHException );
}
/**
* If there is a crippled header then an exception should be thrown
*/
void testOnAbruptHeader( void )
{
WLoaderFibers loader( "fixtures/Fibers/crippled_header.fib" );
TS_ASSERT_THROWS_EQUALS( loader.readHeader(),
const WDHException &e,
e.what(),
std::string( "Unexpected end of file: fixtures/Fibers/crippled_header.fib" ) );
}
/**
* After reading the points the point vector of WLoaderFibers should be
* filled with valid numbers.
*/
void testReadPoints( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loader.readHeader();
loader.readPoints();
double delta = 0.0001;
TS_ASSERT_EQUALS( loader.m_points.size(), 1224 );
TS_ASSERT_DELTA( loader.m_points.at( 1223 )[2], 60.4135, delta );
TS_ASSERT_DELTA( loader.m_points.at( 0 )[0], 46.2582, delta );
TS_ASSERT_DELTA( loader.m_points.at( 0 )[1], 36.7184, delta );
TS_ASSERT_DELTA( loader.m_points.at( 0 )[2], 65.7245, delta );
}
/**
* Every line is stored in fib files with
* 1. Its number of points (length)
* 2. All references to the points its using
*/
void testReadAllLines( void )
{
using boost::shared_ptr;
using std::vector;
using wmath::WPosition;
WLoaderFibers loader( "fixtures/Fibers/small_example_one_fiber.fib" );
loader.readHeader();
loader.readPoints();
shared_ptr< vector< WFiber > > actual = loader.readLines();
TS_ASSERT_EQUALS( actual->size(), 1 );
vector< WPosition > pointList;
// CAUTION: we use here floats since the positions are stored with
// floats as well. If we would use doubles here, the both vectors are
// different then.
pointList.push_back( WPosition( 1.2f, 3.4f, 5.6f ) );
pointList.push_back( WPosition( 7.8f, 9.0f, -1.2f ) );
WFiber expected( pointList );
TS_ASSERT_EQUALS( expected, actual->back() );
}
/**
* When e.g. the CopyConstructor is invoked, all internals (including)
* all pointers will be destructed and deleted.
*/
void testDestructor( void )
{
std::vector< WLoaderFibers > loaders;
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
loaders.push_back( loader );
// destructor invoked
}
TS_ASSERT( loaders[0].m_ifs->is_open() );
loaders.clear(); // second destruction
}
/**
* The () operator normaly starts the thread, so we check here if every thing
* terminates quite well.
*/
void testBracesOperatorTerminatesWell( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib" );
TS_ASSERT( loader.load() );
}
};
#endif // WLOADERFIBERS_TEST_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WLOADERLIBEEP_TEST_H
#define WLOADERLIBEEP_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WLoaderLibeep.h"
/**
* Tests for the loader for the CNT format supported by the libeep library.
*/
class WLoaderLibeepTest : public CxxTest::TestSuite
{
public:
/**
* Test loading a CNT file
*/
void testLoading( void )
{
// Need a fixture to test anything ...
}
};
#endif // WLOADERLIBEEP_TEST_H
......@@ -22,20 +22,20 @@
//
//---------------------------------------------------------------------------
#ifndef WLOADEREEGASCII_TEST_H
#define WLOADEREEGASCII_TEST_H
#ifndef WREADEREEGASCII_TEST_H
#define WREADEREEGASCII_TEST_H
#include <ctime>
#include <string>
#include <cxxtest/TestSuite.h>
#include <boost/thread.hpp>
#include "../WLoaderEEGASCII.h"
#include "../WReaderEEGASCII.h"
/**
* Tests for the loader of ASCII EEG files.
*/
class WLoaderEEGASCIITest : public CxxTest::TestSuite
class WReaderEEGASCIITest : public CxxTest::TestSuite
{
public:
/**
......@@ -46,9 +46,9 @@ public:
std::string fileName = "../fixtures/eeg_testData.asc";
std::cout << std::endl << "Test loading of " << fileName << "." << std::endl;
WLoaderEEGASCII eegASCIILoader( fileName );
TS_ASSERT( eegASCIILoader.load() );
WReaderEEGASCII eegASCIIReader( fileName );
TS_ASSERT( eegASCIIReader.load() );
}
};
#endif // WLOADEREEGASCII_TEST_H
#endif // WREADEREEGASCII_TEST_H
......@@ -22,28 +22,47 @@
//
//---------------------------------------------------------------------------
#ifndef WLOADERNIFTI_TEST_H
#define WLOADERNIFTI_TEST_H
#ifndef WREADERNIFTI_TEST_H
#define WREADERNIFTI_TEST_H
#include <vector>
#include <boost/shared_ptr.hpp>
#include <cxxtest/TestSuite.h>
#include "../WLoaderNIfTI.h"
#include "../WLoaderNIfTI.cpp" //need this to be able instatiate template function
#include "../../../common/WLogger.h"
#include "../../exceptions/WDHNoSuchFile.h"
#include "../WReaderNIfTI.h"
#include "../WReaderNIfTI.cpp" //need this to be able instatiate template function
/**
* test class the nifti loader class
* test class the nifti reader class
*/
class WLoaderNIfTITest : public CxxTest::TestSuite
class WReaderNIfTITest : public CxxTest::TestSuite
{
public:
/**
* Per test initialization routines
*/
void setUp( void )
{
WLogger::startup();
}
/**
* For each test the tidy up function.
*/
void tearDown( void )
{
}
/**
* Test instantiation with non existing file
*/
void testInstantiationNonExisting( void )
{
TS_ASSERT_THROWS( WLoaderNIfTI( "no such file" ), WDHIOFailure );
TS_ASSERT_THROWS( WReaderNIfTI( "no such file" ), const WDHNoSuchFile &e );
}
/**
......@@ -51,12 +70,12 @@ public:
*/
void testInstantiation( void )
{
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/scalar_signed_short.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/scalar_unsigned_char.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/scalar_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/vector_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/symmetric_2nd_order_tensor_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WLoaderNIfTI( "../fixtures/vector_unsigned_char.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/scalar_signed_short.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/scalar_unsigned_char.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/scalar_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/vector_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/symmetric_2nd_order_tensor_float.nii.gz" ) );
TS_ASSERT_THROWS_NOTHING( WReaderNIfTI( "../fixtures/vector_unsigned_char.nii.gz" ) );
}
/**
......@@ -64,19 +83,19 @@ public:
*/
void testLoading( void )
{
WLoaderNIfTI loader1( "../fixtures/scalar_signed_short.nii.gz" );
WLoaderNIfTI loader2( "../fixtures/scalar_unsigned_char.nii.gz" );
WLoaderNIfTI loader3( "../fixtures/scalar_float.nii.gz" );
WLoaderNIfTI loader4( "../fixtures/vector_float.nii.gz" );
WLoaderNIfTI loader5( "../fixtures/symmetric_2nd_order_tensor_float.nii.gz" );
WLoaderNIfTI loader6( "../fixtures/vector_unsigned_char.nii.gz" );
TS_ASSERT( loader1.load() );
TS_ASSERT( loader2.load() );
TS_ASSERT( loader3.load() );
TS_ASSERT( loader4.load() );
TS_ASSERT( loader5.load() );
TS_ASSERT( loader6.load() );
WReaderNIfTI reader1( "../fixtures/scalar_signed_short.nii.gz" );
WReaderNIfTI reader2( "../fixtures/scalar_unsigned_char.nii.gz" );
WReaderNIfTI reader3( "../fixtures/scalar_float.nii.gz" );
WReaderNIfTI reader4( "../fixtures/vector_float.nii.gz" );
WReaderNIfTI reader5( "../fixtures/symmetric_2nd_order_tensor_float.nii.gz" );
WReaderNIfTI reader6( "../fixtures/vector_unsigned_char.nii.gz" );
TS_ASSERT( reader1.load() );
TS_ASSERT( reader2.load() );
TS_ASSERT( reader3.load() );
TS_ASSERT( reader4.load() );
TS_ASSERT( reader5.load() );
TS_ASSERT( reader6.load() );
}
/**
......@@ -103,9 +122,9 @@ public:
dummy.m[3][3] = 1.17;
// need this for calling the function
WLoaderNIfTI loader1( "../fixtures/scalar_signed_short.nii.gz" );
WReaderNIfTI reader1( "../fixtures/scalar_signed_short.nii.gz" );
wmath::WMatrix< double > result = loader1.convertMatrix( dummy );
wmath::WMatrix< double > result = reader1.convertMatrix( dummy );
TS_ASSERT_EQUALS( result.getNbRows(), 4 );
TS_ASSERT_EQUALS( result.getNbCols(), 4 );
......@@ -135,7 +154,7 @@ public:
void testCopyArray( void )
{
// need this for calling the function
WLoaderNIfTI loader1( "../fixtures/scalar_signed_short.nii.gz" );
WReaderNIfTI reader1( "../fixtures/scalar_signed_short.nii.gz" );
const size_t nbVoxels = 10;
const size_t vDim = 3;
......@@ -149,9 +168,9 @@ public:
dataArray[i] = 1.1 * i;
}
}
std::vector< double > vec = loader1.copyArray( dataArray, nbVoxels, vDim );
boost::shared_ptr< std::vector< double > > vec = reader1.copyArray( dataArray, nbVoxels, vDim );
TS_ASSERT_EQUALS( vec.size(), nbVoxels * vDim );
TS_ASSERT_EQUALS( vec->size(), nbVoxels * vDim );
double delta = 1e-16;
for( unsigned int voxId = 0; voxId < nbVoxels; ++voxId )
......@@ -159,12 +178,12 @@ public:
for( unsigned int dim = 0; dim < vDim; ++dim )
{
// The following two test exactly the same thing.
TS_ASSERT_DELTA( vec[voxId * vDim + dim], dataArray[voxId + nbVoxels * dim], delta );
TS_ASSERT_DELTA( vec[voxId * vDim + dim], 1.1 * ( voxId + nbVoxels * dim ), delta );
TS_ASSERT_DELTA( vec->at( voxId * vDim + dim ), dataArray[voxId + nbVoxels * dim], delta );
TS_ASSERT_DELTA( vec->at( voxId * vDim + dim ), 1.1 * ( voxId + nbVoxels * dim ), delta );
}
}
delete[] dataArray;
}
};
#endif // WLOADERNIFTI_TEST_H
#endif // WREADERNIFTI_TEST_H
......@@ -30,13 +30,12 @@
#include <QtGui/QMenu>
#include "../../common/WPreferences.h"
#include "../../kernel/combiner/WApplyCombiner.h"
#include "../../kernel/combiner/WModuleOneToOneCombiner.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleCombiner.h"
#include "../../kernel/combiner/WModuleOneToOneCombiner.h"
#include "../../kernel/combiner/WApplyCombiner.h"
#include "guiElements/WQtModuleOneToOneCombinerAction.h"
#include "WMainWindow.h"
#include "WQtCombinerActionList.h"
WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles,
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMDETTRACTCLUSTERING_TEST_H
#define WMDETTRACTCLUSTERING_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WMDetTractClustering.h"
/**
* TODO(math): Document this!
*/
class WMDetTractClusteringTest : public CxxTest::TestSuite
{
public:
/**
* TODO(math): Document this!
*/
void testSomething( void )
{
}
};
#endif // WMDETTRACTCLUSTERING_TEST_H
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