Commit 78f2ac41 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - fiber display simple is now able to take a WDataSetFiberClustering as...

[ADD] - fiber display simple is now able to take a WDataSetFiberClustering as input and show the fibs accordingly
parent 1e79341f
......@@ -44,6 +44,16 @@ class OWCOMMON_EXPORT WConditionSet: public WCondition
friend class WConditionSetTest;
public:
/**
* Shared pointer to instance of this class.
*/
typedef boost::shared_ptr< WConditionSet > SPtr;
/**
* Shared pointer to const instance of this class.
*/
typedef boost::shared_ptr< const WConditionSet > ConstSPtr;
/**
* Default constructor.
*/
......
//---------------------------------------------------------------------------
//
// 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 <string>
#include "WInvalidID.h"
WInvalidID::WInvalidID( const std::string& msg )
: WException( msg )
{
// init members
}
WInvalidID::~WInvalidID() throw()
{
// clean up
}
//---------------------------------------------------------------------------
//
// 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 WINVALIDID_H
#define WINVALIDID_H
#include <string>
#include "../WException.h"
#include "../WExportCommon.h"
/**
* Indicates invalid element access of a container.
*/
class OWCOMMON_EXPORT WInvalidID : public WException
{
public:
/**
* Default constructor.
* \param msg the exception message.
*/
explicit WInvalidID( const std::string& msg = "Invalid ID specified." );
/**
* Destructor.
*/
virtual ~WInvalidID() throw();
protected:
private:
};
#endif // WINVALIDID_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/>.
//
//---------------------------------------------------------------------------
#include "WDataSetFiberClustering.h"
// The prototype as singleton. Created during first getPrototype() call
boost::shared_ptr< WPrototyped > WDataSetFiberClustering::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetFiberClustering::WDataSetFiberClustering()
{
// initialize members
}
WDataSetFiberClustering::~WDataSetFiberClustering()
{
// cleanup
}
boost::shared_ptr< WPrototyped > WDataSetFiberClustering::getPrototype()
{
if( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetFiberClustering() );
}
return m_prototype;
}
const std::string WDataSetFiberClustering::getName() const
{
return "DataSetFiberClustering";
}
const std::string WDataSetFiberClustering::getDescription() const
{
return "A collection of fiber clusters.";
}
void WDataSetFiberClustering::setCluster( size_t id, WFiberCluster::SPtr cluster )
{
m_clusters[ id ] = cluster;
}
WFiberCluster::SPtr WDataSetFiberClustering::getCluster( size_t id )
{
WFiberCluster::SPtr result = m_clusters[ id ];
if( !result )
{
throw WInvalidID( "The cluster with the specified ID does not exist." );
}
return result;
}
WFiberCluster::SPtr WDataSetFiberClustering::getOrCreateCluster( size_t id )
{
WFiberCluster::SPtr result = m_clusters[ id ];
if( !result )
{
// create an empty one
WFiberCluster::SPtr newCluster( new WFiberCluster() );
m_clusters[ id ] = newCluster;
return newCluster;
}
return result;
}
void WDataSetFiberClustering::removeCluster( size_t id )
{
if( !m_clusters.count( id ) )
{
return;
}
m_clusters.erase( id );
}
WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::begin() const
{
return m_clusters.begin();
}
WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::begin()
{
return m_clusters.begin();
}
WDataSetFiberClustering::ClusterMap::const_iterator WDataSetFiberClustering::end() const
{
return m_clusters.end();
}
WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::end()
{
return m_clusters.end();
}
//---------------------------------------------------------------------------
//
// 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 WDATASETFIBERCLUSTERING_H
#define WDATASETFIBERCLUSTERING_H
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
#include "datastructures/WFiberCluster.h"
#include "../common/exceptions/WInvalidID.h"
#include "../common/WTransferable.h"
/**
* This is a dataset which represent a clustering of fibers. It does not itself contain the fiber-data. This dataset only contains the indices of
* fibers belonging to the clusters.
*
* Each cluster has its own ID. A mapping between names and IDs is possible.
*/
class WDataSetFiberClustering: public WTransferable
{
public:
/**
* Convenience typedef for a boost::shared_ptr< WDataSetFiberClustering >.
*/
typedef boost::shared_ptr< WDataSetFiberClustering > SPtr;
/**
* Convenience typedef for a boost::shared_ptr< const WDataSetFiberClustering >.
*/
typedef boost::shared_ptr< const WDataSetFiberClustering > ConstSPtr;
/**
* The type of the cluster map
*/
typedef std::map< size_t, WFiberCluster::SPtr > ClusterMap;
/**
* Default constructor.
*/
WDataSetFiberClustering();
/**
* Destructor.
*/
virtual ~WDataSetFiberClustering();
/**
* The name of this transferable. This is useful information for the users.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
*
* The description of this transferable. This is useful information for the users.
*
* \return A description
*/
virtual const 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();
/**
* Sets the cluster at the given ID. If there is a cluster at this ID, it is replaced.
*
* \param id the ID of the cluster
* \param cluster the cluster
*/
virtual void setCluster( size_t id, WFiberCluster::SPtr cluster );
/**
* Returns the cluster with the given ID.
*
* \throw WInvalidID if the ID is not known.
*
* \param id the ID of the cluster to get
*
* \return the cluster
*/
virtual WFiberCluster::SPtr getCluster( size_t id );
/**
* Returns the cluster with the given ID. If there is no cluster with this ID, an empty one is returned.
*
* \param id the ID of the cluster to get
*
* \return the cluster
*/
virtual WFiberCluster::SPtr getOrCreateCluster( size_t id );
/**
* Removes the cluster with the specified ID. If it does not exist, nothing happens.
*
* \param id the id of the cluster
*/
virtual void removeCluster( size_t id );
/**
* The begin iterator of the clustering for const iteration.
*
* \return the begin iterator
*/
ClusterMap::const_iterator begin() const;
/**
* The begin iterator of the clustering for non-const iteration.
*
* \return the begin iterator
*/
ClusterMap::iterator begin();
/**
* The end iterator of the clustering for const iteration.
*
* \return the begin iterator
*/
ClusterMap::const_iterator end() const;
/**
* The end iterator of the clustering for non-const iteration.
*
* \return the end iterator
*/
ClusterMap::iterator end();
protected:
/**
* Prototype for this dataset
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
/**
* The map between ID and cluster.
*/
std::map< size_t, WFiberCluster::SPtr > m_clusters;
};
#endif // WDATASETFIBERCLUSTERING_H
......@@ -24,6 +24,7 @@
#include <list>
#include <vector>
#include <algorithm>
#include <boost/shared_ptr.hpp>
......@@ -34,14 +35,8 @@
#include "../WDataSetFiberVector.h"
#include "WFiberCluster.h"
// TODO(math): The only reason why we store here a Reference to the fiber
// dataset is, we need it in the WMVoxelizer module as well as the clustering
// information. Since we don't have the possibility of multiple
// InputConnectors we must agglomerate those into one object. Please remove this.
// initializes the variable and provides a linker reference
// \cond Suppress_Doxygen
// The prototype as singleton. Created during first getPrototype() call
boost::shared_ptr< WPrototyped > WFiberCluster::m_prototype = boost::shared_ptr< WPrototyped >();
// \endcond
WFiberCluster::WFiberCluster()
: WTransferable(),
......@@ -58,6 +53,27 @@ WFiberCluster::WFiberCluster( size_t index )
m_memberIndices.push_back( index );
}
WFiberCluster::WFiberCluster( const WFiberCluster::IndexList& indices, const WColor& color )
: WTransferable(),
m_memberIndices( indices ),
m_color( color ),
m_centerLineCreationLock( new boost::shared_mutex() ),
m_longestLineCreationLock( new boost::shared_mutex() )
{
// init
}
WFiberCluster::WFiberCluster( WFiberCluster::IndexList::const_iterator indicesBegin,
WFiberCluster::IndexList::const_iterator indicesEnd, const WColor& color )
: WTransferable(),
m_color( color ),
m_centerLineCreationLock( new boost::shared_mutex() ),
m_longestLineCreationLock( new boost::shared_mutex() )
{
// now copy the index list
std::copy( indicesBegin, indicesEnd, m_memberIndices.begin() );
}
WFiberCluster::WFiberCluster( const WFiberCluster& other )
: WTransferable( other ),
m_memberIndices( other.m_memberIndices ),
......@@ -88,7 +104,7 @@ WFiberCluster::~WFiberCluster()
void WFiberCluster::merge( WFiberCluster& other ) // NOLINT
{
std::list< size_t >::const_iterator cit = other.m_memberIndices.begin();
WFiberCluster::IndexList::const_iterator cit = other.m_memberIndices.begin();
for( ; cit != other.m_memberIndices.end(); ++cit)
{
m_memberIndices.push_back( *cit );
......@@ -99,6 +115,13 @@ void WFiberCluster::merge( WFiberCluster& other ) // NOLINT
other.clear();
}
void WFiberCluster::merge( WFiberCluster::IndexList::const_iterator indicesBegin,
WFiberCluster::IndexList::const_iterator indicesEnd )
{
// now copy the index list
m_memberIndices.insert( m_memberIndices.end(), indicesBegin, indicesEnd );
}
// NODOXYGEN
// \cond Suppress_Doxygen
void WFiberCluster::setDataSetReference( boost::shared_ptr< const WDataSetFiberVector > fibs )
......@@ -110,11 +133,12 @@ boost::shared_ptr< const WDataSetFiberVector > WFiberCluster::getDataSetReferenc
{
return m_fibs;
}
// TODO(math): The only reason why we store here a Reference to the fiber
// dataset is, we need it in the WMVoxelizer module as well as the clustering
// information. Since we don't have the possibility of multiple
// InputConnectors we must agglomerate those into one object. Please remove this.
// \endcond
boost::shared_ptr< WPrototyped > WFiberCluster::getPrototype()
{
if( !m_prototype )
......@@ -123,7 +147,6 @@ boost::shared_ptr< WPrototyped > WFiberCluster::getPrototype()
}
return m_prototype;
}
// \endcond
void WFiberCluster::generateCenterLine() const
{
......@@ -139,7 +162,7 @@ void WFiberCluster::generateCenterLine() const
// make copies of the fibers
boost::shared_ptr< WDataSetFiberVector > fibs( new WDataSetFiberVector() );
size_t avgFiberSize = 0;
for( std::list< size_t >::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
for( WFiberCluster::IndexList::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
{
fibs->push_back( m_fibs->at( *cit ) );
avgFiberSize += fibs->back().size();
......@@ -219,7 +242,7 @@ void WFiberCluster::elongateCenterLine() const
// in the beginning all fibers participate
boost::shared_ptr< WDataSetFiberVector > fibs( new WDataSetFiberVector() );
for( std::list< size_t >::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
for( WFiberCluster::IndexList::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
{
fibs->push_back( m_fibs->at( *cit ) );
}
......@@ -268,7 +291,7 @@ void WFiberCluster::elongateCenterLine() const
}
// second ending of the centerline
boost::shared_ptr< WDataSetFiberVector > fobs( new WDataSetFiberVector() );
for( std::list< size_t >::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
for( WFiberCluster::IndexList::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
{
fobs->push_back( m_fibs->at( *cit ) );
}
......@@ -379,7 +402,7 @@ boost::shared_ptr< WFiber > WFiberCluster::getLongestLine() const
WBoundingBox WFiberCluster::getBoundingBox() const
{
WBoundingBox result;
for( std::list< size_t >::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
for( WFiberCluster::IndexList::const_iterator cit = m_memberIndices.begin(); cit != m_memberIndices.end(); ++cit )
{
result.expandBy( computeBoundingBox( m_fibs->at( *cit ) ) );
}
......
......@@ -40,10 +40,25 @@
/**
* Represents a cluster of indices of a WDataSetFiberVector.
*/
class OWDATAHANDLER_EXPORT WFiberCluster : public WTransferable // NOLINT
class OWDATAHANDLER_EXPORT WFiberCluster: public WTransferable // NOLINT
{
friend class WFiberClusterTest;
public:
/**
* Shared pointer abbreviation.
*/
typedef boost::shared_ptr< WFiberCluster > SPtr;
/**
* Const shared pointer abbreviation.
*/
typedef boost::shared_ptr< const WFiberCluster > ConstSPtr;
/**
* This is the list of indices of fibers.
*/
typedef std::list< size_t > IndexList;
/**
* Constructs an cluster with one fiber and a reference to the fiber dataset
* to compute the intercluster distance.
......@@ -52,6 +67,24 @@ public:
*/
explicit WFiberCluster( size_t index );
/**
* Constructs a cluster with the specified set of indices and the given color.
*
* \param indices the indices initially used for this clustering
* \param color the color of this cluster
*/
WFiberCluster( const IndexList& indices, const WColor& color = WColor() );
/**
* Constructs a clustering with the given set of indices. The indexlist is generated using the given iterators. It copies the elements in
* [indicesBegin,indicesEnd).
*
* \param indicesBegin begin iterator in the predefined index set
* \param indicesEnd end iterator in the predefined index set
* \param color the color of this cluster
*/
WFiberCluster( IndexList::const_iterator indicesBegin, IndexList::const_iterator indicesEnd, const WColor& color = WColor() );
/**
* Copies the specified \ref WFiberCluster Instance. The copy does not contain a valid centerline or longest line.
*
......@@ -84,19 +117,28 @@ public:
*/
void merge( WFiberCluster &other ); // NOLINT
/**
* Copy the elements denoted by the two iterators to this cluster. In contrast to the other merge() methods, this will not clean the source
* list.
*
* \param indicesBegin begin iterator in the predefined index set
* \param indicesEnd end iterator in the predefined index set
*/
void merge( IndexList::const_iterator indicesBegin, IndexList::const_iterator indicesEnd );
/**
* Returns a const reference of all indices inside this cluster
*
* \return the index list
*/
const std::list< size_t >& getIndices() const;
const IndexList& getIndices() const;
/**
* Reset the indices belonging to that cluster
*
* \param indices list of indices
*/
void setIndices( const std::list< size_t >& indices );
void setIndices( const IndexList& indices );
/**
* Sort the indices of fibers associated with this cluster in ascending
......@@ -132,18 +174,17 @@ public:
WColor getColor() const;