Commit d29d5594 by schurade

[CHANGE] moved the fiber selector stuff to kernel to make it available for other modules

parent 2e5f226a
......@@ -24,7 +24,7 @@
#include <iostream>
#include "../../kernel/WKernel.h"
#include "../kernel/WKernel.h"
#include "WFiberSelector.h"
......
......@@ -28,7 +28,7 @@
#include <list>
#include <vector>
#include "../../dataHandler/WDataSetFibers.h"
#include "../dataHandler/WDataSetFibers.h"
#include "WSelectorRoi.h"
#include "WSelectorBranch.h"
......
......@@ -25,8 +25,8 @@
#include <algorithm>
#include <vector>
#include "../../common/WAssert.h"
#include "../../common/WLogger.h"
#include "../common/WAssert.h"
#include "../common/WLogger.h"
#include "WKdTree.h"
......
......@@ -28,7 +28,7 @@
#include <algorithm>
#include <vector>
#include "../../common/WThreadedRunner.h"
#include "../common/WThreadedRunner.h"
/**
* implements the compare function for std::nth_element on a point array
......
......@@ -29,7 +29,7 @@
#include <vector>
#include "WSelectorRoi.h"
#include "../../kernel/WRMBranch.h"
#include "../kernel/WRMBranch.h"
/**
* TODO(schurade): Document this!
......
......@@ -23,8 +23,8 @@
//---------------------------------------------------------------------------
//#include "../../../graphicsEngine/WGraphicsEngine.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../../graphicsEngine/WROIArbitrary.h"
#include "../graphicsEngine/WROIBox.h"
#include "../graphicsEngine/WROIArbitrary.h"
#include "WSelectorRoi.h"
......
......@@ -27,9 +27,9 @@
#include <vector>
#include "../../dataHandler/WDataSetFibers.h"
#include "../dataHandler/WDataSetFibers.h"
#include "../../graphicsEngine/WROI.h"
#include "../graphicsEngine/WROI.h"
#include "WKdTree.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 <iostream>
#include "../../graphicsEngine/WGEUtils.h"
#include "WDendrogram.h"
/**
* Class implements a dendrogram as an osg geode
*/
WDendrogram::WDendrogram( 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();
}
WDendrogram::~WDendrogram()
{
}
void WDendrogram::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 WDendrogram::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 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
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 WDENDROGRAM_H
#define WDENDROGRAM_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 WDendrogram : 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
*
*/
WDendrogram( 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
*/
~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:
/**
* 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 // WDENDROGRAM_H
......@@ -35,7 +35,7 @@
#include <osg/ShapeDrawable>
#include <osg/Group>
#include "WFiberSelector.h"
#include "../../kernel/WFiberSelector.h"
class WDataSetFibers;
......
......@@ -34,10 +34,10 @@
#include "../../graphicsEngine/WROIBox.h"
#include "../../graphicsEngine/WShader.h"
#include "../../kernel/WFiberSelector.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "WFiberSelector.h"
#include "WFiberDrawable.h"
/**
......
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