Commit d43f2d5e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - datasets now offer prototypes

[CHANGE] connectors now use dataset prototypes for compatibility checking
parent 3ff047a2
......@@ -27,6 +27,8 @@
#include <string>
#include <boost/shared_ptr.hpp>
/**
* Interface class for the concept "Prototype". The requirements are a zero-param constructor.
*/
......@@ -60,7 +62,6 @@ public:
virtual std::string getDescription() const = 0;
protected:
private:
};
......
//---------------------------------------------------------------------------
//
// 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 "../common/WPrototyped.h"
#include "WTransferable.h"
WTransferable::WTransferable()
: WPrototyped()
{
// initialize members
}
WTransferable::~WTransferable()
{
// cleanup
}
......@@ -22,56 +22,35 @@
//
//---------------------------------------------------------------------------
#ifndef WCOMPARABLE_H
#define WCOMPARABLE_H
#ifndef WTRANSFERABLE_H
#define WTRANSFERABLE_H
#include "../common/WPrototyped.h"
/**
* Interface class for the concept of type comparable (runtime) classes, The functionality provided by this class can and will be
* achieved by facilities provided by the upcoming C++0X standard as they get available.
* Class building the interface for classes that might be transferred using WModuleConnector.
* \see WModuleConnector. All transferable objects need a prototype.
*
* \ingroup Kernel
*/
template < typename T >
class WTypeComparable
class WTransferable: public WPrototyped
{
public:
/**
* Default constructor. Creates a instance of the class. This not necessarily mean that the instance is fully usable. This is
* required for type checking and inheritance checking.
* Default constructor.
*/
WTypeComparable();
WTransferable();
/**
* Destructor.
*/
virtual ~WTypeComparable();
/**
* Checks whether the specified type is castable to the true type of this instance.
*
* \return true if castable using dynamic_cast.
*/
template < typename U > bool isCompatibleType()
{
T* a = T::factory();
U* b = U::factory();
}
virtual ~WTransferable();
protected:
private:
};
template < typename T >
WTypeComparable< T >::WTypeComparable()
{
// init
}
template < typename T >
WTypeComparable< T >::~WTypeComparable()
{
// clean up
}
#endif // WTYPECOMPARABLE_H
#endif // WTRANSFERABLE_H
......@@ -27,11 +27,15 @@
#include "exceptions/WDHException.h"
#include "WDataTexture3D.h"
#include "../common/WTransferable.h"
#include "WDataSet.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSet::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSet::WDataSet()
: m_fileName( "" )
: WTransferable(),
m_fileName( "" )
{
}
......@@ -56,3 +60,23 @@ boost::shared_ptr< WDataTexture3D > WDataSet::getTexture()
throw WDHException( "This dataset does not provide a texture." );
}
std::string WDataSet::getName() const
{
return "WDataSet";
}
std::string WDataSet::getDescription() const
{
return "Encapsulates the whole common feature set of all datasets.";
}
boost::shared_ptr< WPrototyped > WDataSet::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSet() );
}
return m_prototype;
}
......@@ -28,6 +28,8 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include "../common/WTransferable.h"
class WDataTexture3D;
/**
......@@ -37,7 +39,7 @@ class WDataTexture3D;
* steps) respectively.
* \ingroup dataHandler
*/
class WDataSet
class WDataSet: public WTransferable
{
public:
/**
......@@ -79,7 +81,34 @@ public:
*/
virtual boost::shared_ptr< WDataTexture3D > getTexture();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual std::string getDescription() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
/**
* Name of the file this data set was loaded from. This information
......
......@@ -25,8 +25,13 @@
#include <algorithm>
#include <vector>
#include "WDataSet.h"
#include "WDataSetFibers.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetFibers::m_prototype = boost::shared_ptr< WPrototyped >();
void WDataSetFibers::sortDescLength()
{
std::sort( m_fibers->begin(), m_fibers->end(), wmath::hasGreaterLengthThen );
......@@ -52,8 +57,17 @@ bool WDataSetFibers::isTexture() const
return false;
}
WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< wmath::WFiber > > fibs ) : m_fibers( fibs )
WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< wmath::WFiber > > fibs )
: WDataSet(),
m_fibers( fibs )
{
}
WDataSetFibers::WDataSetFibers()
: WDataSet(),
m_fibers()
{
// default constructor used by the prototype mechanism
}
size_t WDataSetFibers::size() const
......@@ -66,3 +80,24 @@ const wmath::WFiber& WDataSetFibers::operator[]( const size_t index ) const
assert( index < m_fibers->size() );
return (*m_fibers)[index];
}
std::string WDataSetFibers::getName() const
{
return "WDataSetFibers";
}
std::string WDataSetFibers::getDescription() const
{
return "Contains tracked fiber data.";
}
boost::shared_ptr< WPrototyped > WDataSetFibers::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetFibers() );
}
return m_prototype;
}
......@@ -43,6 +43,11 @@ public:
*/
explicit WDataSetFibers( boost::shared_ptr< std::vector< wmath::WFiber > > fibs );
/**
* Constructs a new set of WFibers. The constructed instance is not usable.
*/
WDataSetFibers();
/**
* Get number of fibers in this data set.
*/
......@@ -71,7 +76,34 @@ public:
*/
virtual bool isTexture() const;
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual std::string getDescription() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
boost::shared_ptr< std::vector< wmath::WFiber > > m_fibers;
};
......
......@@ -22,5 +22,37 @@
//
//---------------------------------------------------------------------------
#include "../common/WPrototyped.h"
#include "WDataSetMultiple.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetMultiple::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetMultiple::WDataSetMultiple()
: WDataSet()
{
// TODO(wiebel): implement this
}
std::string WDataSetMultiple::getName() const
{
return "WDataSetMultiple";
}
std::string WDataSetMultiple::getDescription() const
{
// TODO(all): write this
return "Please write me.";
}
boost::shared_ptr< WPrototyped > WDataSetMultiple::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetMultiple() );
}
return m_prototype;
}
......@@ -25,6 +25,7 @@
#ifndef WDATASETMULTIPLE_H
#define WDATASETMULTIPLE_H
#include "../common/WPrototyped.h"
#include "WDataSet.h"
/**
......@@ -35,14 +36,38 @@ class WDataSetMultiple : public WDataSet
{
public:
/**
* Dummy constructor.
* Constructs a new empty dataset. The constructed instance is not usable.
*/
explicit WDataSetMultiple()
: WDataSet()
{
// TODO(wiebel): implement this
};
WDataSetMultiple();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual std::string getDescription() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
};
......
......@@ -25,9 +25,13 @@
#include "WDataTexture3D.h"
#include "WValueSet.hpp"
#include "WGrid.h"
#include "../common/WPrototyped.h"
#include "WDataSetSingle.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetSingle::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetSingle::WDataSetSingle( boost::shared_ptr<WValueSetBase> newValueSet,
boost::shared_ptr<WGrid> newGrid )
: WDataSet()
......@@ -41,6 +45,15 @@ WDataSetSingle::WDataSetSingle( boost::shared_ptr<WValueSetBase> newValueSet,
m_texture3D = boost::shared_ptr< WDataTexture3D >( new WDataTexture3D( m_valueSet, m_grid ) );
}
WDataSetSingle::WDataSetSingle()
: WDataSet(),
m_valueSet(),
m_grid(),
m_texture3D()
{
// default constructor used by the prototype mechanism
}
WDataSetSingle::~WDataSetSingle()
{
}
......@@ -57,7 +70,7 @@ boost::shared_ptr<WGrid> WDataSetSingle::getGrid() const
bool WDataSetSingle::isTexture() const
{
// TODO(seralph): this is not sophisticated. This should depend on type of data (vectors? scalars? tensors?)
// TODO(all): this is not sophisticated. This should depend on type of data (vectors? scalars? tensors?)
return true;
}
......@@ -66,3 +79,24 @@ boost::shared_ptr< WDataTexture3D > WDataSetSingle::getTexture()
return m_texture3D;
}
std::string WDataSetSingle::getName() const
{
return "WDataSetSingle";
}
std::string WDataSetSingle::getDescription() const
{
// TODO(all): write this
return "Please write me.";
}
boost::shared_ptr< WPrototyped > WDataSetSingle::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetSingle() );
}
return m_prototype;
}
......@@ -42,12 +42,21 @@ class WDataTexture3D;
class WDataSetSingle : public WDataSet
{
public:
/**
* Constructs an instance out of a value set and a grid.
*
* \param newValueSet the value set to use
* \param newGrid the grid which maps world space to the value set
*/
WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid );
/**
* Construct an empty and unusable instance. This is useful for prototypes.
*/
WDataSetSingle();
/**
* Destroys this DataSet instance
*/
......@@ -94,17 +103,45 @@ public:
*/
virtual boost::shared_ptr< WDataTexture3D > getTexture();
private:
/**
* Stores the reference of the WGrid of this DataSetSingle instance.
* Gets the name of this prototype.
*
* \return the name.
*/
boost::shared_ptr< WGrid > m_grid;
virtual std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual std::string getDescription() const;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
/**
* Stores the reference of the WValueSet of this DataSetSingle instance.
*/
boost::shared_ptr< WValueSetBase > m_valueSet;
/**
* Stores the reference of the WGrid of this DataSetSingle instance.
*/
boost::shared_ptr< WGrid > m_grid;
/**
* The 3D texture representing this dataset.
*/
......
......@@ -22,9 +22,13 @@
//
//---------------------------------------------------------------------------
#include "WEEG.h"
#include "../common/WPrototyped.h"
#include "../common/WLimits.h"
#include "WEEG.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WEEG::m_prototype = boost::shared_ptr< WPrototyped >();
WEEG::WEEG( const WEEGSegmentArray& data,
const WEEGElectrodeLibrary& electrodeLib,
......@@ -48,8 +52,34 @@ WEEG::WEEG( const WEEGSegmentArray& data,
m_channelLabels = channelLabels;
}
WEEG::WEEG()
: WRecording()
{
// do nothing here. Only useful for prototypes.
}
bool WEEG::isTexture() const
{
return false;
}
std::string WEEG::getName() const
{
return "WEEG";
}
std::string WEEG::getDescription() const
{
return "Contains data acquired using EEG.";
}
boost::shared_ptr< WPrototyped > WEEG::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WEEG() );
}
return m_prototype;
}
......@@ -29,7 +29,7 @@
#include <string>
#include <vector>
#include "WRecording.h"
#include "../common/WPrototyped.h"
///======================================
......@@ -86,6 +86,11 @@ public:
const WEEGElectrodeLibrary& electrodeLib,
const WEEGChannelLabels& channelLabels );
/**
* Constructor creating a quite unusable instance. Useful for prototype mechanism.
*/
WEEG();
/**
* Access operator for single samples.
*/
......@@ -135,7 +140,34 @@ public:
*/
virtual bool isTexture() const;
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual std::string getName() const;
/**