Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
a3666615
Commit
a3666615
authored
Nov 10, 2009
by
Sebastian Eichelbaum
Browse files
[CHANGE] - updated module communication and infrastructure
parent
b7b2264f
Changes
42
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
68 additions
and
218 deletions
+68
-218
src/OpenWalnut.cpp
src/OpenWalnut.cpp
+1
-0
src/common/WProperties.h
src/common/WProperties.h
+6
-0
src/common/WThreadedRunner.cpp
src/common/WThreadedRunner.cpp
+10
-1
src/common/WThreadedRunner.h
src/common/WThreadedRunner.h
+16
-0
src/dataHandler/WDataHandler.cpp
src/dataHandler/WDataHandler.cpp
+0
-27
src/dataHandler/WDataHandler.h
src/dataHandler/WDataHandler.h
+0
-20
src/dataHandler/WLoader.cpp
src/dataHandler/WLoader.cpp
+0
-2
src/dataHandler/WLoader.h
src/dataHandler/WLoader.h
+4
-4
src/dataHandler/WLoaderManager.cpp
src/dataHandler/WLoaderManager.cpp
+0
-89
src/dataHandler/WLoaderManager.h
src/dataHandler/WLoaderManager.h
+0
-51
src/dataHandler/io/WLoaderBiosig.cpp
src/dataHandler/io/WLoaderBiosig.cpp
+2
-5
src/dataHandler/io/WLoaderBiosig.h
src/dataHandler/io/WLoaderBiosig.h
+5
-4
src/dataHandler/io/WLoaderEEGASCII.cpp
src/dataHandler/io/WLoaderEEGASCII.cpp
+3
-1
src/dataHandler/io/WLoaderEEGASCII.h
src/dataHandler/io/WLoaderEEGASCII.h
+6
-3
src/dataHandler/io/WLoaderFibers.cpp
src/dataHandler/io/WLoaderFibers.cpp
+2
-1
src/dataHandler/io/WLoaderFibers.h
src/dataHandler/io/WLoaderFibers.h
+4
-3
src/dataHandler/io/WLoaderNIfTI.cpp
src/dataHandler/io/WLoaderNIfTI.cpp
+3
-2
src/dataHandler/io/WLoaderNIfTI.h
src/dataHandler/io/WLoaderNIfTI.h
+4
-3
src/dataHandler/io/test/WLoaderEEGASCII_test.h
src/dataHandler/io/test/WLoaderEEGASCII_test.h
+1
-1
src/dataHandler/io/test/WLoaderFibers_test.h
src/dataHandler/io/test/WLoaderFibers_test.h
+1
-1
No files found.
src/OpenWalnut.cpp
View file @
a3666615
...
...
@@ -64,6 +64,7 @@ int main( int argc, char* argv[] )
// init the kernel
WKernel
kernel
=
WKernel
(
argc
,
argv
,
gui
);
kernel
.
getRootContainer
()
->
getModuleReadySignal
()
->
connect
(
boost
::
bind
(
&
WGUI
::
slotAddDatasetToBrowser
,
gui
,
_1
)
);
return
kernel
.
run
();
}
src/common/WProperties.h
View file @
a3666615
...
...
@@ -112,6 +112,8 @@ public:
{
return
findProp
(
prop
)
->
getValue
<
T
>
();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return
0
;
}
...
...
@@ -121,6 +123,8 @@ public:
{
return
findProp
(
prop
)
->
getMin
<
T
>
();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return
0
;
}
...
...
@@ -130,6 +134,8 @@ public:
{
return
findProp
(
prop
)
->
getMax
<
T
>
();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return
0
;
}
...
...
src/common/WThreadedRunner.cpp
View file @
a3666615
...
...
@@ -49,12 +49,21 @@ void WThreadedRunner::wait( bool requestFinish )
{
if
(
requestFinish
)
{
m_FinishRequested
=
requestFinish
;
// first notify
notifyStop
();
// then signal it
m_FinishRequested
=
requestFinish
;
m_stopCondition
.
notify_all
();
}
m_Thread
->
join
();
}
void
WThreadedRunner
::
waitForStop
()
{
m_stopCondition
.
wait
(
m_stopConditionMutex
);
}
void
WThreadedRunner
::
threadMain
()
{
}
...
...
src/common/WThreadedRunner.h
View file @
a3666615
...
...
@@ -25,6 +25,7 @@
#ifndef WTHREADEDRUNNER_H
#define WTHREADEDRUNNER_H
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
/**
...
...
@@ -91,6 +92,21 @@ protected:
*/
void
sleep
(
const
int
t
)
const
;
/**
* Let the thread sleep until a stop request was given.
*/
void
waitForStop
();
/**
* Condition mutex used by m_stopCondition.
*/
boost
::
mutex
m_stopConditionMutex
;
/**
* Condition getting fired whenever the thread should quit. This is useful for waiting for stop requests.
*/
boost
::
condition_variable_any
m_stopCondition
;
private:
};
...
...
src/dataHandler/WDataHandler.cpp
View file @
a3666615
...
...
@@ -29,7 +29,6 @@
#include "WDataHandler.h"
#include "WSubject.h"
#include "exceptions/WDHNoSuchDataSet.h"
#include "WLoaderManager.h"
WDataHandler
::
WDataHandler
()
{
...
...
@@ -58,29 +57,3 @@ unsigned int WDataHandler::getNumberOfSubjects() const
return
m_subjects
.
size
();
}
void
WDataHandler
::
loadDataSets
(
std
::
vector
<
std
::
string
>
fileNames
)
{
WLoaderManager
lm
;
for
(
size_t
i
=
0
;
i
<
fileNames
.
size
()
;
++
i
)
{
try
{
lm
.
load
(
fileNames
[
i
],
shared_from_this
()
);
}
catch
(
WDHException
e
)
{
std
::
cerr
<<
"Error :: DataHandler :: "
<<
e
.
what
()
<<
std
::
endl
;
}
}
}
void
WDataHandler
::
signalLoadFinished
(
boost
::
shared_ptr
<
WDataSet
>
data
)
{
m_signalAddDataset
(
data
);
}
boost
::
signal1
<
void
,
boost
::
shared_ptr
<
WDataSet
>
>*
WDataHandler
::
getSignalAddDataset
()
{
return
&
m_signalAddDataset
;
}
src/dataHandler/WDataHandler.h
View file @
a3666615
...
...
@@ -77,21 +77,6 @@ public:
*/
unsigned
int
getNumberOfSubjects
()
const
;
/**
* Calls WLoaderManager to load the given input file.
*/
void
loadDataSets
(
std
::
vector
<
std
::
string
>
fileNames
);
/**
* is called from a loader object and signals a pointer to the loaded object
*/
void
signalLoadFinished
(
boost
::
shared_ptr
<
WDataSet
>
data
);
/**
*
*/
boost
::
signal1
<
void
,
boost
::
shared_ptr
<
WDataSet
>
>*
getSignalAddDataset
();
protected:
private:
...
...
@@ -99,11 +84,6 @@ private:
* A container for all WSubjects.
*/
std
::
vector
<
boost
::
shared_ptr
<
WSubject
>
>
m_subjects
;
/**
* boost signal object for signaling the addition of a dataset to the datahandler
*/
boost
::
signal1
<
void
,
boost
::
shared_ptr
<
WDataSet
>
>
m_signalAddDataset
;
};
/**
...
...
src/dataHandler/WLoader.cpp
View file @
a3666615
...
...
@@ -56,6 +56,4 @@ void WLoader::commitDataSet( boost::shared_ptr< WDataSet > data )
subject
=
m_dataHandler
->
getSubject
(
0
);
}
subject
->
addDataSet
(
data
);
m_dataHandler
->
signalLoadFinished
(
data
);
}
src/dataHandler/WLoader.h
View file @
a3666615
...
...
@@ -53,11 +53,11 @@ public:
};
/**
*
This function is automatically called when creating a new thread for the
*
loader with boost::thread. The method is pure virtual here to ensure
*
that subclasses implement it
.
*
Loads the dataset.
*
*
\return the dataset loaded
.
*/
virtual
void
operator
()
()
=
0
;
virtual
boost
::
shared_ptr
<
WDataSet
>
load
()
=
0
;
protected:
/**
...
...
src/dataHandler/WLoaderManager.cpp
deleted
100644 → 0
View file @
b7b2264f
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include "WLoaderManager.h"
#include "exceptions/WDHException.h"
#include "io/WLoaderNIfTI.h"
#include "io/WLoaderBiosig.h"
#include "io/WLoaderEEGASCII.h"
#include "io/WLoaderFibers.h"
std
::
string
getSuffix
(
std
::
string
name
)
{
boost
::
filesystem
::
path
p
(
name
);
return
p
.
extension
();
}
void
WLoaderManager
::
load
(
std
::
string
fileName
,
boost
::
shared_ptr
<
WDataHandler
>
dataHandler
)
throw
(
WDHException
)
{
std
::
string
suffix
=
getSuffix
(
fileName
);
if
(
suffix
==
".nii"
||
suffix
==
".gz"
)
{
if
(
suffix
==
".gz"
)
// it may be a NIfTI file too
{
boost
::
filesystem
::
path
p
(
fileName
);
p
.
replace_extension
(
""
);
suffix
=
getSuffix
(
p
.
string
()
);
assert
(
suffix
==
".nii"
&&
"currently only nii files may be gzipped"
);
}
WLoaderNIfTI
niiLoader
(
fileName
,
dataHandler
);
boost
::
thread
loaderThread
(
niiLoader
);
}
else
if
(
suffix
==
".edf"
)
{
WLoaderBiosig
biosigLoader
(
fileName
,
dataHandler
);
boost
::
thread
loaderThread
(
biosigLoader
);
}
else
if
(
suffix
==
".asc"
)
{
WLoaderEEGASCII
eegAsciiLoader
(
fileName
,
dataHandler
);
boost
::
thread
loaderThread
(
eegAsciiLoader
);
}
else
if
(
suffix
==
".vtk"
)
{
// This is a dummy implementation.
// You need to provide a real implementation here if you want to load vtk.
std
::
cout
<<
"VTK not implemented yet"
<<
std
::
endl
;
assert
(
0
);
}
else
if
(
suffix
==
".fib"
)
{
WLoaderFibers
fibLoader
(
fileName
,
dataHandler
);
boost
::
thread
loaderThread
(
fibLoader
);
}
else
{
throw
WDHException
(
"Unknown file type: '"
+
suffix
+
"'"
);
}
}
src/dataHandler/WLoaderManager.h
deleted
100644 → 0
View file @
b7b2264f
//---------------------------------------------------------------------------
//
// 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 WLOADERMANAGER_H
#define WLOADERMANAGER_H
#include <string>
#include <boost/shared_ptr.hpp>
#include "exceptions/WDHException.h"
class
WDataHandler
;
/**
* Decouples file loading from the rest of OpenWalnut into a single thread.
* \ingroup dataHandler
*/
class
WLoaderManager
{
public:
/**
* Selects correct loader for fileName and creates loader thread.
*/
void
load
(
std
::
string
fileName
,
boost
::
shared_ptr
<
WDataHandler
>
dataHandler
)
throw
(
WDHException
);
protected:
private:
};
#endif // WLOADERMANAGER_H
src/dataHandler/io/WLoaderBiosig.cpp
View file @
a3666615
...
...
@@ -56,7 +56,7 @@ void WLoaderBiosig::fillSegment( std::vector<std::vector<double> >* segment, bio
}
}
void
WLoaderBiosig
::
biosigL
oad
er
()
boost
::
shared_ptr
<
WDataSet
>
WLoaderBiosig
::
l
oad
()
{
std
::
cout
<<
"BIOSIGLOADER"
<<
std
::
endl
;
hd
=
sopen
(
m_fileName
.
c_str
(),
"r"
,
0
);
...
...
@@ -131,9 +131,6 @@ void WLoaderBiosig::biosigLoader()
std
::
cout
<<
"BIOSIG loading done."
<<
std
::
endl
;
std
::
cout
<<
"==================================="
<<
std
::
endl
;
return
eeg
;
}
void
WLoaderBiosig
::
operator
()()
{
biosigLoader
();
}
src/dataHandler/io/WLoaderBiosig.h
View file @
a3666615
...
...
@@ -49,13 +49,14 @@ public:
WLoaderBiosig
(
std
::
string
fileName
,
boost
::
shared_ptr
<
WDataHandler
>
dataHandler
);
/**
* This function is automatically called when creating a new thread for the
* loader with boost::thread.
* Loads the dataset.
*
* \return the dataset loaded.
*/
virtual
void
operator
()();
virtual
boost
::
shared_ptr
<
WDataSet
>
load
();
protected:
private:
void
biosigLoader
();
void
fillSegment
(
std
::
vector
<
std
::
vector
<
double
>
>*
segment
,
biosig_data_type
*
data
);
/**
...
...
src/dataHandler/io/WLoaderEEGASCII.cpp
View file @
a3666615
...
...
@@ -39,7 +39,7 @@ WLoaderEEGASCII::WLoaderEEGASCII( std::string fileName, boost::shared_ptr< WData
{
}
void
WLoaderEEGASCII
::
operator
()
()
boost
::
shared_ptr
<
WDataSet
>
WLoaderEEGASCII
::
load
()
{
std
::
ifstream
in
(
m_fileName
.
c_str
()
);
if
(
in
.
fail
()
)
...
...
@@ -84,4 +84,6 @@ void WLoaderEEGASCII::operator()()
boost
::
shared_ptr
<
WEEG
>
eeg
=
boost
::
shared_ptr
<
WEEG
>
(
new
WEEG
(
segments
,
lib
,
labels
)
);
eeg
->
setFileName
(
m_fileName
);
commitDataSet
(
eeg
);
return
eeg
;
}
src/dataHandler/io/WLoaderEEGASCII.h
View file @
a3666615
...
...
@@ -45,10 +45,13 @@ public:
WLoaderEEGASCII
(
std
::
string
fileName
,
boost
::
shared_ptr
<
WDataHandler
>
dataHandler
);
/**
* This function is automatically called when creating a new thread for the
* loader with boost::thread.
* Loads the dataset.
*
* \return the dataset loaded.
*/
virtual
void
operator
()();
virtual
boost
::
shared_ptr
<
WDataSet
>
load
();
void
operator
()();
protected:
private:
...
...
src/dataHandler/io/WLoaderFibers.cpp
View file @
a3666615
...
...
@@ -54,7 +54,7 @@ WLoaderFibers::~WLoaderFibers() throw()
{
}
void
WLoaderFibers
::
operator
()()
throw
()
boost
::
shared_ptr
<
WDataSet
>
WLoaderFibers
::
load
()
{
using
boost
::
shared_ptr
;
using
std
::
vector
;
...
...
@@ -81,6 +81,7 @@ void WLoaderFibers::operator()() throw()
commitDataSet
(
fibers
);
assert
(
!
m_ifs
->
is_open
()
);
return
fibers
;
}
void
WLoaderFibers
::
readHeader
()
throw
(
WDHIOFailure
,
WDHException
)
...
...
src/dataHandler/io/WLoaderFibers.h
View file @
a3666615
...
...
@@ -61,10 +61,11 @@ public:
virtual
~
WLoaderFibers
()
throw
();
/**
* This function is automatically called when creating a new thread for the
* loader with boost::thread. It calls the methods of the NIfTI I/O library.
* Loads the dataset.
*
* \return the dataset loaded.
*/
virtual
void
operator
()()
throw
();
virtual
boost
::
shared_ptr
<
WDataSet
>
load
();
protected:
/**
...
...
src/dataHandler/io/WLoaderNIfTI.cpp
View file @
a3666615
...
...
@@ -73,8 +73,7 @@ wmath::WMatrix< double > WLoaderNIfTI::convertMatrix( const mat44& in )
return
out
;
}
void
WLoaderNIfTI
::
operator
()()
boost
::
shared_ptr
<
WDataSet
>
WLoaderNIfTI
::
load
()
{
nifti_image
*
header
=
nifti_image_read
(
m_fileName
.
c_str
(),
0
);
int
columns
=
header
->
dim
[
1
];
...
...
@@ -142,6 +141,8 @@ void WLoaderNIfTI::operator()()
boost
::
shared_ptr
<
WDataSet
>
newDataSet
=
boost
::
shared_ptr
<
WDataSet
>
(
new
WDataSetSingle
(
newValueSet
,
newGrid
)
);
newDataSet
->
setFileName
(
m_fileName
);
commitDataSet
(
newDataSet
);
return
newDataSet
;
}
...
...
src/dataHandler/io/WLoaderNIfTI.h
View file @
a3666615
...
...
@@ -50,10 +50,11 @@ public:
WLoaderNIfTI
(
std
::
string
fileName
,
boost
::
shared_ptr
<
WDataHandler
>
dataHandler
);
/**
* This function is automatically called when creating a new thread for the
* loader with boost::thread. It calls the methods of the NIfTI I/O library.
* Loads the dataset.
*
* \return the dataset loaded.
*/
virtual
void
operator
()
();
virtual
boost
::
shared_ptr
<
WDataSet
>
load
();
protected:
private:
...
...
src/dataHandler/io/test/WLoaderEEGASCII_test.h
View file @
a3666615
...
...
@@ -51,7 +51,7 @@ public:
TS_ASSERT_EQUALS
(
dataHandler
->
getNumberOfSubjects
(),
0
);
WLoaderEEGASCII
eegASCIILoader
(
fileName
,
dataHandler
);
boost
::
thread
loaderThread
(
eegASCIILoader
);
eegASCIILoader
.
load
(
);
std
::
clock_t
startTime
;
startTime
=
std
::
clock
();
...
...
src/dataHandler/io/test/WLoaderFibers_test.h
View file @
a3666615
...
...
@@ -276,7 +276,7 @@ public:
{
TS_ASSERT_EQUALS
(
m_dataHandler
->
getNumberOfSubjects
(),
0
);
WLoaderFibers
loader
(
"fixtures/Fibers/valid_small_example.fib"
,
m_dataHandler
);
loader
();
loader
.
load
();
TS_ASSERT_EQUALS
(
m_dataHandler
->
getNumberOfSubjects
(),
1
);
}
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment