Commit 29efacae by schurade

[FIX] made the cluster display module working with the new roi structure

parent a73d8acb
......@@ -88,7 +88,7 @@ void WFiberDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
state.disableAllVertexArrays();
state.setVertexPointer( 3, GL_FLOAT , 0, &( *m_verts )[0] );
state.setColorPointer( 3 , GL_FLOAT , 0, &( *m_colors )[0] );
state.setNormalPointer( GL_FLOAT , 0, &( *m_tangents )[0] );
//state.setNormalPointer( GL_FLOAT , 0, &( *m_tangents )[0] );
for ( size_t i = 0; i < m_active->size(); ++i )
{
if ( (*m_active)[i] )
......
......@@ -61,6 +61,9 @@ void WRMBranch::propertyChanged()
void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
{
m_rois.push_back( roi );
boost::function< void() > changeRoiSignal = boost::bind( &WRMBranch::setDirty, this );
roi->addChangeNotifier( changeRoiSignal );
setDirty();
}
......
//---------------------------------------------------------------------------
//
// 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 "../../graphicsEngine/WGEUtils.h"
#include "WDendrogramGeode.h"
/**
* Class implements a dendrogram as an osg geode
*/
WDendrogramGeode::WDendrogramGeode( WHierarchicalTree* tree, size_t cluster, size_t minClusterSize,
float xSize, float ySize, float xOffset, float yOffset ) :
osg::Geode(),
m_tree( tree ),
m_rootCluster( cluster ),
m_minClusterSize( minClusterSize ),
m_xSize( xSize ),
m_ySize( ySize ),
m_xOff( xOffset ),
m_yOff( yOffset )
{
create();
}
WDendrogramGeode::~WDendrogramGeode()
{
}
void WDendrogramGeode::create()
{
m_colors = osg::ref_ptr<osg::Vec4Array>( new osg::Vec4Array );
m_vertexArray = new osg::Vec3Array;
m_lineArray = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
float xMax = static_cast<float>( m_tree->size( m_rootCluster ) - 1 );
float yMax = m_tree->getLevel( m_rootCluster );
m_xMult = m_xSize / xMax;
m_yMult = m_ySize / yMax;
layout( m_rootCluster, 0.0f, static_cast<float>( m_tree->size( m_rootCluster ) - 1 ) );
for ( size_t i = 0; i < m_vertexArray->size(); ++i )
{
(*m_vertexArray)[i].x() = (*m_vertexArray)[i].x() * m_xMult + m_xOff;
(*m_vertexArray)[i].y() = (*m_vertexArray)[i].y() * m_yMult + m_yOff;
}
osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
geometry->setVertexArray( m_vertexArray );
geometry->addPrimitiveSet( m_lineArray );
geometry->setColorArray( m_colors );
geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
osg::StateSet* state = geometry->getOrCreateStateSet();
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
addDrawable( geometry );
}
void WDendrogramGeode::layout( size_t cluster, float left, float right )
{
float height = m_tree->getLevel( cluster );
float size = right - left;
if ( m_tree->getLevel( cluster ) > 0 )
{
size_t leftCluster = m_tree->getChildren( cluster ).first;
size_t rightCluster = m_tree->getChildren( cluster ).second;
float leftHeight = m_tree->getLevel( leftCluster );
float leftSize = static_cast<float>( m_tree->size( leftCluster ) );
float rightHeight = m_tree->getLevel( rightCluster );
float rightSize = static_cast<float>( m_tree->size( rightCluster ) );
if ( ( leftSize >= m_minClusterSize ) && ( rightSize < m_minClusterSize ) )
//if ( rightSize < 2 )
{
// left cluster is much bigger, draw only left
m_vertexArray->push_back( osg::Vec3( ( left + size / 2.0 ), height, 0 ) );
m_vertexArray->push_back( osg::Vec3( ( left + size / 2.0 ), leftHeight, 0 ) );
m_lineArray->push_back( m_vertexArray->size() - 2 );
m_lineArray->push_back( m_vertexArray->size() - 1 );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
layout( leftCluster, left, right );
}
else if ( ( rightSize >= m_minClusterSize ) && ( leftSize < m_minClusterSize ) )
//else if ( leftSize < 2 )
{
// right cluster is much bigger, draw only right
m_vertexArray->push_back( osg::Vec3( ( left + size / 2.0 ), height, 0 ) );
m_vertexArray->push_back( osg::Vec3( ( left + size / 2.0 ), rightHeight, 0 ) );
m_lineArray->push_back( m_vertexArray->size() - 2 );
m_lineArray->push_back( m_vertexArray->size() - 1 );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
layout( rightCluster, left, right );
}
else
{
float mult = size / ( leftSize + rightSize );
m_vertexArray->push_back( osg::Vec3( ( left + leftSize * mult / 2.0 ), height, 0 ) );
m_vertexArray->push_back( osg::Vec3( ( right - rightSize * mult / 2.0 ), height, 0 ) );
m_lineArray->push_back( m_vertexArray->size() - 2 );
m_lineArray->push_back( m_vertexArray->size() - 1 );
m_vertexArray->push_back( osg::Vec3( ( left + leftSize * mult / 2.0 ), leftHeight, 0 ) );
m_vertexArray->push_back( osg::Vec3( ( right - rightSize * mult / 2.0 ), rightHeight, 0 ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_colors->push_back( wge::osgColor( m_tree->getColor( cluster ) ) );
m_lineArray->push_back( m_vertexArray->size() - 4 );
m_lineArray->push_back( m_vertexArray->size() - 2 );
m_lineArray->push_back( m_vertexArray->size() - 3 );
m_lineArray->push_back( m_vertexArray->size() - 1 );
layout( leftCluster, left, left + leftSize * mult );
layout( rightCluster, right - rightSize * mult, right );
}
}
}
size_t WDendrogramGeode::getClickedCluster( int xClick, int yClick )
{
m_xClicked = ( xClick - m_xOff ) / m_xSize * ( m_tree->size( m_rootCluster ) - 1 );
m_yClicked = ( yClick - m_yOff ) / m_ySize * ( m_tree->getLevel( m_rootCluster ) - 1 );
getClickClusterRecursive( m_rootCluster, 0.0f, static_cast<float>( m_tree->size( m_rootCluster ) - 1 ) );
//std::cout << xClick << "," << yClick << " : " << m_xClicked << "," << m_yClicked << std::endl;
return m_clickedCluster;
}
void WDendrogramGeode::getClickClusterRecursive( size_t cluster, float left, float right )
{
int height = m_tree->getLevel( cluster );
if ( height == m_yClicked )
{
m_clickedCluster = cluster;
return;
}
int size = right - left;
if ( m_tree->getLevel( cluster ) > 0 )
{
size_t leftCluster = m_tree->getChildren( cluster ).first;
size_t rightCluster = m_tree->getChildren( cluster ).second;
float leftSize = static_cast<float>( m_tree->size( leftCluster ) );
float rightSize = static_cast<float>( m_tree->size( rightCluster ) );
if ( ( leftSize >= m_minClusterSize ) && ( rightSize < m_minClusterSize ) )
{
// left cluster is much bigger, draw only left
getClickClusterRecursive( leftCluster, left, right );
}
else if ( ( rightSize >= m_minClusterSize ) && ( leftSize < m_minClusterSize ) )
{
// right cluster is much bigger, draw only right
getClickClusterRecursive( rightCluster, left, right );
}
else
{
float mult = size / ( leftSize + rightSize );
if ( m_xClicked < left + leftSize * mult )
{
getClickClusterRecursive( leftCluster, left, left + leftSize * mult );
}
else
{
getClickClusterRecursive( rightCluster, right - rightSize * mult, right );
}
}
}
}
//---------------------------------------------------------------------------
//
// 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 WDENDROGRAMGEODE_H
#define WDENDROGRAMGEODE_H
#include <osg/Geode>
#include <osg/Vec3>
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include "WHierarchicalTree.h"
/**
* Class creates a dendrogram from a hierarchical clustering
*/
class WDendrogramGeode : public osg::Geode
{
public:
/**
* constructor
*
* \param tree reference to the tree object to work on
* \param cluster root cluster for the dendrogram
* \param minClusterSize minimum for cluster to be drawn, when i the whole tree is drawn
* \param xSize number of pixel to scale the tree on along the x axis
* \param ySize number of pixel to scale the tree on along the y axis
* \param xOffset translation alogn the x axis
* \param yOffset translation alogn the y axis
*
*/
WDendrogramGeode( WHierarchicalTree* tree, size_t cluster, size_t minClusterSize = 1, float xSize = 1000.f,
float ySize = 500.f, float xOffset = 0.0f, float yOffset = 0.0f );
/**
* destructor
*/
~WDendrogramGeode();
/**
* calculate which cluster was clicked from given pixel coordinates
* \param xClick the x coordinate
* \param yClick the y coordinate
* \return the cluster id, will return the root cluster if no cluster can be determinded
*/
size_t getClickedCluster( int xClick, int yClick );
protected:
private:
/**
* helper function the starts the layout process from the input data in the constructor
*/
void create();
/**
* recursive funtion that lays out the tree from top to bottom
* \param cluster the current cluster to work on
* \param left left border of the current subcluster
* \param right right border of the current subcluster
*/
void layout( size_t cluster, float left, float right );
/**
* recurse function that follows the layout to determine the cluster from pixel coordinates
*
* \param cluster cluster to check against coordinates
* \param left left boundary of cluster
* \param right right boundary of cluster
*/
void getClickClusterRecursive( size_t cluster, float left, float right );
WHierarchicalTree* m_tree; //!< the tree to work on
size_t m_rootCluster; //!< top cluster to draw the tree from
osg::ref_ptr<osg::Vec4Array> m_colors; //!< color array
osg::Vec3Array* m_vertexArray; //!< vertex array
osg::DrawElementsUInt* m_lineArray; //!< line array
size_t m_minClusterSize; //!< minimum cluster size to be considered while laying out the dendrogram
float m_xSize; //!< x size in pixel of the final dendrogram
float m_ySize; //!< y size in pixel of the final dendrogram
float m_xOff; //!< x offset
float m_yOff; //!< y offset
float m_xMult; //!< helper variable for the recursive function
float m_yMult; //!< helper variable for the recursive function
int m_xClicked; //!< stores the click position for use int he recursive function
int m_yClicked; //!< stores the click position for use int he recursive function
size_t m_clickedCluster; //!< the clicked cluster
};
#endif // WDENDROGRAMGEODE_H
......@@ -87,7 +87,7 @@ void WHierarchicalTree::addCluster( size_t cluster1, size_t cluster2, size_t lev
++m_clusterCount;
}
boost::shared_ptr< std::vector<bool> >WHierarchicalTree::getOutputBitfield( size_t cluster )
boost::shared_ptr< std::vector<bool> > WHierarchicalTree::getOutputBitfield( size_t cluster )
{
boost::shared_ptr< std::vector< bool > > bf;
// only a single fiber selected
......@@ -311,7 +311,6 @@ std::vector<size_t> WHierarchicalTree::getBestClustersFittingRoi( float ratio, s
float WHierarchicalTree::getRatio( size_t cluster )
{
boost::shared_ptr< std::vector< bool > > roiSelection = WKernel::getRunningKernel()->getRoiManager()->getRoiBitfield();
std::vector<size_t>fibersInCluster = getLeafesForCluster( cluster );
size_t countFibersInCluster = fibersInCluster.size();
......@@ -319,7 +318,7 @@ float WHierarchicalTree::getRatio( size_t cluster )
for ( size_t i = 0; i < countFibersInCluster; ++i )
{
if ( ( *roiSelection )[fibersInCluster[i]] )
if ( ( *m_roiSelection )[fibersInCluster[i]] )
{
++fibersFromClusterActive;
}
......
......@@ -187,6 +187,12 @@ public:
*/
size_t size( size_t cluster );
/**
* setter
* \param bitfield
*/
void setRoiBitField( boost::shared_ptr< std::vector<bool> > bitfield );
protected:
private:
/**
......@@ -247,6 +253,11 @@ private:
* a color value for each cluster
*/
std::vector<WColor>m_colors;
/**
* stores a pointer to the bitfield by the current roi setting
*/
boost::shared_ptr< std::vector<bool> > m_roiSelection;
};
inline size_t WHierarchicalTree::getLeafCount()
......@@ -320,5 +331,9 @@ inline WColor WHierarchicalTree::getColor( size_t cluster )
return m_colors[cluster];
}
inline void WHierarchicalTree::setRoiBitField( boost::shared_ptr< std::vector<bool> > bitfield )
{
m_roiSelection = bitfield;
}
#endif // WHIERARCHICALTREE_H
......@@ -37,7 +37,9 @@
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
#include "WDendrogram.h"
#include "../../kernel/WFiberSelector.h"
#include "WDendrogramGeode.h"
#include "WOSGButton.h"
#include "WHierarchicalTree.h"
......@@ -205,6 +207,11 @@ private:
void dendrogramClick( WPickInfo pickInfo );
/**
* helper function to initialize a fiber display node
*/
void createFiberGeode();
/**
* Input connector for a fiber dataset.
*/
boost::shared_ptr< WModuleInputData< const WDataSetFibers > > m_fiberInput;
......@@ -287,6 +294,16 @@ private:
WHierarchicalTree m_tree;
/**
* Point to a fiber selector, which is an adapater between the roi manager and the this module
*/
boost::shared_ptr< WFiberSelector>m_fiberSelector;
/**
* stores pointer to the fiber drawer
*/
osg::ref_ptr< WFiberDrawable > m_fiberDrawable;
/**
* The root node used for this modules graphics.
*/
osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
......@@ -305,7 +322,7 @@ private:
osg::Camera* m_camera; //!< stores the camera object
WDendrogram* m_dendrogramGeode; //!< stores the dendrogram geode
WDendrogramGeode* m_dendrogramGeode; //!< stores the dendrogram geode
osgWidget::WindowManager* m_wm; //!< stores a pointer to the window manager used for osg wdgets and overlay stuff
......
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