Commit beffb203 authored by jforberg's avatar jforberg
Browse files

[ADD] New datasets, reader and additional data structures for reading clusterings from fdg files.

parent a54c0610
......@@ -23,7 +23,7 @@
//---------------------------------------------------------------------------
#include <string>
#include <map>
#include "WDataSetFiberClustering.h"
// The prototype as singleton. Created during first getPrototype() call
......@@ -34,6 +34,12 @@ WDataSetFiberClustering::WDataSetFiberClustering()
// initialize members
}
WDataSetFiberClustering::WDataSetFiberClustering( const ClusterMap &clustering )
{
m_clusters = clustering;
}
WDataSetFiberClustering::~WDataSetFiberClustering()
{
// cleanup
......@@ -115,3 +121,9 @@ WDataSetFiberClustering::ClusterMap::iterator WDataSetFiberClustering::end()
return m_clusters.end();
}
size_t WDataSetFiberClustering::size() const
{
return m_clusters.size();
}
......@@ -64,6 +64,13 @@ public:
*/
WDataSetFiberClustering();
/**
* constructor with cluster list.
*
* \param clustering the cluster map defining the clustering
*/
explicit WDataSetFiberClustering( const ClusterMap &clustering );
/**
* Destructor.
*/
......@@ -154,6 +161,13 @@ public:
*/
ClusterMap::iterator end();
/**
* Returns the amount of clusters in the clustering
*
* \return the amount of clusters in the clustering
*/
size_t size() const;
protected:
/**
* Prototype for this dataset
......@@ -167,4 +181,3 @@ private:
};
#endif // WDATASETFIBERCLUSTERING_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 <map>
#include <string>
#include <vector>
#include "WDataSetHierarchicalClustering.h"
// The prototype as singleton. Created during first getPrototype() call
boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetHierarchicalClustering::WDataSetHierarchicalClustering()
{
// initialize members
}
WDataSetHierarchicalClustering::WDataSetHierarchicalClustering( WTreeNode::SPtr rootNode,
std::map< size_t, WFiberCluster::SPtr > allClusters )
{
m_rootNode = rootNode;
m_clusters = allClusters;
}
WDataSetHierarchicalClustering::~WDataSetHierarchicalClustering()
{
// cleanup
}
boost::shared_ptr< WPrototyped > WDataSetHierarchicalClustering::getPrototype()
{
if( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetHierarchicalClustering() );
}
return m_prototype;
}
const std::string WDataSetHierarchicalClustering::getName() const
{
return "DataSetHierarchicalClustering";
}
const std::string WDataSetHierarchicalClustering::getDescription() const
{
return "A tree of fiber clusters.";
}
WTreeNode::SPtr WDataSetHierarchicalClustering::getRootNode()
{
return m_rootNode;
}
std::map< size_t, WFiberCluster::SPtr > WDataSetHierarchicalClustering::getClusterMap()
{
return m_clusters;
}
std::vector< size_t > WDataSetHierarchicalClustering::getClustersDownToLevel( WTreeNode::SPtr node, size_t level )
{
std::vector< size_t > result;
if( node->level() <= level )
{
result.push_back( node->index() );
return result;
}
for( size_t i = 0; i < node->getChildren().size(); i++ )
{
std::vector< size_t > c = getClustersDownToLevel( node->getChildren()[i], level );
result.insert( result.end(), c.begin(), c.end() );
}
return result;
}
//---------------------------------------------------------------------------
//
// 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 WDATASETHIERARCHICALCLUSTERING_H_
#define WDATASETHIERARCHICALCLUSTERING_H_
#include <map>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../common/exceptions/WInvalidID.h"
#include "../common/WTransferable.h"
#include "datastructures/WFiberCluster.h"
#include "datastructures/WTreeNode.h"
#include "WDataSet.h"
/**
* Represents a hierarchy of clusters
*/
class WDataSetHierarchicalClustering : public WDataSet // NOLINT
{
public:
// some type alias for the used arrays.
/**
* Pointer to dataset.
*/
typedef boost::shared_ptr< WDataSetHierarchicalClustering > SPtr;
/**
* Pointer to const dataset.
*/
typedef boost::shared_ptr< const WDataSetHierarchicalClustering > ConstSPtr;
/**
* Constructs a hierarchical clustering dataset
*
* \param rootNode the root node of the WTreeNode-tree holding indices to the clusterMap
* \param clusterMap a map of fiber clusters accessible via index
*/
WDataSetHierarchicalClustering( WTreeNode::SPtr rootNode, std::map< size_t, WFiberCluster::SPtr > clusterMap );
/**
* Constructs a new set of tracts. The constructed instance is not usable but needed for prototype mechanism.
*/
WDataSetHierarchicalClustering();
/**
* Destructor.
*/
virtual ~WDataSetHierarchicalClustering();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the 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();
/**
* Returns the root cluster
*
* \return the root cluster
*/
WTreeNode::SPtr getRootNode();
/**
* Returns the whole cluster map
*
* \return the whole cluster map
*/
std::map< size_t, WFiberCluster::SPtr > getClusterMap();
/**
* Returns all clusters down (root node has highest level) to a certain level in the hierarchy
*
* \param node the node used as a starting point for the recursive lookup
* \param level the maximum level for a node to be selected
* \return the clusters down to a certain level in the hierarchy
*/
std::vector< size_t > getClustersDownToLevel( WTreeNode::SPtr node, size_t level );
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
/**
* Pointer to the root cluster
*/
WTreeNode::SPtr m_rootNode;
/**
* Stores the cluster map
*/
std::map< size_t, WFiberCluster::SPtr > m_clusters;
};
#endif // WDATASETHIERARCHICALCLUSTERING_H
......@@ -179,6 +179,20 @@ public:
*/
WColor getColor() const;
/**
* Sets the main direction of the cluster
*
* \param mainDirection the cluster's main direction
*/
void setMainDirection( osg::Vec3 mainDirection );
/**
* Gets the main direction of the cluster ( if set )
*
* \return the cluster's main direction
*/
osg::Vec3 getMainDirection() const;
/**
* The name of this transferable. This is useful information for the users.
*
......@@ -326,6 +340,11 @@ private:
*/
WColor m_color;
/**
* The cluster's main direction
*/
osg::Vec3 m_mainDirection;
/**
* Lock the modification in the m_centerLine mutable. The lock is stored as pointer to avoid copy construction problems.
*/
......@@ -381,6 +400,16 @@ inline WColor WFiberCluster::getColor() const
return m_color;
}
inline void WFiberCluster::setMainDirection( osg::Vec3 mainDirection )
{
m_mainDirection = mainDirection;
}
inline osg::Vec3 WFiberCluster::getMainDirection() const
{
return m_mainDirection;
}
inline const std::string WFiberCluster::getName() const
{
return "FiberCluster";
......
//---------------------------------------------------------------------------
//
// 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 <vector>
#include "../../common/WStringUtils.h"
#include "WTreeNode.h"
WTreeNode::WTreeNode( size_t index, size_t level )
{
m_index = index;
m_level = level;
}
WTreeNode::~WTreeNode()
{
}
size_t WTreeNode::level()
{
return m_level;
}
size_t WTreeNode::index()
{
return m_index;
}
void WTreeNode::addChild( WTreeNode::SPtr child )
{
m_children.push_back( child );
}
std::vector< WTreeNode::SPtr > WTreeNode::getChildren()
{
return m_children;
}
//---------------------------------------------------------------------------
//
// 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 WTREENODE_H
#define WTREENODE_H
#include <sstream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
/**
* A node in a tree, holding an index, a level in the tree and pointers to its child nodes
*/
class WTreeNode
{
public:
/**
* Shared pointer abbreviation.
*/
typedef boost::shared_ptr< WTreeNode > SPtr;
/**
* Constructs a new TreeNode.
*
* \param index the index of the new Node.
* \param level the level of the Node in the Tree
*/
WTreeNode( size_t index, size_t level );
/**
* Default destructor.
*/
~WTreeNode();
/**
* Adds a childnode to this node
*
* \param child the child node to add
*/
void addChild( WTreeNode::SPtr child );
/**
* Returns the index of the TreeNode
*
* \return the node's index
*/
size_t index();
/**
* Returns the level of the TreeNode. All level-0-nodes are leaves.
*
* \return the node's level
*/
size_t level();
/**
* Returns the child nodes of this node
*
* \return the child nodes of this node
*/
std::vector< WTreeNode::SPtr > getChildren();
private:
/**
* Stores the childnodes of this node
*/
std::vector< WTreeNode::SPtr > m_children;
/**
* Stores the level of this node
*/
size_t m_level;
/**
* Stores the index of this node
*/
size_t m_index;
};
#endif // WTREENODE_H
......@@ -51,6 +51,7 @@
#include "io/WReaderLibeep.h"
#include "io/WReaderVTK.h"
#include "io/WPagerEEGLibeep.h"
#include "io/WReaderClustering.h"
#include "WMData.h"
#include "WMData.xpm"
......@@ -290,6 +291,11 @@ void WMData::moduleMain()
WReaderFiberVTK fibReader( fileName );
m_dataSet = fibReader.read();
}
else if( suffix == ".fdg" )
{
WReaderClustering clusterReader( fileName );
m_dataSet = clusterReader.read();
}
else if( suffix == ".vtk" )
{
WReaderVTK vtkReader( fileName );
......
......@@ -213,4 +213,3 @@ private:
};
#endif // WMDATA_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 <cstdlib>
#include <fstream>
#include <list>
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/regex.hpp>
#include <boost/shared_ptr.hpp>
#include "core/common/WAssert.h"
#include "core/common/WIOTools.h"
#include "core/common/WLimits.h"
#include "core/common/WLogger.h"
#include "core/common/WStringUtils.h"
#include "core/dataHandler/datastructures/WFiberCluster.h"
#include "core/dataHandler/exceptions/WDHIOFailure.h"
#include "core/dataHandler/exceptions/WDHNoSuchFile.h"
#include "core/dataHandler/exceptions/WDHParseError.h"
#include "core/dataHandler/WDataSetHierarchicalClustering.h"
#include "WReaderClustering.h"
WReaderClustering::WReaderClustering( std::string fname )
: WReader( fname )
{
}
WReaderClustering::~WReaderClustering() throw()
{
}
boost::shared_ptr< WDataSetHierarchicalClustering > WReaderClustering::read()
{
//Read file to line list
boost::shared_ptr< std::ifstream > ifs( new std::ifstream() );
ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
if( !ifs || ifs->bad() )
{
throw WDHIOFailure( std::string( "internal error while opening file" ) );
}
std::vector< std::string > lines;
std::string line;
while( !ifs->eof() )