Commit 51975dcc authored by schurade's avatar schurade

[ADD] a right click in the dendrogram now selects the cluster at that position

parent 920e636d
......@@ -158,3 +158,61 @@ void WDendrogram::layout( size_t cluster, float left, float right )
}
}
}
size_t WDendrogram::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 WDendrogram::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
layout( 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 );
}
}
}
}
......@@ -59,6 +59,14 @@ public:
*/
~WDendrogram();
/**
* 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:
/**
......@@ -74,6 +82,14 @@ private:
*/
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
......@@ -93,6 +109,11 @@ private:
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 // WDENDROGRAM_H
......@@ -338,7 +338,7 @@ void WMClusterDisplay::properties()
m_propBoxClusterRatio->setMin( 0.0 );
m_propBoxClusterRatio->setMax( 1.0 );
m_propShowTree = m_properties->addProperty( "Show tree", "", true, m_propCondition );
m_propShowTree = m_properties->addProperty( "Show widget", "", false, m_propCondition );
m_propShowDendrogram = m_properties->addProperty( "Show dendrogram", "", true, m_propCondition );
m_propTreeFile = m_properties->addProperty( "Tree file", "", WPathHelper::getAppPath() );
......@@ -348,6 +348,9 @@ void WMClusterDisplay::properties()
void WMClusterDisplay::moduleMain()
{
boost::signals2::connection con = WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->getPickSignal()->
connect( boost::bind( &WMClusterDisplay::dendrogramClick, this, _1 ) );
m_moduleState.setResetable( true, true );
m_moduleState.add( m_propCondition );
m_moduleState.add( m_active->getUpdateCondition() );
......@@ -480,6 +483,7 @@ void WMClusterDisplay::moduleMain()
WKernel::getRunningKernel()->getRoiManager()->setUseExternalBitfield( m_active->get( true ) );
}
}
con.disconnect();
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
......@@ -494,7 +498,7 @@ void WMClusterDisplay::handleSelectedClusterChanged()
WKernel::getRunningKernel()->getRoiManager()->setExternalBitfield( m_tree.getOutputBitfield( m_rootCluster ) );
m_propSubLevelsToColor->setMax( m_tree.getLevel( m_rootCluster ) );
colorClusters( m_propSelectedCluster->get( true ) );
//colorClusters( m_propSelectedCluster->get( true ) );
m_dendrogramDirty = true;
}
......@@ -899,3 +903,15 @@ void WMClusterDisplay::setColor( std::vector<size_t> clusters, WColor color )
}
}
}
void WMClusterDisplay::dendrogramClick( WPickInfo pickInfo )
{
if ( !m_propShowDendrogram->get() || !( pickInfo.getName() == "nothing" ) )
{
return;
}
int x = pickInfo.getPickPixelPosition().first;
int y = pickInfo.getPickPixelPosition().second;
m_propSelectedCluster->set( m_dendrogramGeode->getClickedCluster( x, y ) );
}
......@@ -193,6 +193,11 @@ private:
*/
std::string createLabel( size_t id );
/**
* listenes to the pickhandler and determines if a click into the dendrogram happened
*/
void dendrogramClick( WPickInfo pickInfo );
/**
* Input connector for a fiber dataset.
*/
......
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